fxDreema

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

    Indicator rounding and cross (x> and x<) logic

    Bug Reports
    3
    9
    2044
    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.
    • S
      sidmcfarland last edited by

      After some extensive testing, it seems there is a bug with how X> and X< behaves related to indicator values... especially when those indicator values are very close together. Based on observation, this appears to be due to rounding. The result is that not all X> and X< events are captured. Let me explain.

      I have this condition block, which checks to see if EMA(8) crossed above EMA(13) in the previous candle (Candle ID = 1)...
      0_1602880923797_83725224-3c1e-4573-b973-3687472781ad-image.png

      When I backtest this EA in MT5 I see indicator values that look like this (last four bars)...

      Candle ID = 3 (3 candles ago)
      0_1602881218737_5fb6961a-cb61-40bf-8ad1-edcbf07e802d-image.png
      Candle ID = 2 (2 candles ago)
      0_1602881132844_c24da54b-87e3-494c-8b15-d4a51fa9f3b4-image.png
      Candle ID = 1 (1 candle ago)
      0_1602881279634_80899cab-4aa7-47b2-9bab-045ad80321bb-image.png
      Candle ID = 0 (current candle)
      0_1602881453700_db12a21f-cf08-4fbf-ac57-853f976eefd0-image.png

      Notice how EMA(8) is below EMA(13) for candle 3 and candle 2, but then climbs above it on candle 1 and further above on candle 0. The cross happens on candle 1. That is... it SHOULD happen. But it does not. The condition is never met in the EA. And based on reviewing several such examples, it seems to be related to rounding. It seems that the EA treats EMA(8) and EMA(13) as the same value since they both round to 1.17582, and as a result the "greater than" (>) comparison in the MQL code results in a FALSE value. As such, the cross is never detected.

      At least... that's what SEEMS to be going on. Thoughts? How do I make sure ALL of my EMA crosses produce a trigger every time... even when the difference between the EMA values is a fraction of a point? Do I need custom MQL code block and/or some variables to store the EMA values so that this rounding doesn't occur?

      roar 1 Reply Last reply Reply Quote 2
      • roar
        roar @sidmcfarland last edited by

        @sidmcfarland you have a example EA proving this bug? Maybe draw a vertical line every time the MAs cross?

        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 1
        • S
          sidmcfarland last edited by

          I do have an EA, but I'm not at liberty to share it. However, I did confirm the issue is due to rounding of the EMA value. I added a comment block to output the EMA values onto the chart. It looks like this...

          0_1602882587846_f73d46c7-9846-4d33-95f4-1b7943749eb4-image.png

          However, on that same candle MT5 reports the EMA values like this...
          0_1602882627848_835bc831-a2b4-44bf-9b00-6afa146d8b53-image.png

          So the EA seems to be ignoring that last digit or rounding (pretty sure it's rounding based on other examples I've seen). As a result, the cross is never detected.

          If needed, I could create a very simple EA that just looks for an EMA cross and demonstrate how it doesn't capture ALL crosses.

          1 Reply Last reply Reply Quote 1
          • S
            sidmcfarland last edited by sidmcfarland

            Here's a good example.
            https://fxdreema.com/shared/zL7SQMC4

            I ran that EA in strategy tester in MT5 on EURUSD 1-hour chart for the current month (Oct 1, 2020 to Oct 16, 2020). Here are the results.

            0_1602883315642_cd44a475-f2f2-47b7-bf4c-b21b06081e2b-image.png

            Notice how there are several crosses that have no lines.

            roar 1 Reply Last reply Reply Quote 1
            • roar
              roar @sidmcfarland last edited by

              @sidmcfarland I think you are on to something... I even modified the example so that there is no cross operator, just two separate conditions with candle ID 1 and 2 (= how the cross theoritically works).
              Even then I dont get a line on one particular cross.

              https://fxdreema.com/shared/PY7X9YzLc
              0_1602884808489_b491009f-5f6e-4e98-98c0-62f589dc0caa-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 2
              • S
                sidmcfarland last edited by

                You're getting more lines than me after making your changes to define the cross explicitly with two conditions (< on candle 1 and > on candle 2, and vice versa). However, you're still not getting them all (as you mentioned/circled). I think that's probably because you're using < and > instead of <= and >=. Just a guess.

                So I suppose I could replace my X> and X< conditions with two conditions...

                Instead of A (candle 1) X> B (candle 1), use A (candle 1) > B (candle 1) AND A (candle2) <= B (candle 2)
                Instead of A (candle 1) X< B (candle 1), use A (candle 1) < B (candle 1) AND A (candle2) >= B (candle 2)

                A little more complex, but it works (I got all the crosses now)...
                https://fxdreema.com/shared/aTk06CFM
                0_1602885657339_a5a771d5-26ae-40f1-857e-9d5e19e51c07-image.png

                Unfortunately, it defeats the purpose of X> and X<, and is a little more complex (requires two condition blocks instead of one).

                roar 1 Reply Last reply Reply Quote 1
                • roar
                  roar @sidmcfarland last edited by

                  @sidmcfarland yeah, maybe that is the bug inside the cross operator: it forgets to check the = case, just like I did

                  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 1
                  • S
                    sidmcfarland last edited by

                    Lesson learned. Steer clear of X> and X<
                    ... at least until they work correctly. Use two blocks instead explicitly specifying <,>= or >,<= Thanks for the help @roar.

                    1 Reply Last reply Reply Quote 2
                    • TipsyWisdom
                      TipsyWisdom last edited by

                      i knew my logic wasn't flawed...thanks for the workaround too.

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

                      Online Users

                      M
                      P
                      S
                      A
                      E
                      M
                      F

                      21
                      Online

                      146.6k
                      Users

                      22.4k
                      Topics

                      122.6k
                      Posts

                      Powered by NodeBB Forums | Contributors