2 conditions for order, how many bar between the 2?
Forums › ProRealTime English forum › ProOrder support › 2 conditions for order, how many bar between the 2?
- This topic has 13 replies, 3 voices, and was last updated 5 years ago by GraHal.
-
-
04/22/2018 at 1:50 PM #68927
Hi,
I tried a search but didn’t find anything, so I ask:
I’m trying to code a buy trigger (f.e.) like this:
123456c1 = ExponentialAverage[9](MACDline[12,26,9](close))CROSSES OVER 0c2 = fastMA CROSSES OVER slowMAIF c1 AND c2 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENBUY 1 CONTRACT AT MARKETENDIFThe problem is: the order is not always opened, even if both conditions happen: whenever c1 or c2 happens first, after the remaining condition happens the buy order should always be triggered.
Is there a minimum or max numbers of bars between the 2 events by default?
Or do I need to code a specific instruction for it?
Thanks
04/22/2018 at 2:39 PM #68929IF c1 AND c2 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN BUY 1 CONTRACT AT MARKET ENDIF
Hi Alex
All code is read / executed at the end of each bar and so conditions need to occur within that bar.
As you are using AND between each of the 4 conditions then all 4 need to occur on the same bar.
Also your C1 and C2 conditions both use crosses over and to get two ‘crosses over’ in 1 bar could be rare / not often occur??
04/22/2018 at 10:33 PM #68947Exact, that’s what I thought.
But what if I want both crossover within x bar since the first one? Is it possible to code it?
If I just use “>” for one condition it gives too much false signals with a misinterpretation of my strategy.
1 user thanked author for this post.
04/22/2018 at 10:50 PM #68948But what if I want both crossover within x bar since the first one?
sounds like there is 3 crossovers with one crossover repeating itself??
Below might help with C2 crossover occurring x bars ago?
12c1 = ExponentialAverage[9](MACDline[12,26,9](close))CROSSES OVER 0c2 = fastMA[x] CROSSES OVER slowMA[x]Anybody feel free to add any ideas you may have (my brain needs sleep! :)?
04/22/2018 at 11:30 PM #6895012345678910111213141516171819IF (condition1) and Not Flag = 2 THENFlag = 1Bar = BarIndexENDIFIF (condition2) and Not Flag = 1 THENFlag = 2Bar = BarIndexENDIFIF Flag = 1 and BarIndex - Bar < (however many bars you want) and (condition2) THENBUY 1 contract at MarketFlag = 0ENDIFIF Flag = 2 and BarIndex - Bar < (however many bars you want) and (condition1) THENBUY 1 contract at MarketFlag = 0ENDIFThe above might be what you want? It will look for both conditions and then if one of them is met it will buy if the second condition is met within your desired number of bars I think. Not tested and written after a few glasses of wine so might be rubbish!
1 user thanked author for this post.
04/22/2018 at 11:40 PM #68951Just realised that if both conditions happen in the same candle then a position will not be opened so you would need to change it to this for that to happen:
Still might be rubbish as not tested and another few sips of wine!
1234567891011121314151617181920212223IF (condition1) and Not Flag = 2 THENFlag = 1Bar = BarIndexENDIFIF (condition2) and Not Flag = 1 THENFlag = 2Bar = BarIndexENDIFIF Flag = 1 and BarIndex - Bar < (however many bars you want) and (condition2) THENBUY 1 contract at MarketFlag = 0ENDIFIF Flag = 2 and BarIndex - Bar < (however many bars you want) and (condition1) THENBUY 1 contract at MarketFlag = 0ENDIFIF (condition1 and condition2) THENBUY 1 contract at MarketENDIF1 user thanked author for this post.
04/24/2018 at 4:06 PM #69098Thanks guys, I will try your codes asap, but it seems to me that Vonasi’s last one is what I was looking for.
It surprises me nobody else before had a similar problem. Due to the limits of PRT (lack of mtf f.e.) I find useful to have a restricted number of bars within having my conditions met.
04/24/2018 at 7:41 PM #6910104/24/2018 at 8:40 PM #69102GraHal as the ‘Keeper of the Snippet Library’ could add it in for others to easily find.
Done / added, but I’m not the keeper! 🙂 It’s open to anybody to add Snippets … takes 10 seconds.
What if I get knocked down by a bus!? 🙂
https://docs.google.com/spreadsheets/d/1rgboqj7sVwsP9ZRhOduOefye48QMWC07jWVXCl-KJPU/edit?usp=sharing
04/25/2018 at 7:59 AM #69121but I’m not the keeper! What if I get knocked down by a bus!?
…but I would have to learn a whole new process. You’ll be expecting me to let the butler go next. As for the bus – try to avoid standing in the road when they are approaching. If it does happen then at least you will have left a legacy. ‘Here lies GraHal – creator and keeper of the snippet library at https://docs.google.com/spreadsheets/d/1rgboqj7sVwsP9ZRhOduOefye48QMWC07jWVXCl-KJPU/edit#gid=0‘. Although maybe on second thoughts that would cost a bit too much to have chiselled on your tombstone. 🙂
3 users thanked author for this post.
04/29/2018 at 3:57 PM #69379It doesn’t seems to work.
I excluded the condition
123IF (condition1 and condition2) THENBUY 1 contract at MarketENDIFto test the double conditions within x bars, and I used variable numbers between 3 and 10, but nothing at all.
Any ideas?
05/03/2018 at 2:35 PM #69729I found the working function:
1if summation[x](c1) and summation[x](c2) thenwhere x is the numbers of bar between the two events
2 users thanked author for this post.
05/04/2018 at 10:08 AM #69776I found the working function:
Excellent. Reviewing my code now in the sober light of day I can see that the flag is never reset to zero if both conditions are not met within the number of bars. Your solution is much neater and simpler – I don’t know why but my brain never thinks to use SUMMATION when I’m coding.
Grahal – you might want to change the snippet library to point at AlexF’s code rather than mine as his works!
05/04/2018 at 10:14 AM #69777Grahal – you might want to change the snippet library to point at AlexF’s code rather than mine as his works!
Done! I had them both in for a day or so, thanks for letting me know … 26 Snippets now
-
AuthorPosts