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

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #20118 quote
    robdav
    Participant
    Veteran

    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 quote
    Joachim Nilsson
    Participant
    Average

    Yep.

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

    Nicolas thanked this post
    #20123 quote
    robdav
    Participant
    Veteran

    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 quote
    Elsborgtrading
    Participant
    Veteran

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

    cheers kasper

    robdav and Nicolas thanked this post
    #20127 quote
    robdav
    Participant
    Veteran

    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 quote
    robdav
    Participant
    Veteran

    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 quote
    robdav
    Participant
    Veteran

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

    #20181 quote
    JC_Bywan
    Moderator
    Master

    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:

    c1 = (a>b)
    c2 = (c>d)

    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:

    if (c1 and c2) or (c1[1] and c2) or (c1 and c2[1]) then
    ...insert what you want to do when the line above is true
    endif 
    

    the rest is up to you…

    Nicolas and robdav thanked this post
    #20202 quote
    robdav
    Participant
    Veteran

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

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

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


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
robdav @robdav Participant
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by robdav
9 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/07/2017
Status: Active
Attachments: No files
Logo Logo
Loading...