Hi guys,
i had problems with one of my EAs, after normalizing prices i still got outputs like this:
I dont know why this is there, considering all prices are normalized.Ill send my code, if someone could help!
Thanks
It is happening when printing a Normalized Double. Use DoubleToString() to avoid this when using Print().
Here it is from the documentation.
"Please note that when output to Journal using the Print() function, a normalized number may contain a greater number of decimal places than you expect..."
- docs.mql4.com
Well, I removed all Normalize Doubles, but this still appears, and the tester returns 4501(because it pput the TP and SL in OrderModify).Ive accounted for stoplevel, price decimals, refresh rate, and so on, but nothing! I think it could be because of this(of the many decimals, so that price>price)
any one, any ideas how to solve it?
Thanks
double stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL)*point; //====== =========== ============ ======================= if(!AreThereOrders() && rsi0>rsi_buylevel && stoch0>stoch_buylevel && maFast_0>maSlow_0 && maFast_1<maSlow_1) // Order 1 setup { for(int i=OrdersTotal()-1;i>=0;i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderMagicNumber()==magic && OrderSymbol()==Symbol() && OrderType()==OP_SELL) { bool close=OrderClose(OrderTicket(),OrderLots(),Ask,slippage,clrNONE); } } RefreshRates(); if(CheckMoneyForTrade(Symbol(),LotSize,0)==false) return; //======================================================== SL=Bid-stoploss*point; if(stoploss*point<stoplevel)SL=Bid-stoplevel; if(stoploss==0 && stoploss==0)SL=0; TP=Bid+takeprofit*point; if(takeprofit*point<stoplevel)TP=Bid+stoplevel; if(takeprofit==0 && stoplevel==0)TP=0; //====================================================== ticket=OrderSend(Symbol(),OP_BUY,NormalizeLots(LotSize),Ask,slippage*pips2points,0,0,NULL,magic,0,clrGreen); RefreshRates(); if(ticket>0) { Print("Order Opened BUY !!"); } else Print("Error occured BUY not sent! Error code :",GetLastError()); } //--- check for short position (SELL) possibility else if(!AreThereOrders() && rsi0<rsi_selllevel && stoch0<stoch_selllevel && maFast_0<maSlow_0 && maFast_1>maSlow_1) { for(int i=OrdersTotal()-1;i>=0;i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderMagicNumber()==magic && OrderSymbol()==Symbol() && OrderType()==OP_BUY) { bool close=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,clrNONE); } } RefreshRates(); if(CheckMoneyForTrade(Symbol(),LotSize,1)==false) return; //======================================================== SL=Ask+stoploss*point; if(stoploss*point<stoplevel)SL=Ask+stoplevel; if(stoploss==0 && stoplevel==0)SL=0; TP=Ask-takeprofit*point; if(takeprofit*point<stoplevel)TP=Ask-stoplevel; if(takeprofit==0 && stoplevel==0)TP=0; //======================================================================= ticket=OrderSend(Symbol(),OP_SELL,NormalizeLots(LotSize),Bid,slippage*pips2points,0,0,NULL,magic,0,clrRed); RefreshRates(); if(ticket>0) { Print("Order Opened SELL !!"); } else Print("Error occured SELL not sent! Error CODE:",GetLastError()); } }
Well, I removed all Normalize Doubles, but this still appears, and the tester returns 4501(because it pput the TP and SL in OrderModify).Ive accounted for stoplevel, price decimals, refresh rate, and so on, but nothing! I think it could be because of this(of the many decimals, so that price>price)
any one, any ideas how to solve it?
Thanks
Don't remove all the NormalizeDouble(), I said you don't need to use it for Ask and Bid.
and as mentioned in the Documentation use DoubleToString() when printing a Normalized Double.
Print(DoubleToString(TP,Digits)," TP ",DoubleToString(SL,Digits)," SL ");
Alternative(better) function for NormalizeDouble() https://www.mql5.com/en/forum/146370#comment_3693988
- 2013.08.16
- www.mql5.com
Well Ive normalize them back, but this appeared.Just to see i set Double ToStr with 16decimal places to see if it will be only 0000 after the fifth sign, but apparently not! Could this be causing 4501 error (invalid param value)?
Thanks
Well Ive normalize them back, but this appeared.Just to see i set Double ToStr with 16decimal places to see if it will be only 0000 after the fifth sign, but apparently not! Could this be causing 4501 error (invalid param value)?
Thanks
I don't think so. I think you are referring to error 130 (trade server). I don't think so. But also check out that alternative function, NormalizePrice(), in the link I gave above.
But can the SL/TP be modified for pips and also normalized with the Normalized Price f-n ?
-
Floating point has infinite number of decimals, it's your not understanding
floating point and that some numbers can't be represented exactly. (like 1/10.)
Double-precision floating-point format - Wikipedia, the free encyclopediaSee also The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum
Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.
-
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't
use it. It's use is usually wrong, as it is in this case.
- Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 and MetaTrader 4 - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 and MetaTrader 4 - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys,
i had problems with one of my EAs, after normalizing prices i still got outputs like this:
I dont know why this is there, considering all prices are normalized.Ill send my code, if someone could help!
Thanks