Helps to finalize a simple mathematical calculation indicator based on number of candles and complex loop.

 

I am developing an indicator based on comparing candles, two to two, on a number of candles (period).

I'm having a hard time finalizing the math calculation so that it works and it is possible to change the number of candles directly in the display, for a fixed number of candles it is easy to construct the indicator, however, it is a heavy indicator with a lot of processing.

To be able to change the number of candles would require some type of loop only in the calculation until finalizing each point of the indicator, this is impossible because of the number of dynamic variables in the calculation, at least for me.

The calculation with loop is basically this.

I = 100 candle

N = i
X = i
M = i
Y = i-1

Beginning of the loop
(N- (x-1))> (m- (y-1) = xxx ++
(N- (x-1)) <(m- (y-1) = xxx--
Y = y-1;

Loop

For y = 0

{X = x-1;} example x = 100-1 x = 99

{Y = x-1;} example y = 99-1 y = 98

Loop


Manually I wrote the calculation of the indicator as follows

N = 100 candles

CLOSE1> CLOSE2 = x ++

CLOSE1 <CLOSE2 = x--

...

CLOSE1> CLOSE100 = x ++

CLOSE1 <CLOSE100 = x--

CLOSE2> CLOSE3 = x ++

CLOSE2 <CLOSE3 = x--

CLOSE2> CLOSE4 = x ++

CLOSE2 <CLOSE4 = x--

...

CLOSE2> CLOSE100 = x ++

CLOSE2 <CLOSE100 = x--

...

CLOSE99> CLOSE100 = x ++

CLOSE99 <CLOSE100 = x-- end of calculation

Can anyone with experience help me solve this impasse?

 
Please use the SRC button if you  want to post code!!
 
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 begin = 0;
   int x = 0;
   int StartCalcPosition=0;
//--- check for bars count
   if(rates_total<StartCalcPosition)
      return(0);
//--- correct draw begin
   if(begin>0) PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,0);
//--- calculate position
   int pos=prev_calculated-1;
   if(pos<StartCalcPosition)
      pos=StartCalcPosition;
//--- main cycle
   for(int i=0;i<rates_total-prev_calculated;i++)
     {
     
   x=0;   
   ArraySetAsSeries(close,1);
   ArraySetAsSeries(ExtBuffer,1);
   
   if(close[i]>close[i+1]){x++;}
   if(close[i]<close[i+1]){x--;}
   
   if(close[i]>close[i+2]){x++;}
   if(close[i]<close[i+2]){x--;}

   if(close[i]>close[i+3]){x++;}
   if(close[i]<close[i+3]){x--;}

   if(close[i]>close[i+4]){x++;}
   if(close[i]<close[i+4]){x--;}

   if(close[i]>close[i+5]){x++;}
   if(close[i]<close[i+5]){x--;}

   if(close[i]>close[i+6]){x++;}
   if(close[i]<close[i+6]){x--;}

   if(close[i]>close[i+7]){x++;}
   if(close[i]<close[i+7]){x--;}

   if(close[i]>close[i+8]){x++;}
   if(close[i]<close[i+8]){x--;}

   if(close[i]>close[i+9]){x++;}
   if(close[i]<close[i+9]){x--;}

   if(close[i+1]>close[i+2]){x++;}
   if(close[i+1]<close[i+2]){x--;}

   if(close[i+1]>close[i+3]){x++;}
   if(close[i+1]<close[i+3]){x--;}

   if(close[i+1]>close[i+4]){x++;}
   if(close[i+1]<close[i+4]){x--;}

   if(close[i+1]>close[i+5]){x++;}
   if(close[i+1]<close[i+5]){x--;}

   if(close[i+1]>close[i+6]){x++;}
   if(close[i+1]<close[i+6]){x--;}

   if(close[i+1]>close[i+7]){x++;}
   if(close[i+1]<close[i+7]){x--;}

   if(close[i+1]>close[i+8]){x++;}
   if(close[i+1]<close[i+8]){x--;}
   
   if(close[i+1]>close[i+9]){x++;}
   if(close[i+1]<close[i+9]){x--;}

   if(close[i+2]>close[i+3]){x++;}
   if(close[i+2]<close[i+3]){x--;}

   if(close[i+2]>close[i+4]){x++;}
   if(close[i+2]<close[i+4]){x--;}

   if(close[i+2]>close[i+5]){x++;}
   if(close[i+2]<close[i+5]){x--;}

   if(close[i+2]>close[i+6]){x++;}
   if(close[i+2]<close[i+6]){x--;}

   if(close[i+2]>close[i+7]){x++;}
   if(close[i+2]<close[i+7]){x--;}

   if(close[i+2]>close[i+8]){x++;}
   if(close[i+2]<close[i+8]){x--;}

   if(close[i+2]>close[i+9]){x++;}
   if(close[i+2]<close[i+9]){x--;}

   if(close[i+3]>close[i+4]){x++;}
   if(close[i+3]<close[i+4]){x--;}

   if(close[i+3]>close[i+5]){x++;}
   if(close[i+3]<close[i+5]){x--;}

   if(close[i+3]>close[i+6]){x++;}
   if(close[i+3]<close[i+6]){x--;}

   if(close[i+3]>close[i+7]){x++;}
   if(close[i+3]<close[i+7]){x--;}

   if(close[i+3]>close[i+8]){x++;}
   if(close[i+3]<close[i+8]){x--;}

   if(close[i+3]>close[i+9]){x++;}
   if(close[i+3]<close[i+9]){x--;}

   if(close[i+4]>close[i+5]){x++;}
   if(close[i+4]<close[i+5]){x--;}

   if(close[i+4]>close[i+6]){x++;}
   if(close[i+4]<close[i+6]){x--;}

   if(close[i+4]>close[i+7]){x++;}
   if(close[i+4]<close[i+7]){x--;}

   if(close[i+4]>close[i+8]){x++;}
   if(close[i+4]<close[i+8]){x--;}

   if(close[i+4]>close[i+9]){x++;}
   if(close[i+4]<close[i+9]){x--;}

   if(close[i+5]>close[i+6]){x++;}
   if(close[i+5]<close[i+6]){x--;}

   if(close[i+5]>close[i+7]){x++;}
   if(close[i+5]<close[i+7]){x--;}

   if(close[i+5]>close[i+8]){x++;}
   if(close[i+5]<close[i+8]){x--;}

   if(close[i+5]>close[i+9]){x++;}
   if(close[i+5]<close[i+9]){x--;}

   if(close[i+6]>close[i+7]){x++;}
   if(close[i+6]<close[i+7]){x--;}

   if(close[i+6]>close[i+8]){x++;}
   if(close[i+6]<close[i+8]){x--;}

   if(close[i+6]>close[i+9]){x++;}
   if(close[i+6]<close[i+9]){x--;}

   if(close[i+7]>close[i+8]){x++;}
   if(close[i+7]<close[i+8]){x--;}

   if(close[i+7]>close[i+9]){x++;}
   if(close[i+7]<close[i+9]){x--;}

   if(close[i+8]>close[i+9]){x++;}
   if(close[i+8]<close[i+9]){x--;}
      
      
      ExtBuffer[i]=x;
   
      Comment((x," ", close[i], " ", i);
     
     }
I was forced to do it manually because I can not find a way to make a formula that works like loop.
 
Joao Luiz Sa Marchioro: I was forced to do it manually because I can not find a way to make a formula that works like loop.
   if(close[i]>close[i+1]){x++;}
   if(close[i]<close[i+1]){x--;}
   :
   if(close[i]>close[i+9]){x++;}
   if(close[i]<close[i+9]){x--;}

   if(close[i+1]>close[i+2]){x++;}
   if(close[i+1]<close[i+2]){x--;}
   :
   if(close[i+8]>close[i+9]){x++;}
   if(close[i+8]<close[i+9]){x--;}
You weren't forced, you were just to lazy to think.
for(int iLeft=0; iLeft < 9; ++iLeft){
   for(int iRight = iLeft+1; iRight < 10; ++iRight){
      if(close[i+iLeft]>close[i+iRight]){x++;}
      if(close[i+iLeft]<close[i+iRight]){x--;}
} }
 
whroeder1:
You weren't forced, you were just to lazy to think.
kkkkkkkkkkkk
Thanks buddy.

I'm still very dumb in programming.

I'll test to see if I understand correctly.
 
whroeder1 :
You weren't forced, you were just to lazy to think.


I would like to thank you for your great help, I would not have been able to do it without everyone's support.

I think it was a good indicator with a good trend indication.

I decided to let it reversed to work as follows, touched up means bullish trend, bullied down mean bullish trend, but if you want can change.

I thought it got a little heavy, if you have how to make this indicator lighter it would be of great help.

It is attached the Indicator, in thanks to the help, for those who want to improve and use, I still have not been able to configure it to use in EA, if anyone knows how to do could post here.

Files:
ICC.mq5  5 kb
 
Joao Luiz Sa Marchioro: I still have not been able to configure it to use in EA, if anyone knows how to do could post here.
Detailed explanation of iCustom - MQL4 forum
 


Fiz o EA baseado no indicador criado com sua ajuda, no entanto ele não funciona.

Fiz da mesma forma que faço outros EAs com indicadores personalizados, mas nesse caso o EA ficou louco, acredito que o problema possa ser no Indicador.

Pode me ajudar?

Files:
EA_ICC.mq5  13 kb
Reason: