the example was to illustrate how expectancy is to be calculated when risk is set to 0.01 of equity. it doesnt say how 0.01 is to be achieved, whether it is via position sizing or stoploss or both.
 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Geoff Mulhall
Sent: Monday, 13 March 2006 3:34 PM
To: [email protected]
Subject: [amibroker] Calculating Position Size Based on a % of Current Equity

Hi,

In the example provided by Tomasz below I do't see how the risk
relates to the position size.

When I enter a trade my position size in number of shares is
calculated as  $ to Risk /(entry price - stop price)
and I want my $ to risk on the trade to be a % of my currect equity.

I was expecting to see the SetPositionSize used in the example below
but it does not appear - so I'm wondering how the Risk value in the
example below is used to set the position size in the trade.

Any help appreciated.

Geoff

Example follows ->

SetCustomBacktestProc("");
MaxLossPointStop = 2*ATR(10); // dynamic volatility stoploss, 1st
modification

function FindEquityAtDateTime( eq, dt, Value )
{
   found = -1;
   for( i = 0; i < BarCount AND found == -1; i++ )
   {
      if( dt[ i ] == Value ) found = i;
   }
   return IIf( found != -1, eq[ found  - 1 ], Null );
}
if( Status("action") == actionPortfolio )
{
    bo = GetBacktesterObject();
    bo.Backtest(1); // run default backtest procedure
    SumProfitPerRisk = 0;
    NumTrades = 0;
    dt = DateTime();
    eq = Foreign("~~~EQUITY", "C" );

   for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade
() )
   {
      EquityAtEntry = FindEquityAtDateTime( eq, dt,
trade.EntryDateTime );

      Risk = 0.01 * EquityAtEntry ; //risk is defined as a constant
1% of current equity.

      RiskAsPecentOfCurrentEquity = 100 * Risk / EquityAtEntry;
      RMultiple = trade.GetProfit()/Risk;
      trade.AddCustomMetric("Initial risk $", Risk  );        
      trade.AddCustomMetric("Equity at entry", EquityAtEntry );
      trade.AddCustomMetric("Risk as % of Eq.",
RiskAsPecentOfCurrentEquity );

      trade.AddCustomMetric("R-Multiple", RMultiple  );
      SumProfitPerRisk = SumProfitPerRisk + RMultiple;
      NumTrades++;
   }
    Expectancy3 = SumProfitPerRisk / NumTrades;
    bo.AddCustomMetric( "Expectancy (per risk)", Expectancy3 );
    bo.ListTrades();
}
// your trading system here

ApplyStop( stopTypeLoss, stopModePoint, MaxLossPointStop );







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




Reply via email to