How To Get The Previous Days Pivot Lines Indicator Value From An EA ?

 
Hi Guys 

I want to Get The previous Days values of a Pivot points indicator . 



I Use The iCustom() To Do That 

   int DayBarNumber=iBarShift( NULL, PERIOD_H1, TimeDay( Time[1] ));

// Day 1
   double D1R3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 0, DayBarNumber );
   double D1R2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 1, DayBarNumber );
   double D1R1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 2, DayBarNumber );
   double D1P =iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 3, DayBarNumber );
   double D1S1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 4, DayBarNumber );
   double D1S2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 5, DayBarNumber );
   double D1S3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 6, DayBarNumber );
   // Day 2
   double D2R3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 0, DayBarNumber-23 );
   double D2R2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 1, DayBarNumber-23 );
   double D2R1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 2, DayBarNumber-23 );
   double D2P =iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 3, DayBarNumber-23 );
   double D2S1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 4, DayBarNumber-23 );
   double D2S2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 5, DayBarNumber-23 );
   double D2S3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 6, DayBarNumber-23 );
   // Day 3
   double D3R3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 0, DayBarNumber-46 );
   double D3R2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 1, DayBarNumber-46 );
   double D3R1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 2, DayBarNumber-46 );
   double D3P =iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 3, DayBarNumber-46 );
   double D3S1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 4, DayBarNumber-46 );
   double D3S2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 5, DayBarNumber-46 );
   double D3S3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 6, DayBarNumber-46 );
Print( D1R3," - ",D1R2," - ",D1R1," - ",D1P," - ",D1S1," - ",D1S2," - ",D1S3 );

 
But , These lines give me a wrong Values 
2015.01.11 12:03:18.760 MarketInfo EURUSD,H1: 2147483647.0 - 2147483647.0 - 2147483647.0 - 2147483647.0 - 2147483647.0 - 2147483647.0 - 2147483647.0

I Think This Problem Is in The Shift Value 

What Do you Think The problem is ?

Thanks For Your Help. 

 

Hello!

TimeDay() returns the day of month (numbers 1...31), not datetime.

Try this code (this is Script):

//+------------------------------------------------------------------+
//|                                                    PivotTest.mq4 |
//+------------------------------------------------------------------+
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
extern int maxWeeks=50;
extern bool weeklyNotDaily = true;
extern bool showPivotLines = TRUE;
extern bool showPivotLabels= TRUE;
extern bool showPivotIcons = FALSE;
extern int pivotThickness= 0;
extern int pivotFontSize = 8;
extern string pivotFont="Impact";
extern color R3Color = Red;
extern color R2Color = Red;
extern color R1Color = Red;
extern color PColor=Blue;
extern color S1Color = Green;
extern color S2Color = Green;
extern color S3Color = Green;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   uint day = 1; // number of day
   datetime prevDayTime=iTime(_Symbol,PERIOD_D1, day);
   int DayBarNumber=iBarShift(NULL,PERIOD_H1,prevDayTime);

// Day 1
   double D1R3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 0, DayBarNumber );
   double D1R2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 1, DayBarNumber );
   double D1R1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 2, DayBarNumber );
   double D1P =iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 3, DayBarNumber );
   double D1S1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 4, DayBarNumber );
   double D1S2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 5, DayBarNumber );
   double D1S3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 6, DayBarNumber );
// Day 2
   double D2R3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 0, DayBarNumber-23 );
   double D2R2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 1, DayBarNumber-23 );
   double D2R1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 2, DayBarNumber-23 );
   double D2P =iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 3, DayBarNumber-23 );
   double D2S1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 4, DayBarNumber-23 );
   double D2S2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 5, DayBarNumber-23 );
   double D2S3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 6, DayBarNumber-23 );
// Day 3
   double D3R3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 0, DayBarNumber-46 );
   double D3R2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 1, DayBarNumber-46 );
   double D3R1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 2, DayBarNumber-46 );
   double D3P =iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 3, DayBarNumber-46 );
   double D3S1=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 4, DayBarNumber-46 );
   double D3S2=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 5, DayBarNumber-46 );
   double D3S3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 6, DayBarNumber-46 );
   Print("prevDayTime = ", prevDayTime, "; DayBarNumber = ",DayBarNumber," || ", D1R3," - ",D1R2," - ",D1R1," - ",D1P," - ",D1S1," - ",D1S2," - ",D1S3);
  }
//+------------------------------------------------------------------+
You can also use a special function that searches for the desired shift of the bar. Example:
...
uint getDayShift(const uint dayNumder)
{
   uint currentDaysShift = 0;
   for(int i = 0; i < Bars(_Symbol, PERIOD_H1) - 1; i++)
   {
      if(TimeDay(Time[i]) != TimeDay(Time[i+1]))
      {
         currentDaysShift++;
         if(currentDaysShift == dayNumder+1)
         {
            return i;
         }   
      }
   }
   return 0;
}

void OnStart()
  {
//---

   uint DayBarNumber = getDayShift(1);

// Day 1
   double D1R3=iCustom( NULL, PERIOD_H1, "FXI Weekly Pivots" , maxWeeks,weeklyNotDaily,showPivotLines,showPivotLabels,showPivotIcons,pivotThickness,pivotFontSize,pivotFont,R3Color,R2Color,R1Color,PColor,S1Color,S2Color,S3Color, 0, DayBarNumber );
...
...and bars count in days will not necessarily be 23.
I recommend determine the offset for each day separately, eg:
   int DayBarNumber_1=iBarShift(NULL,PERIOD_H1,iTime(_Symbol,PERIOD_D1, 1));
...
   int DayBarNumber_2=iBarShift(NULL,PERIOD_H1,iTime(_Symbol,PERIOD_D1, 2));
...
   int DayBarNumber_2=iBarShift(NULL,PERIOD_H1,iTime(_Symbol,PERIOD_D1, 3));
...
etc
 
  1.  0, DayBarNumber-23 );
    Going to the past is increasing bar numbers.
  2. Do not assume that all bars are present. Use iBarShift like ENSED said.
 
WHRoeder:
  1. Going to the past is increasing bar numbers.
  2. Do not assume that all bars are present. Use iBarShift like ENSED said.
Thanks Alot ENSED , It works now , but I increase The "currentDaysShift" by 1 to give me the 3 first days values . Because if I leave it 0 , it gives me The 2nd , 3rd and the 4th Days values .

WHRoeder , Thanks :) , it's a stupid mistake .
Reason: