Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Opening Range Filter

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

    Opening Range Filter

    Hi,

    I'm having trouble adding an opening range filter to my strategy. I want my breakout strategy to fire if the current breakout candle is higher than the 15 min opening range on the long side and below the 15 min opening range on the short side. What's a simple way of introducing that?

    Thank you.

    #2
    Hello snoinvest,

    You want a condition where the current close price is greater than the high of all bars in the first 15 minutes after a session open, is this correct?

    Assuming the chart is a 1 minute chart.

    In OnBarUpdate():
    int lastBarOfOpening15Min = Bars.GetBar(Time[Bars.BarsSinceNewTradingDay].AddMinutes(15));

    if (Close[0] > High[HighestBarAgoInRange(High, ((CurrentBar - lastBarOfOpening15Min - Bars.BarsSinceNewTradingDay) * -1), lastBarOfOpening15Min)])
    {
    }

    Within the scope of the class:
    // must be called from a data driven method or used with TriggerCustomEvent
    private int HighestBarAgoInRange(ISeries<double> inputSeries, int period, int barsAgo)
    {
    int startBarsAgo = ((period + barsAgo - 1) < CurrentBar) ? (period + barsAgo - 1) : CurrentBar;
    int returnVal = startBarsAgo;

    //for (int index = CurrentBar - barsAgo; index < CurrentBar - period - barsAgo; ++index)
    for (int index = startBarsAgo - 1; index >= barsAgo; --index)
    if (inputSeries[index] > inputSeries[returnVal])
    returnVal = index;

    return returnVal;
    }

    https://forum.ninjatrader.com/forum/ninjatrader-8/indicator-development/95460-how-to-get-bar-number-of-max-value?p=1113896#post1113896​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes that 's correct. I tried this but it didn't trigger anything. Perhaps I'm not adding it in correctly. The below are the long and short code that i want to add this additional opening range filter to. Could you please add the additional opening range code in the right way? Also, I plan on using 5 min candles to be the breakout candles of the 15 min opening range.

      For Long Breakout Candle:
      bool isInitialBreakoutLong = Close[0] > Close[1] && High[0] > High[1] && Open[0] < Close[0] &&
      (High[0] - Low[0]) >= (atrValue * ATRMultiplier) &&
      (!EnableVWAPFilter || Close[0] >= (vwap8[0] + atrValue * ATRVWAPThresholdLong)) &&
      (!EnableDonchianChannelFilter || High[0] >= donchianChannel.Upper[0]);​

      For Short Breakout Candle:
      bool isInitialBreakoutShort = Close[0] < Close[1] && Low[0] < Low[1] && Open[0] > Close[0] &&
      (High[0] - Low[0]) >= (atrValue * ATRMultiplier) &&
      (!EnableVWAPFilter || Close[0] <= (vwap8[0] - atrValue * ATRVWAPThresholdShort)) &&
      (!EnableDonchianChannelFilter || Low[0] <= donchianChannel.Lower[0]);

      Thank you.​

      Comment


        #4
        Hello snoinvest,

        "I tried this but it didn't trigger anything."

        I'm not seeing the suggested code was used, but you can certainly add debugging prints to understand why your conditions are not evaluating as true at the time you expect.

        In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.
        The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.
        The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.

        Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.
        After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.

        I am happy to assist you with analyzing the output from the output window.

        Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

        Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.


        Let me know the date and time the behavior occurred or when you are expecting the behavior to occur.

        Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print or enabling TraceOrders.​


        "Could you please add the additional opening range code in the right way?"

        I'm not able to modify your code, however this thread will remain open for any community members that would like to do this as a convenience to you.

        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        110 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        59 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        37 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        41 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        78 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X