MTF – one trade per bar
Forums › ProRealTime English forum › ProOrder support › MTF – one trade per bar
- This topic has 6 replies, 1 voice, and was last updated 3 years ago by robertogozzi.
-
-
04/10/2019 at 8:03 AM #95906
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…
04/10/2019 at 8:36 AM #95908On 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):
12345IF Not OnMarket THENBarCount = 0ELSEBarCount = BarCount + 1ENDIFNext, at the very beginning of the code on your 1-second TF, add:
12345678ONCE TradeON = 1IF IntraDayBarIndex = 0 THENTradeON = 1ENDIFTradeBar = BarCountIF Not OnMarket AND TradeBar <> TradeBar[1] THENTradeON = 1ENDIFThen add TradeON to your conditions to enter a trade and clear it to avoid further trading until the next 10-minute bar:
1234IF MyConditions AND Not OnMarket AND TradeON THENBUY/SELLSHORT...TradeON = 0ENDIFedited on May 5th, 2021:
lines
12345IF Not OnMarket THENBarCount = 0ELSEBarCount = BarCount + 1ENDIFdo not work properly and should be replaced by this single line:
1BarCount = BarIndex1 user thanked author for this post.
04/10/2019 at 8:39 AM #9590904/10/2019 at 8:48 AM #95913The first lines of code I posted;
12345IF Not OnMarket THENBarCount = 0ELSEBarCount = BarCount + 1ENDIFshould 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…
1 user thanked author for this post.
04/10/2019 at 10:09 AM #95922I added to here
Please could one reader say if you see the link above as the words … ‘Snippet Link Library’ … or something else?
2 users thanked author for this post.
04/10/2019 at 11:04 AM #9593705/05/2021 at 9:45 AM #168806Actually lines:
12345IF Not OnMarket THENBarCount = 0ELSEBarCount = BarCount + 1ENDIFdo not work properly (thanks to MauroPro at https://www.prorealcode.com/topic/singola-operazione-multitimeframe/) and should be replaced by this single line:
1BarCount = BarIndexI also edited in RED the original post above (so the link in the Snippet Library is still valid).
-
AuthorPosts