Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Max Number of Trade Per Day

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Max Number of Trade Per Day

    I'm running a strategy on 100 stock symbols. Is there a way I can limit the number of trades per day ? I don't want the strategy to make more than 10 transactions per day. Thanks.

    Andy

    #2
    Hello Andy,

    Thank you for your post.

    You can create a int to track the number of entries per day. For example:
    Code:
            #region Variables
            private int previousTrades = 0;
            #endregion
    
    		protected override void OnBarUpdate()
    		{
    			if(Bars.FirstBarOfSession)
    			{
    				previousTrades = Performance.AllTrades.Count;
    			}
    			
    			if(Performance.AllTrades.Count - previousTrades == 10)
    				return;
    Using the count of the trades you can check to make sure only 10 trades are made each day. For information on Performance.AllTrades.Count please visit the following link: http://www.ninjatrader.com/support/h...nt7/count2.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      Will this work if I'm running the strategy against 100 different stock symbols ? Does the Performance.AllTrades.Count get updated for any trade in the list of 100 stocks ? I tried this previously in backtesting and it didn't seem to work. Thanks.

      Andy

      Comment


        #4
        Originally posted by mechinvestor View Post
        Will this work if I'm running the strategy against 100 different stock symbols ? Does the Performance.AllTrades.Count get updated for any trade in the list of 100 stocks ? I tried this previously in backtesting and it didn't seem to work. Thanks.

        Andy
        I'm not even about to attempt that...but did you try...

        "private int previousTrades = 0;"

        with

        "private static int previousTrades = 0;"

        Comment


          #5
          Log("Time = " + Time[0] + ", Performance.AllTrades.Count = " + Performance.AllTrades.Count, NinjaTrader.Cbi.LogLevel.Information);

          It's always returning 0 during a backtest. Maybe this variable is only updated during live execution ?

          Andy

          Comment


            #6
            Hello mechinvestor,

            Thank you for your response.

            Performance.AllTrades.Count will pull all trades historical or and real-time, so this will work in backtesting. You can pull only real time trades with Performance.RealtimeTrades.Count.

            Are all 100 stocks added into the one strategy's code? Or is this a basket test of 100 instruments? If it is a basket test then Performance.AllTrades.Count will not pull each instrument, but will pull all trades for the instance of the strategy running or instrument in the basket test.

            Does the value return as zero even after trades are placed? Is the backtest done on Daily data (Day, Week, Month or Year intervals)?

            I look forward to assisting you further.

            Comment


              #7
              Hi everyone!
              Look at my code, please. I run it on demo account (not strategy analyser, only realtime) but Performance.AllTrades.Count always returns zero.

              My sample code is in attachment.
              Attached Files
              Handlar
              NinjaTrader Ecosystem Vendor - Handlar

              Comment


                #8
                Hello handlar,

                Thank you for your post.

                SystemPerformance will be pulled for the strategy instance itself. This means it will not have information if the strategy, like yours, is not placing trades. Please visit the following link for more information: https://ninjatrader.com/support/help...erformance.htm

                There is not a supported means to pull Account Performance in NinjaScript.

                Please let me know if you have any questions.

                Comment


                  #9
                  Thank you for answer! If I get you right, my strategy can have access only for information about trades from my strategy? It will return zero before the first trade will be done from my strategy?
                  Handlar
                  NinjaTrader Ecosystem Vendor - Handlar

                  Comment


                    #10
                    Hello handlar,

                    Thank you for your response.

                    The Performance.AllTrades will pull all trades the strategy calculates historically and in realtime.

                    You can also pull just Long, Short, or Realtime Trades as well. Please see the following link for more information: https://ninjatrader.com/support/help...erformance.htm

                    Please let me know if you have any questions.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by WeyldFalcon, 08-07-2020, 06:13 AM
                    11 responses
                    1,422 views
                    0 likes
                    Last Post jculp
                    by jculp
                     
                    Started by RubenCazorla, Today, 09:07 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post RubenCazorla  
                    Started by BarzTrading, Today, 07:25 AM
                    2 responses
                    29 views
                    1 like
                    Last Post BarzTrading  
                    Started by devatechnologies, 04-14-2024, 02:58 PM
                    3 responses
                    21 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by tkaboris, Today, 08:01 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post tkaboris  
                    Working...
                    X