Why repeated RSI recoveries need a separate entry gate
In a sideways market, RSI can repeatedly cross above 30 without producing a durable recovery. A bar-count cooldown limits the frequency of accepted entry signals without changing the oscillator itself. It is a trade-frequency control, not proof of a profitable edge.
Define the event precisely
Use RSI(14) on completed candles. A long candidate occurs when the preceding completed RSI is below 30 and the latest completed RSI is at least 30. Accept a candidate only if at least four new bars have opened since the last accepted candidate. Rejected candidates do not reset the clock. This design measures accepted signals, not fills or exits.
For example, the hypothetical RSI sequence 40, 28, 24, 34, 42, 27, 35, 39, 26, 36 produces recoveries at indices 3, 6 and 9. Index 3 is accepted, index 6 is rejected because only three bars elapsed, and index 9 is accepted because six bars elapsed.

Hypothetical RSI sequence: green marks accepted candidates, red marks a rejected candidate. The gray interval represents the four-bar waiting period.
MQL4 implementation
// Entry gate fragment for an MQL4 Expert Advisor
input int CooldownBars = 4;
datetime seen = 0, lastAccepted = 0;
void OnTick()
{
if (Bars < 30 || Time[0] == seen) return;
seen = Time[0];
double prev = iRSI(NULL,0,14,PRICE_CLOSE,2);
double curr = iRSI(NULL,0,14,PRICE_CLOSE,1);
if (!(prev < 30 && curr >= 30)) return;
if (lastAccepted != 0)
{
int age = iBarShift(NULL,0,lastAccepted,true);
if (age < 0 || age < CooldownBars) return;
}
lastAccepted = Time[0];
Print("Accepted RSI recovery: ", curr);
// Integrate position checks and OrderSend here.
}
The fragment uses iRSI with shifts 1 and 2 to avoid using an unfinished candle. iBarShift measures elapsed chart bars rather than wall-clock time, so weekends do not artificially advance the cooldown. The first tick of a new bar evaluates the preceding close; it is not guaranteed to arrive at the scheduled opening instant. The code logs signals only, not actual orders.
Execution and exits
To turn this into an EA, check open orders by symbol and magic number before submitting a buy via OrderSend. For a testable exit model, use a stop distance of 1.5 times the completed-bar ATR(14), a target of twice that stop distance, and one position at a time. Calculate prices from the executable quote, normalize to the instrument tick size, respect broker stop and volume constraints, and reconcile actual fills. Persist the cooldown timestamp across restarts if required; the sample resets on reinitialization. Validate CooldownBars as nonnegative. If cooldown should start only after a successful fill, move the timestamp update into the successful execution path and reconcile broker state.
Testing and limitations
Compare cooldowns of 0, 2, 4 and 8 bars with identical exit rules, realistic spread, commission and slippage. Inspect accepted and rejected signals separately, test gaps and restarts, and reserve unseen data for validation. A cooldown can suppress good entries as well as bad ones. This example has not been compiled or backtested here. Leveraged trading can cause substantial losses.
For persistent state, broker-specific execution and custom exit rules, explore Custom MT4 strategy Development Services.