//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+

input ENUM_TIMEFRAMES TimeFrame = PERIOD_M1;
datetime lastBarTime = 0;
input double InitialLots = 0.1;
bool send_b = false;
bool send_s = false;


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

//±-----------------------------------------------------------------+
//| |
//±-----------------------------------------------------------------+
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()
  {
//—

   send_b = false;
   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)
  {

   MqlRates rates_array[];

// Получаем данные последней закрытой свечи
   if(CopyRates(_Symbol, _Period, 1, 1, rates_array) > 0)
     {

      double highLowDifference = MathAbs(rates_array[0].high - rates_array[0].low);

      double StopLoss = rates_array[0].low;
      double TakeProfit = SymbolInfoDouble(_Symbol, SYMBOL_ASK) + highLowDifference*2;
      Print(StopLoss);
      Print(TakeProfit);

      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.sl = StopLoss;
      request.tp = TakeProfit;

      //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);
     }
  }
//±-----------------------------------------------------------------+

//±-----------------------------------------------------------------+

//±-----------------------------------------------------------------+

//±-----------------------------------------------------------------+
//+------------------------------------------------------------------+
 в эту программу нужн одобавить что он будет заходить в сделки только если не открыто других сделок