Daily High Low timing for last day bar

 

Hi, I have this code for calculating current day High/Low Timing, That works perfectly,

But If change the Bar= 0 to Bar=1

Then for last day High low timing it shows wrong as obviously I counted with TimeCurrent()

Instead of counting it with TimeCurrent() is there any way to show last day high low time in other way?

Here is the code:

 
   datetime ThisD = iTime(Symbol(),PERIOD_D1,Bar);
   int      Start  = iBarShift(Symbol(),PERIOD_M1,ThisD),
            Count  = iBarShift(Symbol(),PERIOD_M1,TimeCurrent()),
            Index  = iLowest(Symbol(),PERIOD_M1,MODE_LOW,Start,Count),
            Index2 = iHighest(Symbol(),PERIOD_M1,MODE_HIGH,Start,Count);
   datetime LowT   = iTime(Symbol(),PERIOD_M1,Index);
   datetime HighT  = iTime(Symbol(),PERIOD_M1,Index2);

Thanks in advance.

Regards

 

I tried doing it in following way, It showing high time correctly but low time is wrong.

 datetime HighT,LowT;
  if(Bar == 0)
  {
   datetime ThisD = iTime(Symbol(),PERIOD_D1,Bar);
   int      Start  = iBarShift(Symbol(),PERIOD_M1,ThisD),
            Count  = iBarShift(Symbol(),PERIOD_M1,TimeCurrent()),
            Index  = iLowest(Symbol(),PERIOD_M1,MODE_LOW,Start,Count),
            Index2 = iHighest(Symbol(),PERIOD_M1,MODE_HIGH,Start,Count);
   LowT   = iTime(Symbol(),PERIOD_M1,Index);
   HighT  = iTime(Symbol(),PERIOD_M1,Index2);
   
  }
 //-----------For checking past data---------// 
  else
  {
   datetime ThisD = iTime(Symbol(),PERIOD_D1,Bar);
   int      Start  = iBarShift(Symbol(),PERIOD_M1,ThisD),
            Count  = iBarShift(Symbol(),PERIOD_M1,(ThisD+86400)),
            Index  = iLowest(Symbol(),PERIOD_M1,MODE_LOW,Start,Count),
            Index2 = iHighest(Symbol(),PERIOD_M1,MODE_HIGH,Start,Count);
   LowT   = iTime(Symbol(),PERIOD_M1,Index);
   HighT  = iTime(Symbol(),PERIOD_M1,Index2);
 
   }

 High showing 9:30 Low time 15:43

But in reality High time is 9:30 & low time is 0:18 

I tested with another example, there it showing low time correct but high time wrong. Why its happening like this? 

 
  1.          Count  = iBarShift(Symbol(),PERIOD_M1,TimeCurrent()),
    Count will be zero always.
  2.           Index  = iLowest(Symbol(),PERIOD_M1,MODE_LOW,Start,Count)
    The number of bars between Start and Count including both is Start - Count + 1. You never look at the first bar of the day.
  3. Count  = iBarShift(Symbol(),PERIOD_M1,(ThisD+86400)),
    This assumes there are no gaps in time, like on the weekend and market holidays. Get the time of the second daily bar and don't count the first bar of today.
     datetime  Today     = iTime(Symbol(),PERIOD_D1,Bar);
     datetime  Yesterday = iTime(Symbol(),PERIOD_D1,Bar+1);
     int      StartToday      = iBarShift(Symbol(),PERIOD_M1,Today),
              StartYesterday  = iBarShift(Symbol(),PERIOD_M1,Yesterday),
              EndYesterday    = StartToday - 1,
              Index  =  iLowest(Symbol(),PERIOD_M1,MODE_LOW, StartYesterday - EndYesterday + 1, EndYesterday),
              Index2 = iHighest(Symbol(),PERIOD_M1,MODE_HIGH,StartYesterday - EndYesterday + 1, EndYesterday),

 

Hi,

Thank you for the correction. 

For 1st point, I know its zero. That's what I want to get current day high low on live chart.

About the 2nd point, if a day low forms at 0:00 on current day then I need to look at the 1st bar of the day isn't it ?

I added the 3rd code when Bar>0 (for last day) but it doesn't worked. Still showing one data correct other one wrong. 

Regards

 
cashcube: About the 2nd point, if a day low forms at 0:00 on current day then I need to look at the 1st bar of the day isn't it?
Index  = iLowest(Symbol(),PERIOD_M1,MODE_LOW,Start,Count)
Yes and that is not what you are doing
start                    count
  5    4    3    2    1    0
    [  5    4    3    2    1] iLowest( length=start, begin=count)
 ^ first bar not scanned. 5 bars scanned 0 through 4.
 
WHRoeder:
Yes and that is not what you are doing

Hi

Thank you for posting the explanation.  

I tried using your code on both cases for Bar == 0 (Current day)

for Bar >0, its showing wrong data.

In fact for Bar == 0 my previous code is working.

but for Bar>0 nothing is working.

 
//------------TIming-----------//
  datetime HighT,LowT;
  if(Bar == 0)
  {
   datetime ThisD = iTime(Symbol(),PERIOD_D1,Bar);
   int      Start  = iBarShift(Symbol(),PERIOD_M1,ThisD),
            Count  = iBarShift(Symbol(),PERIOD_M1,TimeCurrent()),
            Index  = iLowest(Symbol(),PERIOD_M1,MODE_LOW,((Start-Count)+1),Count),
            Index2 = iHighest(Symbol(),PERIOD_M1,MODE_HIGH,((Start-Count)+1),Count);
   LowT   = iTime(Symbol(),PERIOD_M1,Index);
   HighT  = iTime(Symbol(),PERIOD_M1,Index2);
   
  }
 //-----------For checking past data---------// 
  else
  {
   datetime  Today     = iTime(Symbol(),PERIOD_D1,Bar);
   datetime  Yesterday = iTime(Symbol(),PERIOD_D1,Bar+1);
   int       StartToday      = iBarShift(Symbol(),PERIOD_M1,Today),
             StartYesterday  = iBarShift(Symbol(),PERIOD_M1,Yesterday),
             EndYesterday    = StartToday - 1,
   Index  = iLowest(Symbol(),PERIOD_M1,MODE_LOW, StartYesterday - EndYesterday + 1, EndYesterday),
   Index2 = iHighest(Symbol(),PERIOD_M1,MODE_HIGH,StartYesterday - EndYesterday + 1, EndYesterday);
   LowT   = iTime(Symbol(),PERIOD_M1,Index);
   HighT  = iTime(Symbol(),PERIOD_M1,Index2);
 
   }

Among this code Bar == 0 is working well but not Bar >0  in 2nd part.

There is a problem with the 2nd code.

 
 //-----------For checking past data---------// 
  else
  {
   datetime  Today     = iTime(Symbol(),PERIOD_D1,Bar);

if Bar !=0, you will not be working with Today, same with Yesterday.

if Bar==1 you will be getting the high and low time of the day before yesterday

 
GumRai:

if Bar !=0, you will not be working with Today, same with Yesterday.

if Bar==1 you will be getting the high and low time of the day before yesterday


Yes in case of current day its forward checking & in case of Bar>0 its a back ward checking way where high low is already formed.

My current day code is working but I am not sure what i need to do for 2nd part.

I try removing the else part instead added if(Bar>0) or even with if(Bar!=0) then the 2nd code. But its not working. Bar>0 is means always the last day data & so on.

Then is the 2nd code is totally wrong for Bar == 1, Bar==2 or anything above 0?

 

I'm not sure that we are understanding each other

instead of

   datetime  Today     = iTime(Symbol(),PERIOD_D1,Bar);
   datetime  Yesterday = iTime(Symbol(),PERIOD_D1,Bar+1);

try

   datetime  Today     = iTime(Symbol(),PERIOD_D1,Bar-1);
   datetime  Yesterday = iTime(Symbol(),PERIOD_D1,Bar);

then when Bar==1 it will work with yesterday's data

 
GumRai:

I'm not sure that we are understanding each other

instead of

try

then when Bar==1 it will work with yesterday's data


Thank you for pointing out.

Now its working!