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?

Viewing 14 posts - 1 through 14 (of 14 total)
  • #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:

    The 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

    #68929

    IF 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??

    #68947

    Exact, 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.
    #68948

    But 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?

    Anybody feel free to add any ideas you may have (my brain needs sleep! :)?

    #68950

    The 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.
    #68951

    Just 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!

     

    1 user thanked author for this post.
    #69098

    Thanks 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.

     

    #69101

    No problem AlexF – glad to be of assistance. If it works OK then maybe GraHal as the ‘Keeper of the Snippet Library’ could add it in for others to easily find.

    #69102

    GraHal 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

    #69121

    but 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.
    #69379

    It doesn’t seems to work.

    I excluded the condition

    to test the double conditions within x bars, and I used variable numbers between 3 and 10, but nothing at all.

    Any ideas?

    #69729

    I found the working function:

    where x is the numbers of bar between the two events

    2 users thanked author for this post.
    #69776

    I 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!

    #69777

    Grahal – 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

    Snippet Link Library

Viewing 14 posts - 1 through 14 (of 14 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login