Averaging based on condition

Forums ProRealTime English forum ProBuilder support Averaging based on condition

  • This topic has 8 replies, 4 voices, and was last updated 2 years ago by avatargfx.
Viewing 9 posts - 1 through 9 (of 9 total)
  • #198485
    gfx

    Hi all,

    I hope you are doing fine.  I am stuck with a single problem so I’d rather ask help than building another 1000 lines indicator 🙂

    The idea is to create a moving average of n candles  ( n is user defined) but only of up candles.

    I was thinking of a while loop with a counter, but I can’t even get a first function to work.

    I get infinite loop warning when running this …

    Thks in advance for your hints.

    gfx

     

    #198486

    What I did for you is testing with

    • More and less bars (possibility of reading beyond the first bar in the chart)
    • More than one instrument (Fx vs Index)
    • Setting up the loop completely different (so PRT could not pre-process it and have false alarms on e.g. i not increasing for a while)
    • Finding the threshold

    Regarding the latter, it is always around (triggerbars) 2300 – 2500 that it fails. Under 2300 thus works (for what I tested with).

    You could make a Technical Report (via the Help menu – check the checkbox to allow PRT to open and read the code – just this code but with triggerbars initiated at 3000 or so) and tell them that you found a bug.
    It could be better to find a workaround because the solution may stay out many months (if ever).

     

    1 user thanked author for this post.
    avatar gfx
    #198488
    gfx

    Thks. I added

    and indeed it works. Though…

    I tried this …

    and see attached picture.

    First it only executes on 4 last bars … not 5.

    Wired enough… if condition is not exectued as expected

     

     

     

     

    #198490
    gfx

    this drives me nuts !!

    #198504
    JS

    Hi @gfx,

    Try this…

    #198527

    hi…

    From your original post, I think the reason you may be getting the infinite loop is this:

    To exit the loop ‘i’ has to equate up to ‘triggerBars’+1.

    Now let’s say halve the candles in your chart are bull candles, ‘i’ can only increment up to halve of what ever you set ‘triggerBars’ to, since it only increments on a bull candle via the if condition. Along with this may be some error checking of historical bars loaded and also it has to end the loop before moving on to next bar. Don’t really fully understand whats going on, but that’s my thinking

    If you replace ‘i’ with runback in the ‘while’ condition, ‘runback’ always ends up ‘1’ bigger at the end of each loop iteration. This then terminates the loop at the end of the iteration when ‘triggerBars’ value is hit.

    Any way, I was looking at huge problem and your ‘up candle moving average’ kind of brushed against a concept I come up with and was thinking of using to solve it.

    While testing the concept I knocked up this code, which I think does something very close to what you were trying to do.

    It identify up candle’s and uses them to display a SMA via a lookback value. Two things to note, your up candle may be different from my define, and the SMA doesn’t use the current candle, not tested.

    Hold on to nuts, get your head around this!

     

    1 user thanked author for this post.
    avatar gfx
    #198532

    This one works. 🙂

    2nd attachment shows the down-bars.
    Both are equal-ish, which I suppose it possible tonight. The chart comprises of 10K bars but it runs for a while so more bars populated.

    It will do the calculation at each new bar, so maybe it is not smart to let this run forever.

     

    First it only executes on 4 last bars … not 5.

    Yes, something seems wrong there because DrawOnLastBars can not be 1 (error message) and with 2 it draws 1.

     

    1 user thanked author for this post.
    avatar gfx
    #198544
    gfx

    looks good 🙂

     

    #198549
    gfx

    I ended up with this approach…

     

     

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

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