Entry program for closing candles.

 
Hello! I need a program that opens a position when the candle closes below or above the line placed on the chart. 
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.
 
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());
    }
}
 
Oleksandr Medviediev #:
      OpenPosition(OP_BUY, Lots, stopLoss);

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.

 
Oleksandr Medviediev #:
Time planes is difficult to get. For MT5 can try this: 

Dont use AI to code mate. It wont work......we can only help you if you show an attempt to try

 
Olekszandr Medviediev #:
Az idősíkokat nehéz megszerezni. MT5 esetén ezt próbáld ki: 
Thanks for the help, what to do with this?