Two conditions met in side by side candles, is it possible to open a position?

Forums ProRealTime English forum ProOrder support Two conditions met in side by side candles, is it possible to open a position?

Viewing 9 posts - 1 through 9 (of 9 total)
  • #20118

    I am developing a system that has two conditions required to open a position. Sometimes these conditions come together in the same candle so it is easy to open the position.

    However, sometimes one condition happens in one candle and the second in the next candle. Is it possible to code in order to catch this happening and then open the position? The candles are always side by side or I’m not interested.

    Does anyone know if this is possible? If so could you please provide some sample code?

    Many thanks

    Robert

    #20121

    Yep.

    Example: If indicator1 >= indicator2 and ma5 crosses over ma20 then

     

    1 user thanked author for this post.
    #20123

    Thanks Joachim but this means both conditions are met in the same candle, not one in one candle and the second in the next candle, does it not?

    #20125

    Hi. You can define curret candle and last candle and n’th candle. For example close[1]=indicator2 and close=indicator1

    cheers kasper

    2 users thanked author for this post.
    #20127

    I actually realised there are three scenarios to cater for.

    1. Both conditions happening in one candle
    2. Condition 1 in the first candle and condition 2 in the second candle
    3. Condition 2 in the first candle and condition 1 in the second candle

    So I took the example from Nicolas’s code here https://www.prorealcode.com/topic/rsi-sab-strategy/

    However, close[1]=indicator2 and close=indicator1 will be useful as well.

    Thanks.

    #20163

    Hi Kasper

    Does this “Close[1]=indicator2 and close=indicator1” definitely work with indicators and not just price functions? I can’t seem to get it to act but from GRAPH output I can see the conditions are being met in the two candles.

    Thanks

    Rob

    #20166

    OK, I think my problem is I’m trying to use conditions and not indicators. Does that make sense?

    #20181

    Hi,

    You store your 2 conditions in c1 and c2, I don’t know what they are but let’s take these 2 just for the sake of illustrating with an ewample:

    then c1 and c2 will return at each candle a result true (equal to 1) or false (equal to 0) depending of course in this example of a,b,c,d behaviour, and it’s worth knowing there are two ways checking a condition to be true in any “if” statement: either writing “if c1=1 then…” or just writing “if c1 then…” you can drop the =1 it makes it faster the code knows and interprets it as “if c1 is true then…”

    from there, using [1] after any variable name will call the value of that variable at the previous candle, this is true for conditions too (they are nothing else than just a variable equal to 0 or 1)

    so your 3 scenarios can be checked with the simple following “if” statement:

    the rest is up to you…

    2 users thanked author for this post.
    #20202

    Many thanks Noobywan, very clear and perfect explanation to the solution. Thanks again.

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

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