Color Histogram with Conditions

 

Hi All,

I'm new to this forum, so apologise if I'm violating any rules.

I'm trying to re-create a Tradingview indicator on MQL and come across an issue when it comes to coloring the Histogram.


Tradingview logic I'm trying to copy:

plotColor = if histo > 0

    histo > histo[1] ? lime : green

else 

    histo < histo[1] ? maroon : red


My current MQL5 code which is not working:

   

for(int i=start; i<rates_total && !IsStopped(); i++)

    {

      if(ExtHistoBuffer[i]<0)

        {

        if(ExtHistoBuffer[i-1] < ExtHistoBuffer[i]) 

          ColorBuffer[i]=2;

        else

          ColorBuffer[i]=3;

        }

       else

         {

         if(ExtHistoBuffer[i-1] < ExtHistoBuffer[i])

            ColorBuffer[i]=0;

         else

            ColorBuffer[i]=1;

         }     

     }



For whatever reason, the loop doesn't let me compare to the previous value a second time?

The moment I take this line,

if(ExtHistoBuffer[i-1] < ExtHistoBuffer[i])

 it works fine, but only gives me a 3 color solution.

Any ideas what I'm doing wrong or how I could fix it?

Many Thanks

 
Show the full code, please.