ERROR 29: Variable IND used without having been initialized

I use AB 6.30.5 and Windows 11
In the formula below,
I can use line 7( BBB(Ind,P) )
If I replace line 6 with line 5
AB answers me:
ERROR 29: Variable IND used without having been initialized
If I can't use IND on line 5,
Why is it correct on line 7

Thanks
Yves Laliberté

_SECTION_BEGIN("CrBB+++++ Week In Daily de base");		
/*   Plusieur Cross(C,Boll.Bands) = 1er journée	*/


//function BBT(Ind,P)	{ bon= BBandTop(Ind,P,2) ; return bon ; } ;
function BBT(P)	{ bon= BBandTop(C,P,2) ; return bon ; } ;
function BBB(Ind,P)	{ bon= BBandBot(Ind,P,2) ; return bon ; } ;
function CrBBT(P)	{ bon= Cross(C,BBT(P)) ; return bon ; } ;
MaxP= BarsSince(Cross(StochK(9,3),StochD(9,3,3)) AND LLV(StochK(9,3),3)<=20) ;
function BrOutBb(Ind,P) 
	{bon= IIf( CrBBT(P) AND Ref(BarsSince(CrBBT(P))>MaxP,-1) , 1 ,0 ) ;
	Bon= IIf(Bon==1,2,0) ; return Bon ; }	
	


TimeFrameSet( inweekly ); // switch now to week
Br= BrOutBb(C,15) ;
TimeFrameRestore(); // restore time frame to original 
BrW= TimeFrameExpand( Br, inWeekly) ;
Plot(BrW,"BrOut-W",colorDarkRed,styleOwnScale );
Plot(BBB(C,15),"BBB-W",colorBlue,styleOwnScale );


_SECTION_END();

Scripting languages usually do not support function overloading. Like python or javascript.
It is the strongly typed languages that can dynamically figure it out.
In python, the last defined function is used and the previous overload definitions are ignored.

so in short you can't have two functions with the same name and different parameter list.

function BBT( Ind, P ) { /* code */ }
function BBT( P ) { /* code */ }

Now, what happens is you use 1 argument Cross(C,BBT(P)) and uncomment function BBT( Ind, P ) then argument will mis-match and you get different kind of error.
I am getting error 17 missing arguments, when i change line in your code. not 29

You should not use ";" semi-colon after function

function test( x )
{
    return x;
} // no semi-colon required here

So you do this,

BBT1( p ) { /* code */ }
BBT2( Ind, p ) { /* code */ }

// then use
a = Cross( C, BBT1( P ) )...
b = Cross( C, BBT2( Ind, P ) )...

I tried to overload in my AFL test and got errors that I expected.

function test1( x ) { printf("1"); }
function test1( x, y ) { printf("2"); }
// when either one is commented it works
// but when both uncommented, there is error Syntax Error 31
1 Like

I tried with line 5,6 and 7 you wrote

My post wasn't saved, can you show how you get Error 29?

@nsm51, you are right. The BBT() function is called from the CrBBT() one and expects 2 parameters. (The commented out version had only P as a param). - The error message in this specific case is not clear, but below there is another one that indicates the actual issue:

@yveslaliberte you should invoke the BBT() function passing the 2 required parameters (where in my screenshot you see error 17).

3 Likes

it shows in syntax checker, during exec 17 comes before i think.