| 
 PureBytes Links 
Trading Reference Links 
 | 
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 ); 
------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~-> 
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
 
Yahoo! Groups Links
<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/
<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 
 |