Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy doesn't trigger on desired candle

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

    Strategy doesn't trigger on desired candle

    Hi,

    I have a strategy where I want long trade to be executed when the current candle (isnewhighcandle) makes a new high by two ticks vs the previous candle (pullback candles) if certain conditions (RSI,MACD levels..) are met on the pullback candles. But no matter what i try, it keeps waiting for the isnewhighcandle to close and then executes the trades on the following candle after two ticks. How do I get it to fire on the isnewhighcandle? Calculation is set on eachtick. Below is the relevant section of the code. The execution part is highlighted in black. I can provide full code if needed. I've attached a picture at the end which illustrates the issue as well. The execution should be happening on the candle with the pink arrow around the blue horizontal line; instead it executes one bar later. Thank you:


    bool isNewHighCandle = ((isFirstPullbackSeriesLong[1] == 1 && previousRSILong < RsiInitialThresholdLong) ||
    (isSubsequentPullbackSeriesLong[1] == 1 && previousRSILong < RsiSubsequentThresholdLong)) &&
    High[0] > High[1] &&
    (!EnableAdxFilter || previousADXLong > AdxThresholdLong) &&
    previousMACDLong > MacdThresholdLong;
    isNewHighCandleSeriesLong[0] = isNewHighCandle ? 1 : 0;

    if (isNewHighCandle)
    {
    Draw.ArrowDown(this, "NewHigh" + CurrentBar, false, 0, High[0] + 2 * TickSize, Brushes.Pink);
    }

    // Execute Long Trade
    if (EnableLongTrades && isNewHighCandle && High[0] >= High[1] + 2 * TickSize)
    {
    Print("Long Entry condition met on bar: " + CurrentBar);
    EnterLongStopLimit(NumberOfContracts, High[0] + 2 * TickSize, High[0] + 2 * TickSize, "Long Entry");
    SetStopLoss("Long Entry", CalculationMode.Ticks, FixedStopLossTicks, false);
    SetProfitTarget("Long Entry", CalculationMode.Ticks, FixedTargetProfitTicks);



    ​​

    #2
    Hello snoinvest,

    Thank you for your inquiry.

    Can you clarify if this is happening when testing in real-time, or are you seeing this happen when the strategy is processing in historical (or testing in the analyzer)?

    If so, you should enable Tick Replay which will ensure that the market data (bid/ask/last) that went into building a bar is loaded in the exact sequence of market data events. This guarantees that your indicators and strategies are historically calculated tick-per-tick exactly as they would have been if the indicator/strategy was running live during a period.

    Tick Replay: https://ninjatrader.com/support/help...ick_replay.htm

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

    Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data.​

    I look forward to your reply.​

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    30 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    64 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X