2 minute time frame in strategy
Forums › ProRealTime English forum › ProOrder support › 2 minute time frame in strategy
- This topic has 30 replies, 6 voices, and was last updated 4 years ago by robertogozzi.
Tagged: mtf, mtf indicators
-
-
09/23/2020 at 9:50 AM #14504809/23/2020 at 9:59 AM #14505009/23/2020 at 10:24 AM #145052
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?
09/23/2020 at 11:07 AM #145055Try this (not tested):
12345678910111213141516171819202122232425DEFPARAM CUMULATEORDERS = FALSETimeframe (2 minutes, updateonclose)td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Mondaytd2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesdaytd3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesdaytd4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursdaytd5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Fridaytd = td1 or td2 or td3 or td4 or td5TIMEFRAME(2mn, updateonclose)BBlow = low < Bollingerdown[20](close)IF BBlow AND Not OnMarket THENMySL = range + 1*pipsizeMyTP = 1*MySLENDIFRisk = 10IF NOT ShortOnMarket AND summation[2](BBlow) and td THENSet stop loss MySLBuy (Risk / range) CONTRACTS AT High + 1*pipsize StopSET TARGET PROFIT MyTPENDIF09/23/2020 at 11:09 AM #145056This could be a better approach (not tested):
123456789101112131415161718192021222324252627DEFPARAM CUMULATEORDERS = FALSETimeframe (2 minutes, updateonclose)td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Mondaytd2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesdaytd3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesdaytd4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursdaytd5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Fridaytd = td1 or td2 or td3 or td4 or td5TIMEFRAME(2mn, updateonclose)BBlow = low < Bollingerdown[20](close)IF BBlow AND Not OnMarket THENMySL = range + 1*pipsizeMyTP = 1*MySLENDIFRisk = 10TIMEFRAME(deafult)IF NOT ShortOnMarket AND BBlow and td THENSet stop loss MySLBuy (Risk / range) CONTRACTS AT High + 1*pipsize StopSET TARGET PROFIT MyTPENDIF1 user thanked author for this post.
09/23/2020 at 11:34 AM #145063Hi 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.
1 user thanked author for this post.
09/23/2020 at 11:47 AM #14506709/23/2020 at 12:51 PM #145076I’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! 🙂
09/23/2020 at 12:54 PM #145077Hi 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:
123456789101112131415161718192021222324252627DEFPARAM CUMULATEORDERS = FALSETimeframe (2 minutes, updateonclose)td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Mondaytd2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesdaytd3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesdaytd4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursdaytd5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Fridaytd = td1 or td2 or td3 or td4 or td5TIMEFRAME(2mn, updateonclose)BBlow = low < Bollingerdown[20](close)IF BBlow AND Not OnMarket THENMySL = range + 1*pipsizeMyTP = 1*MySLENDIFRisk = 10TIMEFRAME(deafult)IF NOT ShortOnMarket AND BBlow and td THENSet stop loss MySLBuy (Risk / range) CONTRACTS AT High + 1*pipsize StopSET TARGET PROFIT MyTPENDIFI’ll try your other suggestion next when I get a chance.
09/23/2020 at 1:07 PM #145078Hi 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:
123456789101112131415161718192021DEFPARAM CUMULATEORDERS = FALSETimeframe (2 minutes, updateonclose)td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Mondaytd2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesdaytd3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesdaytd4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursdaytd5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Fridaytd = td1 or td2 or td3 or td4 or td5TIMEFRAME(2mn, updateonclose)BBlow = low < Bollingerdown[20](close)Risk = 10IF NOT ShortOnMarket AND BBlow and td THENSet stop loss High - low + 1Buy (Risk / (High - Low)) CONTRACTS AT High + 1 StopSET TARGET PROFIT 1*(High - low + 1)ENDIFLuckily the conditions were met just there when I ran it to give you the perfect example. Are you not seeing behaviour like this?
09/23/2020 at 1:15 PM #14508109/23/2020 at 3:12 PM #145084I 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:
123456789101112131415161718192021222324252627282930313233DEFPARAM CUMULATEORDERS = FALSETimeframe (2 minutes, updateonclose)td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Mondaytd2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesdaytd3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesdaytd4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursdaytd5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Fridaytd = td1 or td2 or td3 or td4 or td5TIMEFRAME(2mn, updateonclose)BBlow = low < Bollingerdown[20](close)IF BBlow AND Not OnMarket THENMySL = range + 1*pipsizeMyTP = 1*MySLMyHI = High + 1*pipsizeENDIFRisk = 10TIMEFRAME(default)IF NOT ShortOnMarket AND BBlow and td THENSet stop loss MySLBuy (Risk / range) CONTRACTS AT MyHI StopSET TARGET PROFIT MyTPENDIF//graph BBlowGraphonprice 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:
1RETURN 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.
09/25/2020 at 3:31 PM #145406Hi 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 :
12345678910111213141516171819202122232425262728DEFPARAM CUMULATEORDERS = FALSETimeframe (2 minutes, updateonclose)td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= 000000 AND OpenTime <= 235900 //Mondaytd2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= 000000 AND OpenTime <= 235900 //Tuesdaytd3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= 000000 AND OpenTime <= 235900 //Wednesdaytd4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= 000000 AND OpenTime <= 235900 //Thursdaytd5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 000000 AND OpenTime <= 235900 //Fridaytd = td1 or td2 or td3 or td4 or td5TIMEFRAME(2mn, updateonclose)BBlow = low < Bollingerdown[2](close)IF BBlow AND Not OnMarket THENMySL = range + 1*pipsizeMyTP = 1*MySLMyHI = High + 1*pipsizeENDIFRisk = 10TIMEFRAME(default)IF NOT ShortOnMarket AND BBlow and td THENSet stop loss MySLBuy (Risk / range) CONTRACTS AT MyHI StopSET TARGET PROFIT MyTPENDIFI 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:
1Return 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..
09/25/2020 at 3:48 PM #145412On 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.
09/25/2020 at 4:46 PM #14541820 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?
-
AuthorPosts
Find exclusive trading pro-tools on