The right way to progress from a successful backtest to real-time trading

I will start to post my newbie questions here.

THE FIRST QUESTION: How does one manage the position sizes for concurrent signals in a real-time IBC trading system?

For the backtest, I am doing portfolio position sizing in the CBT. That means, I have a general position size rule in the 1st phase AFL basing on the volume of the -7th bar (trading hourly) and I modify the resulting order size in the CBT (1) to check if it does not exceed 20% of the protfolio equity and (2) to divide the available cash equally between multple signals received at the same bar. While (1) can be done outside the CBT, (2) cannot ALAIK.

I read that it is possible to submit orders from the CBT form there: Launch orders from portfolio backtester . But there is no "AR Backtest" option similar to Scan/Explore. In the official IBC guide IBController 1.3.8 READ ME, the order is placed in the 1st phase, just right after specifying Buy and Sell arrays (Example 1). However, it is not possible to access the signals array for the bar from there (feel free to correct me if I am mistaken).

I downloaded the AB and started with AFL in the middle of the July 2021 and I am greatly pleased with the concepts of the language, the documentation, the information found in the forum and most of all, the flashing performance. However, while all the necessary information to assemble an automatic trading system might actually be present in the docs, a "Hello World" type sample project would be most welcome to make it less confusing.

If you want to run backtests on a recurring basis, you can use AmiBroker's batch file processing and the AmiBroker scheduler.

1 Like

Thanks, that solves the first question. All comments are still welcome.

what timeframe/products are you trading @John_Dolittle?

Hourly, SP500 stocks.

@Tomasz , you recently wrote that Backtests are not meant for live trading: How to act on actual entry exit signals instead of coded signals?

Do you discourage the approach below and if yes, why?

SetOption("UseCustomBacktestProc", True); 

if (Status("action") == actionPortfolio) {
	bo = GetBacktesterObject();
	// backtest with historic bars
	for (bar=0; bar < BarCount-2; bar++) {
		for (sig=bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar)) {
			if (sig.isLong) {				
				if (sig.isEntry) {
					qty = sig.PosSize;

					// the sizing algorithm omitted

					sig.PosSize = qty;
				if (sig.isExit) {
					_TRACE("Long exit signal: " + sig.Symbol + " " + NumToStr(round(bar), format=1.0));
		_TRACE("Trade signals processed for bar " + NumToStr(bar, format=1.0));	
		_TRACE(" ");
	// live orders		
	ibc = GetTradingInterface("IB");

	if (ibc.IsConnected()) {	
		bar = BarCount - 1;		

		for (sig=bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar))  {				
			if (sig.IsLong AND sig.isEntry) {

				// sizing and submission of live orders omitted




Plot_indicators = ParamList("Plot indicators", "Price Chart");

buy_conditions = False;
sell_conditions = False;

// Formula calculations omitted

Buy = buy_conditions;	  	  
Sell = sell_conditions;

Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );

SetPositionSize( round(Ref(Volume, -7)*0.01), spsShares ); // hourly

if (Plot_indicators == "Price Chart") {
	Plot ( Close, "Open", colorWhite, style=styleCandle );
	shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
	PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low-0.1, High+0.1 ) );	

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.