X happened withing y periods

Forums ProRealTime English forum ProBuilder support X happened withing y periods

Viewing 10 posts - 1 through 10 (of 10 total)
  • #18449

    Hi,

    How do i code when i want something to have happened within a period? To make a restriction.

    For example,

    if x =1  and y = 1 and Q = 0 within the previous 500 bars then

    a = 1
    else
    a = 0
    endif

    How do i code “within the previous 500 bars”

    Thanks alot guys!

    #18450

    If you really need all 3 conditions on x y and Q to be true at the same time during each of the previous 500 bars, then you can make it a condition which is worth 1 when true, and make a summation of that during the past 500 bars, anything less than 500 means it wasn’t true during at least one bar so:

    but if you meant you wanted this to have happened just once at least within the last 500 bars, then same trick using summation but >0 rather than =500:

    1 user thanked author for this post.
    #18454

    Thanks for answer!

    What i want is to have all three to have happened atleast one time within the 500 previous bars. There would be a problem with this code, if x is true three times and not the others, i would still get the sum = 3. Maybe a Once count in this on each of the x,y,q? So that i can use summation to get the sum = 3 in the last 500 bars. Any idea to do this?

    It’s a good idea with summation, i thought it should also exist some simpler version versus this following approach; “if x or x[1] or x[2] or x[3]…..” A simplified code, can’t do this 500 times ^_^’

    PS: Tried your code above but didn’t manage to get it to work correctly.

     

     

    #18457

    “(x=1 and y=1 and Q>0)” all together works as one condition, so all three of them true is a condition true (=1) or untrue (=0), but not =3

    So if you want this condition to be true at least once within past 500 bars (and allow for it to be true more than once if the case may be), you are in the second case I suggested: using >0 instead of =500

    #18460

    Thank you alot, but i’m sorry if I am not clear enought, x,y and q will never be true at the same time, that’s why i want to get a value if they were true close to eachother, as within 500 bars.

    To illustrate with an example, if we had a bearish engulfing, a bullish engulfing and a doji the last 500 bars i would like to return these to a value = 1 and if not true, value 0. As happens there could be alot of doji’s in these 500 bars, but i don’t want this to influence my true value = 1. For me it seems that a ONCE code could be in place, but i’m not sure how to do this, because i want the “loop” to continue. I figure, because they should probably be taken individually-the x,y,q- we maybe should use a seperate summation for them.

    If the 3 conditions is true atleast once(each of them) in the previous 500 bars i want the function to equal 1.

    #18462

    ok, so, if the 3 conditions x=1, y=1, Q=0 are independant from each other and don’t have to be simultaneously true, but each one of those need to have happened at least once:

    1 user thanked author for this post.
    #18467

    With that code ProOrder has to sum occurrences 500 times at each bar.

    This code should be less time consuming:

     

    #18469

    Thanks alot Noobywan, simple things is hard until right idea! Should work now [y]!

     

    Thanks robertogozzi for input! But i don’t see how this works for me, did you read my code goal? I’ll add a code below, i hope you can simplify that one, would be terrific! Really need to speed up the calculations…
    “If the 3 conditions is true atleast once(each of them) in the previous 500 bars i want the function to equal 1.”

     

    #108385

    Im also curious about the answer to this one. I would like to know for example if a Stochastic crossed below 20 and for example an RSI did the same within for example 10 bars of each other.

    #108388

    There you go, C will be true whenever one of the two occurs at a distance of 10 bars:

     

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

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