- Your question makes no sense. A double has infinite digits, always. If you want to see the extra zeros when you print it
string price_as_string(double price){return DoubleToString(price, _Digits); }
- You want to use it, just use it.
- If you want to convert a price to the lower level:
Lev00Ask = MathRoundDown(MarketInfo(Pair,MODE_ASK),100*_Point); double MathNearest( double v, double to){ return to * MathRound(v / to); } double MathRoundDown(double v, double to){ return to * MathFloor(v / to); } double MathRoundUp( double v, double to){ return to * MathCeil( v / to); }
MT4:NormalizeDouble - General - MQL5 programming forum
How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum
- Your question makes no sense. A double has infinite digits, always. If you want to see the extra zeros when you print it
- You want to use it, just use it.
- If you want to convert a price to the lower level:
MT4:NormalizeDouble - General - MQL5 programming forum
How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum
Thank you for responding.
I created a function to check if a BuyStop order exist at a certain price. If not, it should place an order at that price.
But it always return false. I reckon it's because I'm comparing Lev00Ask 1.133 with OrderOpenPrice() which is 1.13300.
Please see code below
bool BuyStopExistAtLev00() { for( int i=OrdersTotal()-1;i>=0;i-- ) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==Pair && (OrderType()==OP_BUYSTOP || OrderType()==OP_BUY) && OrderOpenPrice()==Lev00Ask) return(true); } return (false); }
Thank you for responding.
I created a function to check if a BuyStop order exist at a certain price. If not, it should place an order at that price.
But it always return false. I reckon it's because I'm comparing Lev00Ask 1.133 with OrderOpenPrice() which is 1.13300.
Please see code below
This is a feature of double. Doubles are rarely equal. You should compare a difference. See the example below.
bool BuyStopExistAtLev00() { for( int i=OrdersTotal()-1;i>=0;i-- ) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==Pair && (OrderType()==OP_BUYSTOP || OrderType()==OP_BUY) && fabs(OrderOpenPrice()-Lev00Ask)<_Point*0.1) return(true); } return (false); }
This is a feature of double. Double are rarely equal. You should compare a difference. See the example below.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm learning to code.
When I execute this code, it gives me "Lev00Ask = 1.133"
I want to convert the result to 1.13300 and use it in my next calculation.
I've not been able to find a way around it.
Any help is appreciated.