Looking for a function, which can tell if there is an event happend in the last

Forums ProRealTime English forum ProBuilder support Looking for a function, which can tell if there is an event happend in the last

Viewing 14 posts - 1 through 14 (of 14 total)
  • #241118

    For example, I will check if in or within the last n days the SMA(5) crosses over the SMA(10).

    #241119

    You can ever use Barssince if you want to know when it happened last time (and then check if it is within the last n bars,

    https://www.prorealcode.com/documentation/barssince/

    or Summation to check if it happened at least once within the last n bars

    https://www.prorealcode.com/documentation/summation/

    3 users thanked author for this post.
    #241132

    Here’s an example of using BARSSINCE and SUMMATION. This may not be the only way to do this.

     

     

    2 users thanked author for this post.
    #241136

    Many thanks all!

    #241150

    Here i smy indicator:

    MyMA5 = Average[5](close)
    MyMA20 = Average[20](close)

    cond2 = MyMA5 crosses over MyMA20
    testCross = BarsSince(cond2, 1)

    return testCross

    The output looks like the saw signal. But what I want is like pulse as shown as in the attached picture. Is it possible?

    #241155

    It appears from image, that you want to highlight when crossovers occur.

     

     

    #241156

    wonderful, many thanks!

    #241162

    @druby

    Hi, I thnik it is not correct since you used the cond2 but not the testCross.

     

    Surely it maybe because I used the ‘1’ in the BarsSince(). In this case the Barssince() has less meaning.  I should change it to any number greater than 1.

     

     

    #241163

    Not sure where you going with this, with regards to original question.

    BarsSince(condition,0) with’0′ gets the bar offset to last condition that was true, from the current bar..

    Using ‘1’ gets the offset to the true condition prior to the last.

    The saw tooth action is plotting the current continuous offset value,  since it is plotted every bar from on return line.

    Additionally, the staggering level of the low of the saw tooth is because, when a new crossover happens,

    the one being plotted stops being the prior one and the prior last one becomes the current prior one, and so on after each new crossover.

    From your image I took it as you were highlighting the crossover points which is when you use ‘0’ in barsSince.

    Regardless, of what value you put in BarsSince, each crossover will be highlighted other than  crossovers below n down to ‘0’

    So the crossovers never change position with respects to the averages and the bars number there on, just the offset from the current barindex value.

    Why did you only highlight 3 crossovers in your image?

    #241174

    Hi,

    my original question is: I wonder if there is a function which can tell me in the last or within the last n days an event or condition comes true.

    I use another chart software where there is a function called EXIST(event, days). I attach a screesnhot. Maybe  you can understand what I wat better?

    #241183

    This will return the number of occurrences withim the last N bars:

     

    #241190

    HI @roberto,

    here i smy code:

    ONCE N = 3
    MyMA5 = Average[5](close)
    MyMA10 = Average[10](close)
    MyMA20 = Average[20](close)

    c1 = MyMA5 crosses over MyMA10
    c2 = MyMA5 crosses over MyMA20

    return summation[n](c1 and c2)

     

    Attached is the creenshot. One can see there is much less signals.

     

     

    #241198

    In your code, fast MA have to cross the 2 others at same barindex…

    1 user thanked author for this post.
    #241199

    beautiful! Many thanks!

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