//+------------------------------------------------------------------+
//|                                                     best_ex2.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

input ENUM_TIMEFRAMES TimeFrame = PERIOD_M1;
datetime lastBarTime = 0;
input double InitialLots = 0.1;


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool YesOrNo()
  {
   MqlRates rates_array[];

// Получаем данные последней закрытой свечи
   if(CopyRates(_Symbol, _Period, 1, 1, rates_array) > 0)
     {
      double openCloseDifference = MathAbs(rates_array[0].open - rates_array[0].close);
      double highLowDifference = MathAbs(rates_array[0].high - rates_array[0].low);

      double bodyToShadowRatio = openCloseDifference / highLowDifference;

      double lowerBodyEnd; // Нижняя часть тела свечи

      if(rates_array[0].open > rates_array[0].close)
        {
         // Медвежья свеча
         lowerBodyEnd = rates_array[0].close;
        }
      else
        {
         // Бычья свеча
         lowerBodyEnd = rates_array[0].open;
        }

      double bodyPositionRatio = (lowerBodyEnd - rates_array[0].low) / highLowDifference;

      // Проверяем, удовлетворяет ли тело свечи всем условиям
      if(bodyToShadowRatio <= 0.3 && bodyPositionRatio >= 0.5)
        {
         Print("ДА");
         return true;
        }
     }
   else
     {
      Print("Ошибка при получении данных свечи.");
     }
   Print("НЕТ");
   return false;


  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   MqlRates rates[];
   if(CopyRates(_Symbol, TimeFrame, 0, 1, rates) > 0)
     {
      lastBarTime = rates[0].time;
     }
   else
     {
      Print("Ошибка при получении информации о барах: ", GetLastError());
      return (INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);

  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   bool send_b = false;
   bool send_s = false;
   
   datetime currentTime = TimeCurrent();
   ENUM_TIMEFRAMES Time = TimeFrame;

   if(Time > 16000)
     {
      Time = (ENUM_TIMEFRAMES)((Time - 16384) * 60);
     }

   if(currentTime >= lastBarTime+Time*60)
     {
      if(YesOrNo() == true);
        {
         while(send_b != true)
           {
            OpenOrder(ORDER_TYPE_BUY, InitialLots, "B");
           }
        }

      lastBarTime = lastBarTime+Time*60;
     }

  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OpenOrder(ENUM_ORDER_TYPE type, double lots, string orderMagic)
  {

   MqlTradeRequest request = {};
   MqlTradeResult result = {};

// Заполнение полей структуры запроса на сделку
   request.action = TRADE_ACTION_DEAL;
   request.symbol = Symbol();
   request.volume = lots;
   request.type = type;
   request.deviation = 5;
   request.magic = StringToInteger(orderMagic + IntegerToString(GetTickCount()));

//request.comment = "Auto trade order";

   if(type == ORDER_TYPE_BUY)
      request.price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   else
      if(type == ORDER_TYPE_SELL)
         request.price = SymbolInfoDouble(_Symbol, SYMBOL_BID);

   if(!OrderSend(request, result))
     {
      Print("OrderSend failed with error #", GetLastError());
      Print("Details: symbol=", request.symbol, ", volume=", request.volume, ", type=", (request.type==ORDER_TYPE_BUY?"BUY":"SELL"), ", price=", request.price);
      if(request.type == ORDER_TYPE_BUY)
        {
         send_b = false;
        }
      else
         if(request.type == ORDER_TYPE_SELL)
           {
            send_s = false;
           }
     }
   else
      if(request.type == ORDER_TYPE_BUY)
        {
         send_b = true;
        }
      else
         if(request.type == ORDER_TYPE_SELL)
           {
            send_s = true;
           }

   PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);

  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
эта программа выдает такие ошибки empty controlled statement found	best_ex2.mq5	117	28
'send_b' - undeclared identifier	best_ex2.mq5	162	10
'send_s' - undeclared identifier	best_ex2.mq5	167	13
'send_b' - undeclared identifier	best_ex2.mq5	173	10
'send_s' - undeclared identifier	best_ex2.mq5	178	13
 что делать