State machine vs expressions

Forums ProRealTime English forum ProBuilder support State machine vs expressions

Tagged: 

Viewing 13 posts - 1 through 13 (of 13 total)
  • #86685

    Hi

    I am developing an indicator for the following entry setup:

     

    1. significant high = touch of the upper Bollinger (high >= BollingerUp)

    2. one one or more lower closes (than the close in 1)

    3. One or more higher closes (than the close in 2)

    This setup is invalid after X bars.  Where X is 5 but would like to test different values.

     

    I am struggling with 2 and 3 as it is a variable number of bars so I want to avoid hardcoding bar indexes…

     

    Any suggestions?

    #86687

    You have to use variables following the five steps (see attached pic) while in ProBuilder:

    1. click on the spanner (upper left corner)
    2. assign a name to your variable (one each time, but you can add many), that name will appear automatically mext to the sparrow  after confirmation
    3. assign a type and default value to your variable
    4. close the window
    5. confirm your indicator by validating it

    you’ll then be able to use the indicator properties to change their value anytime.

    3 users thanked author for this post.
    #86693

    I learnt something entirely new there … using a function I never knew existed, thank you Roberto!

    Just hope I remember for when I need it! 🙂

    1 user thanked author for this post.
    #86818

    Thank you Roberto for the quick and helpful response.

    To clarify, I’m looking for coding insights to detect candlestick patterns over a variable range of bars.

    As I see it – based on minor experience so far with this platform – there are two generalised ways to approach solving this:

    1. use in-built mathematical and statistical functions to express the conditions.  This leads to a common pattern of decomposing the condition into elements (commonly named c1, c2, c3…) and then testing the truth of the conditions combined using logical operators.
    2. write a state machine with lots of if/then and hand coded counters.

     

    In my view, the first approach is a lot more elegant but more importantly to me, leads to less bugs as you avoid manual handling of state.  I believe this approach is advocated in the manual for performance reasons (can’t find the reference now).  There is no “problem” per se with 2, but I do find it a lot more error prone when creating the code.

    So I’m pondering how to codify ‘one or more higher closes (than the prior bar)’ followed by ‘one or more lower closes (than the prior bar)’ in the spirit of approach 1 and looking for code ideas to point me in the right direction.  Perhaps a test of the closing price causing a TRUE value and then testing an array variable for consecutive TRUE values…but in a one-two liner :).

    I’m stuck so would really welcome ideas – however off the wall they may be.

     

    #86823

    If you need to detect whether an ENGULFING (Bullish and Bearish) pattern can be detected (currently or previously) you can write:

    is that something that might help you?

     

    1 user thanked author for this post.
    #86832

    Thanks again Roberto.  This is the style of solution I am thinking of.  Converting your engulfing candle to my “higher/lower closes” is simple enough:

    So I am trying to figure out how to go from “count how many times the condition appears in the previous X bars” to “tell me when the condition is true in a repeated sequence up to X times”….

     

    #86834

    This

    will be true when, within the last “n” bars, the condition occurred twice.

     

    1 user thanked author for this post.
    #86835

    Sorry, this is true even when not consecutive.

    #86836

    We are now in the same ballpark 🙂

    #86837

    this will be true when for ALL “n” bars the condition was true.

    To spot any 2 consecutive occurrences within n bars:

     

    1 user thanked author for this post.
    #86841

    Actually in my last example, 6 bars will be used, since if the condition is true on bar 5 it’s because it joins bar 6 to make the pair 6-5.

    To make sure you have the exact number of bars you should insert this line between 2 and 3:

    in this case n will return 4, which scans n+1 bars.

     

    1 user thanked author for this post.
    #86842

    That’s a clever approach but I think we’ve moved away from the original requirement (my post 86832 confused things – sorry for that).

    Here’s the pattern description:

    1. significant high = touch of the upper Bollinger (high >= BollingerUp)

    2. one one or more lower closes (than the close in 1)

    3. One or more higher closes (than the close in 2)

    This setup is invalid after X bars.  Where X is 5 but would like to test different values.

    So counting or specifying a “number of bars requirement” for the “more closes” is not so relevant (but helpful for parameter experimentation in backtesting).

    I imagined something like this:

    Does this make sense?

    #86845

     

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

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