• 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

Bars required to trade

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

    Bars required to trade

    In a Strategy what is bars required to trade? Does it mean it will wait for those many bars to form from the time it is started? Or will it just look back to make sure there are those many bars on the chart already? I want to be able to turn it on and be able to take a trade on the same or very next bar. Because I have seen it skip any setups as soon as it is started even though the setup existed.
    Thank you.

    #2
    Hello Trader17,

    Thanks for your post.

    Our help guide page on BarsRequiredToTrade gives the following definition:
    The number of historical bars required before the strategy starts processing order methods called in the OnBarUpdate() method. This property is generally set via the UI when starting a strategy.
    BarsRequiredToTrade - https://ninjatrader.com/support/help...redtotrade.htm

    If you would like to have the strategy submit historical orders with the first bar of historical data available, you can set this to 0.

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      So does it mean it will wait for 20 new bars to form before it takes a setup in real time after being turned on?
      Thank you.

      Comment


        #4
        Hello Trader17,

        No, the strategy will wait until 20 bars have been processed beginning with the first historical bar before it can submit orders. If you started the strategy with less than 20 historical bars, then you would need to wait for that many bars to be processed with realtime data before your order methods can fire.

        Please let us know if you have any questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          That is what I am confused about. When you say historical does that mean from the time I start the strategy it will wait for 20 bars to finish before firing any orders or say if there are a 1000 bars on the chart already when I start the strategy then the condition is already fulfilled? I hope I am not confusing you.

          Comment


            #6
            Hello Trader17,

            Historical data is data that exists on your PC that has been loaded onto a chart, or loaded with the data series that the strategy is applied to.

            Realtime data is data that gets streamed in from your data provider or when using the Playback Connection.

            When a strategy is enabled, it processes the historical data loaded with that data series to determine the trades that would have been made from that data. This determines the strategy's virtual position. The Start Behavior determines how the strategy should start trading live depending on this virtual position. You can read more about Start Behaviors at the link below.

            Syncing Account Positions - https://ninjatrader.com/support/help..._positions.htm

            Strategy vs. Account Position - https://ninjatrader.com/support/help..._account_p.htm

            Any order methods that are reached before the strategy processes enough bars to satisfy BarsRequiredToTrade will be ignored.

            I suggest adding some prints to a simple strategy so you can better visualize this behavior. For example:

            Code:
            protected override void OnBarUpdate()
            {
                if(Position.MarketPosition == MarketPosition.Flat)
                    EnterLong();
                else
                    ExitLong();
                Print(String.Format("CurrentBar: {0} BarsRequiredToTrade: {1} State: {2}", CurrentBar, BarsRequiredToTrade, State));
            }
            
            protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity,
                Cbi.MarketPosition marketPosition, string orderId, DateTime time)
            {
                Print("Order Executed");
            }
            Please let us know if you have any additional questions.
            JimNinjaTrader Customer Service

            Comment


              #7
              Thank you. I do have enough bars on the chart. What I do not understand is that as soon a strategy is turned on a chart it does not take the trade immediately on the next bar or two even though a signal was generated. I like to enable a strategy when I see a possible situation that I might want to get in real quick. That is why I am not sure why it does not take the very next trade as soon as started.
              Thank you.

              Comment


                #8
                Hello Trader17,

                Have you confirmed by setting up debugging prints that the order method was reached? If a print by the order method is not reached, then I suggest adding debugging prints for the expressions used to evaluate your conditions outside of the conditions so you can better determine why that logic was not becoming true.

                Have you also enabled TraceOrders to better determine what is happening with order submissions?

                Is the strategy in a virtual position from processing historical data and your Start Behavior is preventing the strategy from making a trade with realtime data? This would be the case for Wait Until Flat. I would recommend reviewing the Syncing Account Positions documentation in my previous message for more details on how start behaviors work to better understand this. You could add a print for Position.MarketPosition when State == State.Realtime to confirm this. You can also check the Strategies tab of the Control Center. If the strategy is green, it is allowed to trade live. If it is yellow/orange, it is in a virtual position and WaitUntilFlat is having the strategy wait until it reaches a flat position before it can submit live trades.

                Debugging tips - https://ninjatrader.com/support/help...script_cod.htm

                TraceOrders - https://ninjatrader.com/support/help...aceorders2.htm

                Please let us know if you have any questions on the debug output you are receiving.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  I changed ti immediate and sync account and am seeing it take trades right away now. It was not doing so when I had chosen Wait Until Flat. Am still playing around and learning the software. Thanks for all the support! it means so much.
                  Thank you.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by stenberg98, Today, 04:53 AM
                  2 responses
                  4 views
                  0 likes
                  Last Post NinjaTrader_Marco  
                  Started by wukefuha, Today, 03:20 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Marco  
                  Started by mbcmbc, Yesterday, 10:12 PM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_ChrisSch  
                  Started by fx.practic, Today, 03:44 AM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_Marco  
                  Started by pjsmith, Today, 03:28 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post pjsmith
                  by pjsmith
                   
                  Working...
                  X