How to convert the value to 4 decimal place for trade

 

Sorry newbie at work and need some advice.

I trying out my first EA and facing many error. Anyone can advice me on this issue first.

double AverageHL = HH - LL;
double p0272 = HH + (AverageHL*0.272);

OrderSend(Symbol(),OP_BUYSTOP,Lots,p0272,3,0,0,"",12321,0,Green);

I beening prompt that my entry with invalid number as it came out 8 decimal place. How should i set it to only 4 decimal place. I try using "DoubleToStr'" but still cannot, think i use wrongly. any advice. thanks

 
georgecheng:

Sorry newbie at work and need some advice.

I trying out my first EA and facing many error. Anyone can advice me on this issue first.

double AverageHL = HH - LL;
double p0272 = HH + (AverageHL*0.272);

OrderSend(Symbol(),OP_BUYSTOP,Lots,p0272,3,0,0,"",12321,0,Green);

I beening prompt that my entry with invalid number as it came out 8 decimal place. How should i set it to only 4 decimal place. I try using "DoubleToStr'" but still cannot, think i use wrongly. any advice. thanks


U need to use NormalizeDouble(). See example here -> MQL4 Reference -> Conversion functions -> NormalizeDouble

p.s. i recommend u use more descriptive variable names than something like p0272... but it's up to u.

 
Sorry guys, i tried and still fail. My order still can't excute due to, too many decimal place. any more advice? Thanks
 

dEntryPrice=NormalizeDouble(p0272,Digits);

Otherwise, show us the relevant section of code and we'll advise.


CB

 
Thanks gordon and cloudbreaker, I finally get the EA to work using your advice. It's all because I didn't place the wording correctly. Nevertheless, thanks again.
 

You can not set a buyStop closer to Ask than MODE_STOPLEVEL

dEntryPrice=MathMax(NormalizeDouble(p0272,Digits),
                   Ask+MarketInfo( Symbol(), MODE_STOPLEVEL )*Point);
Reason: