# Fixing Clenow's Strategy

Hello! I was looking for a clenow strategy in google and came across this code. But there is a problem with it. "Variable used without having been initialized." Can anyone fix it? I have zero knowledge in coding AFL

``````////////////////////////////////////////////

// the calculation for ranking

////////////////////////////////////////////

colD = log(Close ); // the natural log of the close

colE = LinRegSlope( colD, 90 ); // this gives the slope of the regression line

// and we've manipulated it from dollars/day to average percentage move/day

colF = ( ( exp( colE ) ) ^ 250 ) - 1 ;

// we took the natural log so now reverse that and e raised to power of colE

// lets annualize it to get percentage move per year, so ^ 250 trading days (approx/year)

// strangely and unfortunately AmiBroker doesn't have R-Squared built in

colG = ( Correlation( Cum( 1 ), colD, 90 ) ^ 2 ); // 90 day R-Squared of column D, the log(C)

// this will ultimately be a Long Only Rotational system

// slope can be negative, and EnableRotational would initiate Short trades

// so a simple little manipulation will preserve rank and eliminate negative scores

PositionScore = IIf( Rotate, score, scoreNoRotate ) ;

///////////////////

``````

The error means that your code is incomplete, you did not assign any value to "Rotate" variable prior to reading it.
User guide explains all errors
http://www.amibroker.com/guide/errors/29.html

@luthersuerte welcome to this community.

The "Clenow" strategy was previously discussed here with some working code examples.

I suggest to study the thread and review the associated code, but at the same time, I encourage you to start your journey to learn AFL with some simpler strategy.

The AmiBroker KB is a good resource to use along the must-read AFL tutorial (in particular see the AmiBroker Formula Language section) and the categorized list of functions.

Be sure also to review the "How do I learn AFL" and "How do I debug my formula" threads.

7 Likes