Question on coding MTF: tradeindex

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #102273 quote
    stefou102
    Participant
    Veteran

    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.

    Capture.png Capture.png
    #102281 quote
    Nicolas
    Keymaster
    Master

    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.

    #102391 quote
    stefou102
    Participant
    Veteran

    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?

    #102392 quote
    stefou102
    Participant
    Veteran

    ok I solved it by using another command, “countofposition”.

    But it’s these little thing which makes the migration of code toward MTF difficult

    #102393 quote
    Nicolas
    Keymaster
    Master

    Since you are launching order on a single TF, TRADEINDEX to used should only compared to the BARINDEX of that TF.

    #102395 quote
    stefou102
    Participant
    Veteran

    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
    
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Question on coding MTF: tradeindex


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
stefou102 @stefou102 Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by stefou102
6 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/09/2019
Status: Active
Attachments: 1 files
Logo Logo
Loading...