i c u can't sleep so
Sym = Symbol(); // declare the var Sym as Symbol() TimeFrame = Period(); // declare the var TimeFrame as Period() SymPoints = MarketInfo( Sym, MODE_POINT ); // declare the var SymPoints what is the Point size in the quote currency SymDigits = MarketInfo( Sym, MODE_DIGITS ); // declare the var SymDigits how many digits after decimal point in the symbol prices //--- if( SymPoints == 0.001) // checking: if the Point size = 0.001 then { SymPoints = 0.01; SymDigits = 3; } // changing var SymPoints to 0.01 & SymDigits to 3 else if( SymPoints == 0.00001 ) // if the Point size = 0.00001 then { SymPoints = 0.0001; SymDigits = 5; } // changing var SymPoints to 0.0001 & SymDigits to 5
i c u can't sleep so
"i c u can't sleep so" ... LOL ... that's a true statement!
BTW, wrote that last night, but now it's the afternoon now where I'm am. I am still a little foggy on this part.
A couple quick questions:
You said: "// declare the var SymDigits how many digits after decimal point in the symbol prices"\
1) The statement:
if( SymPoints == 0.001)
checks to see if the double variable 'SymPoints' (the points size) is equal to 0.001. If true, then these statements:
{ SymPoints = 0.01; SymDigits = 3; }
are executed, which change the double variable 'SymPoints' to 0.01, and the int variable ' SymDigits' to 3. This I understand 100%
.
2) What I don't understand is: what exactly is the purpose of this? Is it because the rates are now quoted with 3 digits (JPY) to the right of the decimals,
and 5 decimals (EUR, GBP, etc...) ?
.
3) If so, then does that mean these statements are telling the program to ignore the last digits to the right (the 3rd or 5th or sub-pips)
and read only the 2nd and 4th? (the 'traditional pip' from the older style rates that were quoted with 2 or 4 digits to the right of the decimal) ... I'm still a bit confused.
2) What I don't understand is: what exactly is the purpose of this? Is it because the rates are now quoted with 3 digits (JPY) to the right of the decimals,
and 5 decimals (EUR, GBP, etc...) ?
.
3) If so, then does that mean these statements are telling the program to ignore the last digits to the right (the 3rd or 5th or sub-pips)
and read only the 2nd and 4th? (the 'traditional pip' from the older style rates that were quoted with 2 or 4 digits to the right of the decimal) ... I'm still a bit confused.
A) Don't assume everyone now uses 3 & 5 DP - some brokers still use 2 & 4 DP.
B) Some people/EAs still think in terms of 'old' pips & need to convert to the 'old way', as "slippage of 3 pips" say is fine for '2 & 4 DP' but not for '3 & 5 DP'
Personally, I write code that works with any number of DP, but I can't force my run-anywhere-even-furlongs-a-fortnight methodology on the rest of the world
If you want a trailing stop of say 10 pips, the value passed to the broker must be adjusted to a double. On a 4 digit broker you just multiply by Point, but on a 5 digit you multiply by 10*Point.
The problem with the above code is it does NOT adjust slippage.
//++++ These are adjusted for 5 digit brokers. double pips2points, // slippage 3 pips 3=points 30=points pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
If you want a trailing stop of say 10 pips, the value passed to the broker must be adjusted to a double. On a 4 digit broker you just multiply by Point, but on a 5 digit you multiply by 10*Point.
The problem with the above code is it does NOT adjust slippage.
OK, now I get it thanks to everyone's help here, I really appreciate it. I am working on my own EA and I was "borrowing" a section of code out of the MA Cross EA (the one that comes with MT4 platform). I had an idea but could not quite get what it was actually for. BTW, I just stumbled on a good article that deals with EAs and IBFX's new 5 dec rates. Here's the link for anyone who may need ther info:
- 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 was wondering what exactly is happening in the following block of code:
I understand the first 4 lines, I only want to know what exactly are the 'if' and 'else if' statements doing? And why? Are they saying: "If the position of the pip is 0.001, then change it to 0.01"? (Same thing with the 0.00001, changing it to 0.0001).
.
Then does that mean we are ignoring the 'sub pips' in this situation (what was the 0.00001 and the 0.001) ? ... and only using the 0.0001 and 0.01 instead, like back when when the rates were quoted with just 2 or 4 decimals instead of the newer 3 or 5 decimals. Or do I have this wrong? I have taken a couple years off from FX and a few things have changed with IBFX.
.
I have gone through the reference in the MQL4 book, as well as the dictionary in MetaEditor, and searched the forums here, but I am still unclear about this little section of code.
.
So, if somebody could explain this, I'd REALLY appreciate it. I know this is a basic question, but I'm just starting to learn MQL. TIA.