Download MetaTrader 5

Help for modify pending order

To add comments, please log in or register
Daminda
110
Daminda  

 I need to modify BuyStop order when market revers with keeping 2 pips Gap. i use this following code. but it is not working. someone help me to fix it.

 

void BuyStopModify()
{
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_BUYSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
        {

           if (OrderOpenPrice()-Ask<Gap*point)

 {

OrderModify(OrderTicket(), OrderOpenPrice(), Ask-Stoploss*point, Ask+TakeProfit*point, 0, Blue);

return (0);

        }
    }
    
}
Keith Watford
Moderator
10614
Keith Watford  

If I understand you correctly, you wish to modify the price that the pending order will open at?

OrderModify(OrderTicket(), OrderOpenPrice(), Ask-Stoploss*point, Ask+TakeProfit*point, 0, Blue);

 You are not modifying the opening price.

Also SL and TP should be calculated in relation to the new opening price, not the current Ask 

Daminda
110
Daminda  
thanks for comment Gumrai.. can you correct my code?
Keith Watford
Moderator
10614
Keith Watford  
daminda1989:
thanks for comment Gumrai.. can you correct my code?
Yes, I probably can. But it is better for you to try to correct the code and post your attempt. Then you will get further advice and will learn a little bit more.
Daminda
110
Daminda  
i tried more times changing code. but still i can't write code... i will try to calculate SL & TP. but can you tell me price calculation. it is difficult for me...
Keith Watford
Moderator
10614
Keith Watford  
daminda1989:
i tried more times changing code. but still i can't write code... i will try to calculate SL & TP. but can you tell me price calculation. it is difficult for me...

When I was first learning how to code, I had replies from RaptorUK and WHRoeder that didn't give the complete answer, but made me think. Always made me post my own attempt at the solution.

Believe me, if you are just handed the solution to your problem with no effort on your own behalf, you will learn nothing.

I am not the best coder, but I am a much better coder than I would have been without the input of  RaptorUK and WHRoeder.

Daminda
110
Daminda  
GumRai:

When I was first learning how to code, I had replies from RaptorUK and WHRoeder that didn't give the complete answer, but made me think. Always made me post my own attempt at the solution.

Believe me, if you are just handed the solution to your problem with no effort on your own behalf, you will learn nothing.

I am not the best coder, but I am a much better coder than I would have been without the input of  RaptorUK and WHRoeder.

 

ok Gumrai, i will try to write code.... can you tell mw, where the best place to learning mql4?
SYED NAUFAL GADDAFI
1399
SYED NAUFAL GADDAFI  

https://docs.mql4.com/

https://book.mql4.com/

Daminda
110
Daminda  
deysmacro:

https://docs.mql4.com/

https://book.mql4.com/

thanks
whroeder1
16105
whroeder1  
daminda1989:  I need to modify BuyStop order when market revers with keeping 2 pips Gap. i use this following code.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. The closest you can put it is MarketInfo(market_pair, MODE_STOPLEVEL) * Point.
  3. Why use a BuyStop and move it. Stops and Limits are for Humans that can't watch the market every tick. EA's can. Just remember your trigger price and open when market reaches it.
    #define INF 0x6FFFFFFF  // Not quite infinite, Jul 2029, or 1,879,048,191
    double triggerBuy;
    OnInit(){ triggerBuy = INF;
    OnTick(){
       :
       if(nOrders > 0) triggerBuy = INF;
       else{
          triggerBuy = MathMin(triggerBuy, Bid + Gap * point);
          if(Bid >= triggerBuy) OpenBuy();
    
  4. learn to code
  5. Check your return codes (OrderModify) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Daminda
110
Daminda  
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. The closest you can put it is MarketInfo(market_pair, MODE_STOPLEVEL) * Point.
  3. Why use a BuyStop and move it. Stops and Limits are for Humans that can't watch the market every tick. EA's can. Just remember your trigger price and open when market reaches it.
  4. learn to code
  5. Check your return codes (OrderModify) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

i will use SRC button for code next time....

i need bustop move if market goes reverse side. if market goes right side need to stop moving & pending order will be filled. 

To add comments, please log in or register