Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
I want to enter the trade when current candle crosses high of previous candle. But issue there's something wrong that `high` is always less than previous candle high.
In attached screenshot you can see it's printing high less than previous high even bullish candles are forming.
Your code appears to be limiting operations to run only upon population of a new bar, but you have an iHigh() set to bar 0.
So then following the first reference to bar 0, LastBars is set to bars and you're left with only the initially appearing high price of the currently forming bar.
double high2, close1; void OnTick() { if ((!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)) || (!TerminalInfoInteger(TERMINAL_CONNECTED)) || (SymbolInfoInteger(_Symbol, SYMBOL_TRADE_MODE) !=SYMBOL_TRADE_MODE_FULL)) return; int bars = Bars(_Symbol, _Period); if (LastBars != bars) { LastBars = bars; high2 = iHigh(_Symbol, PERIOD_CURRENT, 2); close1 = iClose(_Symbol, PERIOD_CURRENT, 1); if (close1 > high2) { // buy condition here } } }
You might want to rethink your logic, it should be like this:
- Get the High value from the bar index 2
- Get the Close value from the bar index 1 (supposing you want to get the Close cross)
- You will be running the logic off the bar index 0 always
Thank you everyone for support. After trying all of recommendations, I solved the problem by using Pending orders.
So you can place order and keep one trade per candle.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want to enter the trade when current candle crosses high of previous candle. But issue there's something wrong that `high` is always less than previous candle high.
In attached screenshot you can see it's printing high less than previous high even bullish candles are forming.