fxDreema

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

    Counting Bars Question

    Questions & Answers
    3
    5
    918
    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.
    • MrDaisyBates
      MrDaisyBates last edited by

      I'll try to keep this brief and to the point. I'm coding for MT5 if it's relevant, but I don't think it is.

      I have an EA that basically runs a loop and if it identifies a candle with a specific condition, I take the candleID from it, and I also store the time for the candle in another variable.

      Here's what I need it to do:

      Once per bar, I want it to check if the candle that happened at that time stored is more than a certain amount of bars away, that way I can have it reset something.

      Here's a better example if you're having a difficult time visualizing it.

      On init, it scans and finds that candle id 10 meets the condition. The candle id is stored and the time is also stored. Once per bar, I want it to check if that candle is more than 24 bars away, for example, that way I don't have to run the ENTIRE loop once per bar to see how far back the event occurred.

      The loop was fine, the storing of those variables is fine. I cannot find a node/condition/etc that allows me to look up a candle ID by its time so that I can somehow count how many bars back it was.

      I hate At'ing people, but if you've got time and are willing, maybe @roar might have an idea?

      Thanks to whomever has a solution!

      bk7 roar 2 Replies Last reply Reply Quote 1
      • bk7
        bk7 @MrDaisyBates last edited by

        @cdwilder1
        instead of candle id you can store the time of the candle
        take the current candle time - the stored time and divide it by the time a candle needs and you have a result of how many bars this event is in the past (like 1m = 60 seconds and so on) or just look for the difference in time of candle 1 minus candle 2 so you don't have to put in an number (issue with last candle friday and first could be tricky)

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

          @cdwilder1 thats a very important question and I'm happy to know the answer, lol

          Convert candle ID to time:
          v1 = iTime(NULL,0, 123)
          Put this code in a custom mql5 block and the open time of 123th candle is stored to variable v1.
          https://www.mql5.com/en/docs/series/itime

          Convert time to candle ID:
          v1 = iBarShift(NULL,0, D'2020.02.22 12:00')
          Put this code in a custom mql5 block and the ID of D'2020.02.22 12:00' candle is stored to variable v1.
          https://www.mql5.com/en/docs/series/ibarshift

          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

          MrDaisyBates 1 Reply Last reply Reply Quote 1
          • MrDaisyBates
            MrDaisyBates @bk7 last edited by

            @bk7 Ah! That's an excellent work around that I hadn't considered! Thanks for that. But, like you said, that weekend gap may cause issues and this is counting hourly candles, so that may be an issue (but it may be one I can work around, so I'll surely keep this in mind!)

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

              @roar Thanks, Roar! Hahaha. You're the best.

              Surprisingly, I did NOT expect it to be that complicated! hahaha. I'm still a complete nub with custom coding (hence why I'm drawn to FxDreema). I don't fully grasp it still, but I think you've given me more than enough to try and figure it out. Thanks, bud!

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

              Online Users

              A
              D
              E
              N
              N
              F
              M
              A
              L
              O

              20
              Online

              146.7k
              Users

              22.4k
              Topics

              122.6k
              Posts

              Powered by NodeBB Forums | Contributors