- Instant Execution - Opening and Closing Positions - Trade - MetaTrader 5 for iPhone
- Instant Execution - Opening and Closing Positions - Trade - MetaTrader 5 for Android
- Request Execution - Opening and Closing Positions - Trade - MetaTrader 5 for iPhone
//++++ 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
WHRoeder I'm beginning to think you have that code sitting in a text document on your desktop, always ready for copy and paste. ;) I use it myself, although I have changed it. I place it in my init() function, followed by...
TP *= pips2dbl; SL *= pips2dbl; slip *= pips2dbl;
...and I don't use the Digits.pips.
- Anomalous:Actually I do, straight out of my EA as I watch the tester in visual mode.
WHRoeder I'm beginning to think you have that code sitting in a text document on your desktop, always ready for copy and paste. - Anomalous:I assume TP, SL are global (extern) variables. That will not work. Every parameter/TF/pair change or a chart refresh will perform an deinit/init cycle. So the slip will go 3, 30, 300, 3000...
I use it myself, although I have changed it. I place it in my init() function, followed by...TP *= pips2dbl; SL *= pips2dbl; slip *= pips2dbl;
TP/SL are prices (pips2dbl,) slippage is in points (pips2points.) What? Huh? Duh! Code correction:
int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.0015 0.00150
- Anomalous:Only used for printing
... and I don't use the Digits.pips.string PriceToStr(double p){ return(DoubleToStr(p, Digits); } string DeltaToPips(double d){ if (d > 0) string sign = "+"; else sign = ""; double pips = d / pips2dbl; return(sign + DoubleToStr(pips, Digits.pips)); } Print("TP=",PriceToStr(TP)," (",DeltaToPips(TP-Bid),")");
Gotcha. Thanks for the tips. So far my only experience is with the tester, so my code was working as I expected it to.
When you talk about this...
Every parameter/TF/pair change or a chart refresh will perform an deinit/init cycle.
...I realize there are some important things I don't understand about MT4. How does a chart refresh happen? And how do the first 3 events you mention occur without the EA being unloaded and reloaded? Are there circumstances where globals go out of scope but externs do not?
Thanks
Refresh happens via right click-> refresh. Possibly after a lost connection/relogin.
The events do NOT reload the EA, they only call deInit/init. To reload an EA you must remove it from the chart and reattach. That resets the globals.
If you close and restart the terminal, you are reloading the EA so the globals are reset, the externs will be reset to the last saved values (GUI set values, not internal modifications.)
What's the point in a global with a constant value. Use #define instead.
A global with a calculated value must be initialized. In init if constant, in start if not. "Global *= 10;" is not an initialization, it is a modification.
Externs are set with their initial values prior to init, make them read only, do not modify them.
What's the point in a global with a constant value. Use #define instead.
A global with a calculated value must be initialized. In init if constant, in start if not. "Global *= 10;" is not an initialization, it is a modification.
Externs are set with their initial values prior to init, make them read only, do not modify them.
Well I don't use globals for constants. To clarify my question:
int global = 0;
or
int global;
init() { global = 0; }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use