Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Opening Range Breakout

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

    Opening Range Breakout

    I am currently working on a simple opening range breakout strategy but am struggling to figure out to make my strategy enter exactly at 1 tick above/below the range, whenever the range may be broken.

    For example. I am testing on the 15min chart and I check IsFirstBarOfSession and mark my openingRangeHigh/Low then place StopMarket orders in each direction at the high/low +- TickSize. However I believe this will only result in 1 side of the order. The scenario I am trying to achieve is the following.

    First 15min candle closes with a high of 101.99 and a low of 101.01. I would like to enter a long position whenever we hit 102.00 or a short position if we high 101.00. I can use If I am using CrossAbove/CrossBelow with a minute chart and load the 15min bars as well but do not like this hacky approach and would not give accurate backtesting results.

    I also understand that some candles will cross both the high & low of my range and at that point some assumptions have to be made about how the candle formed, however I am not finding any documentation on how to achieve my desired result.

    PHP Code:
    if (Bars.IsFirstBarOfSession)
    {
       openingRangeHigh = High[0];
       openingRangeLow = Low[0];
       var qty = StrategyHelpers.GetOrderSizeByAmount(OrderAmount, Close[0]);
    
       EnterShortStopMarket(qty, openingRangeLow - TickSize, @"short");
       EnterLongStopMarket(qty,openingRangeHigh + TickSize, @"buy");
    
    }​ 
    
    Thank you in advance for the support.
    Last edited by proptradingshop; 03-10-2024, 05:42 PM. Reason: fomatting

    #2
    Hello proptradingshop,

    Thanks for your post.

    It would not be possible to place an enter short stop market order and an enter long stop market order on the chart at the same time using the Managed Approach as this would violate the Managed Approach Internal Order Handling Rules.

    Managed Approach Internal Order Handling Rules: https://ninjatrader.com/support/help...d_approach.htm

    You could consider creating an if-elseif statement that checks if the Close price is greater than openingRangeHigh the call EnterLongStopMarket() else if the Close price is less than openingRangeLow then call EnterShortStopMarket().

    If you want to place an enter long stop order and an enter short stop order simultaneously, you would need to use the Unmanaged Approach.

    Please see the UnmanagedOCOBracketExample strategy on this forum thread demonstrating how this would be accomplished: https://forum.ninjatrader.com/forum/...579#post770579
    <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


      #3
      NinjaTrader_BrandonH thank you for the response...

      The problem with the if else statement is it will not give accurate real time performance vs backtest results. For example TradingView allows you to calculate backtests on each tick and will use a bar magnifier along with certain assumptions..please reference these links.




      I am not too concerned with placing multiple orders more so than achieving my desired result of being able to accurately backtest a fairly simple strategy.
      Can you please advise on how to achieve accurate backtests for the ORB strategy?

      Thank you for the support.

      Comment


        #4
        Hello proptradingshop,

        Thanks for your notes.

        Please review the help guide document on the differences on real-time vs backtest (historical).


        ​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.

        Below is a link to the help guide on Calculate.


        To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar.

        Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.

        High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

        Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

        SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/help...ipt_strate.htm

        TickReplay — https://ninjatrader.com/support/help...ick_replay.htm

        Developing for Tick Replay - https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm

        Additional information may be found in this NinjaTrader Forum post - https://ninjatrader.com/support/foru...mance?t=102504

        Please let us know if we may be of further assistance to you.
        <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


          #5
          Thank you NinjaTrader_BrandonH for the helpful links and support. It will take me some time to go through this and adjust my code.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          54 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          71 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X