Normalize Question

 

Hello,


Here is a bit of code


Print("High :",High[1]," Low :",Low[1],"Digits :",Digits);
Print("Normalized High :",NormalizeDouble(High[1],Digits)," Nomalized Low :",NormalizeDouble(Low[1],Digits));


And here are the results I'm getting :


2009.08.01 00:02:05 TradingExpertv16 GBPUSD,Weekly: High :1.6584 Low :1.631Digits :5
2009.08.01 00:02:05 TradingExpertv16 GBPUSD,Weekly: Normalized High :1.6584 Nomalized Low :1.631


My problem is that High and Low of the previous Bar don`t seem to return the same amount of digits which ends up causing Error 130 when I submit an order, Normalizing doesn't seem to help either .


Help ?? I`d like everthing to have the same amount of Digits as my broker is returning ..


Cheers

 

:0

To quote

stringo 2008.10.30 19:34

.........

https://docs.mql4.com/common/Print

"Data of double type are printed with 4 decimal digits after point. To output more precisely, use the DoubleToStr() function."

You can use our DoubleToStrMorePrecision from our stdlib. Also see as example CompareDoubles function in our stdlib.

.....

Good Luck

-BB-

 

Hey BarrowBoy,


Thanks for your answer, I`ve tried this :


Level = NormalizeDouble(High[1],Digits);
SL = NormalizeDouble(Low[1],Digits);


BUYPrice = DoubleToStr(Level, Digits);
SLPrice = DoubleToStr(SL, Digits);


Print("BuyPrice :",BUYPrice);
Print("Stop Loss :",SL);


But it still return this :


2009.08.01 00:25:41 TradingExpertv16 GBPUSD,Weekly: BuyPrice :1.65836
2009.08.01 00:25:41 TradingExpertv16 GBPUSD,Weekly: Stop Loss :1.631


I`m confused ...

 
julz:

Hey BarrowBoy,


Thanks for your answer, I`ve tried this :


Level = NormalizeDouble(High[1],Digits);
SL = NormalizeDouble(Low[1],Digits);


BUYPrice = DoubleToStr(Level, Digits);
SLPrice = DoubleToStr(SL, Digits);


Print("BuyPrice :",BUYPrice);
Print("Stop Loss :",SL);


But it still return this :


2009.08.01 00:25:41 TradingExpertv16 GBPUSD,Weekly: BuyPrice :1.65836
2009.08.01 00:25:41 TradingExpertv16 GBPUSD,Weekly: Stop Loss :1.631


I`m confused ...

You're almost there, but have confused yourself with a simple mistake.

Amend

Print("Stop Loss :",SL);

to

Print("Stop Loss :",SLPrice);


Or you could rid yourself of the intermediate variables by just writing:

Print("Buy Price is: ",DoubleToStr(NormalizeDouble(High[1],Digits),Digits));

Print("Stop Loss is: ",DoubleToStr(NormalizeDouble(Low[1],Digits),Digits));


CB

 

Or I`m just retarded ... thanks for spotting that !

Now, while I`m there .. The High/Low prints correctly now but I`m still getting some error 130, which, according to the docs indicates an Invalid SL, I`ve checked I`m in the right direction and that I`m > the min stop loss from my broker .

I thought it would come from my Digits, at first glance it doesn`t look like it, I`m obviously passing the Doubles to the OrderSend(), not the Str :


Ticket=OrderSend(Symb,OP_BUYLIMIT,Lot,Level,2,SL,TP);//Opening Buy


Am I making any sense ?

 
Am I making any sense ?

Maybe - could be you want a OP_BUYSTOP order type, if this is a breakout kind of EA?

Order 130 does not have just one possible cause, you have to step away from the keyboard, get a cup of coffee and think it through, one step at atime ;)

Good Luck

-BB-

 

Ah ... you nailed it !

I really need a cup of coffee now ..


Thanks for your help guys .

Reason: