Lookback with condition

Forums ProRealTime English forum ProBuilder support Lookback with condition

Viewing 5 posts - 1 through 5 (of 5 total)
  • #172502

    Hello All,

    This was posted in reply to Vonassi but didn’t look like it was posted. I am posting here. Apologies if it ended up being double posted.

    I have a fairly simple question
    How do I write a simple code that for example looks back at the last 100 bars and averages only positive values? For example I have an indicator that returns either a + value or – value for every bar. I want to lookback 100 bars and average only the + values (- values are skipped/ignored in average calculation)
    thank you and regards.

    #172505

    It’s an indicator, so its correct support forum is ProBuilder.

    I moved it.

    Try this (not tested, I can’t even know if it is an accepted syntax):

    The idea is to average all positive values, 0 otherwise.

    #172507

    I didn’t work. It returns 0

    #172508

    Maybe a code that goes through the 100 bars and everytime that finds a positive value it stores it in a variable and once it finishes going through the 1oo bars and storing all the positive values it finds then a code to average all positive values found and stored. Perhaps an array variable that can store up to 96 values?? perhaps a much more simpler code?

    #172515

    You must have done something wrong, as it works perfectly (applied to MACD):

    If, instead, you want to count how many times the Histogram was > 0:

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

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