HELP・HELP・HELP

 

Dear,why dose below program always display  ” ordermodify error 130 ” ?

 

 void OnTick()

  {

//---

if(Hour() == 1 && OrdersTotal() == 0)

{

int ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,NULL,1,0,NULL);

       for(int i=0;i<=OrdersTotal();i++)

           {

            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true && OrderType() == OP_SELL && OrderMagicNumber() == 1)

               {

                //--- calculated SL and TP prices must be normalized 

    double stoploss=NormalizeDouble(Bid-80*Point,Digits); /*Digits=3*/

    double takeprofit=NormalizeDouble(Bid+80*Point,Digits); 

                  int rsp = OrderModify(OrderTicket(),OrderOpenPrice(),stoploss,takeprofit,0,NULL);

                }

           }

       }

  }

 

thank you! 

 

 <journal>

2016.01.11 21:20:34.160 USDJPY-a01,M30: 2160205 tick events (2342 bars, 2161205 bar states) processed in 0:00:03.307 (total time 0:00:05.928)

2016.01.11 21:20:34.160 2015.12.29 23:59  Tester: order #1 is closed

2016.01.11 21:20:30.853 2015.10.01 01:00  rr USDJPY-a01,M30: OrderModify error 130

2016.01.11 21:20:30.853 2015.10.01 01:00  rr USDJPY-a01,M30: open #1 sell 0.10 USDJPY-a01 at 119.866 ok

2016.01.11 21:20:30.851 2015.10.01 00:00  rr test started

2016.01.11 21:20:30.282 TestGenerator: spread set to 10

 

You are opening a Sell then trying to modify it with a stoploss below the entry price and a Take profit above the entry price.

Of course you get the invalid stops error 

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

  2. int ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,NULL,1,0,NULL);
    Check your return codes 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
  3. OrderSend takes a Color for the arrow; NULL is not a color.
  4. for(int i=0;i<=OrdersTotal();i++)
    Position total will never exist.
  5. if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true && OrderType() == OP_SELL && OrderMagicNumber() == 1)
    You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
  6. double stoploss=NormalizeDouble(Bid-80*Point,Digits);
    double takeprofit=NormalizeDouble(Bid+80*Point,Digits);
    1. You buy at the ask; sell at the bid. So for sell orders, the stops are buy orders.
    2. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
    3. For sell orders the SL must be above the market.
Reason: