Help for modify pending order

Back to topics list To post a new topic, please log in or register
avatar
9
daminda1989 2015.02.03 09:25
 

 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);

        }
    }
    
}
avatar
Moderator
3412
GumRai 2015.02.03 09:39 #
 

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 

 

avatar
9
daminda1989 2015.02.03 09:44 #
 
thanks for comment Gumrai.. can you correct my code?
avatar
Moderator
3412
GumRai 2015.02.03 12:43 #
 
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.
avatar
9
daminda1989 2015.02.03 12:55 #
 
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...
avatar
Moderator
3412
GumRai 2015.02.03 14:15 #
 
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.

 

avatar
9
daminda1989 2015.02.03 14:20 #
 
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?
avatar
1211
deysmacro 2015.02.03 15:11 #
 

https://docs.mql4.com/

https://book.mql4.com/

avatar
9
daminda1989 2015.02.03 15:43 #
 
deysmacro:

https://docs.mql4.com/

https://book.mql4.com/

thanks
avatar
12992
WHRoeder 2015.02.03 15:44 #
 
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
avatar
9
daminda1989 2015.02.03 16:54 #
 
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. 

Back to topics list  

To add comments, please log in or register