Trading 100 instruments with IB

Posted By: DavidK

Trading 100 instruments with IB - 11/19/22 03:35

I would like to monitor and trade say 100 instruments using two IB accounts. What sort of Zorro configurations of would enable me to do it efficiently?
How would the code inside the run() and tick() functions know which of the assets triggered the call? It seems quite inefficient to have to loop through many assets to
see which assets caused the calls.
Posted By: Grant

Re: Trading 100 instruments with IB - 11/19/22 10:27

Originally Posted by DavidK
I would like to monitor and trade say 100 instruments using two IB accounts. What sort of Zorro configurations of would enable me to do it efficiently?


By either using:

1) A 'for(used_assets)' loop, see https://zorro-project.com/manual/en/fortrades.htm

or

2) A 'while(asset(loop(...' , see https://zorro-project.com/manual/en/loop.htm (examples below) when you want to run optimizations.

Quote

How would the code inside the run() and tick() functions know which of the assets triggered the call? It seems quite inefficient to have to loop through many assets to
see which assets caused the calls.


Always use tock() instead of tick() for a multi-asset script.

Quote:

"Trading with different assets in a tick function can cause backtest snooping bias. When historical price ticks for assets A and B have the same time stamps, the tick function will first run with asset A, then with asset B. In the first run, asset A has the current price, but asset B still the previous price. This can be used to snoop the next B price especially when it strongly depends on the A price. To prevent this effect, use the tock function for trading multiple assets when required, and set TockTime to the tick resolution of the used historical data, or to TickTime in live trading." (https://zorro-project.com/manual/en/tick.htm)


You need to loop this, but c-lite is pretty fast.
Posted By: Gheo

Re: Trading 100 instruments with IB - 01/16/23 20:18

After reading the posts above I built this script to run a statagy on several currancy pairs.

seems to work well.

Code
///////////// MultiPair Live Trade /////////////

#include <profile.c>
#define	run strategy
#include	"AnyAlgo.c"	// <= your script here!!
#undef	run

function run()
{
	set(PRELOAD|COMMONSTART|PLOTNOW|LOGFILE); // reload prices after any cycle
	brokerCommand(SET_AMOUNT,0.01);
	setf(PlotMode,PL_FINE+PL_DIFF+PL_ALLTRADES+PL_LONG+PL_ALL+PL_BENCHMARK);  //PL_FILE+
	PlotScale = 8;
	asset("EUR/USD");
	asset("AUD/USD");
	
#endif
	for(used_assets) {
	strategy();	
	
	}
}
© 2024 lite-C Forums