amibroker

HomeKnowledge Base

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 Equity0);

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 SelectedValuebi );
qty LastValuebi );

Varname Name() + sbi;

if( 
setbuy )
{
  
StaticVarSetVarname);


if( 
setsell )
{
  
StaticVarSetVarname, -);


if( 
setshort )
{
  
StaticVarSetVarname, -);


if( 
setcover )
{
  
StaticVarSetVarname);


if( 
clear )
{
  
StaticVarRemoveVarname );


if( 
clearall )
{
  for( 
0qtyi++ ) StaticVarRemoveName() + );


Buy Sell Short Cover 0;

for( 
0qtyi++ )
{
  
sig StaticVarGetName() + );
  
  if( 
sig == Buy] = True;
  if( 
sig == -Sell] = True;
  if( 
sig == -Short] = True;
  if( 
sig == Cover] = True;


Color IIfBuy OR CovercolorGreencolorRed );

RedundantBuy Buy;
RedundantSell Sell;
RedundantShort Short;
RedundantCover Cover;

Equity1);

Plotbh"Buy-and-Hold"colorBlue ); 
Plote"Equity"colorRed ); 

PlotShapesBuy shapeUpArrow +
              
Sell shapeDownArrow +
              
Short shapeHollowDownArrow +
              
Cover shapeHollowUpArrow,
            
Color0e, -12 );

RedundantBuy RedundantBuy AND NOT Buy;
RedundantSell RedundantSell AND NOT Sell;
RedundantShort RedundantShort AND NOT Short;
RedundantCover RedundantCover AND NOT Cover;
PlotShapesRedundantBuy shapeSmallUpTriangle +
              
RedundantSell shapeSmallDownTriangle +
              
RedundantShort shapeHollowSmallDownTriangle +
              
RedundantCover shapeHollowSmallUpTriangle,
            
Color0e, -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.

DiscretionaryEquity

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.

6 Responses to “Discretionary Equity”

  1. Bert Steele
    June 18th, 2006 | 1:44 pm

    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.

  2. sk haadyai
    July 25th, 2006 | 9:57 pm

    ln:42,col:48:Error30:syntax error
    ln:47,col:45:Error30:syntax error

  3. July 26th, 2006 | 3:51 am

    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.

  4. Herman
    July 30th, 2006 | 9:09 pm

    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

  5. helyesba
    October 29th, 2006 | 4:53 am

    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.

  6. October 29th, 2006 | 5:51 am

    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).