Strategy not exiting position on Renko chart with Calculate.OnEachTick

Hello,

I have a Renko strategy (MNQ 09-26, 20-brick) that is not triggering exit orders correctly. The strategy uses Calculate.OnEachTick and monitors bar direction using Close[0] > Open[0] and Close[0] < Open[0] to detect Renko box color.

The problem: When in a Long position, the exit condition if (boxNegativo && CurrentBar != ultimoBarSaida) never fires, even when clearly negative (red) Renko bars appear on the chart. I can see red bars visually but no ExitLong order is ever sent — confirmed by checking the Orders tab, which shows zero StopReversaoCompra entries during that period.

What I have tried:

  • Calculate.OnBarClose with ExitLongLimit — exit not guaranteed

  • Calculate.OnBarClose with ExitLong (market) — exit still not firing

  • Calculate.OnEachTick with IsFirstTickOfBar — unreliable

  • Calculate.OnEachTick without IsFirstTickOfBar — exit still not firing

  • OnMarketData override — silently ignored

My questions:

  1. Is Close[0] > Open[0] a reliable way to detect Renko bar direction during OnEachTick?

  2. Is IsFirstTickOfBar reliable with Renko data?

  3. What is the correct approach to detect when a new Renko bar closes in a different direction while using Calculate.OnEachTick?

Here is the relevant exit code:

csharp

Calculate = Calculate.OnEachTick;

protected override void OnBarUpdate()
{
    if (CurrentBar < BarsRequiredToTrade) return;
    if (State != State.Realtime) return;

    bool boxPositivo = Close[0] > Open[0];
    bool boxNegativo = Close[0] < Open[0];

    if (Position.MarketPosition == MarketPosition.Long)
    {
        if (boxNegativo && CurrentBar != ultimoBarSaida)
        {
            CancelAllOrders();
            ExitLong("StopReversaoCompra");
            ultimoBarSaida = CurrentBar;
            return;
        }
    }

    if (Position.MarketPosition == MarketPosition.Short)
    {
        if (boxPositivo && CurrentBar != ultimoBarSaida)
        {
            CancelAllOrders();
            ExitShort("StopReversaoVenda");
            ultimoBarSaida = CurrentBar;
            return;
        }
    }
}

Any help is greatly appreciated. Thank you!

I believe when a Renko bar reverses (gets redrawn) there is a new IsFirstTickOfBar, if I remember right.

1 Like

Don’t know how renko bars work so I can’t tell you how that affects how the logic is being played out…but I would add print statements so you can understand how it works in real time. What you can do is after the Long if statement, add something like:

Print("Time[0]: " + Time[0]);

Print("boxPositivo: " + boxPositivo);

Print("CurrentBar : " + CurrentBar );

Print("ultimoBarSaida: " + ultimoBarSaida);

The Time[0] is just extra so you can tell which bar it’s working on…in case you get multiple bars in the output. If it’s not triggering, it should give you a clearer understanding of what is false that is causing you to not enter that piece of code. If it is all true, that means it is triggering and something is wrong with either the CancelAllOrders() or the ExitLong() code…like perhaps something is misspelt and therefore is not exiting for that reason.