MQL4: logical conditions for OrderModify() - problem

 

Hi,


I have a SIMPLE PROBLEM:


There is opened BUY LIMIT order 30 pips lower than current Ask price. If the Ask price increases over 30 pips I would like to modify OpenPrice() of this order (set the OpenPrice() 30 pips lower from current Ask price AGAIN) and do it every 30 pips (not every pip but every 30 pips) until the price continues to rise. However if Ask price drops then nothing changes.


I need HELP for MQL4 SYNTAX HOW TO DO IT. What logical conditions USE to solve this PROBLEM? Has anybody any IDEA?


Thanks in advance.


Puncher,

 
puncher:

Hi,


I have a SIMPLE PROBLEM:


There is opened BUY LIMIT order 30 pips lower than current Ask price. If the Ask price increases over 30 pips I would like to modify OpenPrice() of this order (set the OpenPrice() 30 pips lower from current Ask price AGAIN) and do it every 30 pips (not every pip but every 30 pips) until the price continues to rise. However if Ask price drops then nothing changes.


I need HELP for MQL4 SYNTAX HOW TO DO IT. What logical conditions USE to solve this PROBLEM? Has anybody any IDEA?


Thanks in advance.


Puncher,

Hi,

Your code would look something like this:

int MoveEntryDif = 60; //60 because your original entry is at 30 pips away, and your modified entry will happen if price moves another 30 pips 

int MoveEntry = 30; //this is what the entry will actually move by 

 for(int i = OrdersTotal() -1; i >= 0; i--)

        {

                if(OrderSymbol() == Symbol() && OrderType() == OP_BUYLIMIT)

                        {

                                if(Ask > OrderOpenPrice() + MoveEntryDif * Point)       // This is for 4 digit brokers - if your broker is 5 digits      

                                        {                                               // then MoveEntry should be 600 - or you can use WHRoeder's excellent script

                                        OrderModify(OrderTicket(),OrderOpenPrice() + MoveEntry * Point,StopLoss,TakeProfit,0,CLR_NONE);

                                         }

                          }

        } 
 
gulzaar:
Your code would look something like this:
  1. int MoveEntryDif = 60; //60 because your original entry is at 30 pips away, and your
                           // modified entry will happen if price moves another 30 pips 

    I read the OP as wanting the limit to be at most 30 away.

  2. Don't post TABS as it makes the post unreadable
  3. You forgot the orderSelect
  4. int MaxLimit.Pips = 30;
    for(int iPos = OrdersTotal() - 1; iPos >= 0; iPos--) if(
        OrderSelect(iPos, SELECT_BY_POS)                // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair
    &&  OrderType()         == OP_BUYLIMIT
    ){
        double entry = Ask - MaxLimit.Pips * pips2dbl;
        if (entry > OrderOpenPrice(){
            if (!OrderModify(OrderTicket(), entry, OrderStopLoss(), 
                             OrderTakeProfit(), OrderExpiration())
                Alert("OrderModify failed: ", GetLastError());
        }
    }
    
 
gulzaar:

Hi,

Your code would look something like this:



ok, thx it was useful for me