This Is MQL4 Indicator, I Was Try To Convert
//+------------------------------------------------------------------+ //| Value chart.mq4 | //| | //| Helweg/Stendahl value charts | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" #property indicator_separate_window #property indicator_buffers 5 #property indicator_color3 Gold #property indicator_color4 PaleVioletRed #property indicator_color5 DeepSkyBlue #property indicator_width4 1 #property indicator_width5 1 #property indicator_level1 -8.0 #property indicator_level2 -4.0 #property indicator_level4 4.0 #property indicator_level5 8.0 #property indicator_levelcolor MediumOrchid // // // // // extern int magicNumber = 1; extern int numberOfBars = 70; extern bool showLineChart = false; extern string _ = "Bars settings"; extern color colorBarDown = Red; extern color colorBarUp = LimeGreen; extern color colorBarNeutral = Snow; extern color colorWickUp = LimeGreen; extern color colorWickDown = Red; extern color colorWickNeutral = Snow; extern int widthWick = 1; extern int widthBody = 3; extern string __ = "Line chart settings"; extern int linePrice = PRICE_CLOSE; extern string ___ = "Oma averages settings"; extern int OmaLength1 = 20; extern double OmaSpeed1 = 8.0; extern bool OmaAdaptive1 = true; extern int OmaLength2 = 50; extern double OmaSpeed2 = 8.0; extern bool OmaAdaptive2 = true; // // // // // extern bool alertsOnOmasCross = true; extern bool alertsOn = true; extern bool alertsOnCurrent = true; extern bool alertsMessage = true; extern bool alertsSound = false; extern bool alertsEmail = false; // // // // // string name; int window; double hiBuffer[]; double loBuffer[]; double prBuffer[]; double paBuffer[]; double pbBuffer[]; double maBuffer[]; double mbBuffer[]; double vaBuffer[]; double trend[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int init() { IndicatorBuffers(8); SetIndexBuffer(0,hiBuffer); SetIndexStyle(0,DRAW_NONE); SetIndexBuffer(1,loBuffer); SetIndexStyle(1,DRAW_NONE); SetIndexBuffer(2,prBuffer); SetIndexBuffer(3,maBuffer); SetIndexDrawBegin(3,OmaLength1); SetIndexBuffer(4,mbBuffer); SetIndexDrawBegin(4,OmaLength2); if (showLineChart) SetIndexStyle(2,DRAW_LINE); else SetIndexStyle(2,DRAW_NONE); if (OmaLength1>1) SetIndexStyle(3,DRAW_LINE); else SetIndexStyle(3,DRAW_NONE); if (OmaLength2>1) SetIndexStyle(4,DRAW_LINE); else SetIndexStyle(4,DRAW_NONE); SetIndexBuffer(5,paBuffer); SetIndexBuffer(6,pbBuffer); SetIndexBuffer(7,vaBuffer); OmaLength1 = MathMax(OmaLength1,1); OmaLength2 = MathMax(OmaLength2,1); OmaSpeed1 = MathMax(OmaSpeed1,-1.5); OmaSpeed2 = MathMax(OmaSpeed2,-1.5); numberOfBars = MathMax(numberOfBars,5); name = "Value chart Oma ("+numberOfBars+","+magicNumber+")"; IndicatorShortName(name); return (0); } int deinit() { string oName; for (int i = ObjectsTotal() - 1; i >= 0; i--) { oName = ObjectName(i); if (StringFind(oName, name, 0) >= 0) ObjectDelete(oName); } return (0); } // // // // // 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[]) { int counted_bars = IndicatorCounted(); int i,k,r,limit; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit = MathMin(Bars-counted_bars,Bars-2); window = WindowFind(name); if (counted_bars == 0) { for (i=0;i<OmaLength1;i++) { paBuffer[Bars-i-1] = 0; maBuffer[Bars-i-1] = 0; } for (i=0;i<OmaLength2;i++) { pbBuffer[Bars-i-1] = 0; mbBuffer[Bars-i-1] = 0; } } if (ArraySize(trend)!=Bars) ArrayResize(trend,Bars); // // // // // int nVarP = MathRound(numberOfBars/5.0); double nVarA,nVarB,nVarC,nVarD,nVarE; double nVarR1,nVarR2,nVarR3,nVarR4,nVarR5; double nLRange; Comment(limit," \n", counted_bars); for (i=limit, r=Bars-i-1; i>=0; i--,r++) { // // // // // if (numberOfBars<7) { if (MathAbs(Close[i]-Close[i+1]) >= (High[i]-Low[i])) nVarA = MathAbs(Close[i]-Close[i+1]); else nVarA = (High[i]-Low[i]); vaBuffer[i] = nVarA; // // // // // double average=0; for (k=0; k<5; k++) average += vaBuffer[i]; average /= 5; nLRange = average*0.2; } else { nVarA = iHighesti(nVarP,i)-iLowesti(nVarP,i); if (nVarA == 0 && nVarP == 1) nVarR1 = MathAbs(Close[i]-Close[i+nVarP]); else nVarR1 = nVarA; nVarB = iHighesti(nVarP,i+nVarP+1)-iLowesti(nVarP,i+nVarP); if (nVarB == 0 && nVarP == 1) nVarR2 = MathAbs(Close[i+nVarP]-Close[i+nVarP*2]); else nVarR2 = nVarB; nVarC = iHighesti(nVarP,i+nVarP*2)-iLowesti(nVarP,i+nVarP*2); if (nVarC == 0 && nVarP == 1) nVarR3 = MathAbs(Close[i+nVarP*2]-Close[i+nVarP*3]); else nVarR3 = nVarC; nVarD = iHighesti(nVarP,i+nVarP*3)-iLowesti(nVarP,i+nVarP*3); if (nVarD == 0 && nVarP == 1) nVarR4 = MathAbs(Close[i+nVarP*3]-Close[i+nVarP*4]); else nVarR4 = nVarD; nVarE = iHighesti(nVarP,i+nVarP*4)-iLowesti(nVarP,i+nVarP*4); if (nVarE == 0 && nVarP == 1) nVarR5 = MathAbs(Close[i+nVarP*4]-Close[i+nVarP*5]); else nVarR5 = nVarE; nLRange = ((nVarR1+nVarR2+nVarR3+nVarR4+nVarR5)/5.0)*0.2; } // // // // // if ( nLRange <= 0 ) continue; double hlAverage = 0; for (k=0; k<numberOfBars; k++){ // Comment(i+k); hlAverage += (High[i+k]+Low[i+k])/2.0; } hlAverage /= numberOfBars; double nOpen = (Open[i] - hlAverage) / nLRange; double nHigh = (High[i] - hlAverage) / nLRange; hiBuffer[i] = nHigh; double nLow = (Low[i] - hlAverage) / nLRange; loBuffer[i] = nLow; double nClose = (Close[i] - hlAverage) / nLRange; // // // // // if (showLineChart==false) { color theBarColor = colorBarNeutral; color theWickColor = colorWickNeutral; if (nClose<nOpen) { theBarColor = colorBarDown; theWickColor = colorWickDown; } if (nClose>nOpen) { theBarColor = colorBarUp; theWickColor = colorWickUp; } drawBar(Time[i],nHigh,nLow,nOpen,nClose,theBarColor,theWickColor); } else prBuffer[i] = getPrice(linePrice,nHigh,nLow,nOpen,nClose); if (OmaLength1>1) paBuffer[i] = getPrice(0,nHigh,nLow,nOpen,nClose); if (OmaLength2>1) pbBuffer[i] = getPrice(0,nHigh,nLow,nOpen,nClose); // // // // // if (!alertsOnOmasCross) { trend[r] = trend[r-1]; if (nHigh> 8) trend[r] = 1; if (nLow <-8) trend[r] = -1; if (nLow>-8 && nHigh<8) trend[r] = 0; } } if (OmaLength1>1) for (i=limit; i>=0; i--) maBuffer[i] = iSmooth(paBuffer[i],OmaLength1,OmaSpeed1,OmaAdaptive1,i,0); for(i=limit,r=Bars-i-1; i>=0; i--,r++) { if (OmaLength2>1) mbBuffer[i] = iSmooth(pbBuffer[i],OmaLength2,OmaSpeed2,OmaAdaptive2,i,7); if (alertsOnOmasCross) { trend[r] = trend[r-1]; if (maBuffer[i]>mbBuffer[i]) trend[r] = 1; if (maBuffer[i]<mbBuffer[i]) trend[r] = -1; } } // // // // // if (alertsOn) { int forBar = (alertsOnCurrent != true); // // // // // r = Bars-forBar-1; if (trend[r] != trend[r-1]) { if (alertsOnOmasCross) { Comment(trend[r]); if (trend[r] == 1) doAlert("oma "+OmaLength1+" crossed oma "+OmaLength2+" up"); else doAlert("oma "+OmaLength1+" crossed oma "+OmaLength2+" down"); } else { if (trend[r] == 1) doAlert("broke level 8 up"); else doAlert("broke level -8 down"); } } } return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // void doAlert(string doWhat) { static string previousAlert="nothing"; static datetime previousTime; string message; if (previousAlert != doWhat || previousTime != Time[0]) { previousAlert = doWhat; previousTime = Time[0]; // // // // // message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," value chart ",doWhat); if (alertsMessage) Alert(message); if (alertsEmail) SendMail(StringConcatenate(Symbol(),"value chart "),message); if (alertsSound) PlaySound("alert2.wav"); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // double iHighesti(int period, int i) { if (i>=Bars) return(0); double max = High[i]; for (int k=1;(i+k)<Bars && k<period; k++) if (max<High[i+k]) max = High[i+k]; return(max); } double iLowesti(int period, int i) { if (i>=Bars) return(0); double min = Low[i]; for (int k=1;(i+k)<Bars && k<period; k++) if (min>Low[i+k]) min = Low[i+k]; return(min); } // // // // // double getPrice(int priceType, double high, double low, double open, double close) { double price = 0; switch (priceType) { case PRICE_CLOSE : price = close; break; case PRICE_OPEN : price = open; break; case PRICE_HIGH : price = high; break; case PRICE_LOW : price = low; break; case PRICE_MEDIAN : price = (high+low)/2.0; break; case PRICE_TYPICAL : price = (high+low+close)/3.0; break; case PRICE_WEIGHTED : price = (high+low+close+close)/4.0; } return(price); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // void drawBar(int bTime, double prHigh, double prLow, double prOpen, double prClose, color barColor, color wickColor) { string oName; oName = name+TimeToStr(bTime)+"w"; if (ObjectFind(oName) < 0) ObjectCreate(oName,OBJ_TREND,window,bTime,0,bTime,0); ObjectSet(oName, OBJPROP_PRICE1, prHigh); ObjectSet(oName, OBJPROP_PRICE2, prLow); ObjectSet(oName, OBJPROP_COLOR, wickColor); ObjectSet(oName, OBJPROP_WIDTH, widthWick); ObjectSet(oName, OBJPROP_RAY, false); ObjectSet(oName, OBJPROP_BACK, true); oName = name+TimeToStr(bTime)+"b"; if (ObjectFind(oName) < 0)ObjectCreate(oName,OBJ_TREND,window,bTime,0,bTime,0); ObjectSet(oName, OBJPROP_PRICE1, prOpen); ObjectSet(oName, OBJPROP_PRICE2, prClose); ObjectSet(oName, OBJPROP_COLOR, barColor); ObjectSet(oName, OBJPROP_WIDTH, widthBody); ObjectSet(oName, OBJPROP_RAY, false); ObjectSet(oName, OBJPROP_BACK, true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // double stored[][14]; #define E1 0 #define E2 1 #define E3 2 #define E4 3 #define E5 4 #define E6 5 #define res 6 // // // // // double iSmooth(double price, double averagePeriod, double tconst, bool adaptive, int i, int ashift=0) { if (ArrayRange(stored,0) != Bars) ArrayResize(stored,Bars); if (averagePeriod <=1) return(price); int r = Bars-i-1; double e1=stored[r-1][E1+ashift]; double e2=stored[r-1][E2+ashift]; double e3=stored[r-1][E3+ashift]; double e4=stored[r-1][E4+ashift]; double e5=stored[r-1][E5+ashift]; double e6=stored[r-1][E6+ashift]; // // // // // if (adaptive && (averagePeriod > 1)) { double minPeriod = averagePeriod/2.0; double maxPeriod = minPeriod*5.0; int endPeriod = MathCeil(maxPeriod); double signal = MathAbs((price-stored[r-endPeriod][res+ashift])); double noise = 0.00000000001; for(int k=1; k<endPeriod; k++) noise=noise+MathAbs(price-stored[r-k][res+ashift]); averagePeriod = ((signal/noise)*(maxPeriod-minPeriod))+minPeriod; } // // // // // double alpha = (2.0+tconst)/(1.0+tconst+averagePeriod); e1 = e1 + alpha*(price-e1); e2 = e2 + alpha*(e1-e2); double v1 = 1.5 * e1 - 0.5 * e2; e3 = e3 + alpha*(v1 -e3); e4 = e4 + alpha*(e3-e4); double v2 = 1.5 * e3 - 0.5 * e4; e5 = e5 + alpha*(v2 -e5); e6 = e6 + alpha*(e5-e6); double v3 = 1.5 * e5 - 0.5 * e6; // // // // // stored[r][E1+ashift] = e1; stored[r][E2+ashift] = e2; stored[r][E3+ashift] = e3; stored[r][E4+ashift] = e4; stored[r][E5+ashift] = e5; stored[r][E6+ashift] = e6; stored[r][res+ashift] = price; return(v3); }
Gh Exe:
What does the indicator do?
Hello,
I Try To Convert MQL4 Indicator To MQL5 Indicator But Stucked
This Is My Try
thanks in advance
i appreciate any help
#property indicator_separate_window #property indicator_buffers 8 #property indicator_plots 8 //--- plot value0 #property indicator_label1 "value0" #property indicator_type1 DRAW_LINE #property indicator_color1 clrDarkGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot value1 #property indicator_label2 "value1" #property indicator_type2 DRAW_LINE #property indicator_color2 clrMaroon #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot value2 #property indicator_label3 "value2" #property indicator_type3 DRAW_LINE #property indicator_color3 clrDarkTurquoise #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- plot value3 #property indicator_label4 "value3" #property indicator_type4 DRAW_LINE #property indicator_color4 clrLawnGreen #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- plot value4 #property indicator_label5 "value4" #property indicator_type5 DRAW_LINE #property indicator_color5 clrDarkOrange #property indicator_style5 STYLE_SOLID #property indicator_width5 1 //--- plot value5 #property indicator_label6 "value5" #property indicator_type6 DRAW_LINE #property indicator_color6 clrYellow #property indicator_style6 STYLE_SOLID #property indicator_width6 1 //--- plot value6 #property indicator_label7 "value6" #property indicator_type7 DRAW_LINE #property indicator_color7 clrLime #property indicator_style7 STYLE_SOLID #property indicator_width7 1 //--- plot value7 #property indicator_label8 "value7" #property indicator_type8 DRAW_LINE #property indicator_color8 clrDeepPink #property indicator_style8 STYLE_SOLID #property indicator_width8 1 input int magicNumber = 1; input int numberOf_Bars = 70; input bool showLineChart = false; input string _ = "Bars settings"; input color colorBarDown = Red; input color colorBarUp = LimeGreen; input color colorBarNeutral = Snow; input color colorWickUp = LimeGreen; input color colorWickDown = Red; input color colorWickNeutral = Snow; input int widthWick = 1; input int widthBody = 3; input string __ = "Line chart settings"; input int linePrice = PRICE_CLOSE; input string ___ = "Oma averages settings"; input int OmaLength1 = 20; input double OmaSpeed1 = 8.0; input bool OmaAdaptive1 = true; input int OmaLength2 = 50; input double OmaSpeed2 = 8.0; input bool OmaAdaptive2 = true; input bool alertsOnOmasCross = true; input bool alertsOn = true; input bool alertsOnCurrent = true; input bool alertsMessage = true; input bool alertsSound = false; input bool alertsEmail = false; int numberOfBars = numberOf_Bars; string name; int window; int OnInit() { SetIndexBuffer(0,hiBuffer, INDICATOR_DATA); PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_NONE); SetIndexBuffer(1,loBuffer, INDICATOR_DATA); PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_NONE); SetIndexBuffer(2,prBuffer, INDICATOR_DATA); SetIndexBuffer(3,maBuffer, INDICATOR_DATA); PlotIndexSetInteger(3, PLOT_DRAW_BEGIN, OmaLength1); SetIndexBuffer(4,mbBuffer, INDICATOR_DATA); PlotIndexSetInteger(4, PLOT_DRAW_BEGIN, OmaLength2); if (showLineChart) PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_LINE); else PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_NONE); if (OmaLength1>1) PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_LINE); else PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_NONE); if (OmaLength2>1) PlotIndexSetInteger(4, PLOT_DRAW_TYPE, DRAW_LINE); else PlotIndexSetInteger(4, PLOT_DRAW_TYPE, DRAW_NONE); SetIndexBuffer(5,paBuffer, INDICATOR_DATA); SetIndexBuffer(6,pbBuffer, INDICATOR_DATA); SetIndexBuffer(7,vaBuffer, INDICATOR_DATA); OmaLength1 = MathMax(OmaLength1,1); OmaLength2 = MathMax(OmaLength2,1); OmaSpeed1 = MathMax(OmaSpeed1,-1.5); OmaSpeed2 = MathMax(OmaSpeed2,-1.5); numberOfBars = MathMax(numberOfBars,5); name = "Value chart Oma ("+numberOfBars+","+magicNumber+")"; IndicatorSetString(INDICATOR_SHORTNAME, name); return(INIT_SUCCEEDED); }I translated to OnInit. OnCalculate will translate later. There you need to change the timeseries of all buffers (since in MQL4 in OnCalculate all buffers correspond to the timeseries).
This is my try but stuck with Array out of range
thank you very much for any help
thanks in advance
appreciate any help
//+------------------------------------------------------------------+ //| Value chart.mq4 | //| | //| Helweg/Stendahl value charts | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" #property indicator_separate_window #property indicator_buffers 8 #property indicator_plots 8 #property indicator_color3 Gold #property indicator_color4 PaleVioletRed #property indicator_color5 DeepSkyBlue #property indicator_width4 1 #property indicator_width5 1 #property indicator_level1 -8.0 #property indicator_level2 -4.0 #property indicator_level4 4.0 #property indicator_level5 8.0 #property indicator_levelcolor MediumOrchid extern int magicNumber = 1; extern int numberOfBars = 70; extern bool showLineChart = false; extern string _ = "Bars settings"; extern color colorBarDown = Red; extern color colorBarUp = LimeGreen; extern color colorBarNeutral = Snow; extern color colorWickUp = LimeGreen; extern color colorWickDown = Red; extern color colorWickNeutral = Snow; extern int widthWick = 1; extern int widthBody = 3; extern string __ = "Line chart settings"; extern int linePrice = 0; extern string ___ = "Oma averages settings"; extern int OmaLength1 = 20; extern double OmaSpeed1 = 8.0; extern bool OmaAdaptive1 = true; extern int OmaLength2 = 50; extern double OmaSpeed2 = 8.0; extern bool OmaAdaptive2 = true; extern bool alertsOnOmasCross = true; extern bool alertsOn = true; extern bool alertsOnCurrent = true; extern bool alertsMessage = true; extern bool alertsSound = false; extern bool alertsEmail = false; string name; int window; double hiBuffer[]; double loBuffer[]; double prBuffer[]; double paBuffer[]; double pbBuffer[]; double maBuffer[]; double mbBuffer[]; double vaBuffer[]; double trend[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { SetIndexBuffer(0,hiBuffer, INDICATOR_DATA); PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_NONE); SetIndexBuffer(1,loBuffer, INDICATOR_DATA); PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_NONE); SetIndexBuffer(2,prBuffer, INDICATOR_DATA); SetIndexBuffer(3,maBuffer, INDICATOR_DATA); PlotIndexSetInteger(3, PLOT_DRAW_BEGIN, OmaLength1); SetIndexBuffer(4,mbBuffer, INDICATOR_DATA); PlotIndexSetInteger(4, PLOT_DRAW_BEGIN, OmaLength2); if (showLineChart) PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_LINE); else PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_NONE); if (OmaLength1>1) PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_LINE); else PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_NONE); if (OmaLength2>1) PlotIndexSetInteger(4, PLOT_DRAW_TYPE, DRAW_LINE); else PlotIndexSetInteger(4, PLOT_DRAW_TYPE, DRAW_NONE); SetIndexBuffer(5,paBuffer, INDICATOR_DATA); SetIndexBuffer(6,pbBuffer, INDICATOR_DATA); SetIndexBuffer(7,vaBuffer, INDICATOR_DATA); OmaLength1 = MathMax(OmaLength1,1); OmaLength2 = MathMax(OmaLength2,1); OmaSpeed1 = MathMax(OmaSpeed1,-1.5); OmaSpeed2 = MathMax(OmaSpeed2,-1.5); numberOfBars = MathMax(numberOfBars,5); name = "Value chart Oma ("+IntegerToString(numberOfBars)+","+IntegerToString(magicNumber)+")"; IndicatorSetString(INDICATOR_SHORTNAME,name); return (0); } //+------------------------------------------------------------------+ //| Custom indicator de-initialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { string oName; for (int i = ObjectsTotal(0,window) - 1; i >= 0; i--) { oName = ObjectName(0,i); if (StringFind(oName, name, 0) >= 0) ObjectDelete(0,oName); } } //+------------------------------------------------------------------+ //| 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[]) { //--- int counted_bars = 0; if(prev_calculated==0)counted_bars = 0; else counted_bars = prev_calculated-1; int i,k,r,limit; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit = MathMin(Bars(_Symbol,_Period)-counted_bars,Bars(_Symbol,_Period)-2); window = ChartWindowFind(0,name); //Comment(window); if (counted_bars == 0) { for (i=0;i<OmaLength1;i++) { paBuffer[Bars(_Symbol,_Period)-i-1] = 0; maBuffer[Bars(_Symbol,_Period)-i-1] = 0; } for (i=0;i<OmaLength2;i++) { pbBuffer[Bars(_Symbol,_Period)-i-1] = 0; mbBuffer[Bars(_Symbol,_Period)-i-1] = 0; } } if (ArraySize(trend)!=Bars(_Symbol,_Period)) ArrayResize(trend,Bars(_Symbol,_Period)); int nVarP = (int)MathRound(numberOfBars/5.0); double nVarA,nVarB,nVarC,nVarD,nVarE; double nVarR1,nVarR2,nVarR3,nVarR4,nVarR5; double nLRange; //Comment(limit," \n", counted_bars); for (i=limit, r=Bars(_Symbol,_Period)-i-1; i>=0; i--,r++) { if (numberOfBars<7) { if (MathAbs(close[i]-close[i+1]) >= (high[i]-low[i])) nVarA = MathAbs(close[i]-close[i+1]); else nVarA = (high[i]-low[i]); vaBuffer[i] = nVarA; double average=0; for (k=0; k<5; k++) average += vaBuffer[i];; average /= 5; nLRange = average*0.2; } else { nVarA = iHighesti(nVarP,i)-iLowesti(nVarP,i); if (nVarA == 0 && nVarP == 1) nVarR1 = MathAbs(close[i]-close[i+nVarP]); else nVarR1 = nVarA; nVarB = iHighesti(nVarP,i+nVarP+1)-iLowesti(nVarP,i+nVarP); if (nVarB == 0 && nVarP == 1) nVarR2 = MathAbs(close[i+nVarP]-close[i+nVarP*2]); else nVarR2 = nVarB; nVarC = iHighesti(nVarP,i+nVarP*2)-iLowesti(nVarP,i+nVarP*2); if (nVarC == 0 && nVarP == 1) nVarR3 = MathAbs(close[i+nVarP*2]-close[i+nVarP*3]); else nVarR3 = nVarC; nVarD = iHighesti(nVarP,i+nVarP*3)-iLowesti(nVarP,i+nVarP*3); if (nVarD == 0 && nVarP == 1) nVarR4 = MathAbs(close[i+nVarP*3]-close[i+nVarP*4]); else nVarR4 = nVarD; nVarE = iHighesti(nVarP,i+nVarP*4)-iLowesti(nVarP,i+nVarP*4); if (nVarE == 0 && nVarP == 1) nVarR5 = MathAbs(close[i+nVarP*4]-close[i+nVarP*5]); else nVarR5 = nVarE; nLRange = ((nVarR1+nVarR2+nVarR3+nVarR4+nVarR5)/5.0)*0.2; } if ( nLRange <= 0 ) continue; double hlAverage = 0; for (k=0; k<numberOfBars; k++){ //Comment(i+k); hlAverage += (high[i+k]+low[i+k])/2.0; } hlAverage /= numberOfBars; double nOpen = (open[i] - hlAverage) / nLRange; double nHigh = (high[i] - hlAverage) / nLRange; hiBuffer[i] = nHigh; double nLow = (low[i] - hlAverage) / nLRange; loBuffer[i] = nLow; double nClose = (close[i] - hlAverage) / nLRange; if (showLineChart==false) { color theBarColor = colorBarNeutral; color theWickColor = colorWickNeutral; if (nClose<nOpen) { theBarColor = colorBarDown; theWickColor = colorWickDown; } if (nClose>nOpen) { theBarColor = colorBarUp; theWickColor = colorWickUp; } drawBar(iTime(Symbol(),PERIOD_CURRENT,i),nHigh,nLow,nOpen,nClose,theBarColor,theWickColor); } else {prBuffer[i] = getPrice(linePrice,nHigh,nLow,nOpen,nClose);} if (OmaLength1>1) paBuffer[i] = getPrice(0,nHigh,nLow,nOpen,nClose); if (OmaLength2>1) pbBuffer[i] = getPrice(0,nHigh,nLow,nOpen,nClose); if (!alertsOnOmasCross) { trend[r] = trend[r-1]; if (nHigh> 8) trend[r] = 1; if (nLow <-8) trend[r] = -1; if (nLow>-8 && nHigh<8) trend[r] = 0; } } if (OmaLength1>1) { for (i=limit; i>=0; i--){ maBuffer[i] = iSmooth(paBuffer[i],OmaLength1,OmaSpeed1,OmaAdaptive1,i,0); //printf(value3Buffer[i]); } } for(i=limit,r=Bars(_Symbol,_Period)-i-1; i>=0; i--,r++) { if (OmaLength2>1) mbBuffer[i] = iSmooth(pbBuffer[i],OmaLength2,OmaSpeed2,OmaAdaptive2,i,7); if (alertsOnOmasCross) { trend[r] = trend[r-1]; if (maBuffer[i]>mbBuffer[i]) trend[r] = 1; if (maBuffer[i]<mbBuffer[i]) trend[r] = -1; } } if (alertsOn) { int forBar = (alertsOnCurrent != true); r = Bars(_Symbol,_Period)-forBar-1; if (trend[r] != trend[r-1]) { if (alertsOnOmasCross) { //Comment(trend[r]); if (trend[r] == 1) doAlert("oma "+IntegerToString(OmaLength1)+" crossed oma "+IntegerToString(OmaLength2)+" up"); else doAlert("oma "+IntegerToString(OmaLength1)+" crossed oma "+IntegerToString(OmaLength2)+" down"); } else { if (trend[r] == 1) doAlert("broke level 8 up"); else doAlert("broke level -8 down"); } } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ void doAlert(string doWhat) { static string previousAlert="nothing"; static datetime previousTime; string message; if (previousAlert != doWhat || previousTime != iTime(Symbol(),PERIOD_CURRENT,0)) { previousAlert = doWhat; previousTime = iTime(Symbol(),PERIOD_CURRENT,0); string symbol= Symbol(); message = (string)StringConcatenate(symbol," at ",TimeToString(TimeLocal(),TIME_SECONDS)," value chart ",doWhat); if (alertsMessage) Alert(message); if (alertsEmail) SendMail(Symbol()+"value chart ",message); if (alertsSound) PlaySound("alert2.wav"); } } //+------------------------------------------------------------------+ double iHighesti(int period, int i) { if (i>=Bars(_Symbol,_Period)) return(0); double max = iHigh(Symbol(),PERIOD_CURRENT,i); for (int k=1;(i+k)<Bars(_Symbol,_Period) && k<period; k++) if (max<iHigh(Symbol(),PERIOD_CURRENT,i+k)) max = iHigh(Symbol(),PERIOD_CURRENT,i+k); //Comment(max); return(max); } //+------------------------------------------------------------------+ double iLowesti(int period, int i) { if (i>=Bars(_Symbol,_Period)) return(0); double min = iLow(Symbol(),PERIOD_CURRENT,i); for (int k=1;(i+k)<Bars(_Symbol,_Period) && k<period; k++) if (min>iLow(Symbol(),PERIOD_CURRENT,i+k)) min = iLow(Symbol(),PERIOD_CURRENT,i+k); //Comment(min); return(min); } //+------------------------------------------------------------------+ //int minPrice=0; //int maxPrice=0; double getPrice(int priceType, double high, double low, double open, double close) { double price = 0; switch (priceType) { case 0 : price = close; break; case 1 : price = open; break; case 2 : price = high; break; case 3 : price = low; break; case 4 : price = (high+low)/2.0; break; case 5 : price = (high+low+close)/3.0; break; case 6 : price = (high+low+close+close)/4.0; } /*minPrice=MathMin(price,minPrice); maxPrice=MathMax(price,maxPrice); Comment(price+" "+minPrice+" "+maxPrice);*/ return(price); } //+------------------------------------------------------------------+ void drawBar(datetime bTime, double prHigh, double prLow, double prOpen, double prClose, color barColor, color wickColor) { string oName; oName = name+TimeToString(bTime)+"w"; if (ObjectFind(0,oName) < 0) ObjectCreate(0,oName,OBJ_TREND,window,bTime,prHigh,bTime,prLow); ObjectSetInteger(0,oName, OBJPROP_COLOR, wickColor); ObjectSetInteger(0,oName, OBJPROP_WIDTH, widthWick); ObjectSetInteger(0,oName, OBJPROP_RAY, false); ObjectSetInteger(0,oName, OBJPROP_BACK, true); oName = name+TimeToString(bTime)+"b"; if (ObjectFind(0,oName) < 0)ObjectCreate(0,oName,OBJ_TREND,window,bTime,prOpen,bTime,prClose); ObjectSetInteger(0,oName, OBJPROP_COLOR, barColor); ObjectSetInteger(0,oName, OBJPROP_WIDTH, widthBody); ObjectSetInteger(0,oName, OBJPROP_RAY, false); ObjectSetInteger(0,oName, OBJPROP_BACK, true); /*Comment(bTime+" "+prHigh+" "+prLow+" "+prOpen+" "+prClose+" " +barColor+" "+wickColor);*/ } //+------------------------------------------------------------------+ double stored[][14]; #define E1 0 #define E2 1 #define E3 2 #define E4 3 #define E5 4 #define E6 5 #define res 6 double iSmooth(double price, double averagePeriod, double tconst, bool adaptive, int i, int ashift=0) { //Comment(price+" "+averagePeriod+" "+tconst+" "+adaptive+" "+i+" "+ashift); if (ArrayRange(stored,0) != Bars(_Symbol,_Period)) ArrayResize(stored,Bars(_Symbol,_Period)); if (averagePeriod <=1) return(price); int r = Bars(_Symbol,_Period)-i-1; double e1=stored[r-1][E1+ashift]; double e2=stored[r-1][E2+ashift]; double e3=stored[r-1][E3+ashift]; double e4=stored[r-1][E4+ashift]; double e5=stored[r-1][E5+ashift]; double e6=stored[r-1][E6+ashift]; if (adaptive && (averagePeriod > 1)) { double minPeriod = averagePeriod/2.0; double maxPeriod = minPeriod*5.0; int endPeriod = (int)MathCeil(maxPeriod); double signal = MathAbs((price-stored[r-endPeriod][res+ashift])); double noise = 0.00000000001; for(int k=1; k<endPeriod; k++) noise=noise+MathAbs(price-stored[r-k][res+ashift]); averagePeriod = ((signal/noise)*(maxPeriod-minPeriod))+minPeriod; } double alpha = (2.0+tconst)/(1.0+tconst+averagePeriod); e1 = e1 + alpha*(price-e1); e2 = e2 + alpha*(e1-e2); double v1 = 1.5 * e1 - 0.5 * e2; e3 = e3 + alpha*(v1 -e3); e4 = e4 + alpha*(e3-e4); double v2 = 1.5 * e3 - 0.5 * e4; e5 = e5 + alpha*(v2 -e5); e6 = e6 + alpha*(e5-e6); double v3 = 1.5 * e5 - 0.5 * e6; stored[r][E1+ashift] = e1; stored[r][E2+ashift] = e2; stored[r][E3+ashift] = e3; stored[r][E4+ashift] = e4; stored[r][E5+ashift] = e5; stored[r][E6+ashift] = e6; stored[r][res+ashift] = price; return(v3); } //+------------------------------------------------------------------+
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[] ) { //--- int counted_bars = 0; int i, k, r, limit; if(prev_calculated == 0) counted_bars = 0; else counted_bars = prev_calculated - 1; if(counted_bars < 0) return(-1); ArraySetAsSeries(open, true); ArraySetAsSeries(high, true); ArraySetAsSeries(low, true); ArraySetAsSeries(close, true); ...
Made the conversion to a timeseries in OnCalculate. But the indicator constantly crashes with array out of range. Unfortunately, I don't know the idea. Otherwise, one could try to eliminate the cause of array out of range.
Files:
Saved.mq5
17 kb
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
Hello,
I Try To Convert MQL4 Indicator To MQL5 Indicator But Stucked
This Is My Try
thanks in advance
i appreciate any help