Problem with double numbers

 

Hi All

Please help if you can :)

This code causes the server to return error 130 for the OrderModify command:

double sl;

double tp;

int dig = Digits;

sl = NormalizeDouble(Bid-Stoploss*Points,Digits);

tp = NormalizeDouble(Ask+TakeProfit*Points,Digits);

str_sl = DoubleToStr(sl,Digits);

str_tp = DoubleToStr(tp,Digits);

OrderModify(order_no,0,str_sl,str_tp,0,Green);

if I add the following in...

Print("sl: ",StrToDouble(str_sl)," - tp: ",StrToDouble(str_tp)," - digits: ",dig);

... it prints...

EURUSD,M15: sl: 1.3193 - tp: 1.3199 - digits: 5

From this I can see that the OrderModify is trying to use a sl with only 4 didits after the ".", where the order was opened at 1.31946 (5 digits after the ".").

I have tried everything I can think of to get the sl and tp to normalize correctly with 5 didits after the ".", but nothing I do works.

Any suggestions are welcome :)

 

Before posting please read some of the other threads . . . then you would have seen numerous requests like this one:

Please use this to post code . . . it makes it easier to read.

 

You have a few issues/misconceptions . . . .

double sl;

double tp;

int dig = Digits;

sl = NormalizeDouble(Bid-Stoploss*Points,Digits);

tp = NormalizeDouble(Ask+TakeProfit*Points,Digits);

str_sl = DoubleToStr(sl,Digits);  //  bad idea . .  .

str_tp = DoubleToStr(tp,Digits);  //  bad idea . .  .

OrderModify(order_no,0,  str_sl,str_tp,  0,Green);  //  OrderModify takes doubles for the SL & TP NOT strings

if I add the following in...

Print("sl: ",StrToDouble(str_sl)," - tp: ",StrToDouble(str_tp)," - digits: ",dig);  //  why convert a double to s str then convert a str back to a double ? ?

... it prints...

EURUSD,M15: sl: 1.3193 - tp: 1.3199 - digits: 5
 

Read the documentation for OrderModify() ( <-- click ! ! ) TP & SL are doubles . . . double stoploss, double takeprofit why are you using strings ?

Also in your OrderModify you are trying to use 0 for the Order Price . . . why not just give it OrderOpenPrice() ?

Finally, the reason that Print prints the double values with 4 digits is because that is what it does . . . read the Documentation . . . Print() "Data of double type are printed with 4 decimal digits after point. To output more precisely, use the DoubleToStr() function."

 

Thanks for your reply...

I found the problem and it had nothing to do with the decimals. My bad...


I was using the wrong calcs when working the sl and tp out.


Thanks again