Hi,
I’ll tell you the general format, but first, you need to take into account the maximum history applies to the smallest timeframe, and the initial amount of candles available prior to start point is 10000. So if you need more candles than this, your code wouldn’t take any trade until data “exists” in the biggest timeframe. In backtest on a very long history, you might see some trades, but trading real time you might have to wait for a very long time before history beyond the preloaded 10000 becomes enough if you need more than these 10000.
So, how to work out how many candles you need in smallest timeframe? Take amount of candles for all your data to exist in biggest timeframe (for example, let’s say the longest constraint is a 200 candles moving average, take 200 times 4h =800), and multiply it either by what it takes to reach your smallest timeframe wanted, or, work your way down timeframe by timeframe and stop if going beyond 10000 to know which smaller timeframes are available to you for your code to be working live at launch instead of waiting for more candles to occur after launch. Keeping the example, 800 in 4h, times 4 gives 3200 candles in 1h, and in 15mn you’d already be at 4×3200=12800 beyond the max preloaded of 10000, so would have to wait in real time after launch for 2800 15mn candles before data in 4h exists (and a bit more if 4h candle is not closed yet and you want data on 4h close) and code can work with 15mn as the small timeframe… Anything smaller is even more candles to wait for beyond the max preloaded 10000 candles and it becomes quickly unrealistic.
You get the idea, it means you need to make sure your biggest and smallest timeframe are not too far apart. Either its a non-starter for your setup, or you have to get rid of timeframes at one end of the spectrum (or on each side). And it all depends on how many candles are needed in the biggest one you select.
Format would be:
defparam preloadbars=10000
timeframe(4h)
conditionA=…
timeframe(1h)
conditionB=…
etc…
timeframe(default)//the timeframe the code operates in
if conditionA AND conditionB AND … then
buy x contracts at market
endif
Exitcondition=…
If Exitcondition then
sell at market
endif
3 users thanked author for this post.