EXPERTS / SENIORS Could you please make the below afl workable. Below is the code and error msg screenshot and source from where I got it:
_SECTION_BEGIN("_automatictrendlines");
GraphXSpace=10;
indicatorMode = Status( "action" ) == actionIndicator;
Buy = Short = Sell = Cover = 0;
BuyZone = 0;
ShortZone = 0;
tangent = 0;
firstVisible = Status( "FirstVisibleBarIndex" );
LastVisible = Status( "LastVisibleBarIndex" );
isVisible = 0;
breakOut = 0;
graphColor = colorOrange;
ParamStr("TRIX Default Period", "2");
indyOpt =ParamList("Indicator", "RSI|CCI|ROC|TRIX|BLI");
Period = Param("pds ",7,1,28,1);
//bollingerline Indicator
width = Optimize("width ",Param("width ",2,0.1,10,0.1),2,2,0.1);
C1 = C - BBandBot( Close, period, width) ;
C2 = BBandTop (Close,period,width) - BBandBot( Close, period, width);
RS = (AMA( C1, 0.5 ) / AMA( C2, 0.5 ))*100; //smooth
uptrendS = rs > Ref(rs,-1);
downtrendS = rs < Ref(rs,-1);
//einde
r= Optimize("Reverse ",Param("Reverse ",1,1,28,1),1,28,1);
reverse = r / 100;
pds = Optimize("pds ",Period,1,28,1);
switch (indyOpt)
{
case "RSI":
SetChartOptions(1,0,chartGrid20 |chartGrid50 |chartGrid80);
myArray = RSI( pds );
break;
case "CCI":
SetChartOptions(1,0,chartGrid100 );
myArray = CCI( pds );
break;
case "ROC":
SetChartOptions(1,0,chartGrid0);
myArray = ROC( Close, pds );
break;
case "TRIX":
SetChartOptions(1,0, chartGrid0);
pds = Optimize("pds ",Param("pds ",2,1,28,1),1,28,1);
myArray = Trix( pds );
break;
case "BLI":
SetChartOptions(1,0,chartGrid20|chartGrid30 |chartGrid50 |chartGrid70|chartGrid80);
myArray = RS ;
break;
}
j = 0;
direction[0] = 0;
dd = 0 ;
y[0] = myArray[pds];
x[0] = 0;
for ( i = pds + 1; i < BarCount; i++ )
{
if ( direction[j] == 0 )
{
if ( myArray <= y[j] )
{
y[j] = myArray;
x[j] = i;
}
else
if ( myArray >= y[j]*( 1 + reverse ) )
{
j++;
y[j] = myArray;
direction[j] = 1;
x[j] = i;
}
}
else
{
if ( myArray >= y[j] )
{
y[j] = myArray;
x[j] = i;
}
else
if ( myArray <= y[j]* ( 1 - reverse ) )
{
j++;
y[j] = myArray;
direction[j] = 0;
x[j] = i;
}
}
dd = direction[j];
if ( x[j] >= firstVisible && x[j] <= LastVisible )
isVisible[j] = 1;
if ( j > 2 )
{
dy = ( y[j] - y[j-2] ) ;
dx = x[j] - x[j-2];
tangent[j] = dy / dx;
if ( direction[j] )
{
breakOut[j] = tangent[j] > tangent[j-2] ;
if ( breakOut [j] )
{
BuyZone = 1 ;
graphColor = colorGreen;
}
}
else
{
breakOut[j] = tangent[j] < tangent[j-2];
if ( breakOut[j] )
{
ShortZone = 1;
graphColor = colorDarkRed;
}
}
}
}
Buy = Cover = ExRem( BuyZone, !dd );
Short = Sell = ExRem( ShortZone, dd ) ;
if ( IndicatorMode )
{
Shortname = " USE_"+indyOpt+"("+Pds+")";
Plot ( myArray, Shortname , Graphcolor ,styleThick);
}
PlotShapes( Buy * shapeUpArrow , colorGreen, 0, myArray );
PlotShapes( Short * shapeDownArrow , colorRed, 0, myArray);
//-------display trendlines------------//
tlcolor = colorGreen;
myTrendLine = Null;
for ( n = 1; n <= j; n++ )
{
if ( isVisible[n] && n > 3 )
{
if ( direction[n] )
tlcolor = colorGreen;
else
tlcolor = colorRed;
if ( breakOut[n] )
myTrendline = LineArray( x[n-4], y[n-4], x[n-2], y[n-2], 1 );
myTrendline = IIf( BarIndex() > x[n], Null, myTrendline );
Plot( myTrendline, "", tlcolor, styleLine + styleNoRescale | styleNoLabel | styleDashed );
}
}
_SECTION_END();