Hello Mike, Thank you for your answer. This makes it a bit clearer. I used a more primitive method to count signals. I would set max open positions to 2 x of the watchlist content and set the Bar Stop to one bar. This (I thought) should given me a number of signals.
I tested the AFL you posted. It worked OK, but I can not see PlotForeign line after running it in backtester. Is there a trick to plot "~Signals" from composite array? Regards Richard --- In [email protected], "Mike" <sfclimb...@...> wrote: > > Note that in the code originally posted, the signal position size > will be set to a tiny value when there are many many signals. You > would need to correct for that to be at least some minimum size, with > the realization that it would imply that some signals would go > unfilled due to lack of resources. > > Mike > > --- In [email protected], "Mike" <sfclimbers@> wrote: > > > > > > Hi, > > > > Your question is actually a bit of a trick question, since AmiBroker > > will cap the number of signals to be not more than 2 x the maximum > > permitted open positions (as per your AA settings or in code). To > get > > around that, set the max positions to some large number (e.g. 500). > > > > That being said, you can count (and even chart) the number of > signals at > > each bar. Similarly, you can evenly divide your equity among all > signals > > such that all signals will be taken (up to max permitted). > > > > Have a look at the following (untested) code for some ideas. Run a > > backtest against it, then look at the resulting plot to see how many > > signals are generated at each bar. > > > > Mike > > > > > > SetOption( "MaxOpenPositions", 2 ); > > > > fast = MA( Close, 5 ); > > slow = MA( Close, 25 ); > > > > Buy = Cross( fast, slow ); > > Sell = Cross( slow, fast ); > > > > AddToComposite( 0, "~Signals", "X", atcFlagDefaults | > > atcFlagEnableInPortfolio ); > > PlotForeign( "~Signals", "Signals", colorRed, styleLine ); > > > > SetCustomBacktestProc( "" ); > > > > if ( Status( "action" ) == actionPortfolio ) > > { > > maxPositions = GetOption( "MaxOpenPositions" ); > > signals[0] = 0; > > > > bo = GetBacktesterObject(); > > bo.PreProcess(); > > > > for ( bar = 0; bar < BarCount; bar++ ) > > { > > count = 0; > > > > for ( sig = bo.GetFirstSignal( bar ); sig; sig = > > bo.GetNextSignal( bar ) ) > > { > > if ( sig.IsEntry() ) > > { > > count++; // AmiBroker tracks as many as 2 x > > maxPositions > > } > > } > > > > signals[bar] = count; // Preserve signal count for > charting > > count = min( count, maxPositions ); // Do not exceed > > maxPositions > > > > if ( count > 0 ) > > { > > size = -100 / count; // Divide evenly among candidates > > } > > else > > { > > size = -100; // Prevent divide by zero error. > > } > > > > size = max( size, -5 ); // Max 5% of equity (or whatever > makes > > sense to you) > > > > for ( sig = bo.GetFirstSignal( bar ); sig; sig = > > bo.GetNextSignal( bar ) ) > > { > > if ( sig.IsEntry() ) > > { > > sig.PosSize = size; > > } > > } > > > > bo.ProcessTradeSignals( bar ); > > } > > > > bo.PostProcess(); > > > > AddToComposite( signals, "~Signals", "X", atcFlagDefaults | > > atcFlagEnableInPortfolio ); > > } > > > > > > --- In [email protected], "richpach2" <richpach2@> wrote: > > > > > > A portfolio backtester outputs a long list of system metrics but, > I > > > was not able to find a metric which describes a value of cash / > system > > > utilization. What I mean by that is, do I have enough cash to > take all > > > the signals? After all most systems work on the principle that one > > > must take ALL signals. Not some not a few but ALL. I know I can > > > control it by positionscore, positionsize and number of open > positions > > > as a percentage of portfolio (cash). I want to be able to use my > cash > > > in most efficient way by matching a number of signals the system > > > generates on the portfolio with number of available positions. At > > > least, I want to know how many signals are generated for the given > > > period in test and compare it to total number of trades taken > during > > > the test period. > > > I can see that, there are visual (Green bars) on the equity > display > > > that show available cash but I can not see anything in the > backtester > > > which will measure number of signals compared a number of > positions. > > > Portfolio backtester interface reference guide shows that one can > use > > > "cash" property in FindSignal and FindOpenPositions but, I do not > know > > > how to construct my metric using these methods. > > > Can someone please comment on this question or point me to the > > > examples on how to use custom methods in backtester? > > > > > > Regards > > > Richard > > > > > >
