fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    Counter to check past candles conditions

    Questions & Answers
    3
    4
    2231
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      malfy last edited by

      Hi there!

      I'm trying to realize this idea: if a certain number of past bars closed below the middle bollinger band and the last bar closed above, then buy.

      I tried to do this using a counter "Count n then pass". The idea is this: if i want to count 5 bars under bollinger middle line i need to check 6 bars... 5 under bollinger and 1 above bollinger, so i set a constant (COUNTER CYCLES) equal to 6-2=4. Then i set a variable (ID) equal to the (COUNTER CYCLES)+2.
      The counter should check the condition Candle Close < Bollinger Middle at the candle ID = (ID), if is true, set (ID)=(ID)-1. When the counter passes, If all the past candles closed below the bollinger then (ID) must be == 2 and i just have to check if the last candle closed above and eventually buy.

      This is the project: shared/1g4dy10Hc

      My problem is that the variable (ID) goes immediatly to -1 which should be impossible... if the counter passes 4 times and (ID) is initialized to 4+2 it should never go under 2. I can't get the reason.
      Probably i did a wrong use of the counter. To realize this idea i connected to the yellow dot a "run blocks" command to run the candle condition check.

      Can someone tell me where i'm wrong?

      1 Reply Last reply Reply Quote 0
      • roar
        roar last edited by roar

        Hi!

        My problem is that the variable (ID) goes immediatly to -1 which should be impossible...

        That is because the block #6 executes on every tick (and so does 7), it doesn't need block 5 to run.

        I probably didn't even fully understand the counter block method, there might be a less complicated way 😄
        I would use a counter variable, so I could track the count with the comment block.

        How bout dis:
        https://fxdreema.com/shared/b2lenwGXd
        0_1536427480703_fe520fdf-46c7-4f51-83cd-cf11c82a62d2-image.png

        Need small help? Tag me in your post
        Need big help? https://www.fiverr.com/big_algo/automate-your-winning-strategy-in-mql4-or-mql5

        1 Reply Last reply Reply Quote 0
        • M
          malfy last edited by

          Thanks Roar,

          Your workaround it's certainly less complicated but is not what i want, because you are counting each bar waiting for the condition to buy, while i want a "picture" of X past bars at every new bar.
          Anyway you suggested me where to focus my attention, and i discovered that i was using the wrong counter block. Using Loop (Pass "n" times) it works!

          That's the right version:
          https://fxdreema.com/shared/z2aQGGpae

          1 Reply Last reply Reply Quote 1
          • fxDreema
            fxDreema last edited by

            Try that block called "Indicator moves within limits" 🙂

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post

            Online Users

            C
            A
            X
            J
            A

            13
            Online

            146.7k
            Users

            22.4k
            Topics

            122.6k
            Posts

            Powered by NodeBB Forums | Contributors