wackena posted # :
I have coded this Damiani_volatmeter.mq4 MT-4 indicator to MT-5. The output results on EURUSD M15 chart is not the same. Can someone advise why?
MT-4 version
MT-5 version
Array indexation in other party
Replace a line
double s1=ind_c[i+1]; double s3=ind_c[i+3];
on
double s1=ind_c[i-1]; double s3=ind_c[i-3];
And all will be ok.
vdv2001:
This change did not produce usable results. Pics attached.Array indexation in other party
Replace a line
on
And all will be ok.
Files:
eurusdh1z1.png
16 kb
eurusdh1-1.png
16 kb
wackena:
This change did not produce usable results. Pics attached.
This change did not produce usable results. Pics attached.
In that case it is necessary to change the approach completely.
I will try to help you.
It will take some time.
Try it
#property indicator_separate_window #property indicator_buffers 8 #property indicator_plots 3 #property indicator_color1 Silver #property indicator_type1 DRAW_LINE #property indicator_label1 "Signal" #property indicator_color2 FireBrick #property indicator_type2 DRAW_SECTION #property indicator_label2 "Main" #property indicator_color3 Lime #property indicator_type3 DRAW_LINE #property indicator_label3 "No Trade" //---- input parameters input int InpViscosity=7;//Viscosity input int InpSedimentation=50;//Sedimentation input double InpThreshold_level=1.1;//Threshold level input bool InpLag_supressor=true;//Lag supressor input double InpLag_s_K=0.5;//Lag s K //---- buffers double thresholdBuffer[]; double vol_m[]; double vol_t[]; double ind_c[]; double ExtAtrViscosity[]; double ExtAtrSedimentation[]; double ExtSteDevViscosity[]; double ExtSteDevSedimentation[]; //--- indicator handles int hAtr1; int hAtr2; int hStdDev1; int hStdDev2; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,thresholdBuffer,INDICATOR_DATA); SetIndexBuffer(1,vol_m,INDICATOR_DATA); SetIndexBuffer(2,vol_t,INDICATOR_DATA); SetIndexBuffer(3,ind_c,INDICATOR_CALCULATIONS); SetIndexBuffer(4,ExtAtrViscosity,INDICATOR_CALCULATIONS); SetIndexBuffer(5,ExtAtrSedimentation,INDICATOR_CALCULATIONS); SetIndexBuffer(6,ExtSteDevViscosity,INDICATOR_CALCULATIONS); SetIndexBuffer(7,ExtSteDevSedimentation,INDICATOR_CALCULATIONS); //--- handles init hAtr1 = iATR(NULL, 0, InpViscosity); hAtr2 = iATR(NULL, 0, InpSedimentation); hStdDev1 = iStdDev(NULL, 0, InpViscosity, 0, MODE_LWMA,PRICE_TYPICAL); hStdDev2 = iStdDev(NULL, 0, InpSedimentation, 0, MODE_LWMA,PRICE_TYPICAL); //--- return(0); } //+------------------------------------------------------------------+ //| 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[]) { //--- check for data if(rates_total<MathMax(InpViscosity,InpSedimentation)) return(0); //--- not all data may be calculated if(BarsCalculated(hAtr1)<rates_total || BarsCalculated(hAtr2)<rates_total) { Print("Not all data of ATR is calculated. Error",GetLastError()); return(0); } if(BarsCalculated(hStdDev1)<rates_total || BarsCalculated(hStdDev2)<rates_total) { Print("Not all data of StdDev is calculated. Error",GetLastError()); return(0); } //--- we can copy not all data int to_copy; if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total; else { to_copy=rates_total-prev_calculated; if(prev_calculated>0) to_copy++; } //--- get ATR buffer if(CopyBuffer(hAtr1,0,0,to_copy,ExtAtrViscosity)<=0 || CopyBuffer(hAtr2,0,0,to_copy,ExtAtrSedimentation)<=0) { Print("Getting fast ATR is failed! Error",GetLastError()); return(0); } //--- get StdDev buffer if(CopyBuffer(hStdDev1,0,0,to_copy,ExtSteDevViscosity)<=0 || CopyBuffer(hStdDev2,0,0,to_copy,ExtSteDevSedimentation)<=0) { Print("Getting fast StdDev is failed! Error",GetLastError()); return(0); } double vol=0; int limit; if(prev_calculated==0) limit=MathMax(InpViscosity,InpSedimentation); else limit=prev_calculated-MathMax(InpViscosity,InpSedimentation); for(int i=limit;i<rates_total;i++) { double s1=ind_c[i-1]; double s3=ind_c[i-3]; double atr=NormalizeDouble(ExtAtrViscosity[i],_Digits); if(InpLag_supressor) vol=ExtAtrViscosity[i]/ExtAtrSedimentation[i]+InpLag_s_K*(s1-s3); else vol=ExtAtrViscosity[i]/ExtAtrSedimentation[i]; double t=InpThreshold_level-ExtSteDevViscosity[i]/ExtSteDevSedimentation[i]; if(vol>t) { vol_t[i]=vol; vol_m[i]=vol; IndicatorSetString(INDICATOR_SHORTNAME,"DAMIANI Signal/Noise: TRADE / ATR= "+DoubleToString(atr,_Digits)+", values:"); } else { vol_t[i]=vol; vol_m[i]=EMPTY_VALUE; IndicatorSetString(INDICATOR_SHORTNAME,"DAMIANI Signal/Noise: DO NOT trade / ATR= "+DoubleToString(atr,_Digits)+", values:"); } ind_c[i]=vol; thresholdBuffer[i]=t; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
If not it.
Check up value ATR in MT5 and MT4 they different.
Thanks, I will check out the ATR difference. Please, do not spend more time on this project. Instead of using iCustom() to access indicator data, I coded EA with this code and EA works OK. Again, thanks for the help.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
I have coded this Damiani_volatmeter.mq4 MT-4 indicator to MT-5. The output results on EURUSD M15 chart is not the same. Can someone advise why?
MT-4 version
MT-5 version