The indicator works on the test chart but not on the PD chart

 

Hello

I have a problem on an indicator. It works on Testing chart but not on PD chart.

Testing chart --> Ok

Real chart --> No Ok

My indicator calculates the difference between the close() and a value (named open0 in my code)  which changes at certain times (beginning of the day, open hour FRA40 and open hour US30).

I thought this indicator would be "simple", but I have never encountered this kind of issue...:-(

Could you help me please and tell me if you see something which can explain this issue (i really would like to understand) : 

//+------------------------------------------------------------------+
//|                                                         TPJ3.mq4 |
//|                                                             NBEN |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "ENNB"


#property indicator_separate_window
#property indicator_buffers    1

#property indicator_color1  Red
#property indicator_width1  1


double Open0;
datetime TimeUS,TimeHUS,TimeMUS,Time0jour,TimeFR,Derniereouverture;
bool Nouvellebarre;



//--- buffers

double TPJ[];


//+-------------------------------------------------------------------------------------------------------
//Paramétrage Indicateurs
int init()
{
   IndicatorBuffers(1);


   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,TPJ);
   SetIndexLabel(0,"TPJ");  

   
    IndicatorShortName("TPJ3");

 return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Calcul de l'indicateur                                           |
//+------------------------------------------------------------------+
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 j,limit,counted_bars=IndicatorCounted();
  
   if (counted_bars==0) {limit=Bars-1;}
   if (counted_bars>0) {limit=Bars-counted_bars-1;}
//if (TimeDaylightSavings() == 0)
//{TimeFR = 8;TimeHUS = 14;TimeMUS = 30;}else {TimeFR = 7;TimeHUS = 13;TimeMUS = 30;}

MqlDateTime Debutjour;
    Debutjour.year = TimeYear(TimeCurrent());
    Debutjour.mon = TimeMonth(TimeCurrent()); 
    Debutjour.day = TimeDay(TimeCurrent());
    Debutjour.hour = 0; // Heure
    Debutjour.min = 0; // Minutes
    Debutjour.sec = 0; // Secondes

Time0jour = StructToTime (Debutjour);

MqlDateTime DebutFr;
    DebutFr.year = TimeYear(TimeCurrent());
    DebutFr.mon = TimeMonth(TimeCurrent()); 
    DebutFr.day = TimeDay(TimeCurrent());
    DebutFr.hour = 9; // Heure
    DebutFr.min = 0; // Minutes
    DebutFr.sec = 0; // Secondes

TimeFR = StructToTime (DebutFr)-3600 + TimeDaylightSavings();

MqlDateTime DebutUS;
    DebutUS.year = TimeYear(TimeCurrent());
    DebutUS.mon = TimeMonth(TimeCurrent()); 
    DebutUS.day = TimeDay(TimeCurrent());
    DebutUS.hour = 9; // Heure
    DebutUS.min = 30; // Minutes
    DebutUS.sec = 0; // Secondes

TimeUS = StructToTime (DebutUS)+18000 + TimeDaylightSavings();
   
   for (j=limit;j>=0;j--)      
      {    
        
if (TimeCurrent() == Time0jour) {Open0 = Open[j];Print(TimeCurrent()," ",Open0);}
               else{  if (TimeCurrent() == TimeFR) {Open0 = Open[j];Print(TimeCurrent()," ",Open0);}
                  else { if (TimeCurrent() == TimeUS) {Open0 = Close[j];Print(TimeCurrent()," ",Open0);}}   } 
      
     TPJ[j] = Close[j]-Open0;  

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


Thanks a lot in advance

 
It should work, print the values of TimeCurrent, TimeUs etc. It is not printing (or appearing not to work) as the condition is not yet satisfied as opposed to test charts where the values are not in real time.
 
Thank-god Avwerosuoghene Odukudu #:
It should work, print the values of TimeCurrent, TimeUs etc. It is not printing (or appearing not to work) as the condition is not yet satisfied as opposed to test charts where the values are not in real time.

Hello

I added the print of the value when the event is happening (vertical lines below). It appears the calculation is good and the indicator work properly AFTER a first event on PD. The issue is on the old bars. When i put the indicator on the PD chart, it doesn't take into account the old bar until a first event happens.