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

[amibroker] Re: Number of Open Positions



PureBytes Links

Trading Reference Links

Hi,

Sorry, I missed the charting side of the question. Building on the 
replies so far, perhaps the following is what you're after.

This will include a custom metric in your backtesting report (Max 
Count) giving the highest number of open positions at any single bar. 
It will also produce a composite ticker (named ~MaxCount) which you 
can chart to see the number of open positions on a bar by bar basis.

The Buy/Sell/Short/Cover is just for proof of concept.

SetOption("MaxOpenPositions", 6);
SetBacktestMode(backtestRegularRaw);
SetCustomBacktestProc("");

counts = Cum(0);
largestCount = 0;

if (Status("action") == actionPortfolio) {
	bo = GetBacktesterObject();
	bo.PreProcess();

	for (bar = 0; bar < BarCount; bar++) {
		bo.ProcessTradeSignals(bar);
		count = 0;

		for (pos = bo.getFirstOpenPos(); pos; pos = 
bo.getNextOpenPos()) {
			count++;
			_TRACE("Count: " + count);
		}

		counts[bar] = count;

		if (count > largestCount) {
			largestCount = count;
		}
	}

	bo.PostProcess();
	bo.addCustomMetric("Max Count", largestCount);

	AddToComposite(counts, "~MaxCount", "X", atcFlagDefaults | 
atcFlagEnableInBacktest | atcFlagEnableInPortfolio);
}

Buy = Cross(MA(Close, 30), MA(Close, 100));
Sell = Cross(MA(Close, 100), MA(Close, 30));

Short = Sell;
Cover = Buy;


Mike

--- In amibroker@xxxxxxxxxxxxxxx, "Graham Johnson" <grahamj@xxx> 
wrote:
>
> Thanks
> 
> I've implemented example #3 and at first glance everything looked 
> great - this is the first time I have used AddToComposite so it is 
> good education.
> 
> Perusal of the charts revealed that the # of open trades was in 
some 
> instances far greater than the maximum of 6 set in the AFL.
> 
> Examination of the Detailed Log, as suggested by Mike, revealed 
that 
> there were never more than 6 trades open at one time.
> 
> Obviously (I think), the ATC is implemented before 
> 'SetOption("MaxOpenPositions", 6);' 
> comes into play.
> 
> Is there a way to achieve correct numbers in the chart?
> 
> Particularly during development phase, it would be really helpful 
to 
> have a custom metric for Max Open Positions in the backtest report, 
> without having to scan 10 years of entries in the Detailed Log.
> 
> Graham
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "droskill" <droskill@> wrote:
> >
> > I think I know what you're getting at - take a look at example #3 
on
> > this page:
> > 
> > http://www.amibroker.com/guide/a_addtocomposite.html
> > 
> > "In the third example I will show you how to use the same 
technique 
> to
> > count the number of open positions of your trading system. This is
> > useful if you want to know how big account would you need to trade
> > your system following all the trades. Our formula will be very 
> similar
> > to the one before."
> > 
> > That might help you out - but in general, I, like you, would love 
to
> > see these added to the application's base reports.
> > 
> > /d/
> > 
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> > >
> > > Hi,
> > > 
> > > Before running your backtest, click on the Settings button, 
look 
> under 
> > > the Report tab and selected Detailed log.
> > > 
> > > Then, when you run your backtest, you will see all positions 
held 
> on a 
> > > day by day basis. This is also useful when trying to understand 
> how 
> > > your PositionScore logic works, as it will indicate which 
tickers 
> are 
> > > under consideration and list which were entered/exited at each 
> bar.
> > > 
> > > You can find more information about the backtest settings in 
the 
> > > online help via:
> > > 
> > > Help menu
> > > -Contents tab
> > > --Reference Guide
> > > ---Analysis Tools
> > > ----System test settings window
> > > 
> > > Or from the web here:
> > > http://www.amibroker.com/guide/w_settings.html
> > > 
> > > Mike
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Graham Johnson" <grahamj@> 
> wrote:
> > > >
> > > > There are 2 things that I would like to achieve
> > > > 
> > > > 1. Backtest Report - maximum no. of open positions for the 
> backtest.
> > > > 
> > > > 2. Equity Chart - number of open positions for each bar.
> > > > 
> > > > I've searched the docs and this forum but didn't locate 
> anything.
> > > > 
> > > > Thanks
> > > > 
> > > > Graham
> > > >
> > >
> >
>



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

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 NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

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/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> 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/