uptrend or downtrend code

#1
Hello everyone,

I am trying to write a script for scanning the candlestick patterns for weekly trade. As part of the script, I need to write code to determine the up or down trend. I have the following code currently.


LLClose = LLV( L, 5 );
HHClose = HHV( H, 5 );

// UpTrend
//---------
noUpCount = 0;

for ( i = 0; i <= 10; i++ )
{
// Checking for false condition of up turn for each iteration
noUpCount = IIf( Ref( HHClose, -i ) < Ref( HHClose, -i - 1 ), 1, 0 ) + noUpCount ;
}

// DownTrend
//-----------
UpTrend = IIf( noUpCount == 0, 1, 0 );

noDownCount = 0;

for ( i = 0; i < 10; i++ )
{
// Checking for false condition of down turn for each iteration
noDownCount = IIf( Ref( LLClose, -i ) > Ref( LLClose, -i - 1 ), 1, 0 ) + noDownCount ;
}

DownTrend = IIf( noDownCount == 0, 1, 0 ) ;


The above logic works very well to find out the trend. But, the problem is that the above logic is too strict and results in very less data.

Can someone please help me with this?
1. Either by providing a different logic other than using llv/hhv.
2. or by providing better values to be used in the loop and in llv/hhv.

thank you very much
nagarjuna
 

Similar threads