Hi,
Is it somehow possible to use the optimizer to backtest different timeframes?
I want to test a system with different Supertrend in different timeframes, is this possible somehow?
Have tried:
timeframe([time] minutes)
st = Supertrend[3,10]
Thanks!
JSParticipant
Senior
Hi,
In PRT, it is not possible to use a variable as a parameter in the “TimeFrame” instruction…
You could do something like below, this is the way I would pursue and initially seems to work!
I’ve not used this technique for anything myself yet but, other than using the Timeframe command, the only other way would be to multiple up values to represent other timeframes.
Though depending on the complexity of what your doing , you could run into issues or limits, here’s some:
How many multi timeframes can be used, and the mTF(s) have to be a multiple of the chart/default timeframe.
How many units needed to calculate indicator values, if default TF is small and mTF is large.
If larger amount of units used, will it exceed the tick by tick limit in backtest.
There maybe others.
PRT keeps it’s users on a short leash, don’t want them running on the grass, or get up enough speed, for when they run into the inevitable brick wall of limitations!
Also certain values most probably, need to be different for different TF’s i.e. stops and targets etc.
Maybe good to get an initial view over a number of TF’s. Then filter down to a number of TF’s covering a smaller range, or do several on narrow ranges etc.
Note, you need to set up a optimisation variable, spec at top of code.
defparam preloadbars = 10000
defparam cumulateOrders = false
// Variable optimization variables...
//tf = ... min = 1, max = 5, step = 1
timeframe(1minute,updateonclose)
if tf = 1 then
avg1 = supertrend[3,10]
else
avg1 = undefined
endif
timeframe(5minute,updateonclose)
if tf = 2 then
avg5 = supertrend[3,10]
else
avg5 = undefined
endif
timeframe(15minute,updateonclose)
if tf = 3 then
avg15 = supertrend[3,10]
else
avg15 = undefined
endif
timeframe(30minute,updateonclose)
if tf = 4 then
avg30 = supertrend[3,10]
else
avg30 = undefined
endif
timeframe(1hour,updateonclose)
if tf = 5 then
avg60 = supertrend[3,10]
else
avg60 = undefined
endif
timeframe(default)
if tf = 1 then
avg = avg1
SL = 5
PT = 10
elsif tf = 2 then
avg = avg5
SL = 10
PT = 20
elsif tf = 3 then
avg = avg15
SL = 15
PT = 30
elsif tf = 4 then
avg = avg30
SL = 20
PT = 40
elsif tf = 5 then
avg = avg60
SL = 25
PT = 50
endif
graph tf
graph SL
graph PT
graphonprice avg
if close crosses over avg then
BUY 1 CONTRACTS AT MARKET
set stop ploss SL
set target pProfit PT
endif
if onmarket and close crosses under avg then
sell at market
endif