So MTF is available to everyone, but weirdly we don’t see a lot of posts related to it. In my opinion because it’s too complicated to code.
I have a 15min strategy which is working averagely, but that could be improved I think/hope. All my code is on the 15min, but once there is a position, I want to manage it via the 5min. So in my 15min code, I use the snippet “barindex-tradeindex>0” to avoid taking a position if one was just opened before.
Now in the MTF code, when I test via graph the value of both function, I have tradeindex which is > barindex, which doesn’t seem even possible to me.
can you see why?
Second question: is there a way to use a smaller TF which won’t be the main TF in a MTF code? For exemple if I want to know the close value of an index like the Dax which closes at 17h35, I can’t know it if my TF is 15min. Same goes for the open, for which the correct time is rather 09h02 than 09h.
Not so weird, only available since only 2 weeks. Not everyone is a coder. IG didn’t communicate on it. It’s Summer time! 😀
Each barindex is different in each timeframe. Same goes for tradeindex. Count of elapsed bars aren’t the same for a 5-min or a 15-min TF.
The main TF is always the smallest timeframe. Code is still only read one time, at bar closure, so in order to test TIME = 090200, you still need to run the code on a 1-minute timeframe.
thx for your reply Nicolas.
I’m working with STOP and Limit order in my code, so it’s not always easy to know when a trade has been taken. In a unique timeframe, I use the snippet “barindex-tradeindex=0” to know that a trade has been taken.
But now in MTF, I get how “barindex” is working, but I still don’t get how “tradeindex” is working. How can you compare both, if they don’t use the same scale?
ok I solved it by using another command, “countofposition”.
But it’s these little thing which makes the migration of code toward MTF difficult
Since you are launching order on a single TF, TRADEINDEX to used should only compared to the BARINDEX of that TF.
yes that’s what I’m doing, but it doesn’t work. All the barindex and tradeindex functions are used under the same timeframe (15min) but tradeindex never equal barindex….
Speaking on countofposition, I thought that countofposition[1] would tell me that no trade was opened on the previous bar, but unfortunately this command always return 0 when I graph it…
Either there are still bugs in the MTF engine, or it’s me.
So I recode a fake code to explain my problems…The code is without interest, but what is important is the value of barindex, tradeindex in order to be able to compare them. Same with countofposition, how can I get the value of countofposition for the previous bar?
DEFPARAM FlatAfter = 214500
DEFPARAM cumulateorders=false
ONCE positionsize=1
TIMEFRAME(15 minutes, updateonclose)
graph barindex
graph tradeindex
graph countofposition[1]
myMA7=average[7](close)
myMA20 = average[20](close)
c1=myMA7 crosses over myMA20
cs1= myMA7 crosses under myMA20
if intradaybarindex=0 then
countL=0
CountS=0
endif
If countofposition=positionsize and countofposition[1]=0 then
countL=countL+1
endif
If countofposition=-positionsize and countofposition[1]=0 then
countS=countS+1
endif
If not onmarket and c1 and countL<1 then
BuyLevel=low
buy positionSize contracts at buyLevel STOP
endif
If not onmarket and cs1 and countS<1 then
SellLevel=low
sellshort positionSize contracts at sellLevel STOP
endif
Timeframe (5 minute, updateonclose)
myMA75=average[7](close)
closeL1= myMA75[1]>myMA75[2]
closeL2=close<myMA75
closeS1=myMA75[1]<myMA75[2]
closeS2=close>myMA75
if longonmarket and closeL1 and closeL2 then
sell at market
endif
if shortonmarket and closeS1 and closeS2 then
exitshort at market
endif