May 6, 2006
Discretionary Equity
In the March 2006 “Letters to S&C” section I found the following request:
“I am looking for and add-on […] that would enable me to build an equity curve from buy/sell signals that the trader directly draws over the price graph of a commodity; for example, using specific active vertical lines. Such a software would be of great help for discretionary traders to validate their semiautomatic systems. — PH CHAMBAULT”
And I just thought that it would be nice example of using AFL’s Equity() function and ParamTrigger()
The following code implements the above idea:
Buy = 1;
Sell = Cover = Short = 0;
bh = Equity( 0, 0 );
setbuy = ParamTrigger("Buy", "Buy" );
setsell = ParamTrigger("Sell", "Sell" );
setshort = ParamTrigger("Short", "Short" );
setcover = ParamTrigger("Cover", "Cover" );
clear = ParamTrigger("Clear", "Clear" );
clearall = ParamTrigger("Clear All", "Clear All" );
bi = BarIndex();
sbi = SelectedValue( bi );
qty = LastValue( bi );
Varname = Name() + sbi;
if( setbuy )
{
StaticVarSet( Varname, 1 );
}
if( setsell )
{
StaticVarSet( Varname, -1 );
}
if( setshort )
{
StaticVarSet( Varname, -2 );
}
if( setcover )
{
StaticVarSet( Varname, 2 );
}
if( clear )
{
StaticVarRemove( Varname );
}
if( clearall )
{
for( i = 0; i < qty; i++ ) StaticVarRemove( Name() + i );
}
Buy = Sell = Short = Cover = 0;
for( i = 0; i < qty; i++ )
{
sig = StaticVarGet( Name() + i );
if( sig == 1 ) Buy[ i ] = True;
if( sig == -1 ) Sell[ i ] = True;
if( sig == -2 ) Short[ i ] = True;
if( sig == 2 ) Cover[ i ] = True;
}
Color = IIf( Buy OR Cover, colorGreen, colorRed );
RedundantBuy = Buy;
RedundantSell = Sell;
RedundantShort = Short;
RedundantCover = Cover;
e = Equity( 1, 0 );
Plot( bh, "Buy-and-Hold", colorBlue );
Plot( e, "Equity", colorRed );
PlotShapes( Buy * shapeUpArrow +
Sell * shapeDownArrow +
Short * shapeHollowDownArrow +
Cover * shapeHollowUpArrow,
Color, 0, e, -12 );
RedundantBuy = RedundantBuy AND NOT Buy;
RedundantSell = RedundantSell AND NOT Sell;
RedundantShort = RedundantShort AND NOT Short;
RedundantCover = RedundantCover AND NOT Cover;
PlotShapes( RedundantBuy * shapeSmallUpTriangle +
RedundantSell * shapeSmallDownTriangle +
RedundantShort * shapeHollowSmallDownTriangle +
RedundantCover * shapeHollowSmallUpTriangle,
Color, 0, e, -30 );
GraphXSpace = 10
To use it, simply paste the code in the Formula Editor, press “Apply Indicator”, then click with RIGHT mouse button over chart pane and select “Parameters”. In the parameters dialog you will see several buttons that allow you to place and clear trade signals. To place signal for particular bar first SELECT the bar by clicking on the chart once in desired place and then press one of the buttons in Parameter dialog.
The following picture shows how it works.
Red line shows discretionary system equity while blue line will show buy-and-hold equity. Valid trade entry and exit signals are marked with arrows while redundant signals (for example a buy that comes when the system is already during the long position) are marked with triangles.
Filed by Tomasz Janeczko at 9:06 am under Indicators
6 Comments
Very nice. I have been looking for something like this. “e” seems to be the resulting
equity curve. I will try to use AddToComposite to create resulting ticker for “e” so that I
I can compare visual trading equity curve to various system trading trading equity curves via CAR, Mdd and the like.
ln:42,col:48:Error30:syntax error
ln:47,col:45:Error30:syntax error
As for syntax errors that you got, two possible reasons:
a) using too old version of AmiBroker. You need to use version 4.80
b) you have copied-pasted code incorrectly.
Very nice Tomasz,
would it be possible to add a “Reverse Position” button? I can’t seem to reverse, for example Short on a Sell bar.
Best regards,
herman
Nice Tool. I’ve combined it with the simulator plugin. Unfortunately Aibroker slows down when both tools are running.
Also would be nice if Discretionary Equity could catch keyboard codes. For example “B” button triggers Buy, “S” triggers Sell etc.
You should no longer use old Simulator plugin which is slow.
Instead use AmiBroker’s built in Bar Replay feature (available in version 4.88).