|
本帖最後由 joshsmi 於 13-11-14 21:24 編輯
Here is another updated code to manually draw multiple AFL code trend lines
// Copyright joshsmi, Oct 2013
Version( 5.55 );
function TL_New( dn1, tn1, startval, dn2, tn2, endval )
{ // trendline function
dt = DateTime();
bi = BarIndex();
startdt = dt == DateTimeConvert( 2, dn1, tn1 );
enddt = dt == DateTimeConvert( 2, dn2, tn2 );
x0 = LastValue( ValueWhen( startdt, bi ) );
x1 = LastValue( ValueWhen( enddt, bi ) );
y0 = LastValue( ValueWhen( startdt, startval ) );
y1 = LastValue( ValueWhen( enddt, endval ) );
Line = LineArray( x0, y0, x1, y1, 1, True );
return Line;
}
RequestTimedRefresh( 1 );
tn = TimeNum();
dn = DateNum();
Chartid = NumToStr( GetChartID(), 1.0, False );
TLnumLow = ParamStr( "Input Support TL number", "1" );
TLnumHigh = ParamStr( "Input Resistance TL number", "1" );
if ( ParamTrigger( "Clear trend-line(s)", "CLICK HERE" ) )
StaticVarRemove( Chartid + "TL_new*" ); // or use persitentvarremove, see link below
// using RANGE MARKERs via mouse double-click!
// read here http://www.amibroker.com/guide/h_charting.html?
startdn = ValueWhen( BeginValue( dn ) == dn, dn );
starttn = ValueWhen( BeginValue( tn ) == tn, tn );
enddn = ValueWhen( EndValue( dn ) == dn, dn );
endtn = ValueWhen( EndValue( tn ) == tn, tn );
// alternatively to static variables you can use persistent varaibles to preserve lines after restart of AB
// read here http://www.amibroker.org/userkb/2007/04/24/persistent-variables/
if ( LastValue( startdn ) != dn[0] && LastValue( starttn ) != tn[0] )
{
if ( GetAsyncKeyState( 76 ) < 0 ) // press key "L" and choose range markers
{
StaticVarSet( Chartid + "TL_new start dn Low" + TLnumLow, startdn );
StaticVarSet( Chartid + "TL_new start tn Low" + TLnumLow, starttn );
StaticVarSet( Chartid + "TL_new end dn Low" + TLnumLow, enddn );
StaticVarSet( Chartid + "TL_new end tn Low" + TLnumLow, endtn );
}
if ( GetAsyncKeyState( 72 ) < 0 ) // press key "H" and choose range markers
{
StaticVarSet( Chartid + "TL_new start dn High" + TLnumHigh, startdn );
StaticVarSet( Chartid + "TL_new start tn High" + TLnumHigh, starttn );
StaticVarSet( Chartid + "TL_new end dn High" + TLnumHigh, enddn );
StaticVarSet( Chartid + "TL_new end tn High" + TLnumHigh, endtn );
}
}
Plot( C, "", colorWhite, styleCandle );
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.2f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
for ( i = 1; i <= 10; i++ ) // 10 trend lines each
{
startdnL = Nz( StaticVarGet( Chartid + "TL_new start dn Low" + i ) );
starttnL = Nz( StaticVarGet( Chartid + "TL_new start tn Low" + i ) );
enddnL = Nz( StaticVarGet( Chartid + "TL_new end dn Low" + i ) );
endtnL = Nz( StaticVarGet( Chartid + "TL_new end tn Low" + i ) );
startdnH = Nz( StaticVarGet( Chartid + "TL_new start dn High" + i ) );
starttnH = Nz( StaticVarGet( Chartid + "TL_new start tn High" + i ) );
enddnH = Nz( StaticVarGet( Chartid + "TL_new end dn High" + i ) );
endtnH = Nz( StaticVarGet( Chartid + "TL_new end tn High" + i ) );
if ( LastValue( startdnL ) != 0 )
{
TLlow = TL_New( startdnL, starttnL, L, enddnL, endtnL, L );
Plot( TLlow, "\nSU Trend line " + i, colorRed, styleLine | styleNoRescale );
PlotText( "No." + i, BarCount + 10, LastValue( TLlow ), colorRed );
}
if ( LastValue( startdnH ) != 0 )
{
TLhigh = TL_New( startdnH, starttnH, H, enddnH, endtnH, H );
Plot( TLhigh, "\nRE Trend line " + i, colorBrightGreen, styleLine | styleNoRescale );
PlotText( "No." + i, BarCount + 10, LastValue( TLhigh ), colorBrightGreen );
}
}
|
評分
-
查看全部評分
|