Having sorted out the parameter problem (many thanks to #fxshrat) I now have a working line plot.
For me, it was a useful exercise in understanding a zig-zag type plot by using the selected bar as the endpoint of the plot.
In case anyone is interested I have included the 2 codes (1 include member and the indicator code).
I am aware that other code exists (e.g. zig) but I wanted to see the effect as each bar is clicked.
Cheers,
Gary.
The plot line indicator code :
_TRACE( "!CLEAR!" );
#include_once <linePlotter.afl>;
confirmBars = Param("confirm days", 3, 1, 10, 1 );
showHistory = Paramtoggle("show history", "No|Yes", 0 );
allLines = linePlotter( SelectedValue( bi ), confirmBars, showHistory );
Plot( allLines, "all lines", colorWhite, styleLine, Null, Null, 0 );
and the include code "lineplotter"
//global lineStartBi;
//global lineEndBi;
//global startClose;
//global endClose;
//global confirmLow;
//global confirmHigh;
//global isTrough;
//global isPeak;
//global troughBi;
//global paekBi;
//global confirmBars;
//global confirmedBi;
global inUpSwing;
global inDownSwing;
lineStartBi = lineEndBi = startClose = endClose = 0;
bi = barIndex();
function linePlotter( lineEndBi, confirmBars, showHistory )
{
showHistory = nz( showHistory, false );
outputLine = Null;
//_TRACE( "Selected Bi " + selectedBi );
//_TRACE( "confirmedBi " + confirmedBi );
//_TRACE( "lineEndBi " + lineEndBi );
isFirstLine = True;
while( lineEndBi > 0 )
{
if( isFirstLine )
{
isFirstLine = false;
confirmedBi = lineEndBi - confirmBars;
confirmLow = llv( Close, confirmBars );
confirmHigh = hhv( Close, confirmBars );
isTrough = IIf( bi <= confirmedBi
AND Close < Ref( confirmLow, confirmBars )
AND Close <= Ref( Close, -1 ), True, False );
isPeak = IIf( bi <= confirmedBi
AND Close > Ref( confirmHigh, confirmBars )
AND Close >= Ref( confirmHigh, BarsSince( confirmLow ) * -1 ), True, False );
isPeak = ExRem( isPeak, isTrough );
isTrough = ExRem( isTrough, isPeak );
PlotShapes(ispeak * shapeDownArrow, colorRose, 0, High );
PlotShapes(isTrough * shapeupArrow, colorRose, 0, low );
}
peakBi = ValueWhen( isPeak AND bi < lineEndBi , bi );
troughBi = ValueWhen( isTrough AND bi < lineEndBi, bi );
sincePeak = bi - peakBi;
sinceTrough = bi - troughBi;
inDownSwing = IIf( sincePeak < sinceTrough, True, False );
inUpSwing = IIf( sinceTrough < sincePeak, True, False );
lineStartBi = IIf( inDownSwing, peakBi, troughBi );
lineStartBi = Nz( lineStartBi[lineEndBi] );
startClose = Close[lineStartBi];
lowestSincePeak = LowestSince( bi == peakBi, Close );
highestSinceTrough = highestsince( bi == troughBi, Close );
endClose = IIf( inDownSwing, lowestSincePeak, highestSinceTrough );
endClose = endClose[lineEndBi];
Line = LineArray( lineStartBi, startClose, lineEndBi, endClose );
outputLine = IIf( IsNull( line ), outputLine, line );
if( NOT showHistory )
lineEndBi = -1;
else
lineEndBi = Nz( lineStartBi, -1 );
}
return outputline;
}