Candle Percent Indicator Help

 

G'Day Mates. Everybody well I hope.

Help is appreciated to make this indicator work.

What it should do is divide the current Candle high-low range, example 30, by the sum of the CandlePeriods high-low range. Example, if CandlePeriod = 3, and the sum of the three candles at close = 130 (40+60+30), then the last Candle is divided by the CandleSum of candles for the CandlePeriod. Example, current candle at close = 30 (Candle) / 130 (CandleSum) = 23.07%.

//+------------------------------------------------------------------+
//|
//| Candle Percent.mq4
//|
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Gray
#property indicator_width1 8
//---- input parameters

extern int CandlePeriod = 3;

//---- buffers
double MainBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//----
IndicatorBuffers(1);
IndicatorDigits(Digits);
//---- indicator line
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,MainBuffer);

//---- name for DataWindow and indicator subwindow label
short_name="Candle Percent ("+CandlePeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Candle Percent |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
//----

int limit=Bars-counted_bars-1;
for (i=limit; i+CandlePeriod-1; i>=0; i--) //Sum of the CandlePeriods (high-low). Example, if CandlePeriod = 3, and the sum of the three candles at close = 130 (40+60+30).

double Candle, CandleSum;

{

Candle=High[i]-Low[i];
CandleSum+=High[i]-Low[i];


MainBuffer[i]= (Candle/CandleSum) *100; // Current candle divided by the CandleSum of candles for the CandlePeriod. Example, current candle at close = 30 / 130 = 23.07%.

}
//----
return(0);
}
//+------------------------------------------------------------------+

 

  1. For large amounts of code, attach it

  2. What you have
    What you need
    for (i=limit; i+CandlePeriod-1; i>=0; i--) double Candle, CandleSum;
    {
      // Things inside the brace will execute only once
      // because they NOT connected to the for loop.
    A for loop has (init; check; iterate) your's has 4 sections.
    for (i=limit; i>=0; i--){
       double Candle=High[i]-Low[i];
              CandleSum =
       :

 
WHRoeder:

  1. For large amounts of code, attach it

  2. What you have
    What you need
    A for loop has (init; check; iterate) your's has 4 sections.


Thanks WHRoeder for the try!

I am getting graphics now but the graphics and stats are wrong.

No matter what CandlePeriod I enter, the value and look is always the same as CandlePeriod=1 for all periods.

 
@Theo: hey did you finished coding of your indicator?