OrderModify Error 0, Error Description = no error - page 2

 
/-------------------------------------------------------------------------------------------
// Set Trailing Stop
//-------------------------------------------------------------------------------------------

string Symb=Symbol();                            // Symbol


//------------------------------------------------------------------------------- 2 --

   for(i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
   {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {                                       // Analysis of orders:
         int Tipo=OrderType();                   // Order type
         if(OrderSymbol()!=Symb||Tipo>1)continue;// The order is not "ours"
         SL=OrderStopLoss();                     // SL of the selected order
         //---------------------------------------------------------------------- 3 --
         while(true)                            // Modification cycle
           {
            //double TS=Trail_Stop;                // Initial value
            double  TS=NormalizeDouble(Trail_Stop*StopMultd,Digits); //cambie TS por este valor normalizado
            int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);  //Min. distance
            if (TS < Min_Dist)                             // If less than allowed
            TS=Min_Dist;                                   // New value of TS
            //------------------------------------------------------------------- 4 --
            bool Modify=false;                  // Not to be modified
            switch(Tipo)                         // By order type
              {
               case 0 :                         // Order Buy
                  if (NormalizeDouble(SL,Digits)<           
                     NormalizeDouble(Bid-TS*dblPoints,Digits))    // If it is lower than we want
                    {
                     SL=Bid-TS*dblPoints;           // then modify it
                     string Text=" Buy ";        // Text for Buy 
                     Modify=true;               // To be modified
                    }
                  break;                        // Exit 'switch'
               case 1 :                         // Order Sell
                  if (NormalizeDouble(SL,Digits)> 
                     NormalizeDouble(Ask+TS*dblPoints,Digits)  // If it is higher than we want
                     || NormalizeDouble(SL,Digits)==0)     //or equal to zero
                    {
                     SL=Ask+TS*dblPoints;           // then modify it
                     Text=" Sell ";              // Text for Sell 
                     Modify=true;               // To be modified
                    }
              }                                 // End of 'switch'
            if (Modify==false)                  // If it is not modified
               break;                           // Exit 'while'
            //------------------------------------------------------------------- 5 --
            TP    =OrderTakeProfit();           // TP of the selected order
            double Price =OrderOpenPrice();     // Price of the selected order
            int    Ticket=OrderTicket();        // Ticket of the selected order
 
            Alert ("Modification to",Text,"#",Ticket," - Awaiting response..");
            bool Ans=OrderModify(Ticket,Price,SL,TP,0);//Modify it!
            //------------------------------------------------------------------- 6 --
            if (Ans==true)                      // Got it! :)
              {
               Alert ("Order ",Text,Ticket," is modified:)");
               break;                           // From modification cycle.
              }

Now it should look clearer.

thanks in advance for your help

 
And please take note that I just created this function to verify if the problem is in using " Points " correctly since I use a 5 digit broker
double dblPoints;


 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()


double GetPoints()                               // declaration of function GetPoints()
{ if (Digits == 3 || Digits == 5) dblPoints=Point*10; 
  else dblPoints=Point; 
  return(dblPoints); 
}
 
Justhavingfun: Now it should look clearer.

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.
    EDIT your original post not leave it and add another.

  2. mql4newbie: When I modify my stop loss of an open order, I get this weird Error number 0 with the error description "no error". My result is a FALSE and I cannot understand why.
    You get this when you look at the error number (GetLastError() or _LastError) after a call that successfully completes. Don't look at it unless, e.g. OrderModify returns false.
  3. BarrowBoy: One usual cause is where you OrderModify (for example to move a trailing stop) but actually send unchanged values
    If that was the case you/he would get error 1 OrderModify error 1 during back testing - MQL4 forum
 
//---------------------------------------------------------------------------------  
//  function Trailing Stop
//---------------------------------------------------------------------------------

bool Trailing_Stop(int Stop,int Multd)
{
 string Symb=Symbol();                          // Symbol
 int Tipo=OrderType();                          // Order type
 int i;
 for(i=1; i<=OrdersTotal(); i++)                // Cycle searching in orders
    {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // Select if the next is available
        {                                       // Analysis of orders:
         if(OrderSymbol()!=Symb||Tipo>1)continue;// The order is not "ours"
         double SL=OrderStopLoss();              // SL of the selected order
         while(true)                            // Modification cycle
           {
            double TS=Stop*Multd;               // Valor del Trail Stop x 10
            int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);  //Min. distance
            if (TS < Min_Dist)                  // If less than allowed
            TS=Min_Dist;                        // New value of TS
            bool Modify=false;                  // start with a Not to be modified instruction
            switch(Tipo)                        // Evaluate By order type
              {
               case 0 :                         // Order Buy
                       SL=NormalizeDouble(Bid-TS*Point,Digits);   // calculate new SL
                       if(OrderStopLoss()<SL)    // If Order Stop Loss is lower than what we want
                         {
                          string Text=" Buy ";       // Text for Buy 
                          Modify=true;               // To be modified
                         }
                       break;                        // Exit 'switch'
               case 1 :                              // Order Sell
                       SL=NormalizeDouble(Ask+TS*Point,Digits);           // then modify it
                       if(OrderStopLoss()>SL)        // If Order Stop LOss is higher than what we want
                         {
                          Text=" Sell ";             // Text for Sell 
                          Modify=true;               // To be modified
                         }
              }                                      // End of 'switch'
            if(Modify==false)break;                  // If it is not modified exit while            
            Alert ("Modification to",Text,"#",OrderTicket()," - Awaiting response..");
            bool Ans=OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0);    //Modify it!
            if (Ans==true)                          // Got it! :)
              {
               Alert ("Order ",Text,OrderTicket()," is modified:)");
               break;                               // From modification cycle.
              }
            break;                                  // From modification cycle
           }                                        // End of modification cycle while (true)
         }                                          // End of order analysis
     }                                              // End of order search
  return(Ans);
 }

Hi guys


I have created this Function to perform the Trailing Stop feature, it is very helpful

and it can be used on any EA, it works very well

since I copied most of this code from somene else and I am very pleased with it, I just wanted to publish the function I created and maybe help someone else with it too

important notes:

bool Trailing_Stop(int Stop,int Multd)

the function uses just two parameters:

Stop: is the size of the trailing stop in pips, for example Stop=20 pips

Multd: factor to be used in case your broker is a 5 digit broker instead of a 4 digit broker. If this is the case Multd=10. If you use a 4 digit broker use Multd=1.

 

 
Roberto Dasso:

Hi guys


I have created this Function to perform the Trailing Stop feature, it is very helpful

and it can be used on any EA, it works very well

since I copied most of this code from somene else and I am very pleased with it, I just wanted to publish the function I created and maybe help someone else with it too

important notes:

the function uses just two parameters:

Stop: is the size of the trailing stop in pips, for example Stop=20 pips

Multd: factor to be used in case your broker is a 5 digit broker instead of a 4 digit broker. If this is the case Multd=10. If you use a 4 digit broker use Multd=1.

 

I have same problem now what i do
Files:
Image_1_y15.jpg  251 kb
 
Dr Waleed Mahdy: I have same problem now what i do
  1. Understand what the thread tells you
  2. You
    Server
    Change the SL to XIt is at X!
    Change the SL to XIt is at X!
    Change the SL to XYou are insane
 
whroeder1:
  1. Understand what the thread tells you
  2. You
    Server
    Change the SL to XIt is at X!
    Change the SL to XIt is at X!
    Change the SL to XYou are insane


how i can solve it my friend

the expert is working good 

or not 

 
Dr Waleed Mahdy: how i can solve it
Don't modify the order if nothing needs to change.
 
whroeder1:
Don't modify the order if nothing needs to change.

thanks my friend
Reason: