• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
    Patrick H.NinjaTrader Customer Service

    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.
            Patrick H.NinjaTrader Customer Service

            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.
                Patrick H.NinjaTrader Customer Service

                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.
                    Patrick H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bztynbzp, Yesterday, 11:17 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post bztynbzp  
                    Started by Dan_D_Trader, Yesterday, 03:49 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post Dan_D_Trader  
                    Started by JohnAymin, Yesterday, 02:38 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_Tyler  
                    Started by Rmos22, Yesterday, 02:20 PM
                    2 responses
                    23 views
                    0 likes
                    Last Post Rmos22
                    by Rmos22
                     
                    Started by sawtooth500, Yesterday, 12:59 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_Spencer  
                    Working...
                    X