{"id":29,"date":"2006-05-06T09:06:04","date_gmt":"2006-05-06T14:06:04","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/2006\/05\/06\/discretionary-equity\/"},"modified":"2014-12-04T08:31:21","modified_gmt":"2014-12-04T13:31:21","slug":"discretionary-equity","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2006\/05\/06\/discretionary-equity\/","title":{"rendered":"Discretionary Equity"},"content":{"rendered":"

In the March 2006 “Letters to S&C” section I found the following request:<\/p>

“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”<\/p><\/blockquote>

And I just thought that it would be nice example of using AFL’s Equity()<\/a> function and ParamTrigger()<\/a> <\/p>

The following code implements the above idea:<\/p>Buy <\/span>= <\/span>1<\/span>;
<\/span>Sell <\/span>= <\/span>Cover <\/span>= <\/span>Short <\/span>= <\/span>0<\/span>;

<\/span>bh <\/span>= <\/span>Equity<\/span>( <\/span>0<\/span>, <\/span>0 <\/span>);

<\/span>setbuy <\/span>= <\/span>ParamTrigger<\/span>(<\/span>"Buy"<\/span>, <\/span>"Buy" <\/span>);
<\/span>setsell <\/span>= <\/span>ParamTrigger<\/span>(<\/span>"Sell"<\/span>, <\/span>"Sell" <\/span>);
<\/span>setshort <\/span>= <\/span>ParamTrigger<\/span>(<\/span>"Short"<\/span>, <\/span>"Short" <\/span>);
<\/span>setcover <\/span>= <\/span>ParamTrigger<\/span>(<\/span>"Cover"<\/span>, <\/span>"Cover" <\/span>);
<\/span>clear <\/span>= <\/span>ParamTrigger<\/span>(<\/span>"Clear"<\/span>, <\/span>"Clear" <\/span>);

<\/span>clearall <\/span>= <\/span>ParamTrigger<\/span>(<\/span>"Clear All"<\/span>, <\/span>"Clear All" <\/span>);

<\/span>bi <\/span>= <\/span>BarIndex<\/span>();
<\/span>sbi <\/span>= <\/span>SelectedValue<\/span>( <\/span>bi <\/span>);
<\/span>qty <\/span>= <\/span>LastValue<\/span>( <\/span>bi <\/span>);

<\/span>Varname <\/span>= <\/span>Name<\/span>() + <\/span>sbi<\/span>;

if( <\/span>setbuy <\/span>)
{
  <\/span>StaticVarSet<\/span>( <\/span>Varname<\/span>, <\/span>1 <\/span>);


if( <\/span>setsell <\/span>)
{
  <\/span>StaticVarSet<\/span>( <\/span>Varname<\/span>, -<\/span>1 <\/span>);


if( <\/span>setshort <\/span>)
{
  <\/span>StaticVarSet<\/span>( <\/span>Varname<\/span>, -<\/span>2 <\/span>);


if( <\/span>setcover <\/span>)
{
  <\/span>StaticVarSet<\/span>( <\/span>Varname<\/span>, <\/span>2 <\/span>);


if( <\/span>clear <\/span>)
{
  <\/span>StaticVarRemove<\/span>( <\/span>Varname <\/span>);


if( <\/span>clearall <\/span>)
{
  for( <\/span>i <\/span>= <\/span>0<\/span>; <\/span>i <\/span>< <\/span>qty<\/span>; <\/span>i<\/span>++ ) <\/span>StaticVarRemove<\/span>( <\/span>Name<\/span>() + <\/span>i <\/span>);


<\/span>Buy <\/span>= <\/span>Sell <\/span>= <\/span>Short <\/span>= <\/span>Cover <\/span>= <\/span>0<\/span>;

for( <\/span>i <\/span>= <\/span>0<\/span>; <\/span>i <\/span>< <\/span>qty<\/span>; <\/span>i<\/span>++ )
{
  <\/span>sig <\/span>= <\/span>StaticVarGet<\/span>( <\/span>Name<\/span>() + <\/span>i <\/span>);
  
  if( <\/span>sig <\/span>== <\/span>1 <\/span>) <\/span>Buy<\/span>[ <\/span>i <\/span>] = <\/span>True<\/span>;
  if( <\/span>sig <\/span>== -<\/span>1 <\/span>) <\/span>Sell<\/span>[ <\/span>i <\/span>] = <\/span>True<\/span>;
  if( <\/span>sig <\/span>== -<\/span>2 <\/span>) <\/span>Short<\/span>[ <\/span>i <\/span>] = <\/span>True<\/span>;
  if( <\/span>sig <\/span>== <\/span>2 <\/span>) <\/span>Cover<\/span>[ <\/span>i <\/span>] = <\/span>True<\/span>;


<\/span>Color <\/span>= <\/span>IIf<\/span>( <\/span>Buy <\/span>OR <\/span>Cover<\/span>, <\/span>colorGreen<\/span>, <\/span>colorRed <\/span>);

<\/span>RedundantBuy <\/span>= <\/span>Buy<\/span>;
<\/span>RedundantSell <\/span>= <\/span>Sell<\/span>;
<\/span>RedundantShort <\/span>= <\/span>Short<\/span>;
<\/span>RedundantCover <\/span>= <\/span>Cover<\/span>;

<\/span>e <\/span>= <\/span>Equity<\/span>( <\/span>1<\/span>, <\/span>0 <\/span>);

<\/span>Plot<\/span>( <\/span>bh<\/span>, <\/span>"Buy-and-Hold"<\/span>, <\/span>colorBlue <\/span>); 
<\/span>Plot<\/span>( <\/span>e<\/span>, <\/span>"Equity"<\/span>, <\/span>colorRed <\/span>); 

<\/span>PlotShapes<\/span>( <\/span>Buy <\/span>* <\/span>shapeUpArrow <\/span>+
              <\/span>Sell <\/span>* <\/span>shapeDownArrow <\/span>+
              <\/span>Short <\/span>* <\/span>shapeHollowDownArrow <\/span>+
              <\/span>Cover <\/span>* <\/span>shapeHollowUpArrow<\/span>,
            <\/span>Color<\/span>, <\/span>0<\/span>, <\/span>e<\/span>, -<\/span>12 <\/span>);

<\/span>RedundantBuy <\/span>= <\/span>RedundantBuy <\/span>AND <\/span>NOT Buy<\/span>;
<\/span>RedundantSell <\/span>= <\/span>RedundantSell <\/span>AND <\/span>NOT Sell<\/span>;
<\/span>RedundantShort <\/span>= <\/span>RedundantShort <\/span>AND <\/span>NOT Short<\/span>;
<\/span>RedundantCover <\/span>= <\/span>RedundantCover <\/span>AND <\/span>NOT Cover<\/span>;
<\/span>PlotShapes<\/span>( <\/span>RedundantBuy <\/span>* <\/span>shapeSmallUpTriangle <\/span>+
              <\/span>RedundantSell <\/span>* <\/span>shapeSmallDownTriangle <\/span>+
              <\/span>RedundantShort <\/span>* <\/span>shapeHollowSmallDownTriangle <\/span>+
              <\/span>RedundantCover <\/span>* <\/span>shapeHollowSmallUpTriangle<\/span>,
            <\/span>Color<\/span>, <\/span>0<\/span>, <\/span>e<\/span>, -<\/span>30 <\/span>);

<\/span>GraphXSpace <\/span>= <\/span>10<\/span><\/code>

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. <\/p>

The following picture shows how it works.<\/p>

DiscretionaryEquity<\/p>

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.<\/p>","protected":false},"excerpt":{"rendered":"

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 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[53,15,55],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/29"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":1,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"predecessor-version":[{"id":792,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/29\/revisions\/792"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}