Wait for x bars before entry
Forums › ProRealTime English forum › ProOrder support › Wait for x bars before entry
- This topic has 9 replies, 2 voices, and was last updated 4 years ago by
ProRealP.
-
-
06/05/2021 at 12:25 PM #171194
Hello!
I’ve been using PRT and reading the forums for about 7 months, but haven’t posted anything before now.
My question is quite simple. I would like to wait for x bars before taking an entry when my conditions are met.
Let’s say my system is something like this
1234567891011defparam cumulateorders = falsepositionsize = 1Indicator1 = average[100]indicator2 = average[50]c1 = indicator2 crosses over indicator1If c1 thenbuy positionsize contract at marketendifHow can i get the buy function to first wait x bars before taking position?
I’ve searched the forums, but haven’t been able to find anything like this.Thanks!
06/05/2021 at 1:16 PM #171196Not tested:
12345678910111213141516171819defparam cumulateorders = falseN = 3 //wait 3 barspositionsize = 1Once count = 0Count = count - 1Indicator1 = average[100]indicator2 = average[50]c1 = indicator2 crosses over indicator1If c1 thenCond = 1Count = NendifIf cond and count = 0 thenbuy positionsize contract at marketCond = 0endif1 user thanked author for this post.
06/06/2021 at 7:14 AM #17122306/06/2021 at 8:19 AM #171224I’m experiencing a strange issue. The code works, but sometimes it reverses the position compared to an identical system that doesn’t wait x bars before taking position. The code should only count and then buy/sell, yes? I made it like this to buy and short. Can you see a problem with this, or a reason why it would take a different position?
1234567891011121314151617181920212223N = 3 //wait 3 barsOnce count = 0Count = count - 1If c5 thenCondBuy = 1Count = NendifIf c6 thenCondSell = 1Count = NendifIf CondBuy and count = 0 and not onmarket thenbuy positionsize contract at marketCondBuy = 0endifIf CondSell and count = 0 and not onmarket thensellshort positionsize contract at marketCondSell = 0endif06/06/2021 at 8:41 AM #171225Try replacing line 5 with:
1If c5 and Count < 0 thenand line 10 with:
1If c6 and Count < 0 then06/06/2021 at 9:20 AM #17122606/06/2021 at 9:44 AM #171230What exactly do you mean by “it reverses the position” because it can’t reverse as checking if NOT ON MARKET bans from entering if a trade is open?
06/06/2021 at 9:52 AM #171235Quite! It was poorly explained by me. What I mean is that the system without this code takes a long position, and the one with the code then takes a short position instead, but 3 candles later. I believe this picture will make it clearer.
06/06/2021 at 10:50 AM #171242Try this one:
12345678910111213141516171819202122232425N = 3 //wait 3 barsOnce count = 0Count = count - 1If c5 thenCondBuy = 1CondSell = 0Count = NendifIf c6 thenCondSell = 1CondBuy = 0Count = NendifIf CondBuy and count = 0 and not onmarket thenbuy positionsize contract at marketCondBuy = 0endifIf CondSell and count = 0 and not onmarket thensellshort positionsize contract at marketCondSell = 0endif1 user thanked author for this post.
06/06/2021 at 12:00 PM #171252 -
AuthorPosts
Find exclusive trading pro-tools on