D1 value not shown on H4 chart for Friday

 

Hi Everyone,

I try to create custom indicator that show D1 value of target indicator on H4 chart.

It works ok on everyday but Friday. D1 value of Friday is not show up on H4 chart.

Any help is very much appreciated.

for(int i=1;i<=limit ;i++) 
{ d1bar_1 = iBarShift(Symbol(), D1, Time[i]) + 1; // D1 Bars of H4 

  long_primary[i] = iCustom(NULL,D1,primary_indi,0,d1bar_1); 
}
 
scfx:  It works ok on everyday but Friday. D1 value of Friday is not show up on H4 chart.
  There is no such thing as a "D1 value of Friday" The second argument must be a ENUM_TIMEFRAMES
 
WHRoeder:
scfx:  It works ok on everyday but Friday. D1 value of Friday is not show up on H4 chart.
  There is no such thing as a "D1 value of Friday" The second argument must be a ENUM_TIMEFRAMES
extern int D1= PERIOD_D1;
extern int H4= PERIOD_H4;
extern int H1= PERIOD_H1;

I guess what you mentioned about second arguement is D1. If it is, I already put the above at the beginning.

The situation is that indicator value of Monday-D1 is shown on Tuesday-H4, value Tuesday-D1 shown on Wed-H4 chart. But when there is a skip of calendar date (weekend), the value of Friday-D1 is not shown on Monday-H4 chart.

Thank you,

SCFX

 
If you put the "primary_indi" indicator on the Daily chart, does it show a value for Fridays?
 
Yes, I put D1 and H4 chart side-by-side to compare and primary_indicator show value on D1 but not on H4 (using that code above) for Friday.
 

Try this in a script to see if you are getting the right values that you expect

 

I don't understand why SRC often doesn't work

   int D1=PERIOD_D1;
   string primary_indi=""; //INSERT YOUR INDI NAME HERE
   string day;
   for(int d1bar_1=1;d1bar_1<7;d1bar_1++)
     {
      double long_primary=iCustom(NULL,D1,primary_indi,0,d1bar_1);
      int d1day=TimeDayOfWeek(iTime(Symbol(),D1,d1bar_1));
      switch(d1day)
        {
         case 0:  day="Sunday ";    break;
         case 1:  day="Monday ";    break;
         case 2:  day="Tuesday ";   break;
         case 3:  day="Wednesday "; break;
         case 4:  day="Thursday ";  break;
         case 5:  day="Friday ";    break;
         case 6:  day="Saturday ";  break;
         default: day="No Day";     break;
        }
      Print(day," Indi value= ",DoubleToStr(long_primary,Digits));
     }
 

Below is my code for SAR.

It seems to work ok at the beginning and then giving wrong value.

Can you check my code please?

Thank you,

SCFX

//+------------------------------------------------------------------+
//|                                             www scratch 2_h4.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_maximum 2
#property indicator_minimum -2

#property indicator_buffers 2
#property indicator_plots   2
//--- plot Label1
#property indicator_label1  "SAR_long"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrTurquoise
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

//--- indicator buffers
double SAR_long[];

extern int D1= PERIOD_D1;
extern int H4= PERIOD_H4;
extern int H1= PERIOD_H1;

extern string sar_indi="Parabolic";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,SAR_long);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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=rates_total-prev_calculated-1;
   if(limit<=0) limit=2;
   int d1bar_0,d1bar_1; 

//---
   for(int i=1;i<=limit ;i++)
   {
      d1bar_0 = iBarShift(Symbol(), D1, Time[i]);          //this one is for checking purpose on D1 only
      d1bar_1 = iBarShift(Symbol(), D1, Time[i]) + 1;      // D1 Bars of H4  
      
      double sar_value  = iSAR(NULL,D1,0.02,0.2,d1bar_1);
      
       if(sar_value>High[d1bar_1]) 
         SAR_long[i]=1;
       else 
         SAR_long[i]=-1;
   }

   
//--- return value of prev_calculated for next call
   return(rates_total);
  }