Pivot Points

 

Hi everyone!


I am trying to get my EA to make decisions regarding the Pivot Points, I have declared them in the header and I placed a comment to see the result, however it only calculates me with respect to the candle before the one it starts, if a new candle is opened it does not recalculate.


Can you help me to know what I am doing wrong please?


//+------------------------------------------------------------------+
//+   PIVOT POINTS                                                   +
//+------------------------------------------------------------------+
   //Este cálculo se hace en base al método de puntos de pivote Fibonacci.
   double high = iHigh(NULL,PERIOD_D1,1),
          low = iLow(NULL,PERIOD_D1,1),
          close_ = iClose(NULL,PERIOD_D1,1);
   
   
   double pp = NormalizeDouble((high+low+close_)/3,5),
          r1 = NormalizeDouble(pp + ((high-low)*0.382),5),
          s1 = NormalizeDouble(pp - ((high-low)*0.382),5),
          r2 = NormalizeDouble(pp + ((high-low)*0.618),5),
          s2 = NormalizeDouble(pp - ((high-low)*0.618),5),
          r3 = NormalizeDouble(pp + (high-low),5),
          s3 = NormalizeDouble(pp - (high-low),5);
 
I don't understand why the value doesn't change when a new daily candle arises.
 

I could find a solution as follows:


//+------------------------------------------------------------------+
//+   PIVOT POINTS                                                   +
//+------------------------------------------------------------------+
//Este cálculo se hace en base al método de puntos de pivote Fibonacci.

double PP() {double pp = NormalizeDouble((High[1]+Low[1]+Close[1])/3,5); return(pp);}
double R1() {double r1 = NormalizeDouble(PP() + ((High[1]-Low[1])*0.382),5); return(r1);}
double S1() {double s1 = NormalizeDouble(PP() - ((High[1]-Low[1])*0.382),5); return(s1);}
double R2() {double r2 = NormalizeDouble(PP() + ((High[1]-Low[1])*0.618),5); return(r2);}
double S2() {double s2 = NormalizeDouble(PP() - ((High[1]-Low[1])*0.618),5); return(s2);}
double R3() {double r3 = NormalizeDouble(PP() + (High[1]-Low[1]),5); return(r3);}
double S3() {double s3 = NormalizeDouble(PP() - (High[1]-Low[1]),5); return(s3);}


However, I think something much more elegant and simple could be done, what do you think?