{"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>