Mike, thanks for the CBT code for position-sizing based on the equity curve. That was very helpful.
I have a question for you. What if we wanted the system to system to go short once the equity curve goes beneath the moving average? What I am trying to accomplish (at this point, more to learn how to code it than for any real promise as a system) is a system that buys the top 10 negative ROC5 stocks, and sells them 5 days later. PositionScore=100-(ROC5) Then, if the equity curve falls beneath the moving average, Buy=0 Short=1 PositionScore=ROC5 So now the system is shorting instead of buying, and shorting the top ten highest ROC5 stocks. Anyway, this may be terrible complicated. I know that when I try to work through it in the CBT, I just walk away scratching my head. Thanks for any help or ideas! --- In [email protected], "Mike" <sfclimb...@...> wrote: > > > Hi, > > You must write custom backtester code to do what you are asking. Your > final ~~~Equity is simply an array of the bar by bar values of the > backtester's Equity property (verify that Plots overlap). As such, you > can build up an equivalent equity array as you iterate through the bars > in a custom backtest, calculate a MA using that array, and reduce your > postion size accordingly. > > I have not done any extensive testing on the following code. But, I > believe that it will give you what you are asking for. The logic is > simply to refer to the equity of the previous bar compared to the MA of > equity for that same bar, and reduce position size of the current bar > when the relation is not favorable. > > Double check the trades to make sure that the timing is right. > > Mike > > optimistic = Param("Optimistic", 20, 1, 100, 1); > pessimistic = Param("Pessimistic", 10, 1, 100, 1); > period = Param("Period", 20, 1, 50, 1); > > SetTradeDelays(0, 0, 0, 0); > PositionSize = -1 * optimistic; > > weekDay = DayOfWeek(); > > Buy = weekDay == 1; > BuyPrice = Open; > > Sell = weekDay == 5; > SellPrice = Close; > > SetCustomBacktestProc(""); > > if (Status("action") == actionPortfolio) { > bo = GetBacktesterObject(); > bo.PreProcess(); > > eq[0] = 0; > > for (bar = 0; bar < BarCount; bar++) { > reduceSize = false; > > if (bar > period) { > eqMA = MA(eq, period); > > if (eq[bar - 1] <= eqMA[bar - 1]) { > reduceSize = true; > } > } > > if (reduceSize) { > for (sig = bo.GetFirstSignal(bar); sig; sig = > bo.getNextSignal(bar)) { > sig.PosSize = -1 * pessimistic; > } > } > > bo.ProcessTradeSignals(bar); > eq[bar] = bo.Equity; > } > > bo.PostProcess(); > > AddToComposite(eq, "~~~EQ", "X", atcFlagDefaults | > atcFlagEnableInPortfolio); > } > > eq = Foreign("~~~EQ", "C"); > Plot(eq, "EQ", colorGreen, styleLine); > Plot(Foreign("~~~Equity", "C"), "Equity", colorBlue, styleLine); > Plot(MA(eq, period), "MA20-EQ", colorRed, styleLine); > > > --- In [email protected], Wolfgang Hader <faked@> wrote: > > > > Hi all, > > > > how can I code some like this in Amibroker > > (I know the following code is wrong, but how can I do it correctly in > > Amiboker)? > > > > iif(equity() > ma(equity(),20), positionsize=-20, positionsize=-10); > > > > Thank you, > > BR > > >
