CRIEI UM ROBO DO DUNIGAN COM STOP MOVEL, MAS NÃO CONSIGO EXECUTA-LO NO MINI INDICE. ME AJUDEM A ENCONTRAR O ERRO!!

 

#include <Trade\Trade.mqh>
CTrade ExtTrade;

input string OpeningTime = "10:00:00"; //Opening Time
input string ClosingTime = "17:00:00"; //Closing Time
input int SL = 10;  //Stop Loss(Point)
input int TP = 30;   //Take Profit(Point)
input double Volume = 1.0;

int MagicNumber = 888888;
int Slippage = 5;
string prefix = "";

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   prefix = _Symbol;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   DeleteGlobalVariables();
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
 
  if(IsClosingTime())
  {
    MarketOrderClose(ORDER_TYPE_BUY);
    MarketOrderClose(ORDER_TYPE_SELL);
  }
  if(!IsGoodTime())
  {
    return;
  }
  TrallingStop();
 
   //Print("iClose(_Symbol,PERIOD_CURRENT,0) = ",iClose(_Symbol,PERIOD_CURRENT,0));  
  // Print("iHigh(_Symbol,PERIOD_CURRENT,1)  = ",iHigh(_Symbol,PERIOD_CURRENT,1) );  
  // Print("iLow(_Symbol,PERIOD_CURRENT,1) = ",iLow(_Symbol,PERIOD_CURRENT,1));
   // Print(" CountAllPositions() = ", CountAllPositions());

  if(iClose(_Symbol,PERIOD_CURRENT,0) >= iHigh(_Symbol,PERIOD_CURRENT,1) && CountAllPositions() < 1)
  {
    if(IsBuyNewBar())
    {

      CheckForOpen(ORDER_TYPE_BUY,Volume,SymbolInfoDouble(_Symbol,SYMBOL_ASK),SL,TP);
    }
    
  }
  else if(iClose(_Symbol,PERIOD_CURRENT,0) <= iLow(_Symbol,PERIOD_CURRENT,1) && CountAllPositions() < 1)
  {
    if(IsSellNewBar())
    {
      CheckForOpen(ORDER_TYPE_SELL,Volume,SymbolInfoDouble(_Symbol,SYMBOL_BID),SL,TP);
    }
  }
}

void TrallingStop()
{
  double stoploss = 0;
  double takeprofit = 0;
 
  for(int i=0;i<PositionsTotal();i++)
  {
    //Select each order to get the order number
    ulong   ticket = PositionGetTicket(i);
    // Only process orders for our symbols
    if(PositionGetSymbol(i) == _Symbol)
    {  
      if(PositionGetInteger(POSITION_TYPE) == ORDER_TYPE_BUY)
      {
        if(GVGet("Last buy modiy price" + IntegerToString(ticket)) <= 0
          && (SymbolInfoDouble(_Symbol,SYMBOL_BID) - PositionGetDouble(POSITION_PRICE_OPEN)) >= 1 * _Point)
        {
          bool flag = false;
          if(PositionGetDouble(POSITION_SL) > 0)
          {
            stoploss = PositionGetDouble(POSITION_SL) + 1 * _Point;
          }
          else
          {
            stoploss = 0;
          }
          if(PositionGetDouble(POSITION_TP) > 0)
          {
            takeprofit = PositionGetDouble(POSITION_TP) + 1 * _Point;
          }
          else
          {
            takeprofit = 0;
          }
          
          flag = ExtTrade.PositionModify(ticket,stoploss,takeprofit);
          if(!flag)
          {
            Print("Order modify error %d",GetLastError());
          }
          else
          {
            GVSet("Last buy modiy price" + IntegerToString(ticket),SymbolInfoDouble(_Symbol,SYMBOL_BID));
          }
        }
        else if(GVGet("Last buy modiy price" + IntegerToString(ticket)) > 0
          &&  (SymbolInfoDouble(_Symbol,SYMBOL_BID) - GVGet("Last buy modiy price" + IntegerToString(ticket))) >= 1 * _Point)
        {
          bool flag = false;
          if(PositionGetDouble(POSITION_SL) > 0)
          {
            stoploss = PositionGetDouble(POSITION_SL) + 1 * _Point;
          }
          else
          {
            stoploss = 0;
          }
          if(PositionGetDouble(POSITION_TP) > 0)
          {
            takeprofit = PositionGetDouble(POSITION_TP) + 1 * _Point;
          }
          else
          {
            takeprofit = 0;
          }
          
          flag = ExtTrade.PositionModify(ticket,stoploss,takeprofit);
          if(!flag)
          {
            Print("Order modify error %d",GetLastError());
          }
          else
          {
            GVSet("Last buy modiy price" + IntegerToString(ticket),SymbolInfoDouble(_Symbol,SYMBOL_BID));
          }
        }
      }
     }  //Buy
     if(PositionGetInteger(POSITION_TYPE) == ORDER_TYPE_SELL)  //Sell
     {
       if(GVGet("Last sell modiy price" + IntegerToString(ticket)) <= 0
          && (PositionGetDouble(POSITION_PRICE_OPEN) - SymbolInfoDouble(_Symbol,SYMBOL_ASK)) >= 1 * _Point)
       {
          bool flag = false;
          if(PositionGetDouble(POSITION_SL) > 0)
          {
            stoploss = PositionGetDouble(POSITION_SL) - 1 * _Point;
          }
          else
          {
            stoploss = 0;
          }
          if(PositionGetDouble(POSITION_TP) > 0)
          {
            takeprofit = PositionGetDouble(POSITION_TP) - 1 * _Point;
          }
          else
          {
            takeprofit = 0;
          }
          
          flag = ExtTrade.PositionModify(ticket,stoploss,takeprofit);
          if(!flag)
          {
            Print("Order modify error %d",GetLastError());
          }
          else
          {
            GVSet("Last buy modiy price"  + IntegerToString(ticket),SymbolInfoDouble(_Symbol,SYMBOL_ASK));
          }
        }
        else if(GVGet("Last sell modiy price" + IntegerToString(ticket)) > 0
          && (GVGet("Last sell modiy price" + IntegerToString(ticket)) - SymbolInfoDouble(_Symbol,SYMBOL_ASK)) >= 1 * _Point)
        {
          bool flag = false;
          if(PositionGetDouble(POSITION_SL) > 0)
          {
            stoploss = PositionGetDouble(POSITION_SL) - 1 * _Point;
          }
          else
          {
            stoploss = 0;
          }
          if(PositionGetDouble(POSITION_TP) > 0)
          {
            takeprofit = PositionGetDouble(POSITION_TP) - 1 * _Point;
          }
          else
          {
            takeprofit = 0;
          }
          
          flag = ExtTrade.PositionModify(ticket,stoploss,takeprofit);
          if(!flag)
          {
            Print("Order modify error %d",GetLastError());
          }
          else
          {
            GVSet("Last buy modiy price"  + IntegerToString(ticket),SymbolInfoDouble(_Symbol,SYMBOL_ASK));
          }
        }
     }
  }
}

//+------------------------------------------------------------------+
//| Trade function                                                   |
//+------------------------------------------------------------------+
void OnTrade()
{
//---
}

bool IsGoodTime()
{
  if(TimeCurrent() >= StringToTime(OpeningTime) && TimeCurrent() < StringToTime(ClosingTime))
  {
    return true;
  }
  return false;
}
bool IsClosingTime()
{
  if(TimeCurrent() >= StringToTime(ClosingTime))
  {
    return true;
  }
  return false;
}


int CountAllPositions()
{
   int Positions = 0;
   for(int i=0;i < PositionsTotal();i++)
   {
      ulong ticket = OrderGetTicket(i); ///Do you need to add
      if(_Symbol == PositionGetSymbol(i))
      {
         Positions++;
      }
   }
 
   return(Positions);
}




void CheckForOpen(ENUM_ORDER_TYPE inOrderType,double inLot, double inOpenPrice, double inSL,double inTP)
{  

//--- check signals
   //ENUM_ORDER_TYPE signal=WRONG_VALUE;
   double stoploss = 0;
   double takeprofit = 0;
   
   
   if(inOrderType == ORDER_TYPE_BUY)
   {
     if(inSL > 0)
     {
       stoploss = inOpenPrice - inSL * _Point;
     }
     else
     {
       stoploss = 0;
     }
      if(inTP > 0)
     {
       takeprofit = inOpenPrice + inTP * _Point;
     }
     else
     {
       takeprofit = 0;
     }
   }
   else if(inOrderType == ORDER_TYPE_SELL)
   {
     if(inSL > 0)
     {
       stoploss = inOpenPrice + inSL * _Point;
     }
     else
     {
       stoploss = 0;
     }
      if(inTP > 0)
     {
       takeprofit = inOpenPrice - inTP * _Point;
     }
     else
     {
       takeprofit = 0;
     }
   }
   
   ExtTrade.PositionOpen(_Symbol,inOrderType,inLot, inOpenPrice,
                               stoploss,takeprofit,"");
//---
}

void MarketOrderClose(int inType)
{
 
  for(int i=0;i<PositionsTotal();i++)
  {
    //Select each order to get the order number
    ulong   ticket = PositionGetTicket(i);
    // Only process orders for our symbols
    if(PositionGetSymbol(i) == _Symbol  
       && PositionGetInteger(POSITION_TYPE) == inType)
    {  
      bool isClose = false;
      isClose = ExtTrade.PositionClose(ticket,5);
      if(!isClose)
       {
         Print("Order close error %d",GetLastError());     // If the request cannot be sent, the error code is output
       }
       else //--- Operational information
       {
         Print("Order close success.");
       }
     }
  }
 
  Sleep(100);
  for(int i=0;i<PositionsTotal();i++)
  {
    //Select each order to get the order number
    ulong   ticket = PositionGetTicket(i);
    // Only process orders for our symbols
    if(PositionGetSymbol(i) == _Symbol  
       && PositionGetInteger(POSITION_TYPE) == inType)
    {
      bool isClose = false;
      isClose = ExtTrade.PositionClose(ticket,5);
      if(!isClose)
       {
         Print("Order close error %d",GetLastError());     // If the request cannot be sent, the error code is output
       }
       else //--- Operational information
       {
         Print("Order close success.");
       }
     }
  }
}


//+------------------------------------------------------------------+
double GVGet(string name)
{
   return(GlobalVariableGet(prefix+name));
}

datetime  GVSet(string name,double value)
{
   return(GlobalVariableSet(prefix + name,value));
}

void DeleteGlobalVariables()
{
  for(int tries = 0; tries < 10; tries++)
  {
    int obj = GlobalVariablesTotal();
    for(int o = 0; o < obj;o++)
    {
      string name = GlobalVariableName(o);
      int index = StringFind(name,prefix,0);
      if(index > -1)
      {
        GlobalVariableDel(name);
      }
    }
  }
}

bool IsBuyNewBar()
{
   if((iTime(Symbol(),PERIOD_CURRENT,0) - GVGet("OrderBuyLastBar") != 0))
   {
      GVSet("OrderBuyLastBar",iTime(_Symbol,PERIOD_CURRENT,0));
      return(true);
   }
   else return(false);
}

bool IsSellNewBar()
{
   if((iTime(Symbol(),PERIOD_CURRENT,0) - GVGet("OrderSellLastBar") != 0))
   {
      GVSet("OrderSellLastBar",iTime(_Symbol,PERIOD_CURRENT,0));
      return(true);
   }
   else return(false);

Arquivos anexados:
 

Não cheguei a examinar o código, mas o motivo do erro (ou pelo menos UM DOS motivos) está claro na mensagem de erro anexa:  vc está tentando negociar volumes de 0.01, enquanto que o passo de volume do mini-índice é de 5 pontos.

No mini-índice, vc só vai poder negociar volumes múltiplos de 5, senão vai tomar esse erro aí.

 

Bruno. 

Substitua: 

input double Volume = 1.0;

por:

input int Volume = 1;
Razão: