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

[amibroker] Re: Position sizing based on equity curve



PureBytes Links

Trading Reference Links

>From Reefcap

Getting there but still some minor problems. Try this version...


code:
---------------------------------------------------------------------
-----------

SetCustomBacktestProc("");if(Status("action") == actionPortfolio){ 
bo = GetBacktesterObject(); bo.Backtest();    //NB:backtest 
automatically assigns FIR==[i]=0 and LIR==[i]=barcount-1 SumProfits
[0]   = bo.InitialEquity; dt = DateTime();    //for BIR the equity 
is non-zero; more is better for(i=1; i<BarCount; i++) {     //search 
through closed trade list; get the profit when bar==exitdate  
SumProfits[i] = SumProfits[i-1];  for(trade = bo.GetFirstTrade(); 
trade; trade = bo.GetNextTrade())  {   ExitDate = 
trade.ExitDateTime;   if(ExitDate==dt[i]) { SumProfits[i] = 
SumProfits[i] + trade.GetProfit(); }  }     //search through open 
trades list; get the profit when i==lastbar (close out open trades)  
if(i==BarCount-1)  {   for(trade = bo.getFirstOpenPos(); trade; 
trade = bo.getNextOpenPos())   {    SumProfits[i] = SumProfits[i] + 
trade.GetProfit();   }  } }    //clear composite before each test, 
put in group 253, enable atc in custom portfolio backtest 
AddToComposite(SumProfits,"~ClosedEquity","O",                
atcFlagEnableInPortfolio|atcFlagEnableInBacktest|atcFlagEnableInExplo
re|atcFlagDefaults); AddToComposite
(SumProfits,"~ClosedEquity","C",                
atcFlagEnableInPortfolio|atcFlagEnableInBacktest|atcFlagEnableInExplo
re|atcFlagDefaults);} //-end 
actionportfolio//////////////////////////////////////////////////////
/// your trading system here fast = Optimize("fast", 12, 5, 20, 1 ); 
slow = Optimize("slow", 26, 10, 25, 1 ); Buy=Cross(MACD
(fast,slow),Signal(fast,slow)); Sell=Cross(Signal(fast,slow),MACD
(fast,slow));  BuyPrice=Open;SellPrice=Open;PositionSize=-10;

---------------------------------------------------------------------
-----------

There are unhandled errors and access violations when you first 
generate the composite, it doesn't display data for any symbol.

If you then go to AA settings - portfolio, a popup informs you that 
there isn't a custom backtester formula.

Click OK and see that the custom bactester box is checked. Uncheck 
the box. Re-run the backtest and
things are OK or will be the run after that. I'm not sure if a 
composite existing over the same test period allows the code to 
function properly. If this is the case then there is more for TJ or 
us to do.

As a tool it is OK ie. it does the job so you can verify that 
positionsize is correct.

--------------------
Cheers, Shutty.






--- In amibroker@xxxxxxxxxxxxxxx, "Glenn" <glennokb@xxx> wrote:
>
> Shane,
> 
> Might be better to post the code here as you need to register to 
view 
> ReefCap.
> 
> Cheers
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "michael_shane_baker" <plusnq@> 
> wrote:
> >
> > Hi Tomasz,
> > 
> > My understanding is that Ami calculates its position sizing from 
> open 
> > equity. Recently on Reefcap.com 
> > 
> > http://lightning.he.net/cgi-bin/suid/~reefcap/ultimatebb.cgi?
> > ubb=get_topic;f=49;t=000139;p=3#000034
> > 
> > some code was posted to allow the user to plot the closed equity 
> curve 
> > as well as the open equity curve. Would it be possible to plot 
all 
> > three equity curve types, open, closed and total reduced equity 
> > (closed trades plus open trades at stop) and then allow the user 
to 
> > reference the appropriate curve value for their position sizing 
eg 
> 1% 
> > of open, closed or total reduced equity curve value for 
> > fixedfractional position sizing).
> > 
> > Cheers and thanks
> > 
> > Shane
> >
>