Colorizing Bars referring to value of custom indcator (value from buffer)

 

Hello MQL4/5 Community,

I have a question regarding a function i want to build into my custom indicator "my indicator". So basically my indicator cointains multiple indicators and summarizes them into the buffer sum[i] 

  sum[i]=((MomBuffer3[i]+ADXDIFF[i])*ATR2[i]*RSIDiff[i]*Momentum[i])+Momentum_price[i];

 which is then visualized into a Histogram, working well. Now i want to colorize the Candles of the chart depending on the indicator value. Therefore i initialize the bar Bodies as following:

void SetCandleColor(int col, int i)
{
        double high,low,bodyHigh,bodyLow;


        {
                bodyHigh = MathMax(Open[i],Close[i]);
                bodyLow  = MathMin(Open[i],Close[i]);
                high            = High[i];
                low             = Low[i];
        }

        Bar1[i] = low;  Candle1[i] = bodyLow;
        Bar2[i] = low;  Candle2[i] = bodyLow;
        

        switch(col)
        {
                case 1:         Bar1[i] = high; Candle1[i] = bodyHigh;  break;
                case 2:         Bar2[i] = high; Candle2[i] = bodyHigh;  break;
        
        }
}

and finally plot them using the following code:

 for(int i = MathMax(Bars-1-IndicatorCounted(),1); i>=0; i--)
        {
                double  sum = sum(i);
                                

                                if(sum > 100)           SetCandleColor(1,i);
                else            if(sum < -100)          SetCandleColor(2,i);
        }

I cant figure out why its not working. I have to admit i tried to adapt this concept from another indicator " rsi chart bars". THe concept there is a bit different but i dont know where my adoption failed. Can someone help me with this issue ?


I copied both indicator..my custom indicator and the indicator i took the concept from, in the attachemt.


Best regards and thanks in adavance!

Files:
 
akuh:
 

Now i want to colorize the Candles of the chart depending on the indicator value.

Do you really want to colorize candles? Or do you want to colorize the histogram? I guess the histogram.

What is your goal? How many colors should have your histogram? I guess you want to have an indicator that has three colors. Basic color if the sum is between 100 and -100, another color if the sum is greater than 100 and another color if the sum is less than -100. Am I right? If you confirm that, I can help you with it.

 
Petr Nosek:

Do you really want to colorize candles? Or do you want to colorize the histogram? I guess the histogram.

What is your goal? How many colors should have your histogram? I guess you want to have an indicator that has three colors. Basic color if the sum is between 100 and -100, another color if the sum is greater than 100 and another color if the sum is less than -100. Am I right? If you confirm that, I can help you with it.

Hello Petr Nosek,

No i didnt want to colorize the candles directly. I wanted to plot a candle above the original chart, with these candles colorized. However i could solve the problem and its working now. Im now just having a small issie since i want to plot the candles and the histogram of the indicator simultaneously. 

Can you use #indicator chart window and #indicator seperate window both at the same time?


Cheers akuh

 
akuh:

Can you use #indicator chart window and #indicator seperate window both at the same time?

No, you can't.


akuh:

Im now just having a small issie since i want to plot the candles and the histogram of the indicator simultaneously. 

The easiest way is using two indicators. Another way is using a histogram in the separate window and objects to draw candles but this way isn't trivial.

Reason: