Hi, I have rewritten an indicator from MQL4 to MQL5, but it is not displayed correctly. When I reload it, it shows different values than before.
I don't know why, but the "iMAOnArrayMQL4" doesn't seem to be working properly.
Use "MovingAverages.mqh" instead.
#property indicator_chart_window #property indicator_buffers 6 #property indicator_plots 4 #include <MovingAverages.mqh> #property indicator_label1 "1" //"Blue Line" #property indicator_type1 DRAW_LINE #property indicator_color1 clrBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 2 #property indicator_label2 "2" //"Red Line" #property indicator_type2 DRAW_LINE #property indicator_color2 clrRed #property indicator_style2 STYLE_SOLID #property indicator_width2 2 #property indicator_label3 "3" //"Red Line" #property indicator_type3 DRAW_LINE #property indicator_color3 clrRed #property indicator_style3 STYLE_SOLID #property indicator_width3 2 #property indicator_label4 "4" //"Blue Line" #property indicator_type4 DRAW_LINE #property indicator_color4 clrBlue #property indicator_style4 STYLE_SOLID #property indicator_width4 2 input int num40 = 40; //double appliedprice = 0.0; int num = 0;
int OnInit()
//result = num40 + MathFloor(MathSqrt(num40)); for (int i = 1; i <= MathFloor(MathSqrt(num40)); i++) num += i;
int OnCalculate
int copied1 = CopyBuffer(MovingAverage1, 0, 0, rates_total, MovingAverageBuffer1); int copied2 = CopyBuffer(MovingAverage2, 0, 0, rates_total, MovingAverageBuffer2); /*int currentbarscounted = prev_calculated - 1; if (currentbarscounted < 1) { for (int i = 1; i <= result; i++) ind2[Bars(_Symbol, _Period) - i] = 0; for (int i2 = 1; i2 <= num40; i2++) ind3[Bars(_Symbol, _Period) - i2] = 0; } if (currentbarscounted > 0) currentbarscounted--; int startpoint = Bars(_Symbol, _Period) - 2; //currentbarscounted;*/ // for (int j = 0; j < startpoint; j++) ind3[j] = 2.0 * iMAMQL4(NULL, 0, MathFloor(num40 / 2), 0, MODE_LWMA, PRICE_CLOSE, j) - iMAMQL4(NULL, 0, num40, 0, MODE_LWMA, PRICE_CLOSE, j); int startpoint; if (prev_calculated == 0) startpoint = num40; else startpoint = prev_calculated - 1; for (int j = startpoint; j < rates_total; j++) ind3[j] = 2.0 * MovingAverageBuffer1[j] - MovingAverageBuffer2[j]; LinearWeightedMAOnBuffer(rates_total, prev_calculated, num40, (int)MathFloor(MathSqrt(num40)), ind3, ind2, num); //for (int j2 = startpoint; j2 < rates_total; j2++) //ind2[j2] = iMAOnArrayMQ4(ind3, 0, MathFloor(MathSqrt(num40)), 0, MODE_LWMA, j2); for (int k = startpoint; k < rates_total; k++) { if (ind3[k] > ind2[k]) { ind0[k] = high[k]; ind1[k] = low[k]; } else { if (ind3[k] < ind2[k]) { ind1[k] = high[k]; ind0[k] = low[k]; } } }
Maybe these articles help you:
https://www.mql5.com/de/articles/66
https://www.mql5.com/de/articles/81
Transferring Indicators from MQL4 to MQL5
- www.mql5.com
Hello dear readers! In today's article I'm going to represent you an algorithm of transferring simple price calculations from MQL4 to MQL5. With a glance to the difference between MQL5 and MQL4 I added the library of functions mql4_2_mql5.mqh ; we will learn how to use it after reading this article. 1. Preparing an Indicator for Transferring...
Nagisa Unada:
I don't know why, but the "iMAOnArrayMQL4" doesn't seem to be working properly.
Use "MovingAverages.mqh" instead.
int OnInit()
int OnCalculate
Many, many thanks!!! You have really helped me a lot.
Carl Schreiber:
Maybe these articles help you:
https://www.mql5.com/de/articles/66
https://www.mql5.com/de/articles/81
Thanks, but I already know the article.
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