Trying to create an indicator that will make some candle in another color, but nothing happens when i put it on the chart.
Can see i get a divide by zero error in line 74 in the code, but not sure how to fix it.
Want to mark up candles where the body of the candle is less than 50% of the whole (high to low) candle
Can see i get a divide by zero error in line 74 in the code, but not sure how to fix it.
Want to mark up candles where the body of the candle is less than 50% of the whole (high to low) candle
Inserted Code
//+------------------------------------------------------------------+ //| eCandle.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 clrOrange #property indicator_color2 clrOrange #property indicator_width1 5 #property indicator_width2 5 double BodyHigh[],BodyLow[]; double BodyRange = 0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,BodyHigh); SetIndexBuffer(1,BodyLow); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_HISTOGRAM); //--- 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[]) { //--- for(int i = MathMax(Bars-2-IndicatorCounted(),1); i>=0;i--) { double hi=high[i], lo=low[i], prevhi=high[i+1], prevlo=low[i+1]; double bodyhigh=MathMax(close[i], open[i]); double bodylow=MathMin(close[i], open[i]); // Markup candles where the body of the candle is less than 50% of the whole (high to low) candle double CandleRange = hi - lo; double pCandle = (BodyRange / CandleRange)*100; if (pCandle < 50) //if(hi>prevhi&&lo<prevlo) { BodyHigh[i]=bodyhigh; BodyLow[i]=bodylow; } //This code work if i want to mark up outside candles //double hi=high[i], lo=low[i], prevhi=high[i+1], prevlo=low[i+1]; //double bodyhigh=MathMax(close[i], open[i]); //double bodylow=MathMin(close[i], open[i]); //if(hi>prevhi&&lo<prevlo) //{ // BodyHigh[i]=bodyhigh; // BodyLow[i]=bodylow; //} } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Blindly following others will make you blind!