Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Opening Range Breakout doesn't trigger at the right price

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

    Opening Range Breakout doesn't trigger at the right price

    Hi!

    I'm trying to build an opening range breakout strategy.
    My strategy orders a short position when the current price is lower than the currentDayOpen - (previous day true range) * 0.5.
    However, as you can see in the picture below, the order is in the next day instead of triggering at the right price (pointed by the arrow)

    I use 1 second data series as a secondary data.
    Code:
                    currentOpen = CurrentDayOHL().CurrentOpen[0];
                    priorClose = PriorDayOHLC().PriorClose[0];
                    if (Position.MarketPosition == MarketPosition.Flat)
                    {
                        if (condition && (Close[0] > currentOpen + trueRange1 * 0.5) && priorClose > fiftyDaysAgoClose)
                        {
                            EnterLong(1, 1, "MyEntryLong");
                        }
                        else if (condition && (Close[0] < currentOpen - trueRange1 * 0.5))
                        {
                            Print("Time: " + Time[0] + " Current: " + Close[0]+ " Open: " + Opens[0][0] + " trigger: " + (currentOpen - trueRange1 * 0.5));
                            EnterShort(1, 1, "MyEntryShort");
                        }
                    }​
    The code works sometimes, which is very odd. Some orders are done at the close of the day.
    Click image for larger version  Name:	image.png Views:	0 Size:	112.7 KB ID:	1336364
    Attached Files
    Last edited by muaythai; 03-01-2025, 09:03 PM.

    #2
    What are you using to calculate with? OnBarClose? OnPriceChange? I can't see any dates or time on the picture so I can't tell if it's working as it's supposed to or not.
    You are saying your code is not working all the time, so you need to be printing out things to get more information. I would start with printing your condition, Close[0], currentOpen, truerange1, priorClose and fiftyDaysAgo before that second if statement so you can check that all of those things are giving the values you are expecting.

    Comment


      #3

      Hi rockmanx00!

      Thank you for responding. I use OnPriceChange. The problems were PriorDayOHL() was getting the close value from 2 days ago, and trueRange1 was getting the range value from 2 days ago.
      This is what I changed

      Old:
      priorClose = PriorDayOHLC().PriorClose[0];
      trueRange1 = High[1] - Low[1];

      New:
      priorClose = Closes[0][0];
      trueRange1 = High[0] - Low[0];



      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      77 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X