fxDreema

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

    Looking for a Crossing during last n candles

    Questions & Answers
    2
    4
    1125
    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
      MetaTrader last edited by

      I want to know if there was a ema crossing during the last 5 candles.
      Ok I can add 5 blocks for long condition with different offsets but then i need another 5 blocks for the short condition.

      Is there an simpler way?

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

        If at the moment EMA20 > EMA5 and for the fifth candle EMA20 < EMA5, then this means that there was a crossover somewhere in between. This is what the "Cross width" parameter do actually (although I keep this parameter only for compatibility with old projects), but I will recommend to use two blocks instead 🙂

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

          Two blocks is not exactly hitting the point. 😞

          maybe there are more crossings during the last 5 candles. One on candle 4 one on candle 1. Comparing like you say will give me a false where it must be a true....

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

            People are always asking me how to make indicator in the EA, because these calculations are basically this 🙂 And I always explain that the best is to get signals directly from indicators. The difference is that indicators (if well written) does not recalculate on every tick, while in the EA this is hard to make, especially in EA builder.

            Anyway, I finally added this field, which allows us to calculate some things - http://prntscr.com/9egr7i - but your scenario (to detect that only 1 crossover happened in the last N candles) is more complex and specific and I don't feel like I want to do it, at leat not somewhere in Condition 🙂

            Otherwise the logic would be to make "for" loop and count crossovers from below and from above and then to pass only if this count is 1. If the count is 2 - break the loop.

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

            Online Users

            S
            G
            L
            K

            14
            Online

            146.7k
            Users

            22.4k
            Topics

            122.6k
            Posts

            Powered by NodeBB Forums | Contributors