Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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(OrderAmountClose[0]);

       
    EnterShortStopMarket(qtyopeningRangeLow TickSize, @"short");
       
    EnterLongStopMarket(qty,openingRangeHigh TickSize, @"buy");

    }&
    #8203; 
    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
    Brandon H.NinjaTrader Customer Service

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

        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 Segwin, 05-07-2018, 02:15 PM
          14 responses
          1,789 views
          0 likes
          Last Post aligator  
          Started by Jimmyk, 01-26-2018, 05:19 AM
          6 responses
          837 views
          0 likes
          Last Post emuns
          by emuns
           
          Started by jxs_xrj, 01-12-2020, 09:49 AM
          6 responses
          3,293 views
          1 like
          Last Post jgualdronc  
          Started by Touch-Ups, Today, 10:36 AM
          0 responses
          13 views
          0 likes
          Last Post Touch-Ups  
          Started by geddyisodin, 04-25-2024, 05:20 AM
          11 responses
          63 views
          0 likes
          Last Post halgo_boulder  
          Working...
          X