#property copyright "Copyright 2024, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property indicator_buffers 4 #property indicator_plots 4 #property indicator_style1 STYLE_SOLID #property indicator_color1 clrWhiteSmoke #property indicator_label1 "UpperA" #property indicator_style2 STYLE_SOLID #property indicator_color2 clrWhite #property indicator_label2 "LowerB" #property indicator_style3 STYLE_SOLID #property indicator_color3 clrBlue #property indicator_label3 "Avg" #property indicator_style4 STYLE_SOLID #property indicator_color4 clrRed #property indicator_label4 "Close" #property indicator_chart_window input int InpLength = 100; // Length double BufferA[]; double BufferB[]; double BufferAvg[]; double BufferClose[]; double Bufferbullish; double Bufferbullish1; bool crossup, crossdn, crossup1, crossdn1, buy_signal, sell_signal; int countdn, countup, countTrueBarscrossup, countTrueBarscrossdn, countTrueBarscrossup1, countTrueBarscrossdn1; int OnInit() { SetIndexBuffer(0, BufferA); PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetString(0, PLOT_LABEL, "Upper"); ArraySetAsSeries(BufferA, true); SetIndexBuffer(1, BufferB); PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetString(1, PLOT_LABEL, "Lower"); ArraySetAsSeries(BufferB, true); SetIndexBuffer(2, BufferAvg); PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetString(2, PLOT_LABEL, "Average"); ArraySetAsSeries(BufferAvg, true); SetIndexBuffer(3, BufferClose); PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetString(3, PLOT_LABEL, "Close Price"); ArraySetAsSeries(BufferClose, true); /* SetIndexBuffer(4, Bufferbullish); ArraySetAsSeries(Bufferbullish, true); */ return(INIT_SUCCEEDED); } /*-------------------------------------------*/ int countTrueBarscrossup() { countup = 0; int totalBarsCU = Bars(_Symbol, _Period); for (int i = 0; i < totalBarsCU; i++) { if(crossup) { countup++; } } return countup; } int countTrueBarscrossdn() { countdn = 0; int totalBarsCD = Bars(_Symbol, _Period); for (int i = 0; i < totalBarsCD; i++) { if(crossdn) { countdn++; } } return countdn; } /*-------------------------------------------*/ int countTrueBarscrossup1() { countup = 0; int totalBarsCU = Bars(_Symbol, _Period); for (int i = 0; i < totalBarsCU; i++) { if(crossup1) { countup++; } } return countup; } int countTrueBarscrossdn1() { countdn = 0; int totalBarsCD = Bars(_Symbol, _Period); for (int i = 0; i < totalBarsCD; i++) { if(crossdn1) { countdn++; } } return countdn; } /*-------------------------------------------*/ 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[]) { if (rates_total <= InpLength) return 0; if (IsStopped()) return 0; int count = (prev_calculated == 0) ? (rates_total - InpLength) : (rates_total - prev_calculated + 1); ArraySetAsSeries(close, true); for (int i = count - 1; i >= 0; i--) { BufferA[i] = MathMax(close[i], BufferA[i + 1]) - (BufferA[i + 1] - BufferB[i + 1]) / InpLength; // Corrected parentheses BufferB[i] = MathMin(close[i], BufferB[i + 1]) + (BufferA[i + 1] - BufferB[i + 1]) / InpLength; // Corrected parentheses BufferAvg[i] = (BufferA[i] + BufferB[i]) / 2; BufferClose[i] = close[i]; crossup = BufferB[i + 1] < close[i + 1] && BufferB[i] > close[i]; crossdn = BufferA[i + 1] < close[i + 1] && BufferA[i] > close[i]; Bufferbullish = countTrueBarscrossdn() <= countTrueBarscrossup(); crossup1 = BufferB[i + 2] < close[i + 2] && BufferB[i + 1] > close[i + 1]; crossdn1 = BufferA[i + 2] < close[i + 2] && BufferA[i + 1] > close[i + 1]; Bufferbullish1 = countTrueBarscrossdn1() <= countTrueBarscrossup1(); if (Bufferbullish && !Bufferbullish1) Print("Buy signal at bar ", i, " with price = ", BufferClose[i]); else if (!Bufferbullish && Bufferbullish1) Print("Sell signal at bar ", i, " with price = ", BufferClose[i]); } return (rates_total); }