Any insight into how to resolve this would be greatly appreciated.

Code: Select all

`variables:`

MomentumLength ( 1 ),

FlagVar ( 0 ),

MomentumVar ( 0 ),

HighVal ( 0 ),

LowVal ( 0 ),

IndexVar ( 0 );

// Take the one day momentum of price

MomentumVar = Momentum ( C , MomentumLength );

// Check if momentum (MomentumVar) is falling

if MomentumVar< MomentumVar[1] and MomentumVar[1] < MomentumVar[2] then begin

// Set FlagVar flag to -1 for declining momentum

FlagVar = -1;

// end loop

end;

// Check if momentum (MomentumVar) is rising

if MomentumVar> MomentumVar[1] and MomentumVar[1] > MomentumVar[2] then begin

// Set FlagVar flag to +1 for rising momentum

FlagVar = 1;

// end loop

end;

// Check if momentum is flagged rising

if FlagVar = 1 then begin

// Initilize index to 0

IndexVar = 0;

// set HighVal to the high indexed to the flagged bar

HighVal = High[IndexVar];

// if HighVal has a value then hold that value each bar forward using the index counter IndexVar incremented by 1

if HighVal <> 0 then IndexVar = IndexVar + 1;

// end loop

end;

// Check if momentum is flagged falling

if FlagVar = -1 then begin

// Initilize index to 0

IndexVar = 0;

// set LowVal to the Low indexed to the flagged bar

LowVal = Low[IndexVar];

// if LowVal has a value then hold that value for each bar forward using the index counter IndexVar incremented by 1

if LowVal <> 0 then IndexVar = IndexVar + 1;

// end loop

end;

// plot current value of HighVal

plot1 (HighVal,"High");

// plot current value of LowVal

plot2 (LowVal,"Low");