Help: Basic Laguerre Edit Variable Prob

 
Hi guys -- I'm new to MQL.

What I'm looking to do is using the common Laguerre indicator, invert any values under 0.45 and turning those inverted values Red.

I inverted them fine, but I'm having an issue with making the color red. Help would be much appreciated.

 
//+------------------------------------------------------------------+
//|                                                 Laguerre RSI.mq4 |
//|                                Copyright © 2005, David W. Thomas |
//|                                           mailto:davidwt@usa.net |
//+------------------------------------------------------------------+
// based on [url]http://www.mesasoftware.com/TimeWarp.doc[/url].
#property copyright "Copyright © 2005, David W. Thomas"
#property link      "mailto:davidwt@usa.net"
 
#property indicator_separate_window
#property indicator_level2 0.75
#property indicator_level3 0.45
#property indicator_level4 0.15
#property indicator_levelcolor DimGray
#property indicator_color1 Lime
#property indicator_color2 Red
 
 
 
#property indicator_minimum -1
#property indicator_maximum 1
#property indicator_buffers 1
 
//---- input parameters
extern double    gamma=0.7;
extern color HistColor = Lime;
 
 
 
//---- buffers
double RSI[];
double L0[];
double L1[];
double L2[];
double L3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   IndicatorBuffers(5);
//---- indicators
 
   SetIndexDrawBegin(0, 1);
   SetIndexDrawBegin(5, 1);
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3,HistColor);
    SetIndexLabel(0, "Laguerre RSI");
    SetIndexEmptyValue(0, -0.01);
   SetIndexBuffer(0, RSI);
   SetIndexBuffer(1, L0);
   SetIndexBuffer(2, L1);
   SetIndexBuffer(3, L2);
   SetIndexBuffer(4, L3);
//----
   string short_name="LaguerreRSI(" + DoubleToStr(gamma, 2) + ")";
   IndicatorShortName(short_name);
  
 
   return(0);
}
 
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   return(0);
}
 
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
    int    limit;
    int    counted_bars = IndicatorCounted();
    double CU, CD;
    //---- last counted bar will be recounted
    if (counted_bars>0)
        counted_bars--;
    else
        counted_bars = 1;
    limit = Bars - counted_bars;
    //---- computations for RSI
    for (int i=limit; i>=0; i--)
    {
        L0[i] = (1.0 - gamma)*Close[i] + gamma*L0[i+1];
        L1[i] = -gamma*L0[i] + L0[i+1] + gamma*L1[i+1];
        L2[i] = -gamma*L1[i] + L1[i+1] + gamma*L2[i+1];
        L3[i] = -gamma*L2[i] + L2[i+1] + gamma*L3[i+1];
        //Print(i," Close[i]=",Close[i],", (1.0 - gamma)*Close[i]=",(1.0 - gamma)*Close[i],", gamma*L0[i+1]=",gamma*L0[i+1]);
        //Print(i," L0=",L0[i],",L1=",L1[i],",L2=",L2[i],",L3=",L3[i]);
 
        CU = 0;
        CD = 0;
        if (L0[i] >= L1[i])
            CU = L0[i] - L1[i];
        else
            CD = L1[i] - L0[i];
        if (L1[i] >= L2[i])
            CU = CU + L1[i] - L2[i];
        else
            CD = CD + L2[i] - L1[i];
        if (L2[i] >= L3[i])
            CU = CU + L2[i] - L3[i];
        else
            CD = CD + L3[i] - L2[i];
 
      if (CU + CD != 0)
            RSI[i] = CU / (CU + CD);       
       
        if (RSI[i] > 0.45)
        {
         color HistColor = Lime;
        }
      
      if (RSI[i] <= 0.45)
       {
        color HistColor = Red;
        RSI[i] = RSI[i] - RSI[i] - RSI[i];    
       }
      
}
  return(0);
}
//+------------------------------------------------------------------+


As mentioned, I'm new to this language.... can I not just set new variable values if the expression changes? Perhaps there's a function for this that I missed... ..

Thanks.
 

To change color of an indicator on the fly, you can use the SetIndexStyle() function again.

But, you want a line that alternates colors. For that you have to use two different indicator indexes
that trace the same line, but show one (maybe red) when the value is below your threshold, and
showing the other (green) when the value is above.

 
ah.

How would I go about making a second index within the indicator if I'm using 6 buffers already? Isn't the maximum 8?

thanks for the quick reply
 

"How would I go about making a second index within the indicator if I'm using 6 buffers already? Isn't the maximum 8?"

Yes, you are limited to 8.

Actually, only 5 are used right now:

SetIndexBuffer(0, RSI);
SetIndexBuffer(1, L0);
SetIndexBuffer(2, L1);
SetIndexBuffer(3, L2);
SetIndexBuffer(4, L3);

Buffer 5 is never "set", so this line does nothing

SetIndexDrawBegin(5, 1);

So, you can add another index for the second color you want to display,
I might rename RSI to be RSI_GREEN and the new one RSI_RED

--------

See Awesome.mq4 for an example, it comes with MT4

 
Thanks mate, you're a champ. Got it going first shot. Appreciate it.
 

i like to see folks find their way with a clue or two...

Reason: