Exmaple: Bars after the last iMA crossing
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { *** //--- if(MQLInfoInteger(MQL_DEBUG) || MQLInfoInteger(MQL_VISUAL_MODE)) { ChartIndicatorAdd(0,0,handle_iMA_Fast); ChartIndicatorAdd(0,0,handle_iMA_Slow); } //--- return(INIT_SUCCEEDED); }

How to start with MQL5
- 2020.04.09
- www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
Thanks a lot! It looks like somehow I turned on the bid & ask price lines under the strat tester graph and mistook them for the MA lines! :( Any idea how I turn them off? I solved it by deleting my userdata folder and re-running the EA with your ChartIndicatorAdd() suggestion which worked.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I'm trying to just add two moving averages to a chart from an EA, creating them at OnInit() with iMA(). Both MAs are added visually to the strategy tester graph as expected, however the the moving averages are very different lines compared to if I add them manually to a chart for the same M30 pair over the same time period. Anyone know why this might be? Basically the MA's always seem to flow across the top & bottom of candles and never cross. Am I supposed to be doing something to the created indicator in OnTick or OnCalculate? I assumed that should be default.
int OnInit()
{
hEMA1 = iMA(_Symbol, PERIOD_M30, 13, 0, MODE_EMA, PRICE_CLOSE);
hEMA2 = iMA(_Symbol, PERIOD_M30, 3, 0, MODE_EMA, PRICE_CLOSE);
if(hEMA1 == INVALID_HANDLE || hEMA2 == INVALID_HANDLE) {
Print("ERROR: Create Failed, invalid handle");
}
return(INIT_SUCCEEDED);
}
If I go to an M30 pair, and manually add a MA indicator of those two periods, I get very different lines to what the strat tester ends up drawing.
Thanks for any tips!