2 minute time frame in strategy

Viewing 15 posts - 16 through 30 (of 31 total)
  • Author
    Posts
  • #145048 quote
    MAKSIDE
    Participant
    Veteran

    just a little reminder

    always take standard units where everyone is and have a top down approach

    M2, M3, … never used on my side.

    Capture.jpg Capture.jpg
    #145050 quote
    nwa
    Participant
    New

    Cheers for the info. It’s really a technical coding query rather than a strategy / philosophy enquiry but thanks for the input in any case. The code supplied is really just an example.

    #145052 quote
    GraHal
    Participant
    Master

    Can anyone suggest a way of coding the order to remain in place for both of the two 1 minute bars of the two minute bar?

    I (and others?) am confused as the example you show are both on 2mn TF and so there will not be 2 x 1 min bars anyway?

    #145055 quote
    robertogozzi
    Moderator
    Master

    Try this (not tested):

    DEFPARAM CUMULATEORDERS = FALSE
     
    Timeframe (2 minutes, updateonclose)
    td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Monday
    td2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesday
    td3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesday
    td4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursday
    td5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Friday
    td = td1 or td2 or td3 or td4 or td5
     
    TIMEFRAME(2mn, updateonclose)
     
    BBlow = low < Bollingerdown[20](close)
    IF BBlow AND Not OnMarket THEN
       MySL = range + 1*pipsize
       MyTP = 1*MySL
    ENDIF
     
    Risk = 10
     
    IF NOT ShortOnMarket AND summation[2](BBlow) and td THEN
       Set stop loss MySL
       Buy (Risk / range) CONTRACTS AT High + 1*pipsize Stop
       SET TARGET PROFIT MyTP
    ENDIF
    #145056 quote
    robertogozzi
    Moderator
    Master

    This could be a better approach (not tested):

    DEFPARAM CUMULATEORDERS = FALSE
     
    Timeframe (2 minutes, updateonclose)
    td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Monday
    td2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesday
    td3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesday
    td4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursday
    td5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Friday
    td = td1 or td2 or td3 or td4 or td5
     
    TIMEFRAME(2mn, updateonclose)
     
    BBlow = low < Bollingerdown[20](close)
    
    IF BBlow AND Not OnMarket THEN
       MySL = range + 1*pipsize
       MyTP = 1*MySL
    ENDIF
     
    Risk = 10
    
    TIMEFRAME(deafult)
    IF NOT ShortOnMarket AND BBlow and td THEN
       Set stop loss MySL
       Buy (Risk / range) CONTRACTS AT High + 1*pipsize Stop
       SET TARGET PROFIT MyTP
    ENDIF
    nwa thanked this post
    #145063 quote
    nwa
    Participant
    New

    Hi GraHal,

    The strategy I’m looking to implement involves 2m, 5m and 10m meaning in order to run the code I have to use the 1min chart as the basis to enable it to function. I can’t / don’t run it on the 2m time frame / chart for back testing or demo / live auto trading as it will not execute.

    So if you run the example code I pasted using the 1min chart (as I have to do to enable the strategy code to function) you’ll see what I mean about orders placing on the 1st minute of the two minute bar and then cancelling after the 1st 1 minute bar has closed. I assume this is because the basis is the 1min chart and the ‘Stop’ function only places an order on the 1st bar after the condition is satisfied and cancels thereafter i.e. the first 1 minute bar of the conditions being met. Whereas what I’m looking to achieve is to keep the order live / in place for both of the 1 minute bars making up the 2 minute bar – or until the level is breached at which point entry would be made.

    GraHal thanked this post
    #145067 quote
    GraHal
    Participant
    Master

    Thank you @nwa  for your comprehensive explanation … pleasure to read and easy to understand!

    nwa thanked this post
    #145076 quote
    GraHal
    Participant
    Master

    I’m intrigued now re the problem and the fix … I have your code running on Forward Test on 1 min TF and I was expecting to see a Pending Order appear and disappear every 1 minute … is that correct?

    If Yes, well I don’t see, I don’t even get  a Pending Order! 🙂

    #145077 quote
    nwa
    Participant
    New

    Hi Roberto,

    Just running the code on demo briefly, the entry in the code is set to the default (1 minute) time frame and so when the two minute is below the lower bollinger band the system creates orders continually on the basis of the 1 minute bars i.e. it doesn’t respect the two minute time frame with respect to order generation:

    
    DEFPARAM CUMULATEORDERS = FALSE
     
    Timeframe (2 minutes, updateonclose)
    td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Monday
    td2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesday
    td3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesday
    td4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursday
    td5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Friday
    td = td1 or td2 or td3 or td4 or td5
     
    TIMEFRAME(2mn, updateonclose)
     
    BBlow = low < Bollingerdown[20](close)
     
    IF BBlow AND Not OnMarket THEN
       MySL = range + 1*pipsize
       MyTP = 1*MySL
    ENDIF
     
    Risk = 10
     
    TIMEFRAME(deafult)
    IF NOT ShortOnMarket AND BBlow and td THEN
       Set stop loss MySL
       Buy (Risk / range) CONTRACTS AT High + 1*pipsize Stop
       SET TARGET PROFIT MyTP
    ENDIF

    I’ll try your other suggestion next when I get a chance.

    #145078 quote
    nwa
    Participant
    New

    Hi GraHal,

    Running my example code as per below on the 1 minute time frame, see attached screenshots where the order generates in the first minute and disappears in the next:

    DEFPARAM CUMULATEORDERS = FALSE
     
    Timeframe (2 minutes, updateonclose)
    td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Monday
    td2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesday
    td3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesday
    td4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursday
    td5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Friday
    td = td1 or td2 or td3 or td4 or td5
     
    TIMEFRAME(2mn, updateonclose)
     
    BBlow = low < Bollingerdown[20](close)
     
    Risk = 10
     
    IF NOT ShortOnMarket AND BBlow and td THEN
    Set stop loss High - low + 1
    Buy (Risk / (High - Low)) CONTRACTS AT High + 1 Stop
    SET TARGET PROFIT 1*(High - low + 1)
    ENDIF

    Luckily the conditions were met just there when I ran it to give you the perfect example. Are you not seeing behaviour like this?

    Minute-1.png Minute-1.png Minute-2.png Minute-2.png
    #145081 quote
    nwa
    Participant
    New

    Grahal, Orders only appear once the two minute conditions are met, and then only last for 1 minute as opposed to the full duration of the two minute bar

    GraHal thanked this post
    #145084 quote
    robertogozzi
    Moderator
    Master

    I used this code (which is the same as my second one I posted mith the addition of MyHI to make Entry fixed for the 1-minute bars), in addition I added some debugging instructions, Graph & GraphOnPrice, on the 1-min chart:

    DEFPARAM CUMULATEORDERS = FALSE
     
    Timeframe (2 minutes, updateonclose)
    td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Monday
    td2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesday
    td3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesday
    td4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursday
    td5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Friday
    td = td1 or td2 or td3 or td4 or td5
     
    TIMEFRAME(2mn, updateonclose)
     
    BBlow = low < Bollingerdown[20](close)
     
    IF BBlow AND Not OnMarket THEN
       MySL = range + 1*pipsize
       MyTP = 1*MySL
       MyHI = High + 1*pipsize
    ENDIF
     
    Risk = 10
     
    TIMEFRAME(default)
    IF NOT ShortOnMarket AND BBlow and td THEN
       Set stop loss MySL
       Buy (Risk / range) CONTRACTS AT MyHI Stop
       SET TARGET PROFIT MyTP
    ENDIF
    //
    graph BBlow
    Graphonprice positionprice + MySL coloured(255,0,0,255) AS "SL"
    Graphonprice positionprice - MyTP coloured(0,0,255,255) AS "TP"
    graphonprice                 MyHI coloured(0,255,0,255) AS "Entry"

    I also used this indicator on the 2-min chart to have the signals as a histogram:

    RETURN low < Bollingerdown[20](close)

    As you can see from pic BB1, the signal (on Dax €5, today at 14:02 Utc +2 is plotted correctly (there was a signal even the previous candle, but the entry price was never reached), the 1-minute bar at 14:03 (the second 1-minute bar only can see the signal, as it’s generated when the 2-minut bar closes, unless there’s a previous adjacent signal) places the pending order, which is immediately executed.

    As you can see from pic BB2, another signal was plotted on the 2-min bar today at 09:18 Utc+2. The second pending order was placed at 09:20 (the first 1-minute bar AFTER the 2-min bar) and it entered at 09:21.

    Being based on signals showing on the 2-min TF, the pending orders on the 1-min bar can be placed:

    • on the second (or last) 1-min bar of the 2-min bar, since signals are only updated when the 2-minute bar closes
    • on the first 1-min bar of the 2-min bar AFTER the 2-min bar that originated the signal, for the opposite reason, since the signals show on the last 1-min bar of the 2-min bar, the first 1-min bar of each 2-min bar still has the PREVIOUS 2-min bar VALID.

    If you remove UPDATEONCLOSE, you can see the difference.

    If there’s still something incorrectct, please:

    • post the code you used
    • post the name of the instrumend traded
    • post the date and hour of both the 2-min and 1-min candles involved

    so that we can replicate any issue.

    bb1.jpg bb1.jpg bb2.jpg bb2.jpg
    #145406 quote
    nwa
    Participant
    New

    Hi Roberto,

    “Being based on signals showing on the 2-min TF, the pending orders on the 1-min bar can be placed: on the second (or last) 1-min bar of the 2-min bar, since signals are only updated when the 2-minute bar close” or “on the first 1-min bar of the 2-min bar AFTER the 2-min bar that originated the signal, for the opposite reason, since the signals show on the last 1-min bar of the 2-min bar, the first 1-min bar of each 2-min bar still has the PREVIOUS 2-min bar VALID.”

    If I understand correctly from what you’ve said above, then a pending order can only be placed on the close of the last minute of the two minute bar since this is when ‘updateonclose’ executes? Am I correct in my interpretation?

    I ran you code as per below on demo (which I modified the bollinger band length from 20 to 2 purely to generate more frequent orders for observation) on EURUSD around 15:00 UTC + 0 :

    DEFPARAM CUMULATEORDERS = FALSE
     
    Timeframe (2 minutes, updateonclose)
    td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Monday
    td2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesday
    td3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesday
    td4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursday
    td5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Friday
    td = td1 or td2 or td3 or td4 or td5
     
    TIMEFRAME(2mn, updateonclose)
     
    BBlow = low < Bollingerdown[2](close)
     
    IF BBlow AND Not OnMarket THEN
    MySL = range + 1*pipsize
    MyTP = 1*MySL
    MyHI = High + 1*pipsize
    ENDIF
     
    Risk = 10
     
    TIMEFRAME(default)
    IF NOT ShortOnMarket AND BBlow and td THEN
    Set stop loss MySL
    Buy (Risk / range) CONTRACTS AT MyHI Stop
    SET TARGET PROFIT MyTP
    ENDIF

    I observed in picture 1 attached a pending order placed on the open of the second 1 minute bar @ 14:57 on the two minute candle. I don’t understand why this order placed assuming my statement on ‘updateonclose’ as per above being a requirement for order placement.

     

    FYI the indicator BBlow shown in the pictures attached is:

    Return BBlow = low < Bollingerdown[2](close)

     

    I observed in picture 2 attached a pending order being placed at 15:14  on the close of 15:12 on the two minute chart despite no bollinger touch on close the 15:12 candle (BBlow indicator = 0).

    So I’m not observing the behaviour I’d be expecting to see with my current understanding of the code.

    I tried removing ‘updateonclose’ for observation and if I remember correctly saw orders placed on the close of each 1 minute bar when the BBlow indicator was returning 1.

    So still a bit confused on my end..

    1-2.png 1-2.png 2-1.png 2-1.png
    #145412 quote
    robertogozzi
    Moderator
    Master

    On the second minute of the bar which shows the signal + the first minute of the next bar.

    20 is the correct periods for the BB.

    #145418 quote
    nwa
    Participant
    New

    20 is the correct periods for the BB.

    I modified the bollinger band length from 20 to 2 purely to generate more frequent orders for observation

     

    On the second minute of the bar which shows the signal

    The 2min bar which shows the signal must be closed to generate the signal no? So how can it generate an order before generates a signal?

    the first minute of the next bar.

    For clarity do you mean on the open or close of the first minute of the next bar after the signal?

Viewing 15 posts - 16 through 30 (of 31 total)
  • You must be logged in to reply to this topic.

2 minute time frame in strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
nwa @nwa Participant
Summary

This topic contains 30 replies,
has 6 voices, and was last updated by robertogozzi
5 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/05/2020
Status: Active
Attachments: 9 files
Logo Logo
Loading...