I do not understand why my robot that I created does not work.

 

Indeed, I created my own robot on metaeditor 4. After compiling it, I did not notice any error, but when I put it in backtest, I noticed that no purchase or sale order is not performed. I have tried it several times, trying to start it from the graph but still no order! Help me, please! I'm wondering if I have not omitted any data in the code or should I declare myself at mql5 for my robots to work? Or maybe this picture is the cause? If it is please tell me a little about the causes!

here is the code and the image of the result of the backtest as an attachment.

I hope to receive your help

thank you, sincerely


//+------------------------------------------------------------------+
//|                                                ichimoku icci.mq4 |
//+------------------------------------------------------------------+
input double Lots = 0.01 ;
input int
StopLoss = 100,
Magic =18397 ;
extern int TrailingStop = 50 ;
void TrailingStop();
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  double 
  Signal_CCI,            //CCI
  Signal_CCI_Previous;
  double
  senkou_span_A_current, //iIchimoku
  senkou_span_B_current ;
  int 
  total,
  cnt,
  ticket;
//---
 if(Bars<100)
     {
      Print("bars less than 100");
      return;
     } 
     
//--- declaration des fonctions CCI et ICHIMOKU Kumo
  Signal_CCI =iCCI(NULL,0,14,PRICE_TYPICAL,0);            //CCI
  Signal_CCI_Previous =iCCI(NULL,0,14,PRICE_TYPICAL,1);  
  senkou_span_A_current = iIchimoku( NULL,0,9,26,52,MODE_SENKOUSPANA,0);    //iIchimoku
  senkou_span_B_current = iIchimoku( NULL,0,9,26,52,MODE_SENKOUSPANB,0);
   
  total=OrdersTotal();
  if(total<1)
     {
//--- Aucun ordre ouvert identifié
      if(AccountFreeMargin()<(1000*Lots))
         {
         Print("We have no money. Free Margin = ",AccountFreeMargin());
         return;
         }
//--- check for long position (BUY) possibility
      if( (senkou_span_A_current > senkou_span_B_current) && (OrderClosePrice() > senkou_span_A_current) )
         {
            if((Signal_CCI>Signal_CCI_Previous && Signal_CCI>-100) || (Signal_CCI>Signal_CCI_Previous && Signal_CCI>100))
            {
              ticket =OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,0,"ichimoku iCCI buy",Magic,0,Green);/* int OrderSend( string symbol, int cmd, double volume,
                                                                                                     double price, int slippage, double (stoploss), double takeprofit,
                                                                                                     string comment=NULL, int magic=0, datetime expiration=0, 
                                                                                                     color arrow_color=CLR_NONE).........ordre d'achat 
                                                                                                     (pas sure que pour le take profit ce
                                                                                                     soit 0,dans le cas echeant inserer NULL )*/
            if(ticket>0)   // ordre executer
              {
               if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                  Print("BUY order opened : ",OrderOpenPrice());
              }
            else    //ordre non exécuter
              Print("Error opening BUY order : ",GetLastError());
            return;
             } 
          }
//--- check for court position (sell) possibility
       if( (senkou_span_A_current < senkou_span_B_current && OrderClosePrice() < senkou_span_A_current) )
         {
          if((Signal_CCI<Signal_CCI_Previous && Signal_CCI>100) || (Signal_CCI<Signal_CCI_Previous && Signal_CCI<100))
            {
            ticket =OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid-StopLoss*Point,0,"ichimoku iCCI sell",Magic,0,Green);
               if(ticket>0)
               {
               if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                 Print("SELL order opened : ",OrderOpenPrice());
               }
           else
            Print("Error opening SELL order : ",GetLastError());
            }
          }
         return;
      }
//--- it is important to enter the market correctly, but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         //--- long position is opened
         if(OrderType()==OP_BUY)
           {
            //--- should it be closed?
             if( (senkou_span_A_current < senkou_span_B_current) && (OrderClosePrice() < senkou_span_A_current) )
               {
                   if((Signal_CCI<Signal_CCI_Previous && Signal_CCI>100) || (Signal_CCI<Signal_CCI_Previous && Signal_CCI<100))
                     {
               //--- close order and exit
                     if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
                      Print("OrderClose error ",GetLastError());
               return;
                     }
                }
              //--- check for trailing stop
            if(TrailingStop>0)
                {
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                  {
                   if(OrderStopLoss()<Bid-Point*TrailingStop)
                     {
                     //--- modify order and exit
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
                        Print("OrderModify error ",GetLastError());
                     return;
                     }
                  }
               }
            }
         else // go to short position
            {
            //--- should it be closed?
             if( (senkou_span_A_current > senkou_span_B_current) && (OrderClosePrice() > senkou_span_A_current) )
               {
                  if((Signal_CCI>Signal_CCI_Previous && Signal_CCI>-100) || (Signal_CCI>Signal_CCI_Previous && Signal_CCI>100))
                    {
               //--- close order and exit
               if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet))
                  Print("OrderClose error ",GetLastError());
               return;
                    }
                }
             if(TrailingStop>0)
              {
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     //--- modify order and exit
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
                        Print("OrderModify error ",GetLastError());
                     return;
                    }
                 }
              }
           }
        }
     }
//---
  }
//+------------------------------------------------------------------+

thank you, sincerely


 
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid-StopLoss*Point,0,"ichimoku iCCI sell",Magic,0,Green);

Stoploss should be higher than the entry price for a sell order

 
Keith Watford :

Stoploss should be higher than the entry price for a sell order

Hello, thank you for your answer.I will correct the code.Thanks again for your help.
 
604857:
Good evening, I finished the correction but still the same problem while I return in backtest. THANK YOU FOR YOUR ATTENTION
//+------------------------------------------------------------------+
//|                                                        final.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
input double Lots = 0.01 ;
input int
StopLoss = 10,
Magic =18397 ;
extern int TrailingStop = 10 ;
void TrailingStop();
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  double 
  Signal_CCI,            //CCI
  Signal_CCI_Previous;
  double
  senkou_span_A_current, //iIchimoku
  senkou_span_B_current ;
  int 
  total,
  cnt,
  ticket;
//---
 if(Bars<100)
     {
      Print("bars less than 100");
      return;
     } 
     
//--- declaration des fonctions CCI et ICHIMOKU Kumo
  Signal_CCI =iCCI(NULL,0,14,PRICE_TYPICAL,0);            //CCI
  Signal_CCI_Previous =iCCI(NULL,0,14,PRICE_TYPICAL,1);  
  senkou_span_A_current = iIchimoku( NULL,0,9,26,52,MODE_SENKOUSPANA,0);    //iIchimoku
  senkou_span_B_current = iIchimoku( NULL,0,9,26,52,MODE_SENKOUSPANB,0);
   
  total=OrdersTotal();
  if(total<1)
     {
//--- Aucun ordre ouvert identifié
      if(AccountFreeMargin()<(1000*Lots))
         {
         Print("We have no money. Free Margin = ",AccountFreeMargin());
         return;
         }
//--- check for long position (BUY) possibility
   if(((senkou_span_A_current > senkou_span_B_current)&&(OrderClosePrice() > senkou_span_B_current))&&
  ((Signal_CCI>Signal_CCI_Previous && Signal_CCI>-100) || (Signal_CCI>Signal_CCI_Previous && Signal_CCI>100)))
      { 
         ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Ask-StopLoss*Point,0,"ichimoku iCCI buy",Magic,0,Green);/* int OrderSend( string symbol, int cmd, double volume,
                                                                                                     double price, int slippage, double (stoploss), double takeprofit,
                                                                                                     string comment=NULL, int magic=0, datetime expiration=0, 
                                                                                                     color arrow_color=CLR_NONE)*/
          if(ticket>0)   // ordre executer
            { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print("BUY order opened : ",OrderOpenPrice());
           }
          else    //ordre non exécuter
            Print("Error opening BUY order : ",GetLastError());
      return;
        } 
//--- check for court position (sell) possibility
       if(((senkou_span_A_current < senkou_span_B_current) && (OrderClosePrice() < senkou_span_B_current)) &&
         ((Signal_CCI<Signal_CCI_Previous && Signal_CCI<100) || (Signal_CCI<Signal_CCI_Previous && Signal_CCI<-100)))
            {
            ticket =OrderSend(Symbol(),OP_SELL,Lots,Bid,5,Bid+StopLoss*Point,0,"ichimoku iCCI sell",Magic,0,Green);/*int OrderSend( string symbol, int cmd, double volume,
                                                                                                                   double price, int slippage, double (stoploss), double takeprofit,
                                                                                                                     string comment=NULL, int magic=0, datetime expiration=0, 
                                                                                                                     color arrow_color=CLR_NONE)*/
               if(ticket>0)
               {
               if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                 Print("SELL order opened : ",OrderOpenPrice());
               }
           else
            Print("Error opening SELL order : ",GetLastError());
            }
         return;
      }
//--- it is important to enter the market correctly, but it is more important to exit it correctly...   
   for(cnt=total;cnt>=0;cnt--)
       {
      if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         //--- long position is opened
         if(OrderType()==OP_BUY)
           {
            //--- should it be closed?
          if(((senkou_span_A_current < senkou_span_B_current) &&
         ((Signal_CCI<Signal_CCI_Previous && Signal_CCI<100) || (Signal_CCI<Signal_CCI_Previous && Signal_CCI<-100))))
                     {
               //--- close order and exit
                     if(!OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet))
                      Print("Order Close buy error ",GetLastError());
               return;
                     }
                //--- check for trailing stop
   if(TrailingStop>0)
                {
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                  {
                   if(OrderStopLoss()<Bid-Point*TrailingStop)
                     {
                if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,0,0,Red))   /*bool OrderModify(int ticket,
                                                                                     double price, double stoploss, 
                                                                                    doubletakeprofit, datetime expiration,
                                                                                    color arrow_color=CLR_NONE)*/
                        Print("Order Modify buy error ",GetLastError());
                     return;
                    }
                 }
              }
              }
            else // go to short position
            {
            //--- should it be closed?
            if(((senkou_span_A_current > senkou_span_B_current) && (OrderClosePrice() > senkou_span_A_current)) &&
      ((Signal_CCI>Signal_CCI_Previous && Signal_CCI>100) || (Signal_CCI>Signal_CCI_Previous && Signal_CCI>-100)))
                    {
               //--- close order and exit
               if(!OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet))
                  Print("Order Close sell error ",GetLastError());
               return;
                    }
                    //--- check for trailing stop
             if(TrailingStop>0)
              {
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     //--- modify order and exit
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid+Point*TrailingStop,0,0,Red))   /*bool OrderModify(int ticket,
                                                                                                        double price, double stoploss, 
                                                                                                        doubletakeprofit, datetime expiration,
                                                                                                        color arrow_color=CLR_NONE)*/
                        Print("Order Modify sell error ",GetLastError());
                     return;
                    }
                 }
              }
           }
        }
      }
         
//---
   
  }
//+------------------------------------------------------------------+
 

Hello,


At OP_BUY the SL is Bid-StopLoss*Point.

At OP_SELL the SL is Ask+StopLoss*Point.