Download MetaTrader 5

some help in coding

To add comments, please log in or register
Mehrdad Shiri
4637
Mehrdad Shiri  

hi; can you please tell me where i am wrong.

for indicator " Laguerre " i want to determine the first change from value "1" to "0" or Vice versa and those time.

i add high lighted line to the source ( mql5 file attached ).

//+------------------------------------------------------------------+
//|                                                         Laguerre |
//|                                      Copyright © 2009, EarnForex |
//|                                        http://www.earnforex.com/ |
//|                            Based on Laguerre.mq4 by Emerald King |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, EarnForex"
#property link      "http://www.earnforex.com"
#property version   "1.01"
#property description "Laguerre - shows weighted trend-line in a separate indicator window."
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_minimum -0.05
#property indicator_maximum 1.05
#property indicator_type1 DRAW_LINE
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_color1 Magenta
#property indicator_level1 1.00
#property indicator_level2 0.00
//---- input parameters
input double gamma =  0.7;
input int CountBars = 950;
double L0 = 0;
double L1 = 0;
double L2 = 0;
double L3 = 0;
double L0A = 0;
double L1A = 0;
double L2A = 0;
double L3A = 0;
double LRSI = 0;
double CU = 0;
double CD = 0;
double val1[];
//**************************************************************************
int NODE_Laguerre=50;
double Laguerre_UP[50];
datetime Laguerre_UP_TIME[50];
double Laguerre_DOWN[50];
datetime Laguerre_DOWN_TIME[50];
double UP_Laguerre_MINIMUM=1.0;
double DOWN_Laguerre_MAXIMUM=0.0;
//**************************************************************************
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
   IndicatorSetString(INDICATOR_SHORTNAME, "Laguerre");
   SetIndexBuffer(0, val1, INDICATOR_DATA);
//**************************************************************************   
   for( int i=0; i<NODE_Laguerre; i++ ) { Laguerre_UP[i]=0.50; Laguerre_DOWN[i]=0.50; }
//**************************************************************************   
}

//+------------------------------------------------------------------+
//| Data Calculation Function for Indicator                          |
//+------------------------------------------------------------------+
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[])
{
   int limit = CountBars;
   if (CountBars > rates_total) limit = rates_total;
   
   ArraySetAsSeries(Close, true);
   
   int i = limit - 1;
   while(i >= 0)
   {
      L0A = L0;
      L1A = L1;
      L2A = L2;
      L3A = L3;
      L0 = (1 - gamma) * Close[i] + gamma * L0A;
      L1 = - gamma * L0 + L0A + gamma * L1A;
      L2 = - gamma * L1 + L1A + gamma * L2A;
      L3 = - gamma * L2 + L2A + gamma * L3A;

      CU = 0;
      CD = 0;
      
      if (L0 >= L1) CU = L0 - L1; else CD = L1 - L0;
      if (L1 >= L2) CU = CU + L1 - L2; else CD = CD + L2 - L1;
      if (L2 >= L3) CU = CU + L2 - L3; else CD = CD + L3 - L2;

      if (CU + CD != 0) LRSI = CU / (CU + CD);

      val1[rates_total - i - 1] = LRSI;
           i--;
        }
//********************************************************************************
        for( int w=0; w<=rates_total-2; w++ )
        //for( int w=limit; w>=0; w-- )
   {
       if( val1[w+1]>=UP_Laguerre_MINIMUM )   
       { 
       if( Laguerre_UP_TIME[0]<=Laguerre_DOWN_TIME[0] )
         {
           for( int Laguerre_count=NODE_Laguerre-1; Laguerre_count>=1; Laguerre_count-- ) 
               { Laguerre_UP[Laguerre_count]=Laguerre_UP[Laguerre_count-1]; Laguerre_UP_TIME[Laguerre_count]=Laguerre_UP_TIME[Laguerre_count-1]; }
           Laguerre_UP[0]=1.0; Laguerre_UP_TIME[0]=time[w+1];
         }
       }
//----      
       if( val1[w+1]<=DOWN_Laguerre_MAXIMUM )   
       { 
       if( Laguerre_DOWN_TIME[0]<=Laguerre_UP_TIME[0] )
         {
           for( int Laguerre_count=NODE_Laguerre-1; Laguerre_count>=1; Laguerre_count-- ) 
               { Laguerre_DOWN[Laguerre_count]=Laguerre_DOWN[Laguerre_count-1]; Laguerre_DOWN_TIME[Laguerre_count]=Laguerre_DOWN_TIME[Laguerre_count-1]; }
           Laguerre_DOWN[0]=0.0; Laguerre_DOWN_TIME[0]=time[w+1];
         }
       }
   }
//***********************************************************************************
 Comment(""
     
           ,"\nval1[rates_total-1]=",val1[rates_total-1]
           ,"\n"
           ,"\nLaguerre_UP[0]=",Laguerre_UP[0],"          Laguerre_UP_TIME[0]=",Laguerre_UP_TIME[0]
           ,"\nLaguerre_UP[1]=",Laguerre_UP[1],"          Laguerre_UP_TIME[1]=",Laguerre_UP_TIME[1]
           ,"\nLaguerre_UP[2]=",Laguerre_UP[2],"          Laguerre_UP_TIME[2]=",Laguerre_UP_TIME[2]
           ,"\n"
           ,"\nLaguerre_DOWN[0]=",Laguerre_DOWN[0],"          Laguerre_DOWN_TIME[0]=",Laguerre_DOWN_TIME[0]
           ,"\nLaguerre_DOWN[1]=",Laguerre_DOWN[1],"          Laguerre_DOWN_TIME[1]=",Laguerre_DOWN_TIME[1]
           ,"\nLaguerre_DOWN[2]=",Laguerre_DOWN[2],"          Laguerre_DOWN_TIME[2]=",Laguerre_DOWN_TIME[2]
   );  
//----------------------------------------------------------------------------------------------------------//     

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

at first it's ok ; such as below picture;


but suddenly  change and 


there is wrong.

can you please tell me , what is wrong

thank you.
Files:
Alain Verleyen
Moderator
33501
Alain Verleyen  

Why are you looping on whole array on each tick ?

   for( int w=0; w<=rates_total-2; w++ )
Also why make a new loop ? You can insert your code in the existing loop.
Mehrdad Shiri
4637
Mehrdad Shiri  
angevoyageur:

Why are you looping on whole array on each tick ?

with modify the loop ; ( thank you )

//+------------------------------------------------------------------+
//|                                                         Laguerre |
//|                                      Copyright © 2009, EarnForex |
//|                                        http://www.earnforex.com/ |
//|                            Based on Laguerre.mq4 by Emerald King |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, EarnForex"
#property link      "http://www.earnforex.com"
#property version   "1.01"
#property description "Laguerre - shows weighted trend-line in a separate indicator window."
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_minimum -0.05
#property indicator_maximum 1.05
#property indicator_type1 DRAW_LINE
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_color1 Magenta
#property indicator_level1 1.00
#property indicator_level2 0.00
//---- input parameters
input double gamma =  0.7;
input int CountBars = 950;
double L0 = 0;
double L1 = 0;
double L2 = 0;
double L3 = 0;
double L0A = 0;
double L1A = 0;
double L2A = 0;
double L3A = 0;
double LRSI = 0;
double CU = 0;
double CD = 0;
double val1[];
//**************************************************************************
int NODE_Laguerre=50;
double Laguerre_UP[50];
datetime Laguerre_UP_TIME[50];
double Laguerre_DOWN[50];
datetime Laguerre_DOWN_TIME[50];
double UP_Laguerre_MINIMUM=1.0;
double DOWN_Laguerre_MAXIMUM=0.0;
//**************************************************************************
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
   IndicatorSetString(INDICATOR_SHORTNAME, "Laguerre");
   SetIndexBuffer(0, val1, INDICATOR_DATA);
//**************************************************************************   
   for( int i=0; i<NODE_Laguerre; i++ ) { Laguerre_UP[i]=0.50; Laguerre_DOWN[i]=0.50; }
//**************************************************************************   
}

//+------------------------------------------------------------------+
//| Data Calculation Function for Indicator                          |
//+------------------------------------------------------------------+
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[])
{
   int limit = CountBars;
   if (CountBars > rates_total) limit = rates_total;
   
   ArraySetAsSeries(Close, true);
   
   int i = limit - 1;
   while(i >= 0)
   {
      L0A = L0;
      L1A = L1;
      L2A = L2;
      L3A = L3;
      L0 = (1 - gamma) * Close[i] + gamma * L0A;
      L1 = - gamma * L0 + L0A + gamma * L1A;
      L2 = - gamma * L1 + L1A + gamma * L2A;
      L3 = - gamma * L2 + L2A + gamma * L3A;

      CU = 0;
      CD = 0;
      
      if (L0 >= L1) CU = L0 - L1; else CD = L1 - L0;
      if (L1 >= L2) CU = CU + L1 - L2; else CD = CD + L2 - L1;
      if (L2 >= L3) CU = CU + L2 - L3; else CD = CD + L3 - L2;

      if (CU + CD != 0) LRSI = CU / (CU + CD);

      val1[rates_total - i - 1] = LRSI;
           
        
//********************************************************************************      

        if( val1[rates_total - i-2]==UP_Laguerre_MINIMUM )   
       { 
       if( Laguerre_UP_TIME[0]<=Laguerre_DOWN_TIME[0] )
         {
           for( int Laguerre_count=NODE_Laguerre-1; Laguerre_count>=1; Laguerre_count-- ) 
               { Laguerre_UP[Laguerre_count]=Laguerre_UP[Laguerre_count-1]; Laguerre_UP_TIME[Laguerre_count]=Laguerre_UP_TIME[Laguerre_count-1]; }
           Laguerre_UP[0]=1.0; Laguerre_UP_TIME[0]=time[rates_total - i-2];
         }
       }
//----      
       if( val1[rates_total - i-2]==DOWN_Laguerre_MAXIMUM )   
       { 
       if( Laguerre_DOWN_TIME[0]<=Laguerre_UP_TIME[0] )
         {
           for( int Laguerre_count=NODE_Laguerre-1; Laguerre_count>=1; Laguerre_count-- ) 
               { Laguerre_DOWN[Laguerre_count]=Laguerre_DOWN[Laguerre_count-1]; Laguerre_DOWN_TIME[Laguerre_count]=Laguerre_DOWN_TIME[Laguerre_count-1]; }
           Laguerre_DOWN[0]=0.0; Laguerre_DOWN_TIME[0]=time[rates_total - i-2];
         }
       }
   i--;
   } 
//********************************************************************************
 Comment(""
     
           ,"\nval1[rates_total-1]=",val1[rates_total-1]
           ,"\n"
          
           ,"\nLaguerre_UP[0]=",Laguerre_UP[0],"          Laguerre_UP_TIME[0]=",Laguerre_UP_TIME[0]
           ,"\nLaguerre_UP[1]=",Laguerre_UP[1],"          Laguerre_UP_TIME[1]=",Laguerre_UP_TIME[1]
           ,"\nLaguerre_UP[2]=",Laguerre_UP[2],"          Laguerre_UP_TIME[2]=",Laguerre_UP_TIME[2]
           ,"\n"
           ,"\nLaguerre_DOWN[0]=",Laguerre_DOWN[0],"          Laguerre_DOWN_TIME[0]=",Laguerre_DOWN_TIME[0]
           ,"\nLaguerre_DOWN[1]=",Laguerre_DOWN[1],"          Laguerre_DOWN_TIME[1]=",Laguerre_DOWN_TIME[1]
           ,"\nLaguerre_DOWN[2]=",Laguerre_DOWN[2],"          Laguerre_DOWN_TIME[2]=",Laguerre_DOWN_TIME[2]
       
   );  
//----------------------------------------------------------------------------------------------------------//     

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

there is still error. because of :

i don't understand what do you mean by you say : " Why are you looping on whole array on each tick ? "

Alain Verleyen
Moderator
33501
Alain Verleyen  
TIMisthebest:

with modify the loop ; ( thank you )

there is still error. because of :

i don't understand what do you mean by you say : " Why are you looping on whole array on each tick ? "

This is no longer the case since you have changed your loop. OnCalculate is call on each tick.

The problem is here:

       if( NormalizeDouble(val1[rates_total - i-2],2)<=DOWN_Laguerre_MAXIMUM )   
       { 
       if( Laguerre_DOWN_TIME[0]<=Laguerre_UP_TIME[0] )

As your last UP is the more recent, this condition is always true.

Alain Verleyen
Moderator
33501
Alain Verleyen  

Also a suggestion, as you have :

   ArraySetAsSeries(Close, true);

It's probably easier and clearer to use :

   ArraySetAsSeries(val1, true);

and then change

val1[rates_total - i - 1] to val1[i]
...
Mehrdad Shiri
4637
Mehrdad Shiri  
angevoyageur:

Also a suggestion, as you have :

It's probably easier and clearer to use :

and then change

thank you for all,

i will resume that ;

please don't forget this page

i will change them all

Mehrdad Shiri
4637
Mehrdad Shiri  

hi;

my last change and still there is problem :-(

//********************************************************************************      

        if( NormalizeDouble(val1[i+1],2)>=UP_Laguerre_MINIMUM && Laguerre_UP_TIME[0]<=Laguerre_DOWN_TIME[0] && Laguerre_UP[0]==0.5 )   
       { 
        for( int Laguerre_count=NODE_Laguerre-1; Laguerre_count>=1; Laguerre_count-- ) 
           { Laguerre_UP[Laguerre_count]=Laguerre_UP[Laguerre_count-1]; Laguerre_UP_TIME[Laguerre_count]=Laguerre_UP_TIME[Laguerre_count-1]; }
        Laguerre_UP[0]=1.0; Laguerre_UP_TIME[0]=time[i+1]; Laguerre_DOWN[0]=0.5;   
       }
//----       
   if( NormalizeDouble(val1[i+1],2)<=DOWN_Laguerre_MAXIMUM && Laguerre_DOWN_TIME[0]<=Laguerre_UP_TIME[0] && Laguerre_DOWN[0]==0.5 )   
       { 
        for( int Laguerre_count=NODE_Laguerre-1; Laguerre_count>=1; Laguerre_count-- ) 
           { Laguerre_DOWN[Laguerre_count]=Laguerre_DOWN[Laguerre_count-1]; Laguerre_DOWN_TIME[Laguerre_count]=Laguerre_DOWN_TIME[Laguerre_count-1]; }
        Laguerre_DOWN[0]=0.0; Laguerre_DOWN_TIME[0]=time[i+1]; Laguerre_UP[0]=0.5;
       }
   i--;
   } 

file attached; can you please check it.

Mehrdad Shiri
4637
Mehrdad Shiri  

after run of indicator ;

the first value for previous extermum is fault.

then there is no change for another point in forward by time .

can you check it in strategy tester.

thank you.

Kourosh Davallou
48711
Kourosh Davallou  

hi mehrdad 

 

//+------------------------------------------------------------------+
//|                                                         Laguerre |
//|                                      Copyright © 2009, EarnForex |
//|                                        http://www.earnforex.com/ |
//|                            Based on Laguerre.mq4 by Emerald King |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, EarnForex"
#property link      "http://www.earnforex.com"
#property version   "1.01"
#property description "Laguerre - shows weighted trend-line in a separate indicator window."
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_minimum -0.05
#property indicator_maximum 1.05
#property indicator_type1 DRAW_LINE
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_color1 Magenta
#property indicator_level1 1.00
#property indicator_level2 0.00
//---- input parameters
input double gamma =  0.7;
input int CountBars = 950;
double L0 = 0;
double L1 = 0;
double L2 = 0;
double L3 = 0;
double L0A = 0;
double L1A = 0;
double L2A = 0;
double L3A = 0;
double LRSI = 0;
double CU = 0;
double CD = 0;
double val1[];
//**************************************************************************
int NODE_Laguerre=50;
double Laguerre_UP[50];
datetime Laguerre_UP_TIME[50];
double Laguerre_DOWN[50];
datetime Laguerre_DOWN_TIME[50];
double UP_Laguerre_MINIMUM=1.0;
double DOWN_Laguerre_MAXIMUM=0.0;
//**************************************************************************
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
   IndicatorSetString(INDICATOR_SHORTNAME, "Laguerre");
   SetIndexBuffer(0, val1, INDICATOR_DATA);
   
//**************************************************************************   
   for( int i=0; i<NODE_Laguerre; i++ ) { Laguerre_UP[i]=0.50; Laguerre_DOWN[i]=0.50; }
//**************************************************************************   
}

//+------------------------------------------------------------------+
//| Data Calculation Function for Indicator                          |
//+------------------------------------------------------------------+
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[])
{
   int limit = CountBars;
   if (CountBars > rates_total) limit = rates_total;
   
   ArraySetAsSeries(Close, true);
   ArraySetAsSeries(time, true);
   ArraySetAsSeries(val1, true);
   
   int i = limit-1;
   while(i >= 0)
   {
      L0A = L0;
      L1A = L1;
      L2A = L2;
      L3A = L3;
      L0 = (1 - gamma) * Close[i] + gamma * L0A;
      L1 = - gamma * L0 + L0A + gamma * L1A;
      L2 = - gamma * L1 + L1A + gamma * L2A;
      L3 = - gamma * L2 + L2A + gamma * L3A;

      CU = 0;
      CD = 0;
      
      if (L0 >= L1) CU = L0 - L1; else CD = L1 - L0;
      if (L1 >= L2) CU = CU + L1 - L2; else CD = CD + L2 - L1;
      if (L2 >= L3) CU = CU + L2 - L3; else CD = CD + L3 - L2;

      if (CU + CD != 0) LRSI = CU / (CU + CD);

      val1[i] = LRSI;
           
        

   i--;
   } 
  int Countup=0,Countdown=0; 
   
   for ( int j =2 ; j <limit ;j++)
    {
      if( NormalizeDouble(val1[j-2],2)>=UP_Laguerre_MINIMUM)
        if (val1[j]<val1[j-1] && val1[j-1]<val1[j-2])
          {
           Laguerre_UP[Countup]=Close[j-2];
           Laguerre_UP_TIME[Countup++]=time[j-2];
            ObjectCreate(0,"l1"+IntegerToString(j),OBJ_VLINE,0,time[j-2],Close[j-2]);
            ObjectSetInteger(0,"l1"+IntegerToString(j),OBJPROP_COLOR,clrYellowGreen);
            
           }
      if( NormalizeDouble(val1[j-2],2)<=DOWN_Laguerre_MAXIMUM )
          if (val1[j]>val1[j-1]&& val1[j-1]>val1[j-2])
          {
            Laguerre_DOWN[Countdown]=Close[j-2];
           Laguerre_DOWN_TIME[Countdown++]=time[j-2];
             ObjectCreate(0,"d1"+IntegerToString(j),OBJ_VLINE,0,time[j-2],Close[j-2]);
            ObjectSetInteger(0,"d1"+IntegerToString(j),OBJPROP_COLOR,clrPink);
           } 
     } 
     
    
//********************************************************************************
 Comment(""
           ,"\nrates_total=",rates_total,"      limit=",limit
           ,"\nval1[0]=",val1[0]
           ,"\n"
          
           ,"\nLaguerre_UP[0]=",Laguerre_UP[0],"          Laguerre_UP_TIME[0]=",Laguerre_UP_TIME[0]
           ,"\nLaguerre_UP[1]=",Laguerre_UP[1],"          Laguerre_UP_TIME[1]=",Laguerre_UP_TIME[1]
           ,"\nLaguerre_UP[2]=",Laguerre_UP[2],"          Laguerre_UP_TIME[2]=",Laguerre_UP_TIME[2]
           ,"\n"
           ,"\nLaguerre_DOWN[0]=",Laguerre_DOWN[0],"          Laguerre_DOWN_TIME[0]=",Laguerre_DOWN_TIME[0]
           ,"\nLaguerre_DOWN[1]=",Laguerre_DOWN[1],"          Laguerre_DOWN_TIME[1]=",Laguerre_DOWN_TIME[1]
           ,"\nLaguerre_DOWN[2]=",Laguerre_DOWN[2],"          Laguerre_DOWN_TIME[2]=",Laguerre_DOWN_TIME[2]
       
   );  
//----------------------------------------------------------------------------------------------------------//     

   return(rates_total);
}
//+------------------------------------------------------------------+
Mehrdad Shiri
4637
Mehrdad Shiri  
kourosh1347

hi kourosh;

thank you

i will modify it.

Mehrdad Shiri
4637
Mehrdad Shiri  

thank you all

problem solved

//+------------------------------------------------------------------+
//|                                                         Laguerre |
//|                                      Copyright © 2009, EarnForex |
//|                                        http://www.earnforex.com/ |
//|                            Based on Laguerre.mq4 by Emerald King |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, EarnForex"
#property link      "http://www.earnforex.com"
#property version   "1.01"
#property description "Laguerre - shows weighted trend-line in a separate indicator window."
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_minimum -0.05
#property indicator_maximum 1.05
#property indicator_type1 DRAW_LINE
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_color1 Magenta
#property indicator_level1 1.00
#property indicator_level2 0.00
//---- input parameters
input double gamma =  0.7;
input int CountBars = 9950;
double L0 = 0;
double L1 = 0;
double L2 = 0;
double L3 = 0;
double L0A = 0;
double L1A = 0;
double L2A = 0;
double L3A = 0;
double LRSI = 0;
double CU = 0;
double CD = 0;
double val1[];
//**************************************************************************
int NODE_Laguerre=50;
double Laguerre_UP[50];
datetime Laguerre_UP_TIME[50];
double Laguerre_DOWN[50];
datetime Laguerre_DOWN_TIME[50];
double UP_Laguerre_MINIMUM=1.0;
double DOWN_Laguerre_MAXIMUM=0.0;
double Laguerre_up;
double Laguerre_down;
//**************************************************************************
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
   IndicatorSetString(INDICATOR_SHORTNAME, "Laguerre");
   SetIndexBuffer(0, val1, INDICATOR_DATA);
}
//+------------------------------------------------------------------+
//| Data Calculation Function for Indicator                          |
//+------------------------------------------------------------------+
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[])
{
   int limit = CountBars;
   if (CountBars > rates_total) limit = rates_total;
   ArraySetAsSeries(Close, true);
   ArraySetAsSeries(time, true);
   ArraySetAsSeries(val1, true);
   int i = limit - 1;
   while(i >= 0)
   {
      L0A = L0;
      L1A = L1;
      L2A = L2;
      L3A = L3;
      L0 = (1 - gamma) * Close[i] + gamma * L0A;
      L1 = - gamma * L0 + L0A + gamma * L1A;
      L2 = - gamma * L1 + L1A + gamma * L2A;
      L3 = - gamma * L2 + L2A + gamma * L3A;
      CU = 0;
      CD = 0;
      if (L0 >= L1) CU = L0 - L1; else CD = L1 - L0;
      if (L1 >= L2) CU = CU + L1 - L2; else CD = CD + L2 - L1;
      if (L2 >= L3) CU = CU + L2 - L3; else CD = CD + L3 - L2;
      if (CU + CD != 0) LRSI = CU / (CU + CD);
      val1[i] = LRSI;
           i--;
        }
//************************************************************
   for ( int j =limit ; j >0 ;j--)
    {
      if( NormalizeDouble(val1[j],2)>=UP_Laguerre_MINIMUM)
        if (Laguerre_up!=1)
          {
           for( int Laguerre_count=NODE_Laguerre-1; Laguerre_count>=1; Laguerre_count-- ) 
              { Laguerre_UP[Laguerre_count]=Laguerre_UP[Laguerre_count-1]; 
                Laguerre_UP_TIME[Laguerre_count]=Laguerre_UP_TIME[Laguerre_count-1]; }
           Laguerre_UP[0]=Close[j];
           Laguerre_UP_TIME[0]=time[j];
            ObjectCreate(0,"l1"+IntegerToString(j),OBJ_VLINE,0,time[j],Close[j]);
            ObjectSetInteger(0,"l1"+IntegerToString(j),OBJPROP_COLOR,Green);
           Laguerre_up=1.0;
           Laguerre_down=0.5;  
           }
      if( NormalizeDouble(val1[j],2)<=DOWN_Laguerre_MAXIMUM )
          if (Laguerre_down!=0.0)
          {
           for( int Laguerre_count=NODE_Laguerre-1; Laguerre_count>=1; Laguerre_count-- ) 
              { Laguerre_DOWN[Laguerre_count]=Laguerre_DOWN[Laguerre_count-1]; 
                Laguerre_DOWN_TIME[Laguerre_count]=Laguerre_DOWN_TIME[Laguerre_count-1]; }
           Laguerre_DOWN[0]=Close[j];
           Laguerre_DOWN_TIME[0]=time[j];
             ObjectCreate(0,"d1"+IntegerToString(j),OBJ_VLINE,0,time[j],Close[j]);
            ObjectSetInteger(0,"d1"+IntegerToString(j),OBJPROP_COLOR,Red);
           Laguerre_up=0.5;
           Laguerre_down=0.0;  
           } 
     } 
//********************************************************************************
 Comment(""
           ,"\nrates_total=",rates_total,"      limit=",limit
           ,"\nval1[0]=",val1[0]
           ,"\n"
           ,"\nLaguerre_UP[0]=",Laguerre_UP[0],"          Laguerre_UP_TIME[0]=",Laguerre_UP_TIME[0]
           ,"\nLaguerre_UP[1]=",Laguerre_UP[1],"          Laguerre_UP_TIME[1]=",Laguerre_UP_TIME[1]
           ,"\nLaguerre_UP[2]=",Laguerre_UP[2],"          Laguerre_UP_TIME[2]=",Laguerre_UP_TIME[2]
           ,"\n"
           ,"\nLaguerre_DOWN[0]=",Laguerre_DOWN[0],"          Laguerre_DOWN_TIME[0]=",Laguerre_DOWN_TIME[0]
           ,"\nLaguerre_DOWN[1]=",Laguerre_DOWN[1],"          Laguerre_DOWN_TIME[1]=",Laguerre_DOWN_TIME[1]
           ,"\nLaguerre_DOWN[2]=",Laguerre_DOWN[2],"          Laguerre_DOWN_TIME[2]=",Laguerre_DOWN_TIME[2]
   );  
//----------------------------------------------------------------------------------------------------------//
   return(rates_total);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
   ObjectsDeleteAll(0,0,OBJ_VLINE);
   ChartRedraw();
  }

thank you

12
To add comments, please log in or register