MTF : amount of orders drops dramatically if I divide the strategy in 2 TF?
Forums › ProRealTime English forum › ProOrder support › MTF : amount of orders drops dramatically if I divide the strategy in 2 TF?
- This topic has 19 replies, 5 voices, and was last updated 5 years ago by GraHal.
-
-
02/08/2019 at 3:04 PM #90866
Hello,
I’m trying to develop a strategy on the Dax, TF15min. I have some encouraging results, but wanted to improve the position management thank to the MTF. My idea was simply to take position on a signal given on the TF15min, and exit the position on the UT5min.
When I backtest the strategy only on the TF15min , I get in two years several hundred of trades. Logically, adding a code snippet for managing existing position on the TF5min shouldn’t impact the number of trades, or marginally. However, I get down to only 5 trades on the same period. Can someone confirm they have the same behaviour, or do I do something wrong?
Here below a very simple strategy that aims to explain my problem. If you run this code on the TF15min, you get hundred of trades, If you run the same one on the TF5min but with the code in comment uncomment, you get far less trades…
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748DEFPARAM FlatAfter = 215900ONCE positionsize=1//timeframe (15 minutes, updateonclose)myMA=average[7](close)tradetime=time >=090000 and time < 171500 and dayofweek<>0c1=close>myMAc2= myMA>myMA[1] and myMA[1]<myMA[2]cs1=close<myMAcs2= myMA<myMA[1] and myMA[1]>myMA[2]if tradetime then// -- execution logic -----if c1 and c2 and not longonmarket thenBuyLevel=High+1.5*pointsizestopbougie=low-2*pointsizebuy positionSize contracts at buyLevel STOPset stop loss stopbougieendifif cs1 and cs2 and not shortonmarket thenSellLevel=Low-1.5*pointsizestopbougie=high+2*pointsizesellshort positionSize contracts at SellLevel STOPset stop loss stopbougieendifendifif longonmarket thensell at stopbougie stopelsif shortonmarket thenexitshort at stopbougie stopendif//timeframe (5 minute, updateonclose)//myMA5=average[7](close)//if longonmarket and myMA5<myMA5[1] then//sell at market//elsif shortonmarket and myMA5>myMA5[1] then//exitshort at market//endif02/08/2019 at 3:45 PM #9087202/08/2019 at 3:51 PM #90875Did you uncomment the code snippet here below when you tested on the 5min?
//timeframe (15 minutes, updateonclose)
……………..
//timeframe (5 minute, updateonclose)//myMA5=average[7](close)//if longonmarket and myMA5<myMA5[1] then//sell at market//elsif shortonmarket and myMA5>myMA5[1] then//exitshort at market//endif02/08/2019 at 4:14 PM #90876I agree with GraHal, add a “0” to your initial capital.
02/08/2019 at 4:56 PM #9088002/08/2019 at 5:14 PM #90882First, try to GRAPH your buylevel and selllevel with dummy trading conditions that don’t trigger any order.
Do it with and without “timeframe (15 minutes, updateonclose)”, in order to see if the levels are calculated the same way and to incriminate the TIMEFRAME instruction or not.
02/08/2019 at 5:32 PM #90883Ok, I have been able to isolate the code line which is causing trouble. Nothing to do with Demo or Live account, sorry my mistake. The code I provided here above was an example, which was very different from most of the original code with which I have some trouble. So the code here above works fine, the code here below doesn’t work because in the conditions to take a position, I added “barindex-tradeindex(1)>=3”, which is a pretty standard code snippet. Any idea why this condition doesn’t work with the MTF?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748DEFPARAM FlatAfter = 215900ONCE positionsize=1timeframe (15 minutes, updateonclose)myMA=average[7](close)tradetime=time >=090000 and time < 171500 and dayofweek<>0c1=close>myMAc2= myMA>myMA[1] and myMA[1]<myMA[2]cs1=close<myMAcs2= myMA<myMA[1] and myMA[1]>myMA[2]if tradetime then// -- execution logic -----if c1 and c2 and not longonmarket and barindex-tradeindex(1)>=3 thenBuyLevel=High+1.5*pointsizestopbougie=low-2*pointsizebuy positionSize contracts at buyLevel STOPset stop loss stopbougieendifif cs1 and cs2 and not shortonmarket and barindex-tradeindex(1)>=3thenSellLevel=Low-1.5*pointsizestopbougie=high+2*pointsizesellshort positionSize contracts at SellLevel STOPset stop loss stopbougieendifendifif longonmarket thensell at stopbougie stopelsif shortonmarket thenexitshort at stopbougie stopendiftimeframe (5 minute, updateonclose)myMA5=average[7](close)if longonmarket and myMA5<myMA5[1] thensell at marketelsif shortonmarket and myMA5>myMA5[1] thenexitshort at marketendif02/08/2019 at 6:14 PM #9088402/08/2019 at 6:37 PM #90891BarIndex and TradeIndex are determined by the lowest TF (which is the MAIN or Default one). So in your case it’s the index to bars in the 5-minute TF, no matter where you place that line!
If you need to count bars elapsed in the 15-minute TF you should add your own variables to mimick BarIndex and TradeIndex or replace 3 with 9 (three 5-minute bars are required for each 15-minute bar).
02/08/2019 at 7:04 PM #90892Thx Robertogozzi for the info, didn’t know. However, multiplying by 3 the factor doesn’t change the issue. Storing the barindex of the trade seems to work better (via the onmarket not onmarket snippet).
So this code seems now to work fine. However, the fact that tradeindex function isn’t working smoothly with MTF remains a bug for me, or do I miss something?
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152DEFPARAM FlatAfter = 215900ONCE positionsize=1timeframe (15 minutes, updateonclose)myMA=average[7](close)tradetime=time >=090000 and time < 171500 and dayofweek<>0c1=close>myMAc2= myMA>myMA[1] and myMA[1]<myMA[2]cs1=close<myMAcs2= myMA<myMA[1] and myMA[1]>myMA[2]if tradetime then// -- execution logic -----if c1 and c2 and not longonmarket and barindex-mybar>=9 thenBuyLevel=High+1.5*pointsizestopbougie=low-2*pointsizebuy positionSize contracts at buyLevel STOPset stop loss stopbougieendifif cs1 and cs2 and not shortonmarket and barindex-mybar>=9 thenSellLevel=Low-1.5*pointsizestopbougie=high+2*pointsizesellshort positionSize contracts at SellLevel STOPset stop loss stopbougieendifendifif longonmarket thensell at stopbougie stopelsif shortonmarket thenexitshort at stopbougie stopendifif onmarket and not onmarket[1] thenmybar=barindexendiftimeframe (5 minute, updateonclose)myMA5=average[7](close)if longonmarket and myMA5<myMA5[1] thensell at marketelsif shortonmarket and myMA5>myMA5[1] thenexitshort at marketendif02/08/2019 at 7:11 PM #90893BarIndex and TradeIndex DO work smoothly… according to the default TF.
If you use 9, instead of 3 you can keep using TRADEINDEX, my suggestions were ORed, but this won’t affect the strategy, so you can leave it as is now.
02/08/2019 at 7:21 PM #90895Ok but if it works smoothly, can you rework a code using tradexindex and which would work under MTF ? Because I can’t, and the workaround with storing the barindex of the trade is actually not working exactly as the tradeindex function.
02/08/2019 at 7:59 PM #9089602/08/2019 at 8:00 PM #90899Yes, just forget your custom variable and just change the numeric constant:
1barindex-tradeindex(1)>=9 //or barindex-tradeindex >=9it would be 12 in a 1-hour TF or 60 in a 1-hour TF with a 1-minute DEFAULT TF, and so on…
MTF requires that you change the way you think of TF’s. The main one, the one setting the pace, is the LOWEST which guarantees that ANY TF used will at least be executed once when its own bar closes and that’s why all TF’s must be multiple of the default (or main) one.
If, in your case, the 15-minute TF would set the pace, how could ProOrder guarantee that the 1-minute code is executed every minute? Instead, letting the 1-minute TF set the pace, your 15-minute code will be executed every minute and it’s granted it will be executed when the 15-minute bar closes!
This has some drawbacks:
- you have less history data
- you have to do some math to count elapsed bars
But advantages are far more!
MTF is just a new feature, which you can take advantage of or not. You may still write strategies with a single TF because MTF may not be beneficial to them, while other strategies you write do improve when using MTF.
But if tou want to use MTF you must write your code in accordance with it.
02/08/2019 at 8:24 PM #90901Well Understood, but I maintain that using
barindex–tradeindex(1)>=9doesn’t work in my code, almost no position are taken anymore…Or are the instruction to place orders always to be inserted in the lowest TF??
Carefull Grahal, but the code I posted was just to solve the problem, there is no way it can be profitable.
-
AuthorPosts
Find exclusive trading pro-tools on