Endless modifying

 

Hello,

I have a problem and can't find solution with my expert adwisor.

Maybe because I'am absolutely green in programing and it is first programing project in my life :)

The problem is, that last operator in code always is TRUE. I'am talking about this: " if(SL!=Sup-0.0005||TP!=Res+0.0005) ". Why is that? At first iteration when order stop levels not equal to NEW stop levels (sets by new support and resistance levels) this operator is realy could be TRUE - and orders are modified. But why at next tic this operator again TRUE when orders allready is modified? At each tic this operator passing control to operator body. Why is that?

When I removing these arithmetical operations (+0.0005;-0.0005) then everything is ok. But I can't remove them, because I need them.

I would be very thankful for your comments.

P.S. Sorry for my english...




   double Res;
   double Sup;
   double SLnew, TPnew;                         
      
   string symb;
       
   bool modify_conf=false;                    
   

int start()
  {
  
  // ----there are long calculation of new support and resistance levels
  //       --------------- 
  //       -------------
  //-----and result is:
  
  Res=0.9234;                                                        //new resistance level
  Sup=0.9183;                                                        //new support level
  
  Alert("Support level=",Sup,", resistance level=",Res);
 
  
 //-------search for opened BUY orders 
  
  symb=Symbol();                                                    // Security name
    
    for(int i=1; i<=OrdersTotal(); i++)                             // Loop through orders
      {
       if (OrderSelect(i-1,SELECT_BY_POS)==true)                    // If there is the next one
         {
         if (OrderSymbol()!=symb)continue;                          // Another security,continue.
         if (OrderType()!=0) continue;                              //order is not BUY,continue.
                  
         double SL=OrderStopLoss();                                 //existing orders stop level
         double TP=OrderTakeProfit();                               //existing order take profit level
         int ticket=OrderTicket();                                  //existing orders ticket
         
         Alert(SL," ",TP," ",ticket);                              //message to trader about current stop levels
         
         
 //--------orders modification        
         
       
            if(SL!=Sup-0.0005||TP!=Res+0.0005)                        //if existing order's stop levels not equal to support and resistance levels, then...
              {            
              SLnew=Sup-0.0005;                                       //new Stop level for existing order
              TPnew=Res+0.0005;                                       //new take profit level for existing order
              Alert("modifying ",ticket);
              RefreshRates();
              modify_conf=OrderModify(ticket,Ask,SLnew,TPnew,0);        //modify it!
              }
       
      
         }                             //
      }                            //exiting from order counting
      return;                                       //exit start
  }
 
margiliauskas:

Hello,

I have a problem and can't find solution with my expert adwisor.

Maybe because I'am absolutely green in programing and it is first programing project in my life :)

The problem is, that last operator in code always is TRUE. I'am talking about this: " if(SL!=Sup-0.0005||TP!=Res+0.0005) ". Why is that? At first iteration when order stop levels not equal to NEW stop levels (sets by new support and resistance levels) this operator is realy could be TRUE - and orders are modified. But why at next tic this operator again TRUE when orders allready is modified? At each tic this operator passing control to operator body. Why is that?

When I removing these arithmetical operations (+0.0005;-0.0005) then everything is ok. But I can't remove them, because I need them.

I would be very thankful for your comments.

Your English is fine . . . no problems understanding your question

First some general comments:

. . . don't do this

if (OrderType()!=0) continue;                              //order is not BUY,continue.

. . . if you are checking for a BUY then use OP_BUY it makes your code easier to understand.

Did your OrderModify() work ? don't you want to know if it did or didn't ? and if it didn't work don't you want to know why and what the values of the related variables were ?

modify_conf=OrderModify(ticket,Ask,SLnew,TPnew,0);        //modify it!

read this: What are Function return values ? How do I use them ?


It's very easy for this to be true even when you think it isn't . . .

if(SL != Sup - 0.0005 || TP != Res + 0.0005)  

. . . comparing double values has to be done with care and understanding, please read this complete thread: Can price != price ?

 

OrderOPenPrice can only be modified for pending orders and I would think for pending orders, using Ask would result in an error

modify_conf=OrderModify(ticket,Ask,SLnew,TPnew,0);        //modify it!
 
RaptorUK:

Your English is fine . . . no problems understanding your question

First some general comments:

. . . don't do this

. . . if you are checking for a BUY then use OP_BUY it makes your code easier to understand.

Did your OrderModify() work ? don't you want to know if it did or didn't ? and if it didn't work don't you want to know why and what the values of the related variables were ?

read this: What are Function return values ? How do I use them ?


It's very easy for this to be true even when you think it isn't . . .

. . . comparing double values has to be done with care and understanding, please read this complete thread: Can price != price ?

Thank you for your operative answer and useful comments. My worst nightmare is coming true - solution is floating somewhere in "can price!=price?" For newbie it will be difficult task to to find it :D

if talk about messages and confirmation to trader about modifying success, I use them. I didn't show it in my code/question. Just wanted to show real problem without "bonus material". By the way - after trying to modify allready modified order I'm receiving error code=1.

 
margiliauskas: solution is floating somewhere in "can price!=price?"

The == operand. - MQL4 forum

OrderModify with error 1 - MQL4 forum

Reason: