MTF Sequential Setup

Forums ProRealTime English forum ProOrder support MTF Sequential Setup

This topic contains 48 replies, has 8 voices, and was last updated by avatar robertogozzi 4 months, 1 week ago.

Currently, there are 0 users and 1 guest visiting this topic.
View all attachments
Viewing 15 posts - 1 through 15 (of 49 total)
  • #102415

    The problem is how to develop a code that applies a sequential MTF setup ?


    In UT1 an event A is recognized then for a wile (as n periods), we are waiting for a new event B in UT2.

    Then repeat a few more sequential signals, waiting a new event C in UT3, then UT4…

    (UT1 > UT2 > UT3 > UT4)

    I tested several ideas with “summation[n](event)>0” “if event then timeevent = currenttime”, “barindex…”, but nothing works,

    due to the impossibility to mark a first eventA in UT1 and for n period to not detect new eventA

    then only to detect an eventB in UT2 and for n period not to detect again a new eventB

    then only to detect an eventC in UT3…


    There you go:





    Hi Robertogozzi,

    Thank you so much for your code proposal, that I immediately tried to understand 🙂

    • For starters I would just like to check that I have been clear enough in the explanation of my sequential signal need.

    The system need to detect event A in UT1 and to stop detection for n1 period.

    During those n1 period it need to detect envent B in UT2 and to stop detection for n2 period

    During those n2 period it need to detect event C in UT3 and to stop detection for n3 period

    Why to stop detection ? Because of the need to check barindexA < barindexB < barindexC. If the code doesnt stop detection, the sequential setup on the market could be right but not the barindex sequence, and vice versa.

    I can now try to understand your proposal and to discuss it :

    • If I’m right, it detect the eventX and save the bar number (I need that for compare barA<barB<barC<barD) and goes eventX variable from 0 to 1.

    But what happening if the eventX arrives again in the next bar ? Does it save again the new bar number and barX increases by 1 ?(I need him not to do it)

    • Also, if too many bars have elapsed, then it cancel eventX by going eventX variable from 1 to 0. (I need that for to no longer consider that the event took place in the recognition of the sequential signal)
    • Also, on a condition (you chose the opposite condition of the eventX) it goes eventX variable from 1 to 0.

    Would it be possible through a similar or a different method to block the detection of  event A for n periods once it has been detected a first time ?

    We could then get the right sequential purchase signal

    I look forward to reading you !


    This is a squential approach, it will test event B only if event A has occurred and so on for the next events.

    Event A will only last LookBackA bars, then it will be cleared, the same for all other events.

    In my first version I just added an opposite condition to cancel events, but it’s not mandatory, especially now that there is a cancellation due to elapsed bars.

    My first version did not detect the 4 events sequentially, just as they occurred. It only entered a trade when ALL events were true. When a new X event occurred, it simply updated its barindex value.

    This new version is a more strict coding of what you requested.



    Above code added to here

    Snippet Link Library

    1 user thanked author for this post.

    Thank you so much RobertoGozzi, I tried it, and after gaining more knowledge about proorder, I understand better your work and it look clever and simple (a very nice code)

    GraHal, that library is incredible !

    Have a nice Day


    1 user thanked author for this post.

    Now I need time for deep backtests with the complete strategy, and I’ll come here for feed backs


    I couldn’t resist! 🙂

    Changed only TF’s, SL /TP and LookBacks.

    Anybody please backtest on 200k bars and post results.

    Also post any improvements … looks like it has potential and be a shame to waste Philippe’s idea and Roberto’s excellent coding.

    Results attached are with spread = 4.

    ITF attached so you can quickly and easily use the settings in the Optimiser.

    1. PhilRob-MTFSeq-DJI-1M-v1.itf
    1 user thanked author for this post.

    Hello Roberto.

    with MTF, you can not amend a variable set in a timeframe within a lower timeframe. With your code Roberto, any idea how you could reset to 0 variable eventA eventB eventC on case eventD is not=1??


    If eventD is not 1, nothing happens, why resetting the other ones?

    In any case you should add another variable, say FLAG, on the DEFAULT TF, so that when it is set all other TF’s clear their variables or  don’t set their values or, even better, don’t check their conditions.



    Yep sorry I have another case in mind where eventD is the ultimate filtrer and cancel all above signals. Thx for the suggestion, will give a try


    To be clearer, if you use a volatility filter for exemple as last condition ( eventD), if this condition is not right directly, by the time it does, the market has already moved, so you don’t want to take the position.


    You set eventD=0 so no position will be opened.

    You may set FLAG=1 in the DEFAULT TF, then you may want to clear it when needed and use FLAG  in lines 8,21 and 34 with IF:



    Hi there,

    I noticed in your code you are using the average function with the period defined as 10 or 30 followed by comma and 0 such as “average[10,0](close)”.

    What does the zero mean in this average calculation? Is that a variable to define the type of average e.g. simple/geometric etc?

    Hope you can clarify.



    It’s the type of average as from


Viewing 15 posts - 1 through 15 (of 49 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login