The “automatic trend line” AFL (see below) from Amibroker library is a powerful little program. In order to evaluate it as an entrance or exit tool, I need to automatically draw a trend line with reference to a past bar. I thought the function “SelectedValue ” might be a g ood command, but I fail to make it to work. Could someone help me? Thanks.
x = Cum(1);
perchg = 0.3*LastValue( Highest( ROC( Low, 50 ) ));
startvalue = LastValue( Trough( Low, perchg, 1 ) );
endvalue1 = LastValue( Trough( Low, perchg, 2 ) );
startbar = LastValue( ValueWhen( Low == startvalue, x, 1 ) );
endbar = LastValue( ValueWhen( Low == endvalue1, x, 1 ) );
Aa = (endvalue1-startvalue)/(endbar-startbar);
b = startvalue;
trendline = Aa * ( x - startbar ) + b;
Plot( Close, "Price", colorBlue, styleCandle );
Plot( IIf( x >= endbar, trendline, Null ), "Trendline", colorRed