[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Discretionary Equity



PureBytes Links

Trading Reference Links

Hello,
 
1. No. Note that MarginRequirement of 50 needs PositionSize of -200 (200% of cash).
2. No. Note that short trades need to be enabled in AA Settings window and at least one backtest with these settings must be run.
 

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
Sent: Tuesday, May 30, 2006 6:15 PM
Subject: [amibroker] Discretionary Equity

I have made a few changes to TJ's Discretionary Equity code if anyone is interested. Chart now shows date and 3rd line for "always out" ( interest, fixed rate of return ). Start date changed to FVB or Beginning Range Marker. New params for Points/Pct, Margin and Positionsize. I also have a couple of questions if anyone knows:
 
1. It appears that AB ignores Positionsize unless Margin = 100. Is this correct?
2. It appears Positionsize is ignored for sell/cover. Is this correct?
 
Thank you!
 
Steve
 
====================================================================================

// Discretionary Equity

// in AA settings, set trades to "close"/delay of 0 so sigs aren't delayed and equity is calculated with close instead of open.

/* 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. 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. */

// set chart options

SetChartOptions( 0, chartShowDates|chartShowArrows|chartWrapTitle );

GraphXSpace = Param( "GraphXSpace", 7, -50, 100, 1 );

// get params

scalePts = ParamToggle( "Scale $/%", "%|$", 1 );

Margin = Param( "Margin", 100, 50, 100, 1 );

SetOption( "AccountMargin", Margin );

if ( Margin == 100 )

PositionSize = Param( "Position Size ( set margin to 100 )", -100, -100, 1000000, 1 );

setcover = ParamTrigger("Cover", "Cover" );

setbuy = ParamTrigger("Buy", "Buy" );

setsell = ParamTrigger("Sell", "Sell" );

setshort = ParamTrigger("Short", "Short" );

clear = ParamTrigger("Clear", "Clear" );

clearall = ParamTrigger("Clear All", "Clear All" );

// set range

dn = DateNum();

bi = BarIndex();

from = LastValue( ValueWhen( bi == Status( "FirstVisibleBar" ), dn ) );

to = LastValue( ValueWhen( bi == Status( "LastVisiblebar" ) - 1, dn ) );

if ( BeginValue( bi ) )

{

from = BeginValue( dn );

to = EndValue( dn );

}

//set initial equity

iEq = GetOption( "InitialEquity" );

// calculate interest-only equity

Buy = Sell = Cover = Short = 0;

ioEq = Equity( 0, 3, from, to );

ioChg = ( ioEq - iEq ) / iEq * 100;

// calculate buy-and-hold equity

Buy = dn == from;

Sell = Cover = Short = 0;

bhEq = Equity( 0, 3, from, to );

bhChg = ( bhEq - iEq ) / iEq * 100;

// calculate discretionary equity

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;

}

RedundantBuy = Buy;

RedundantSell = Sell;

RedundantShort = Short;

RedundantCover = Cover;

syEq = Equity( 1, 3, from, to );

syChg = ( syEq - iEq ) / iEq * 100;

// plot $/% arrays

if ( scalePts )

{

Plot( iEq, "", colorBrown, styleNoLabel );

Plot( syEq, EncodeColor( colorBlack ) + Date() + EncodeColor( colorBrightGreen ) + " $ Sys", colorBrightGreen );

Plot( bhEq, "$ B&H", colorRed );

Plot( ioEq, "$ Int", colorBlue );

SigColor = IIf( Buy OR Cover, colorBrightGreen, colorRed );

Ypos = syEq;

}

else

{

Plot( 0, "", colorBrown, styleNoLabel );

Plot( syChg, EncodeColor( colorBlack ) + Date() + EncodeColor( colorPaleGreen ) + " % Sys", colorPaleGreen );

Plot( bhChg, "% B&H", colorRose );

Plot( ioChg, "% Int", colorSkyblue );

SigColor = IIf( Buy OR Cover, colorPaleGreen, colorRose );

Ypos = syChg;

}

// plot signals

PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow + Short * shapeHollowDownArrow + Cover * shapeHollowUpArrow, SigColor, 0, Ypos, -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, SigColor, 0, Ypos, -30 );



Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html





SPONSORED LINKS
Investment management software Real estate investment software Investment property software
Software support Real estate investment analysis software Investment software


YAHOO! GROUPS LINKS