Abbie, Instead of wandering around in "loop land" think about arrays (see Users Guide for array discussion). Then something along these lines would give you Davis' rule:
change = Param( "Change", 1.005, 1, 1.01, .001 ); citLow = IIF( MA( C, 27 ) < Ref( MA( C, 27 ) , -1 ), 1, 0 ); citHigh = IIF( MA( C, 27 ) > Ref( MA( C, 27 ), -1 ), 1, 0 ); Plot( ( citLow * -1 ) + ( citHIgh * 1 ), "", IIF( citLow, colorRed, colorWhite ) ); Bill ----- Original Message ----- From: sendfreetest To: [email protected] Sent: August 05, 2010 12:06 PM Subject: [amibroker] Ned Davis' Slope Rule 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); ------------------------------------ **** IMPORTANT PLEASE READ **** This group is for the discussion between users only. This is *NOT* technical support channel. TO GET TECHNICAL SUPPORT send an e-mail directly to SUPPORT {at} amibroker.com TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at http://www.amibroker.com/feedback/ (submissions sent via other channels won't be considered) For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG: http://www.amibroker.com/devlog/ Yahoo! Groups Links
