High Low changes in different time frames

I have coded to get high low (15 minutes intervals) of 3 time periods during the intraday.
a. 9:15am - 9:30am
b. 12.15pm - 12.30pm
c. 14.30pm - 14.30pm

when I am in say 1min TF, i get certain high low values. when I change the TF to 5min, the values changes and again it changes when I am in 15min TF.

Can you please help me identify what changes i should do so that the High Low values across 1min, 5min and 15min Timeframe, they remain static whenever i change the TF between 1m, 5m or 15, I am not switching to 30min or higher timeframe.



SetBarsRequired(86400 / Max(1, Interval() ), -1  );
SetChartOptions(0,chartShowDates|chartShowArrows|chartWrapTitle); //chartLogarithmic
GraphXSpace = 10;
	
dn = DateNum();
tn = TimeNum();
Today = dn != Ref(dn, -1);


marketOpenTime = ValueWhen(Today, tn,1);

// High Low of 09:15 till 09:30  
StartTime	= MarketOpenTime;		
EndTime		= StartTime + 15*100;

StartBar = tn == StartTime; 		
EndBar = tn == EndTime; 
H0930 = IIf(tn < EndTime, Null, ValueWhen( EndBar, HighestSince( StartBar, High ) )); 
L0930 = IIf(tn < EndTime, Null, ValueWhen( EndBar, LowestSince( StartBar, Low ) )); 


// High low of   12:15 to 12:30 
StartTime	= 121500;		
EndTime		= StartTime + 15*100;			
StartBar = tn == StartTime; 	
EndBar = tn == EndTime; 
H1230 = IIf(tn < EndTime, Null, ValueWhen( EndBar, HighestSince( StartBar, High ) )); 
L1230 = IIf(tn < EndTime, Null, ValueWhen( EndBar, LowestSince( StartBar, Low ) )); 

// High Low fo  14:15 till 14:30
StartTime	= 141500;		EndTime		= StartTime + 15*100;			// 10.30am
StartBar = tn == StartTime; 	EndBar = tn == EndTime; 
H1430 = IIf(tn < EndTime, Null, ValueWhen( EndBar, HighestSince( StartBar, High ) )); 
L1430 = IIf(tn < EndTime, Null, ValueWhen( EndBar, LowestSince( StartBar, Low ) )); 


Plot(C,"",colorBlack,styleCandle);
PlotGrid( SelectedValue(C), colorWhite, pattern =1, width=1,False);
	
hlstyle = styleDashed|styleLine|styleNoRescale|styleNoTitle;
hlstyle2 = styleDashed|styleLine|styleNoRescale|styleNoTitle|styleThick;
hlstyle3 = styleDots|styleLine|styleNoRescale|styleNoTitle;


Plot( h0930, "0930amH", colorBlue, hlstyle );
Plot( l0930, "0930amL", colorPlum, hlstyle );
	
Plot( h1230, "1230pmH", colorBlue, hlstyle2 );
Plot( l1230, "1230pmL", colorPlum, hlstyle2 );
	
Plot( h1430, "1430pmH", colorBlue, hlstyle3 );
Plot( l1430, "1430pmL", colorPlum, hlstyle3 );


pdc = TimeFrameGetPrice( "Close", inDaily, -1, expandFirst);
colortext = colorBlack;
//========================================================================================================
//  Chart Title ----
//========================================================================================================
Title = EncodeColor( colortext ) +  Name() + " - " + EncodeColor( colorText ) + Interval( 2 )  +
        "  - "  + Date() + " - " + EncodeColor( colorText ) +
        "O: " + O + " " +	        "H: " + H + " " +
        "L: " + L + " " +	        "C: " + C + " (" +
          NumToStr( 100*( C - pdc) / pdc, 1.2) +  " % ) " +

        "\n 09:30AM H: " + NumToStr( H0930, 1.2 ) +   "   L: " + NumToStr( L0930, 1.2 ) +
        "\n 12:30PM H: " + NumToStr( H1230, 1.2 ) +   "   L: " + NumToStr( L1230, 1.2 ) +
        "\n 14:30PM H: " + NumToStr( H1430, 1.2 ) +   "   L: " + NumToStr( L1430, 1.2 ) 
         
        ;
// ================================================


Here are the images for Reference
1min TF:
image

5min TF:
image

15min TF:
image

For 12.15- 12.30 candle, following is the data for High Low
High = 9417.40
Low= 9390.80

In 1min TF, 15min period the High low values are shown as
High= 9217.05
Low=9196.40

Similarly in 5min TF, 15min period, the high- Low values are shown below:
High=9221.30
Low=9196.40

In 15m TF, high low Levels are shifted by one Candle to 12.30 - 12.45 candle.
How can this be fixed to refer to 12.15-12.30 candle?

There is nothing wrong, you just have to carefully analyze what you are trying to achieve and what you are coding.

This variation will occur because you are assuming the meaning of start time of a candle.
The bar times by default are start times.

Now in 1m TF, when you say 9:30am, it is actually high of that 1m bar.

but in 5m, if you say 9:30am, it is the H upto 9:34:59am.
so in that 4min, if the price goes higher, it will obviously be different.

Same logic for 15m TF.
9:30am bar is actually till the end of the bar that is 9:44:59am <-- highest variation will occur with 1m TF.

I don't know if there is a solution. If I give you a Daily candle, can you tell me exactly how price moved in 5m bars? i think no one can.
You may have to approach it differently depending on what you want to do.

3 Likes

Thanks @nsm51.

The base data is built from 1min timeframe. So, I am not able to understand whey the HL between the specfic time intervals which is multiple of the 1min TF, is shown different..

Please excuse me for the naive question.

It is not about the base time interval. It is about the candle.
You are asking AB to tell you the H/L of a candle in a particular timeframe.
In 15m TF, the 9:30:00am candle represents prices in the period from 9:30:00 to 9:44:59am, AB will return the H/L in that 15m period.

Any correctly written software or logic would do the same.