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 NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      87 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      151 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      80 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      53 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      62 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X