MTF – one trade per bar

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #95906 quote
    Cham
    Participant
    Average

    Example:

    I am using 2 timeframes, 10 minutes and 1 second. Suppose when OnMarket, after it reaches my stoploss, I don’t want the program to open another position within the same bar my stoploss was reached.

    Anybody can help me how to get this done? I searched for it on the forum, but can not find it.

    Thanks in advance…

    #95908 quote
    robertogozzi
    Moderator
    Master

    On which TF, 10-minute or 1-second?

    On 1-second TF it is impossible to acrivate more than one order each bar, since strategies are executed when a bar closes, so another trade could only be opened the next bar, not the same one.

    On a 10-minute TF you should add, at the very beginning of that code (provided UPDATEONCLOSE is used):

    IF Not OnMarket THEN
       BarCount = 0
    ELSE
       BarCount = BarCount + 1
    ENDIF

    Next, at the very beginning of the code on your 1-second TF, add:

    ONCE TradeON = 1
    IF IntraDayBarIndex = 0 THEN
       TradeON = 1
    ENDIF
    TradeBar = BarCount
    IF Not OnMarket AND TradeBar <> TradeBar[1] THEN
       TradeON = 1
    ENDIF

    Then add TradeON to your conditions to enter a trade and clear it to avoid further trading until the next 10-minute bar:

    IF MyConditions AND Not OnMarket AND TradeON THEN
       BUY/SELLSHORT...
       TradeON = 0
    ENDIF

    edited on May 5th, 2021:

    lines

    IF Not OnMarket THEN
       BarCount = 0
    ELSE
       BarCount = BarCount + 1
    ENDIF

    do not work properly and should be replaced by this single line:

    BarCount = BarIndex
    Cham thanked this post
    #95909 quote
    Cham
    Participant
    Average

    Thank you, Roberto…

    I am using 5 timeframes, but just used 10 minutes and 1 sec. as an example. Thank you for the code.

    #95913 quote
    robertogozzi
    Moderator
    Master

    The first lines of code I posted;

    IF Not OnMarket THEN
       BarCount = 0
    ELSE
       BarCount = BarCount + 1
    ENDIF

    should be added to only one TF, i.e. if you are using Daily+h4+h1+10-minute+default(1-second), then if you add that code on the 10-minute TF your next trade would not open till the next 10-minute bar.

    If you add it, instead, to your 1-hour TF, only one trade per hour will be allowed, and so on…

    Cham thanked this post
    #95922 quote
    GraHal
    Participant
    Master

    I added to here

    Snippet Link Library

    Please could one reader say if you see the link above as the words … ‘Snippet Link Library’ … or something else?

    Cham and Midlanddave thanked this post
    #95937 quote
    swapping
    Participant
    Master

    We see correctly the link GraHal , do not worry 😉

    Snippet Link Library

    GraHal thanked this post
    #168806 quote
    robertogozzi
    Moderator
    Master

    Actually lines:

    IF Not OnMarket THEN
       BarCount = 0
    ELSE
       BarCount = BarCount + 1
    ENDIF

    do not work properly (thanks to MauroPro at  https://www.prorealcode.com/topic/singola-operazione-multitimeframe/) and should be replaced by this single line:

    BarCount = BarIndex

    I also edited in RED the original post above (so the link in the Snippet Library is still valid).

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

MTF – one trade per bar


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Cham @cham Participant
Summary

This topic contains 6 replies,
has 1 voice, and was last updated by robertogozzi
4 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/10/2019
Status: Active
Attachments: No files
Logo Logo
Loading...