Finding the Particular Candle's High Low with Timenum()

Hi,
As seen in the code Below,First Candle High and low are always correct.
But when it comes to the Second candle High or low.Exploration shows the correct result sometimes and sometimes not.It is inconsistent.
Can you please guide me where i am making mistake?

Regards,

FirstBar = DateNum()!=Ref(DateNum(),-1);
FIrstBarHigh=ValueWhen(FirstBar,High,1.2);
FirstBarLow=ValueWhen(FirstBar,Low,1.2);

tn=TimeNum();
Time1 = 100500;
Timecond1 = tn == Time1;
SecondCandleHigh= ValueWhen(Timecond1,H,1.2);
SecondCandleLow= ValueWhen(Timecond1,L,1.2);

Filter=Buy || Sell ;
AddColumn(SecondCandleHigh,"100500 High",1.2);
AddColumn(SecondCandleLow,"100500 Low",1.2);

Are you sure that there's always a 10:05:00 bar present in your data?

Why not just find the second bar with:

SecondBar = Ref(FirstBar,-1);

Or if you're really looking for the first bar that occurs on or after 10:05:00, you could do something like this:

TimeCond1 = tn >= Time1 AND ref(tn,-1) < Time1;
1 Like

Yes,
i have physically checked in the chart.
Second bar is always present with 10:05:00 in every chart.
SecondBar = Ref(FirstBar,-1); is a very good idea.
But it still produces mixed results.

Can you show some output with the actual data and annotate it to show the expected data?

@Gloriafilamino, I find that using an Exploration that I set up to show me the values I am using is always helpful. Then I can see where values change and track down the difference between what I was expecting, and what I am really calculating.

But for me,the exploration code produced mixed results.I feel like something wrong with the code.It needs to be corrected by an expert.

Your current logic for TimeCond1 will be true for every bar on or after the 9:24:59 bar. You need to add the AND clause that I sent you earlier. When I do this and run against my data, all the Buy and Sell signals occur at Time1 and the 2nd Candle H & L are correct.

Can you show us some output where the H & L are incorrect?

@Gloriafilamino maybe something like this,

dn 			= DateNum();
//dn = Day(); // alternate method

FirstBar  	= dn != Ref( dn, -1 );
SecondBar 	= Ref( FirstBar , -1 );

FBO = ValueWhen( FirstBar , Open );		// First Bar Open
FBH = ValueWhen( FirstBar , High );   	// First Bar High
FBL = ValueWhen( FirstBar , Low ); 	  	// First Bar Low
FBC = ValueWhen( FirstBar , Close );  	// First Bar Close
FBV = ValueWhen( FirstBar , Volume ); 	// First Bar Volume

SBO = ValueWhen( SecondBar, Open ); 	// Second Bar Open
SBH = ValueWhen( SecondBar, High );		// Second Bar High
SBL = ValueWhen( SecondBar, Low );		// Second Bar Low
SBC = ValueWhen( SecondBar, Close );	// Second Bar Close	
SBV = ValueWhen( SecondBar, Volume );	// Second Bar Volume

image

1 Like

@Gloriafilamino: how would I know which of your output is correct and which is not? The code I've given you works with my five minute data, so there's something else going on here but I don't think you've supplied enough information for anyone else to help you figure it out.

That looks like NSE data, yes? My experience is that NSE data is often inconsistent, has holes, etc. So you might want to look at some examples of incorrect 2nd bar H/L and see if you can find any patterns in the underlying data.

1 Like

Yes,I had some missed candles in some of the scrips thus the inconsistency.Thanks for your help.Now it seems ok.
Thanks again.

Thanks for your code.It is working fine and thanks again for the timely help.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.