Order Modify Error 1 - Please help

 

Hello Experts !

 

Please find the code here. When I try to backtest it, it shows Order Modify Error 1. Your help will be highly appreciated in this regard.

 

//+------------------------------------------------------------------+
// SUPER SONIC EA BASED ON CUSTOM INDICATOR
//+------------------------------------------------------------------+


//-----------------------------------------------------------------|-----+
// INPUTS                                                          |  1  |
//-----------------------------------------------------------------|-----+

extern int        MagicNumber    =  778   ;
extern double     Lots           =  0.1   ;
extern double     StopLoss       =  0     ;
extern double     TakeProfit     =  0     ;
extern int        TrailingStop   =  0     ;
extern int        Slippage       =  3     ;

//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+

int start()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if( TotalOrdersCount()==0 ) 
  {
     int result=0;

      double SS1 = iCustom(Symbol(),0,"SS",0,1);
      double SS2 = iCustom(Symbol(),0,"SS",1,1);


     if(SS1>0) // Here is your open buy rule
     {
        result=OrderSend(Symbol(),OP_BUY,AdvancedMM(),Ask,Slippage,0,0,"SS BUY",MagicNumber,0,Blue);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
     }
     if(SS2<0) // Here is your open Sell rule
     {
        result=OrderSend(Symbol(),OP_SELL,AdvancedMM(),Bid,Slippage,0,0,"SS SELL",MagicNumber,0,Red);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
     }
  }
  
  for(int cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber 
         )  
        {
         if(OrderType()==OP_BUY)  
           {
              if(SS1<0) //here is your close buy rule
              {
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
              }
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else 
           {
                if(SS2>0) // here is your close sell rule
                {
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
                }
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
}

int TotalOrdersCount()
{
  int result=0;
  for(int i=0;i<OrdersTotal();i++)
  {
     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
     if (OrderMagicNumber()==MagicNumber) result++;

   }
  return (result);
}
double AdvancedMM()
{
 int i;
 double AdvancedMMLots = 0;
 bool profit1=false;
 int SystemHistoryOrders=0;
  for( i=0;i<OrdersHistoryTotal();i++)
  {  OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY);
     if (OrderMagicNumber()==MagicNumber) SystemHistoryOrders++;
  }
 bool profit2=false;
 int LO=0;
 if(SystemHistoryOrders<2) return(Lots);
 for( i=OrdersHistoryTotal()-1;i>=0;i--)
  {
     if(OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY))
     if (OrderMagicNumber()==MagicNumber) 
     {
        if(OrderProfit()>=0 && profit1) return(Lots);
        if( LO==0)
        {  if(OrderProfit()>=0) profit1=true;
           if(OrderProfit()<0)  return(OrderLots());
           LO=1;
        }
        if(OrderProfit()>=0 && profit2) return(AdvancedMMLots);
        if(OrderProfit()>=0) profit2=true;
        if(OrderProfit()<0 ) 
        {   profit1=false;
            profit2=false;
            AdvancedMMLots+=OrderLots();
        }
     }
  }
 return(AdvancedMMLots);
}

 Thanks for your kind help.

 

A  lot of errors inside the code  ....  Looks like you have no idea how to code yourself and copied this from somewhere

Like to know what values you did use in the backtest the coding isn't showing us 

Are they the same as you have

extern int        MagicNumber    =  778   ;
extern double     Lots           =  0.1   ;
extern double     StopLoss       =  0     ;
extern double     TakeProfit     =  0     ;
extern int        TrailingStop   =  0     ;
extern int        Slippage       =  3     ;

 inside the code or did you change it ???

 in that case if you didn't change

 

         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);

 will this lead to a result ??

 
deVries:

A  lot of errors inside the code  ....  Looks like you have no idea how to code yourself and copied this from somewhere

Like to know what values you did use in the backtest the coding isn't showing us 

Are they the same as you have

 inside the code or did you change it ???

 in that case if you didn't change

 

 will this lead to a result ??

 

 


Hi Devries !

 

Thanks for your reply. Yes I changed the SL, TP and TS while I was posting code here. You are right I have no idea about coding. So what  want to do is this:

 

I have a Custom Indicator based on which I enter BUY when it is above 0 and close the BUY when it is below (by the time it is above 0 and comes back below 0, we would have already made at least 10 pips). Vice Versa for SELL

 

So this part I entered myself:

  

double SS1 = iCustom(Symbol(),0,"SS",0,1);
double SS2 = iCustom(Symbol(),0,"SS",1,1);

 

If I put SL, TP and TS, this works fine in back-test but still some Order Moidy Errors are there in journal. Can you tell me where I am wrong or you think the whole code is wrong ?

 

Thanks for your help. 

 
12375:


Hi Devries !

I have a Custom Indicator based on which I enter BUY when it is above 0 and close the BUY when it is below (by the time it is above 0 and comes back below 0, we would have already made at least 10 pips). Vice Versa for

The way you use Slippage will lead often to  requote from your broker if you have for example EURUSD price as 1.36675  (with 5 Digits)

 

 Do you know why you have to use Slippage  in your OrderSend and OrderClose command and what value is it on 4 digit , and what value has it 5 digit accounts  how can you make it for both type accounts the same value  ??

 
deVries:

The way you use Slippage will lead often to  requote from your broker if you have for example EURUSD price as 1.36675  (with 5 Digits)

 

 Do you know why you have to use Slippage  in your OrderSend and OrderClose command and what value is it on 4 digit , and what value has it 5 digit accounts  how can you make it for both type accounts the same value  ??

 

 

 

 

 


Thanks for taking time to answer my question Devries. You are a gentleman :). I made this code from forexeadvisor.com based on MACD and then changed the code for the custom indicator. The slippage is added from the code itself, I didn't put it.

 

The problem is I am getting Order Send Errors. How can I solve this ?

 

Can you change the code  ? That would be so nice of you.

 

God Bless You

 

:) 

 
12375:


Thanks for taking time to answer my question Devries. You are a gentleman :). I made this code from forexeadvisor.com based on MACD and then changed the code for the custom indicator. The slippage is added from the code itself, I didn't put it.

 

The problem is I am getting Order Send Errors. How can I solve this ?

 

Can you change the code  ? That would be so nice of you.

 

God Bless You

 

:) 

Ofcours I can make it the way it will work correctly...  not only in tester but also on your account

 Place a Job at Jobs  for deVries  if you want me to do it for you....  

Those who wanna learn how to do get help here free for making it themselves

But if you wanna get it easie use Jobs 

 
12375: I made this code from forexeadvisor.com based on ... The slippage is added from the code itself, I didn't put it. How can I solve this ?
Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.
 
WHRoeder:
Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.


WH Roeder ! NO ONE IS ASKING YOU TO CODE IT FOR ME. YOU MAY BE A CODER BUT YOUR ATTITUDE IS USELESS.

Reason: