Error 10 while exploring stocks

I have been using the below formula to explore stocks(without any issues), recently i have added some more stocks to the database which may have no/missing quotes. since then I am facing error with below part of the code .
if(PPO_H[BarCount-1] > PPO_H[BarCount-2])

I am getting Error 10.

I went through a bunch of posts here for the same error, i am not using a loop and i am not using Barcount, but i am not sure how to fix the error, please help.

PPOShort = 8;
PPOLong = 17;
PPOsignal = 9;
PPO = ( EMA( C, PPOShort ) - EMA( C, PPOLong ) ) / EMA( C, PPOLong );
PPOS = ( EMA( PPO, PPOsignal ) );
PPO_H = PPO - PPOS ;
Mul_Fac = 1;
// Checking Histogram status
if(PPO_H[BarCount-1] > PPO_H[BarCount-2]){

	PPO_Status = "Ticked Up"; 
}	
else{

	PPO_Status = "Ticked Down";
}

Filter = 1;
// Display columns
AddColumn( Close, "Close" );
AddColumn( EMA( Close, 22 ), "22 EMA" );
AddTextColumn(PPO_Status,"PPO Status",width = 1 );

Read this article

You are using subscripting

Either

PPO_Status  = "";

if ( Barcount > 1 ) 
{
	// Checking Histogram status
	if(PPO_H[BarCount-1] > PPO_H[BarCount-2]){

		PPO_Status = "Ticked Up"; 
	}	
	else{

		PPO_Status = "Ticked Down";
	}
}

Or better do as shown by Tomasz below...

1 Like

Really? Then what is that:

if(PPO_H[BarCount-1] > PPO_H[BarCount-2]){

If BarCount happens to be 1 then the line above would cause accesing element with index -1 which is obviously wrong.

You should be using

if( LastValue( PPO_H - Ref( PPO_H, -1 ) ) > 0 ) {
1 Like

My bad, i meant Barcount in a loop.

Thank you so much, learned from both legends today.

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