i attach an ea to eurusd chart,the chart shows the price as five digit like 1.488888
but i use Print function to output,i got the price is 1.449.
and i got similiar result on gbpusd in the same EA .
may someone help me to explain it ? thank you
the code as follow:
......... ..................... .............
double marketask = MarketInfo(Symbol(), MODE_ASK);
double marketbid = MarketInfo(Symbol(), MODE_BID);
double midaskbid = marketbid + (marketask - marketbid) / 2.0;
................. ............ ............
double gbpmarketask = MarketInfo("GBPUSD", MODE_ASK);
double gbpmarketbid = MarketInfo("GBPUSD", MODE_BID);
double gbpmidaskbid = gbpmarketbid + (gbpmarketask - gbpmarketbid) / 2.0;
................................................
Print("midaskbid=",midaskbid);
Print("gbpmidaskbid=",gbpmidaskbid);
Print(Ask);
Print(Bid);
............ ..................... ...........
all the print result is only three digits .
Friend, you must be new to the MT4 language.
When you print a double, you need to convert your double to string format.
INSTEAD OF: Print(Ask);
DO THIS: Print(DoubleToStr(Ask, 5));
Explanation: This converts Ask into 5 digit string format.
"It is my pleasure to give back to the world. Money is not everything. Money is not power. You want power, go into politics. Sponsors are everywhere!"
Friend, you must be new to the MT4 language.
When you print a double, you need to convert your double to string format.
INSTEAD OF: Print(Ask);
DO THIS: Print(DoubleToStr(Ask, 5));
Explanation: This converts Ask into 5 digit string format.
"It is my pleasure to give back to the world. Money is not everything. Money is not power. You want power, go into politics. Sponsors are everywhere!"
thanks ,
i know it
Don't get into bad habits like that, it will bite you later
Print(DoubleToStr(Ask, Digits));Like wise TP and SL values, understand pips and points are not the same on a 5 digit broker.
external int StopPips = 15; external int SlippagePips = 3; //---- These are adjusted for 5 digit brokers. double pips2points = 1, // slippage 3 pips 3=points 30=points pips2dbl; // = Point // Stoploss 15 pips 0.0015 0.00150 int Digits.pips = 0; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init() { pips2dbl = Point; if (Digits == 3 || Digits == 5) { pips2points *= 10; pips2dbl *= 10; Digits.pips++; } } //... OrderSend(Symbol(), OP_BUY, order.lots, NormalizeDouble(order.price,Digits), SlippagePips * pips2points, 0, Bid - StopPips * pips2dbl, ...);
double gbpmidaskbid = gbpmarketbid + (gbpmarketask - gbpmarketbid) / 2.0;
double gbpmidaskbid = (gbpmarketbid + gbpmarketask ) / 2.0;
is the same thing, only easier.
Don't get into bad habits like that, it will bite you later
Like wise TP and SL values, understand pips and points are not the same on a 5 digit broker.Thanks for that. The MetaTrader Help file is less than helpful on the question of slippage.
I had a Live order drop out on me because I had what I thought was 1 pip slippage and was probably actually 0.1 pips since I use a 5 digit broker.
1. gbpmidaskbid = gbpmarketbid + (gbpmarketask - gbpmarketbid)/2;
2. gbpmidaskbid = gbpmarketbid + gbpmarketask/2 - gbpmarketbid/2;
3. gbpmidaskbid = gbpmarketbid - gbpmarketbid/2 + gbpmarketask/2;
4. gbpmidaskbid = gbpmarketbid/2 + gbpmarketask/2;
5. gbpmidaskbid = (gbpmarketbid + gbpmarketask)/2;
6. gbpmidaskbid = (gbpmarketbid + gbpmarketask ) / 2.0;
7. => 5.=6. ergo 1.=6.
8. q.e.d.
- 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 attach an ea to eurusd chart,the chart shows the price as five digit like 1.488888
but i use Print function to output,i got the price is 1.449.
and i got similiar result on gbpusd in the same EA .
may someone help me to explain it ? thank you
the code as follow:
......... ..................... .............
double marketask = MarketInfo(Symbol(), MODE_ASK);
double marketbid = MarketInfo(Symbol(), MODE_BID);
double midaskbid = marketbid + (marketask - marketbid) / 2.0;
................. ............ ............
double gbpmarketask = MarketInfo("GBPUSD", MODE_ASK);
double gbpmarketbid = MarketInfo("GBPUSD", MODE_BID);
double gbpmidaskbid = gbpmarketbid + (gbpmarketask - gbpmarketbid) / 2.0;
................................................
Print("midaskbid=",midaskbid);
Print("gbpmidaskbid=",gbpmidaskbid);
Print(Ask);
Print(Bid);
............ ..................... ...........
all the print result is only three digits .