Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trades not executing when conditions are met

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

    #16
    Hello jaboo,

    Thank you for your note.

    Does your strategy contain an added data series?

    To understand which bar is being referred to when your strategy places an order, you should print the bar index that the order is occurring on. In your strategy, add a print after you call your entry order that prints the bar index for when the order was placed. The print would look something like below. Also, ensure that the Data Box shows the bar index by right-clicking in the Data Box window and checking 'Show Bar Indexes'.

    Print("Bar # " + CurrentBar);

    After adding this print to your strategy, do you see the bar index print match with the Bar Index number in the Data Box window when your order is submitted? Does the High price for that bar index match your print for the High value? Does the Time of that bar index match with your print for the Time value?

    I look forward to assisting further.



    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #17
      Thanks Brandon. I think this will help demonstrate.

      on bar 4160 I submit a buystop with a Limit price of 3858.50.

      Code:
       Print(string.Format("{0} | Test Trade | Signal Bar Time - {1} | Signal Bar high {2} | Chart High {3}", Time[0], CurrentBearLeg.signalBar.barData.time, CurrentBearLeg.signalBar.barData.high, High[0]));
      EnterLongStopLimit(0, true, 1, High[index] + .25, High[index] + 1, "Test Trade - Long");
      Print("Current Bar: " + CurrentBar);
      barNumberOfOrder = CurrentBar;

      Click image for larger version  Name:	2021-03-17 08_46_10-Window.png Views:	0 Size:	71.1 KB ID:	1146979

      Here is the print statement
      Click image for larger version  Name:	2021-03-17 08_44_07-Window.png Views:	0 Size:	22.9 KB ID:	1146981
      it "says" that it entered the trade on the next bar at 9:41:57. However if this were the case it would have reached its profit target at 3859.50. Also, the bar that has the trade label is on the bar AFTER 9:41:57.
      Attached Files
      Last edited by jaboo; 03-17-2021, 11:47 AM.

      Comment


        #18
        Hello jaboo,

        Thank you for that information.

        I see from your screenshot that you are using a 2000 Tick chart and are backtesting your strategy in the Strategy Analyzer.
        • Are you running your strategy OnBarClose, OnPriceChange, or OnEachTick?
        • Do you have Tick Replay enabled?
        • Are you using intrabar granularity for order submissions?
        Please review the help guide document on the differences on real-time vs backtest (historical).
        http://ninjatrader.com/support/helpG...ime_vs_bac.htm

        When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.

        Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.

        Intra-bar granularity adds a second data series such as a 1 tick series using AddDataSeries() so that the strategy or indicator has the individual ticks in the historical data in between the High and Low of the primary series. This allows for more accurate trades by supplying the correct price at the correct time for the order to fill with. The orders placed will need to use the BarsInProgress (BarsArray) index of that finer resolution series.

        Below is a link to an official reference sample that demonstrates how to add intra-bar granularity.
        'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/help...ipt_strate.htm

        Please also see this forum post for more information about backtesting with intrabar granularity, Tick Replay, and Order Fill Resolution.


        Let us know if we may assist further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        63 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        139 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X