کد زیر رو طوری بنویس که قبل از اجزای محاسبات در هر تیک بررسی کند که پوزیشن بازی وجود نداشته باشد
//+------------------------------------------------------------------+
//|                                                        Milad.mq4 |
//|                         Copyright 2024, MetaQuotes Ltd. BitoByte |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd. BitoByte"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property script_show_inputs

//--- user input ---
extern double area_down_level = 0 ;                   //Area Down Level
extern double area_up_level = 100000 ;                //Area Up Level
extern double area_step = 1000 ;                      //Area Step
extern double risk_percent = 1 ;                      //Risk Percent
extern double entry_deviation = 1 ;                   //Entry Deviation
extern double entry_step = 100 ;                      //Entry Step
extern double stoploss_deviation = 1;                 //Stoploss Deviation
extern double profit_loss_ratio = 1;                  //Profit-Loss Ratio
extern double candle_divition = 0.5;                  //Candle Divition
extern double slippage = 5;                           //Slippage Order
extern int startHour1 = 15;                           //Start Hour1
extern int startMinute1 = 30;                         //Start Minute1
extern int endHour1 = 19;                             //End Hour1
extern int endMinute1 = 30;                           //End Minute1
extern int startHour2 = 10;                           //Start Hour2
extern int startMinute2 = 00;                         //Start Minute2
extern int endHour2 = 12;                             //End Hour2
extern int endMinute2 = 00;                           //End Minute2
extern int startHour3 = 22;                           //Start Hour3
extern int startMinute3 = 05;                         //Start Minute3
extern int endHour3 = 24;                             //End Hour3
extern int endMinute3 = 00;                           //End Minute3//******************
//--- allow time for trade ---
bool isTradingTime() {
   int currentHour = Hour();
   int currentMinute = Minute();
   bool withinPeriod1 = (currentHour > startHour1 || (currentHour == startHour1 && currentMinute >= startMinute1)) &&
                       (currentHour < endHour1 || (currentHour == endHour1 && currentMinute <= endMinute1));
   bool withinPeriod2 = (currentHour > startHour2 || (currentHour == startHour2 && currentMinute >= startMinute2)) &&
                       (currentHour < endHour2 || (currentHour == endHour2 && currentMinute <= endMinute2));
   bool withinPeriod3 = (currentHour > startHour3 || (currentHour == startHour3 && currentMinute >= startMinute3)) &&
                       (currentHour < endHour3 || (currentHour == endHour3 && currentMinute <= endMinute3));
   return (withinPeriod1 || withinPeriod2 || withinPeriod3);
}
//******************
//--- area_price ---
double area_price[];
//******************

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   //--- create area level ---
   double base_price = area_down_level;
   int index = 0;
   while(base_price < area_up_level){
      base_price += area_step; 
      ArrayResize(area_price, index + 1);
      area_price[index] = base_price;
      index++;
   }
   //****************
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
     // check not exist open position
     
     if(isTradingTime()) {  // check allow time for trade
         //--- candle/account data ---
         double open1 = Open[1];
         double close1 = Close[1];
         double high1 = High[1];
         double low1 = Low[1];
         double open2 = Open[2];
         double close2 = Close[2];
         double high2 = High[2];
         double low2 = Low[2];
         double account_balance = AccountBalance();                    
         //****************
         //--- check signals ---
         double entry_long_trigger = 0.0;
         double entry_short_trigger = 0.0;
         double stop_loss_price = 0.0;
         double take_profit_price = 0.0;
         for(int i = 0; i<ArraySize(area_price)-1; i++){
            double level_price = area_price[i];       
         }
     }
  }
//+------------------------------------------------------------------+