Hi,

I am trying to use Ned Davis' "slope rule" to determine if the
market is up or down.

The market is bullish when the ^DJU - 27 week simple moving
average has been trending down and then rises by any amount
(i.e. reverses).
( Then the variable djupermit should be assigned a value of 1.)

The market is bearish when the ^DJU - 27 week simple moving
average has been trending up and then falls by 3%.
( Then the variable djupermit should be assigned a value of -1.)


I have been struggling to write a nested loop with multiple
undefined variables to accomplish the above. I'm not sure
if I should be writing a function instead?

Any help or guidance getting the code below to work 
would be most appreciated.

Sincerely,

Abbie Drew


SetForeign( "^DJU" );
TimeFrameSet( inWeekly );
wc = Close ;
sMA = MA( C, 27 );

djupermit[0]=0;

djulow[0] = 0;

djuhigh[0] = 0;

for ( i = 1; i < BarCount; i++ )
//Calculate dju low
{
    if ( djupermit[ i] = -1 AND djupermit[ i -1] != -1 ) { djulow[ i ] = 
sMA[i]; }
    else if ( djupermit[ i] != 1 AND sMA[i] < djulow[ i -1 ]) { djulow[ i ] = 
sMA[i]; }
    else djulow[ i ] = djulow[ i - 1 ];
}

//Calculate dju high
for ( i = 1; i < BarCount; i++ )
{
    if ( djupermit[ i] = 1 AND djupermit[ i -1] != 1 ) { djuhigh[ i ] = sMA[i]; 
}
    else if ( djupermit[ i] != -1 AND sMA[i] > djuhigh[ i -1 ]) { djuhigh[ i ] 
= sMA[i]; }
    else djuhigh[ i ] = djuhigh[ i - 1 ];
}
//Calculate dju permission
for ( i = 1; i < BarCount; i++ )
{

    if ( djupermit[ i -1] != 1 AND sMA[i] > djulow[i - 1]) { djupermit[ i ] = 1 
; }
    else if ( djupermit[ i -1] != -1 AND sMA[i] < (djuhigh[ i -1 ]*0.97)) { 
djupermit[ i ] = -1; }
    else djupermit[ i ] = djupermit[ i - 1 ] ;
}

RestorePriceArrays();
Filter = 1 ;
         AddColumn( TimeFrameExpand( djupermit, inWeekly ), "djupermit", 1.2 );
         AddColumn( TimeFrameExpand( djulow, inWeekly ), "djulow", 1.2 );
         AddColumn( TimeFrameExpand( djuhigh, inWeekly ), "djuhigh", 1.2 );
         AddColumn( TimeFrameExpand( sMA, inWeekly ), "sma", 1.2 );
         AddColumn( TimeFrameExpand( wC, inWeekly ), "wc", 1.2);



Reply via email to