Substituir para ordens pendentes!

 

Olá,

gostaria de saber se alguem pode me auxiliar na substituição das ordens à mercado para ordens pendentes LIMIT. Este EA abre uma operação quando atinge 50% da retração fibonacci durante a correção de uma tendência, este fibonacci é plotado de acordo com o padrão estabelecido para a estratégia.

No entanto gostaria de mudar para ordens pendentes limit, é possível mudar isto? se puderem ajudar fico grato!

//==========================================================================
//INPUT PARAMETERS [HIDE]
//==========================================================================
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  //------------------------------------------------------------------
  DecimalPoints = 1;
  double x = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP) * 10;
  while (x < 1)
  { x *= 10; DecimalPoints += 1; }
  //------------------------------------------------------------------
  gbl = lbl+Symbol()+"."+IntegerToString(MagicNumber)+".";
  if (MQLInfoInteger(MQL_TESTER))
  {
    gbl = "B."+gbl;
    GlobalVariablesDeleteAll(gbl);
  }
  //------------------------------------------------------------------
  ENUM_ORDER_TYPE_FILLING filling_mode;
  if (IsFillingTypeAllowed(_Symbol, SYMBOL_FILLING_FOK)) filling_mode = ORDER_FILLING_FOK;
  else if (IsFillingTypeAllowed(_Symbol, SYMBOL_FILLING_IOC)) filling_mode = ORDER_FILLING_IOC;
  else filling_mode = ORDER_FILLING_RETURN;
  trade.SetTypeFilling(filling_mode);
  trade.SetExpertMagicNumber(MagicNumber);
  trade.SetDeviationInPoints(Slippage);
  hzz = iCustom(NULL, 0, "Zigzag", ZigzagDepth, ZigzagDeviation, ZigzagBackstep);
  lastCandle = 0; zzInfo[0].zz = 0;
  //------------------------------------------------------------------
  if (StopLevel_==sl_10) StopLevel=-10;
  if (StopLevel_==sl_20) StopLevel=-20;
  if (StopLevel_==sl_30) StopLevel=-30;
  if (StopLevel_==sl_40) StopLevel=-40;
  if (StopLevel_==sl_50) StopLevel=-50;
  //------------------------------------------------------------------
  if (TPLevel_==tp_23) TPLevel=23.6;
  if (TPLevel_==tp_38) TPLevel=38.2;
  if (TPLevel_==tp_50) TPLevel=50;
  if (TPLevel_==tp_61) TPLevel=61.8;
  if (TPLevel_==tp_100) TPLevel=100;
  if (TPLevel_==tp_127) TPLevel=127;
  if (TPLevel_==tp_161) TPLevel=161.8;
  //------------------------------------------------------------------
  if (PartialLevel_==tp_23) PartialLevel=23.6;
  if (PartialLevel_==tp_38) PartialLevel=38.2;
  if (PartialLevel_==tp_50) PartialLevel=50;
  if (PartialLevel_==tp_61) PartialLevel=61.8;
  if (PartialLevel_==tp_100) PartialLevel=100;
  if (PartialLevel_==tp_127) PartialLevel=127;
  if (PartialLevel_==tp_161) PartialLevel=161.8;
  //------------------------------------------------------------------
  if (BreakevenStart_==bt_0) BreakevenStart=0;
  if (BreakevenStart_==bt_23) BreakevenStart=23.6;
  if (BreakevenStart_==bt_38) BreakevenStart=38.2;
  if (BreakevenStart_==bt_50) BreakevenStart=50;
  if (BreakevenStart_==bt_61) BreakevenStart=61.8;
  if (BreakevenStart_==bt_100) BreakevenStart=100;
  if (BreakevenStart_==bt_127) BreakevenStart=127;
  if (BreakevenStart_==bt_161) BreakevenStart=161.8;
  //------------------------------------------------------------------
  if (BreakevenStop_==bt_0) BreakevenStop=0;
  if (BreakevenStop_==bt_23) BreakevenStop=23.6;
  if (BreakevenStop_==bt_38) BreakevenStop=38.2;
  if (BreakevenStop_==bt_50) BreakevenStop=50;
  if (BreakevenStop_==bt_61) BreakevenStop=61.8;
  if (BreakevenStop_==bt_100) BreakevenStop=100;
  if (BreakevenStop_==bt_127) BreakevenStop=127;
  if (BreakevenStop_==bt_161) BreakevenStop=161.8;
  //------------------------------------------------------------------
  if (TrailStart_==bt_0) TrailStart=0;
  if (TrailStart_==bt_23) TrailStart=23.6;
  if (TrailStart_==bt_38) TrailStart=38.2;
  if (TrailStart_==bt_50) TrailStart=50;
  if (TrailStart_==bt_61) TrailStart=61.8;
  if (TrailStart_==bt_100) TrailStart=100;
  if (TrailStart_==bt_127) TrailStart=127;
  if (TrailStart_==bt_161) TrailStart=161.8;
  //------------------------------------------------------------------
  if (TrailStop_==bt_0) TrailStop=0;
  if (TrailStop_==bt_23) TrailStop=23.6;
  if (TrailStop_==bt_38) TrailStop=38.2;
  if (TrailStop_==bt_50) TrailStop=50;
  if (TrailStop_==bt_61) TrailStop=61.8;
  if (TrailStop_==bt_100) TrailStop=100;
  if (TrailStop_==bt_127) TrailStop=127;
  if (TrailStop_==bt_161) TrailStop=161.8;
  //------------------------------------------------------------------
  return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
  //------------------------------------------------------------------
  if (reason == REASON_REMOVE) GlobalVariablesDeleteAll(gbl);
  ObjectsDeleteAll(0, lbl);
  Comment("");
  //------------------------------------------------------------------
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void OnTick()
{
  //------------------------------------------------------------------
  MqlRates rt[2]; if (CopyRates(NULL, 0, 0, 2, rt)<2) return;
  Ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK); Bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
  int digits = (int)SymbolInfoInteger(Symbol(), SYMBOL_DIGITS);
  //------------------------------------------------------------------
  if (PositionSelect(Symbol()))
  {
    double lot = PositionGetDouble(POSITION_VOLUME);
    double sl = PositionGetDouble(POSITION_SL), tp = PositionGetDouble(POSITION_TP);
    double sl2 = GlobalVariableGet(gbl+"SL"), tp2 = GlobalVariableGet(gbl+"TP");
    if (NormalizeDouble(sl, _Digits)!=NormalizeDouble(sl2, _Digits) || NormalizeDouble(tp, _Digits)!=NormalizeDouble(tp2, _Digits))
    {
      trade.PositionModify(Symbol(), sl2, tp2);
      sl = sl2; tp = tp2;
    }
    if (PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
    {
      double p1 = GlobalVariableGet(gbl+"Price1"), p2 = GlobalVariableGet(gbl+"Price2"), p3 = GlobalVariableGet(gbl+"Price3");
      datetime t1 = (datetime)GlobalVariableGet(gbl+"Time1"), t2 = (datetime)GlobalVariableGet(gbl+"Time2"), t3 = (datetime)GlobalVariableGet(gbl+"Time3");
      if (TimeFilter && TimeToString(TimeCurrent(), TIME_MINUTES)>=TimeCloseAll) { trade.PositionClose(Symbol()); return; }
      double glot = GlobalVariableGet(gbl+"Lot");
      if (PartialClose && NormalizeDouble(lot, DecimalPoints)==NormalizeDouble(glot, DecimalPoints) && (p3-Bid)/(p1-p2)>=PartialLevel/100)
      {
        Print("try to close "+DoubleToString(PartialLot, DecimalPoints)+" lots of position on "+DoubleToString(PartialLevel, 2)+"% expansion");
        if (IsHedging()) trade.PositionClosePartial(Symbol(), PartialLot);
        else
        {
          trade.PositionOpen(Symbol(), ORDER_TYPE_BUY, PartialLot, Ask, 0, 0, "partial");
          trade.PositionModify(Symbol(), sl, tp);
        }
        return;
      }
      if (Breakeven)
      {
        double beStart = p3-(p1-p2)*BreakevenStart/100, beStop = p3-(p1-p2)*BreakevenStop/100; beStop = Normalize(beStop, 1);
        if (NormalizeDouble(Ask, _Digits)<=NormalizeDouble(beStart, _Digits))
        if (sl==0 || NormalizeDouble(sl, _Digits)>NormalizeDouble(beStop, _Digits))
        {
          sl = NormalizeDouble(beStop, _Digits);
          Print("try to BE sl to "+DoubleToString(sl, _Digits));
          trade.PositionModify(Symbol(), NormalizeDouble(sl, _Digits), tp);
          GlobalVariableSet(gbl+"SL", sl);
        }
      }
      if (Trailing)
      {
        double trStart = p3-(p1-p2)*TrailStart/100, trStop = p3-(p1-p2)*TrailStop/100; trStop = trStop-trStart; trStop = Normalize(trStop, 1);
        if (NormalizeDouble(Ask, _Digits)<=NormalizeDouble(trStart, _Digits))
        if (sl==0 || NormalizeDouble(sl-Ask, _Digits)>=NormalizeDouble(trStop+TrailStep*_Point, _Digits))
        {
          sl = NormalizeDouble(Ask+trStop, _Digits);
          Print("try to trail sl to "+DoubleToString(sl, _Digits));
          trade.PositionModify(Symbol(), NormalizeDouble(sl, _Digits), tp);
          GlobalVariableSet(gbl+"SL", sl);
        }
      }
    }
    if (PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
    {
      double p1 = GlobalVariableGet(gbl+"Price1"), p2 = GlobalVariableGet(gbl+"Price2"), p3 = GlobalVariableGet(gbl+"Price3");
      datetime t1 = (datetime)GlobalVariableGet(gbl+"Time1"), t2 = (datetime)GlobalVariableGet(gbl+"Time2"), t3 = (datetime)GlobalVariableGet(gbl+"Time3");
      if (TimeFilter && TimeToString(TimeCurrent(), TIME_MINUTES)>=TimeCloseAll) { trade.PositionClose(Symbol()); return; }
      double glot = GlobalVariableGet(gbl+"Lot");
      if (PartialClose && NormalizeDouble(lot, DecimalPoints)==NormalizeDouble(glot, DecimalPoints) && (Bid-p3)/(p2-p1)>=PartialLevel/100)
      {
        Print("try to close "+DoubleToString(PartialLot, DecimalPoints)+" lots of position on "+DoubleToString(PartialLevel, 2)+"% expansion");
        if (IsHedging()) trade.PositionClosePartial(Symbol(), PartialLot);
        else
        {
          trade.PositionOpen(Symbol(), ORDER_TYPE_SELL, PartialLot, Bid, 0, 0, "partial");
          trade.PositionModify(Symbol(), sl, tp);
        }
        return;
      }
      if (Breakeven)
      {
        double beStart = p3+(p2-p1)*BreakevenStart/100, beStop = p3+(p2-p1)*BreakevenStop/100; beStop = Normalize(beStop, -1);
        if (NormalizeDouble(Bid, _Digits)>=NormalizeDouble(beStart, _Digits))
        if (sl==0 || NormalizeDouble(sl, _Digits)<NormalizeDouble(beStop, _Digits))
        {
          sl = NormalizeDouble(beStop, _Digits);
          Print("try to BE sl to "+DoubleToString(sl, _Digits));
          trade.PositionModify(Symbol(), NormalizeDouble(sl, _Digits), tp);
          GlobalVariableSet(gbl+"SL", sl);
        }
      }
      if (Trailing)
      {
        double trStart = p3+(p2-p1)*TrailStart/100, trStop = p3+(p2-p1)*TrailStop/100; trStop = trStart-trStop; trStop = Normalize(trStop, -1);
        if (NormalizeDouble(Bid, _Digits)>=NormalizeDouble(trStart, _Digits))
        if (sl==0 || NormalizeDouble(Bid-sl, _Digits)>=NormalizeDouble(trStop+TrailStep*_Point, _Digits))
        {
          sl = NormalizeDouble(Bid-trStop, _Digits);
          Print("try to trail sl to "+DoubleToString(sl, _Digits));
          trade.PositionModify(Symbol(), NormalizeDouble(sl, _Digits), tp);
          GlobalVariableSet(gbl+"SL", sl);
        }
      }
    }
  }
  else if (skipCandle != rt[1].time)
  {
    if (!FillZigzag(rt)) return;
    int sig = -1, idx = 0;
    
//=========================================================================================================
    
    if (zzInfo[0].zz==zzInfo[0].rt.low && 
        zzInfo[1].zz==zzInfo[1].rt.high && 
        zzInfo[2].zz==zzInfo[2].rt.low && 
        zzInfo[3].zz==zzInfo[3].rt.high &&
         
        zzInfo[0].zz<zzInfo[2].zz && 
        zzInfo[1].zz<zzInfo[3].zz &&
         
        zzInfo[0].zz+(zzInfo[1].zz-zzInfo[0].zz)*50.0/100<zzInfo[2].zz) sig = OP_SELL;
        
//=========================================================================================================   
     
    if (zzInfo[0].zz==zzInfo[0].rt.high && 
        zzInfo[0].zz>zzInfo[1].zz && 
        zzInfo[1].zz==zzInfo[1].rt.low && 
        zzInfo[2].zz==zzInfo[2].rt.high && 
        zzInfo[3].zz==zzInfo[3].rt.low && 
        zzInfo[4].zz==zzInfo[4].rt.high && 
        
        zzInfo[1].zz<zzInfo[3].zz && 
        zzInfo[2].zz<zzInfo[4].zz &&
         
        zzInfo[1].zz+(zzInfo[2].zz-zzInfo[1].zz)*50/100<zzInfo[3].zz) { sig = OP_SELL; idx = 1; }

//=========================================================================================================
        
    if (zzInfo[0].zz==zzInfo[0].rt.high && 
        zzInfo[1].zz==zzInfo[1].rt.low && 
        zzInfo[2].zz==zzInfo[2].rt.high && 
        zzInfo[3].zz==zzInfo[3].rt.low &&
         
        zzInfo[0].zz>zzInfo[2].zz && 
        zzInfo[1].zz>zzInfo[3].zz &&
         
        zzInfo[0].zz-(zzInfo[0].zz-zzInfo[1].zz)*50.0/100>zzInfo[2].zz) sig = OP_BUY;
        
//=========================================================================================================
        
    if (zzInfo[0].zz==zzInfo[0].rt.low && 
        zzInfo[0].zz<zzInfo[1].zz && 
        zzInfo[1].zz==zzInfo[1].rt.high && 
        zzInfo[2].zz==zzInfo[2].rt.low && 
        zzInfo[3].zz==zzInfo[3].rt.high && 
        zzInfo[4].zz==zzInfo[4].rt.low &&
         
        zzInfo[1].zz>zzInfo[3].zz && 
        zzInfo[2].zz>zzInfo[4].zz && 
        
        zzInfo[1].zz-(zzInfo[1].zz-zzInfo[2].zz)*50.0/100>zzInfo[3].zz) { sig = OP_BUY; idx = 1; }
        
//=========================================================================================================
        
    if (sig == OP_SELL)
    {
      if (ObjectFind(0, lbl+"FiboEX")!=-1) ObjectDelete(0, lbl+"FiboEX");
      if (DoesSignalCatched(-1, zzInfo[idx+1].rt.time)==-1) DrawFiboRetracement(lbl+"FiboRE", zzInfo[idx+1].zz, zzInfo[idx+1].rt.time, zzInfo[idx].zz, zzInfo[idx].rt.time);
      if ((Bid-zzInfo[idx].zz)/(zzInfo[idx+1].zz-zzInfo[idx].zz)>=50.0/100)
      {
        MqlRates rates[];
        if (zzInfo[idx].rt.time<rt[1].time && CopyRates(NULL, 0, rt[0].time, zzInfo[idx].rt.time, rates)<1) return;
        if (zzInfo[idx].rt.time<rt[1].time && rates[0].time<zzInfo[idx].rt.time) return;
        for (int i = ArraySize(rates)-1; i >= 1; i--)
        {
          if ((rates[i].high-zzInfo[idx].zz)/(zzInfo[idx+1].zz-zzInfo[idx].zz)>=50.0/100) { skipCandle=rt[1].time; return; }
        }
        double sl = NormalizeDouble(rt[1].high-(zzInfo[idx+1].zz-zzInfo[idx].zz)*StopLevel/100, _Digits); sl = Normalize(sl, 1);
        double tp = NormalizeDouble(rt[1].high-(zzInfo[idx+1].zz-zzInfo[idx].zz)*TPLevel/100, _Digits); tp = Normalize(tp, -1);
        if (CheckTime() && DoesSignalCatched(OP_SELL, zzInfo[idx+1].rt.time)==-1 && SetOrder(OP_SELL, sl, tp) > 0)
        {
          GlobalVariableSet(gbl+"Price1", zzInfo[idx+1].zz); GlobalVariableSet(gbl+"Time1", zzInfo[idx+1].rt.time);
          GlobalVariableSet(gbl+"Price2", zzInfo[idx].zz); GlobalVariableSet(gbl+"Time2", zzInfo[idx].rt.time);
          GlobalVariableSet(gbl+"Price3", rt[1].high); GlobalVariableSet(gbl+"Time3", rt[1].time);
          GlobalVariableSet(gbl+"SL", sl); GlobalVariableSet(gbl+"TP", tp);
          ObjectDelete(0, lbl+"FiboRE");
          DrawFiboExpansion(lbl+"FiboEX", zzInfo[idx+1].zz, zzInfo[idx+1].rt.time, zzInfo[idx].zz, zzInfo[idx].rt.time, rt[1].high, rt[1].time);
        }
        else if (!CheckTime()) skipCandle = rt[1].time;
      }
    }

//=========================================================================================================

    if (sig == OP_BUY)
    {
      if (ObjectFind(0, lbl+"FiboEX")!=-1) ObjectDelete(0, lbl+"FiboEX");
      DrawFiboRetracement(lbl+"FiboRE", zzInfo[idx+1].zz, zzInfo[idx+1].rt.time, zzInfo[idx].zz, zzInfo[idx].rt.time);
      if ((zzInfo[idx].zz-Bid)/(zzInfo[idx].zz-zzInfo[idx+1].zz)>=50.0/100)
      {
        MqlRates rates[];
        if (zzInfo[idx].rt.time<rt[1].time && CopyRates(NULL, 0, rt[0].time, zzInfo[idx].rt.time, rates)<1) return;
        if (zzInfo[idx].rt.time<rt[1].time && rates[0].time<zzInfo[idx].rt.time) return;
        for (int i = ArraySize(rates)-1; i >= 1; i--)
        {
          if ((zzInfo[idx].zz-rates[i].low)/(zzInfo[idx].zz-zzInfo[idx+1].zz)>=50.0/100) { skipCandle=rt[1].time; return; }
        }
        double sl = NormalizeDouble(rt[1].low+(zzInfo[idx].zz-zzInfo[idx+1].zz)*StopLevel/100, _Digits); sl = Normalize(sl, -1);
        double tp = NormalizeDouble(rt[1].low+(zzInfo[idx].zz-zzInfo[idx+1].zz)*TPLevel/100, _Digits); tp = Normalize(tp, 1);
        if (CheckTime() && DoesSignalCatched(OP_BUY, zzInfo[idx+1].rt.time)==-1 && SetOrder(OP_BUY, sl, tp) > 0)
        {
          GlobalVariableSet(gbl+"Price1", zzInfo[idx+1].zz); GlobalVariableSet(gbl+"Time1", zzInfo[idx+1].rt.time);
          GlobalVariableSet(gbl+"Price2", zzInfo[idx].zz); GlobalVariableSet(gbl+"Time2", zzInfo[idx].rt.time);
          GlobalVariableSet(gbl+"Price3", rt[1].low); GlobalVariableSet(gbl+"Time3", rt[1].time);
          GlobalVariableSet(gbl+"SL", sl); GlobalVariableSet(gbl+"TP", tp);
          ObjectDelete(0, lbl+"FiboRE");
          DrawFiboExpansion(lbl+"FiboEX", zzInfo[idx+1].zz, zzInfo[idx+1].rt.time, zzInfo[idx].zz, zzInfo[idx].rt.time, rt[1].low, rt[1].time);
        }
        else if (!CheckTime()) skipCandle = rt[1].time;
      }
    }
    if (sig == -1)
    {
      if (ObjectFind(0, lbl+"FiboRE")!=-1) ObjectDelete(0, lbl+"FiboRE");
    }
  }
  //------------------------------------------------------------------
}

//=========================================================================================================

//+------------------------------------------------------------------+
bool FillZigzag(MqlRates &rt[])
{
  if (lastCandle!=rt[1].time || Bid==rt[1].high || Bid==rt[1].low)
  {
    MqlRates rates[]; double zz[];
    int idx = -1, start = 0;
    while (idx < 4 && start < Bars(NULL, 0))
    {
      if (CopyRates(NULL, 0, start, 20, rates)<20) return (false);
      if (CopyBuffer(hzz, 0, start, 20, zz)<20) return (false);
      start += 20;
      for (int i = 19; i >= 0; i--)
      {
        if (zz[i]!=0 && zz[i]!=EMPTY_VALUE)
        {
          idx ++;
          zzInfo[idx].zz = zz[i];
          zzInfo[idx].rt.high = rates[i].high;
          zzInfo[idx].rt.low = rates[i].low;
          zzInfo[idx].rt.open = rates[i].open;
          zzInfo[idx].rt.close = rates[i].close;
          zzInfo[idx].rt.time = rates[i].time;
        }
        if (idx == 4) break;
      }
    }
    lastCandle = rt[1].time;
    if (idx == 4) return (true); else return (false);
  }
  return (true);
  //------------------------------------------------------------------
}
//+------------------------------------------------------------------+
int SetOrder(int type, double sl, double tp)
{
  double price = 0;
  ENUM_ORDER_TYPE cmd = ORDER_TYPE_BUY;
  if (type == OP_BUY)
  {
    cmd = ORDER_TYPE_BUY;
    price = Ask;
  }
  else if (type == OP_SELL)
  {
    cmd = ORDER_TYPE_SELL;
    price = Bid;
  }
  double lot = FixedLot;
  ResetLastError();
  while (account.FreeMarginCheck(Symbol(), cmd, lot, price) < 0 && lot >= SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN))
    lot -= SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP);
  if (lot < SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN))
  {
    Print("not enough money to open trade, signal rejected...");
    return (-2);
  }
  if (trade.PositionOpen(Symbol(), cmd, lot, price, sl, tp, TradeComment))
  {
    _res = PositionSelect(Symbol());
    GlobalVariableSet(gbl+"Lot", lot);
    GlobalVariableSet(gbl+"SL", sl);
    GlobalVariableSet(gbl+"TP", tp);
    return (1);
  }
  else
  {
    int err = GetLastError();
    Print("failed to open trade on error "+IntegerToString(err));
    Print(ErrorDescription(err));
  }
  return (-1);
}
//+------------------------------------------------------------------+
int DoesSignalCatched(int type, datetime from)
{
  if (PositionSelect(Symbol()))
  {
    if (type==OP_BUY && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) return (1);
    if (type==OP_SELL && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) return (1);
  }
  HistorySelect(from, TimeCurrent());
  for (int i = HistoryDealsTotal() - 1 ; i >= 0; i--)
  {
    ulong ticket = HistoryDealGetTicket(i);
    if (HistoryDealGetString(ticket, DEAL_SYMBOL)==Symbol())
    if (HistoryDealGetInteger(ticket, DEAL_ENTRY)==DEAL_ENTRY_IN && HistoryDealGetInteger(ticket, DEAL_TIME)>=from)
      return (1);
  }
  return (-1);
}
//+------------------------------------------------------------------+
bool CheckTime()
{
  //------------------------------------------------------------------
  bool AllowTrade = true;
  if (TimeFilter)
  {
    bool allow1=true;
    string sh1, eh1;
    sh1 = TimeStart; eh1 = TimeEnd;
    //------------------------------------------------------------------
    if (sh1 < eh1)
      if (TimeToString(TimeCurrent(), TIME_MINUTES) < sh1 || TimeToString(TimeCurrent(), TIME_MINUTES) > eh1)
        allow1 = false;
    if (sh1 > eh1)
      if (TimeToString(TimeCurrent(), TIME_MINUTES) < sh1 && TimeToString(TimeCurrent(), TIME_MINUTES) > eh1)
        allow1 = false;
    if (sh1 == eh1) allow1 = false;
    //------------------------------------------------------------------
    if (!allow1) AllowTrade = false;
  }
  //------------------------------------------------------------------
  return (AllowTrade);
  //------------------------------------------------------------------
}
//+------------------------------------------------------------------+
double Normalize(double in, int dir)
{
  //------------------------------------------------------------------
  double ts = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE);
  if (ts != _Point)
  {
    double num = in * MathPow(10, _Digits);
    num = (int)(num / (ts/_Point)) * (ts/_Point);
    num = num / MathPow(10, _Digits);
    if (dir == -1 && num > in) num = num - ts;
    if (dir == 1 && num < in) num = num + ts;
    return (num);
  }
  return (in);
  //------------------------------------------------------------------
}
//+------------------------------------------------------------------+
bool IsFillingTypeAllowed(string symbol,int fill_type)
{
  int filling = (int)SymbolInfoInteger(symbol, SYMBOL_FILLING_MODE);
  return ((filling & fill_type) == fill_type);
}
//+------------------------------------------------------------------+
bool IsHedging()
{
  ENUM_ACCOUNT_MARGIN_MODE margmod = (ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE);
  return(margmod==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING);
}
//+------------------------------------------------------------------+
 

Olá @kwlin_089

Para simplesmente substituir o envio das suas ordem a mercado por ordens pendentes com limite de preço, você precisa, essencialmente, substituir ORDER_TYPE_BUY por ORDER_TYPE_BUY_LIMIT e ORDER_TYPE_SELL por ORDER_TYPE_SELL_LIMIT na hora de abrir posição.

Só que não é tão simples assim. Há outras coisas que precisam ser verificadas/consideradas:

1) Para manter a consistência da lógica operacional do seu EA, você também terá que fazer a mesma substituição em todos os outros lugares do código onde o tipo de ordem é determinado ou verificado (na função SetOrder(), por exemplo).

2) Ordens do tipo LIMIT têm parâmetros adicionais em relação a ordens de mercado. Você terá que acrescentá-los na hora de abrir posição. Veja os parâmetros requeridos para cada tipo de ordem aqui neste link.

3) Ao contrário de ordens a mercado, que em mercados líquidos são sempre executadas de forma integral e imediata, as ordens LIMIT nem sempre são executadas e às vezes são executadas parcialmente. Por isso você terá que acrescentar funções lógicas no seu EA para decidir o que fazer em cada caso. Por exemplo: decidir quando cancelar uma ordem que não foi executada (senão ela fica lá esquecida a vida toda e acaba sendo executada depois, num momento indesejado), decidir até quando manter uma ordem parcialmente executada, se a posição parcialmente aberta deve ser zerada ou mantida e até quando mantê-la, etc..

É provável que haja mais coisas a serem consideradas, além das que enumerei acima, para que o seu EA funcione corretamente em qualquer circunstância com ordens LIMIT.

A menos que você já tenha um conhecimento sólido de programação, que te permita entender tudo o que precisa ser feito estudando por si mesmo a documentação MQL5, recomendo fortemente contratar o serviço de um programador free-lancer para te ajudar. 

Abraços e sucesso!

 
Trader_Patinhas:

Olá @kwlin_089

Para simplesmente substituir o envio das suas ordem a mercado por ordens pendentes com limite de preço, você precisa, essencialmente, substituir ORDER_TYPE_BUY por ORDER_TYPE_BUY_LIMIT e ORDER_TYPE_SELL por ORDER_TYPE_SELL_LIMIT na hora de abrir posição.

Só que não é tão simples assim. Há outras coisas que precisam ser verificadas/consideradas:

1) Para manter a consistência da lógica operacional do seu EA, você também terá que fazer a mesma substituição em todos os outros lugares do código onde o tipo de ordem é determinado ou verificado (na função SetOrder(), por exemplo).

2) Ordens do tipo LIMIT têm parâmetros adicionais em relação a ordens de mercado. Você terá que acrescentá-los na hora de abrir posição. Veja os parâmetros requeridos para cada tipo de ordem aqui neste link.

3) Ao contrário de ordens a mercado, que em mercados líquidos são sempre executadas de forma integral e imediata, as ordens LIMIT nem sempre são executadas e às vezes são executadas parcialmente. Por isso você terá que acrescentar funções lógicas no seu EA para decidir o que fazer em cada caso. Por exemplo: decidir quando cancelar uma ordem que não foi executada (senão ela fica lá esquecida a vida toda e acaba sendo executada depois, num momento indesejado), decidir até quando manter uma ordem parcialmente executada, se a posição parcialmente aberta deve ser zerada ou mantida e até quando mantê-la, etc..

É provável que haja mais coisas a serem consideradas, além das que enumerei acima, para que o seu EA funcione corretamente em qualquer circunstância com ordens LIMIT.

A menos que você já tenha um conhecimento sólido de programação, que te permita entender tudo o que precisa ser feito estudando por si mesmo a documentação MQL5, recomendo fortemente contratar o serviço de um programador free-lancer para te ajudar. 

Abraços e sucesso!

Meu conhecimento é básico, vou seguir o que me disse, vou tentar mudar isso!

Obrigado pela ajuda!

;)

Razão: