Time planes is difficult to get. For MT5 can try this:
// mql #property strict #include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> input double StopLoss = 50; // Stop loss level in pips input double Lots = 0.1; // Position size CPositionInfo position; CTrade trade; int OnInit() { return(INIT_SUCCEEDED); } void OnTick() { // Get the current candle MqlRates rates[]; ArraySetAsSeries(rates, true); int candlesCount = CopyRates(Symbol(), Period(), 0, 3, rates); if (candlesCount < 3) return; // Check if the current candle has closed below or above the previous candle's high/low double prevHigh = rates[1].high; double prevLow = rates[1].low; double currClose = rates[0].close; // Open a buy position if the current candle closes above the previous candle's high if (currClose > prevHigh) { double stopLoss = prevLow - StopLoss * _Point; OpenPosition(OP_BUY, Lots, stopLoss); } // Open a sell position if the current candle closes below the previous candle's low else if (currClose < prevLow) { double stopLoss = prevHigh + StopLoss * _Point; OpenPosition(OP_SELL, Lots, stopLoss); } } void OpenPosition(int cmd, double lots, double stopLoss) { // Open a new position if (trade.PositionOpen(Symbol(), cmd, lots, 0, stopLoss, EMPTY, 0)) { Print("Position opened successfully."); } else { Print("Failed to open position. Error code: ", GetLastError()); } }
Why did you post your MT4 question in the MT5 Trading Systems section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon.
That is not a valid enumeration for MT5. Do not post code that will not even compile.
MT4: Learn to code it.
MT5: Begin learning to code it.
Hello please can I have the code for closing open position at the closure of a candle. That works for SL and TP?

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
For example: if you close below or above the neckline of a double top or double bottom, you open a position. Simply put, a pending order to close the candle.
Main points:
- Work on all time planes.
- Position sizing to a predetermined stop-loss level.
- Folding window
- Metatrader 5
Thank you in advance for your help.