See How to do your lookbacks correctly #9 — #14 & #19. I specifically mention MTF
However, when I try to use it with the strategy tester it does not work and I'm not able to find the problem / solution. I attach a photo where the Ema computation becomes flat.
Unfortunately this can happen with MTF indicators in the strategy tester when testing an EA.
The odd thing is, if just testing the indicator in the tester, the indicator displays correctly.
So you can just test the indicator to check whether it is a problem with the indicator.
I have found that although the indicator displays incorrectly, iCustom calls return the correct values.
Hi William Thanks for your quick reply. I tried some of your tips from your links but I broke everything in my code and I'm not sure of what I need to fix yet. Could you help me?
#property copyright "Copyright 2021, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_chart_window 1 #property indicator_buffers 1 #property indicator_color1 clrRed #property indicator_width1 2 input ENUM_TIMEFRAMES InpTimeFrame = PERIOD_H4; input int InpEmaPeriod = 8; input ENUM_MA_METHOD InpEmaMethod = MODE_EMA; input ENUM_APPLIED_PRICE InpAppliedPrice = MODE_CLOSE; int TimeFrame = InpTimeFrame; double bufferEMA[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { if(TimeFrame == PERIOD_CURRENT) TimeFrame = (ENUM_TIMEFRAMES) _Period; if(TimeFrame < _Period) return(INIT_PARAMETERS_INCORRECT); SetIndexBuffer(0, bufferEMA); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { const int lookback = TimeFrame/_Period; int iBar = rates_total - 1 - MathMax(lookback, prev_calculated); #define LAST 0 int iLast = MathMax(LAST, iBar - 2000); for(; iBar >= iLast; --iBar) { int mtfBar = iBarShift(Symbol(), TimeFrame, time[iBar]); bufferEMA[iBar] = iMA(Symbol(), TimeFrame, InpEmaPeriod, 0, InpEmaMethod, InpAppliedPrice, mtfBar); } return(rates_total); } //+------------------------------------------------------------------+
Unfortunately this can happen with MTF indicators in the strategy tester when testing an EA.
The odd thing is, if just testing the indicator in the tester, the indicator displays correctly.
So you can just test the indicator to check whether it is a problem with the indicator.
I have found that although the indicator displays incorrectly, iCustom calls return the correct values.
Hi Keith thanks for your reply. However as I'm working for a client I need to provide him the MTF indicator which shows correctly during backtesting. If I attach my indicator in real time it seems to work correctly.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Following exactly (https://www.youtube.com/watch?v=dP4VrC_nhJA&list=LL&index=2) I coded the multi timeframe ema.
However, when I try to use it with the strategy tester it does not work and I'm not able to find the problem / solution. I attach a photo where the Ema computation becomes flat.