Sorry for the typo, that should have read: * Write Short logic as if it was a short only system.
Mike --- In [email protected], "Mike" <sfclimb...@...> wrote: > > Any time you want to do any trading based on current equity, final logic > pretty much needs to get moved into custom backtesting code. The reason for > this is that only custom backtest code has access to current equity on a bar > by bar basis. > > For the scenario you describe, I would suggest trying something like the > following: > > * Write Buy logic as if it was a long only system. > * Write Sell logic as if it was a short only system. > * Use custom backtester code to cancel signals that are on the wrong side of > the desired direction. > > For example, just as we reduced the position size based on relation to MA, > you can instead completely zero out PosSize of longs when below MA and > completely zero out PosSize of shorts when above MA. > > You may need to call SetOption("SeparateLongShortRank", true) to ensure that > signals for both directions are preserved going into the backtester. > Otherwise, stronger ranking signals in one direction could prevent weaker > signals in the opposite direction from being processed, even though you > ultimately only wanted to accept the opposite direction signals at that bar. > > Keep in mind that none of what I have provided is necessarily the most > efficient way to do this. But, if it gets you on the road to correct results, > then you can always refine it later. > > Mike > > --- In [email protected], "woodshedder_blogspot" > <woodshedder_blogspot@> wrote: > > > > 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" <sfclimbers@> 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 > > > > > > > > > >
