my EA frequently reports "OrderSend Error 130" during backtest.

 

Dear all, 

my EA frequently reports "OrderSend Error 130" during backtest. The code snippnet is as follow:

a double slprice=NormalizeDouble(High[iHighest(sym,240,MODE_HIGH,10,1)]+40*Point,Digits-1);
    ret=OrderSend(sym,OP_SELL,LotsOptimized(),Bid,3,slprice,0,"",MAGICMA,0,Red);
    return;

in the above code, slprice is used as the stoploss price in the ordersend statement. 

 I searched via google and modified my code(especially the 1st statement in the above code). But the problem remained. How should I enhance my code? Thanks a lot for your time and consideration, and, your prompt reply.

 
tzm:

Dear all, 

my EA frequently reports "OrderSend Error 130" during backtest. The code snippnet is as follow:

 I searched via google and modified my code(especially the 1st statement in the above code). But the problem remained. How should I enhance my code? Thanks a lot for your time and consideration, and, your prompt reply.

What is the point of the   ret  variable if you are not going to use it ?

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

Maybe your SL is too close to Bid ?  does your trade comply with this ?   Requirements and Limitations in Making Trades

You don't need to Normalize a price based on price values taken from a combination of OHLC or point. 

 
RaptorUK:

What is the point of the   ret  variable if you are not going to use it ?

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

Maybe your SL is too close to Bid ?  does your trade comply with this ?   Requirements and Limitations in Making Trades

You don't need to Normalize a price based on price values taken from a combination of OHLC or point. 


Dear RaptorUK,
  Many thanks for your prompt reply. The output of the ordersend is as printed follows:

Bid=1.2467, marketinfo(symbol(),MODE_StopLevel)=20, slprice=1.2456, Point=0.000010

To ensure Bid not too close to stopprice, should the following condition be met?:

Bid - STOPLOSSPrice > marketinfo(symbol(),MODE_STOPLEVEL)* Point

 if so, the first statment in the original question has already ensured the above condition to be met. Anything else is wrong?

Regards and best wishes. 


 
tzm:

Dear RaptorUK,
  Many thanks for your prompt reply. The output of the ordersend is as printed follows:

Bid=1.2467, marketinfo(symbol(),MODE_StopLevel)=20, slprice=1.2456, Point=0.000010

To ensure Bid not too close to stopprice, should the following condition be met?:

Bid - STOPLOSSPrice > marketinfo(symbol(),MODE_STOPLEVEL)* Point

 if so, the first statment in the original question has already ensured the above condition to be met. Anything else is wrong?

Regards and best wishes. 


These are the values when you had an error 130 ?  please show the lines from the log.
 

Below is what printed in the log: 

ordersend error:130
Moving Average01 EURUSD,M15: Bid=1.2461SLevel=20slprice=1.2453Point=0.000010

 

The code used to print the message is as follows, hopefully it's useful....

 

    slprice=High[iHighest(sym,tfforSL,MODE_HIGH,10,1)]+40*Point;
    ret=OrderSend(sym,OP_SELL,LotsOptimized(),Bid,3,slprice,0,"",MAGICMA,0,Red);
    if(ret<0){
      Print("ordersend error:",GetLastError());
      Print("Bid=",Bid,"SLevel=",MarketInfo(sym, MODE_STOPLEVEL), "slprice=",slprice,"Point=",DoubleToStr(Point,6));
    }
 
tzm:

Below is what printed in the log: 

So this is an OP_SELL . . .  you checked the Requirements and Limitations in Making Trades  and found that   Bid - STOPLOSSPrice > marketinfo(symbol(),MODE_STOPLEVEL)* Point   but that is for a BUY.

For a SELL     SL-Ask ≥ StopLevel  so   1.2453  -  Ask   will not be greater than 20 points ,  how do I know ?  well your Bid is 1.2461  your Ask will be above this so   1.2453  -  Ask   will give a negative number.

 

Dear RaptorUK,

  At last, I get your point. Thank you so much!

Reason: