fxDreema

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

    How to close trade on moving average crossover? Or moving average direction change?

    Questions & Answers
    3
    10
    727
    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.
    • Julianrob
      Julianrob last edited by

      Hi,

      I've read similar posts but I'm not able to get it working. How do I close an open trade if the moving averages crossover? Or, if a moving average changes direction?

      I've got 'for each trade' (buy), condition MA crossover, close buy trade, and the reciprocal for sell trades.

      In backtest I'm getting journal errors: Invalid price parameter for trade function (4107)

      Here is my code:
      http://fxdreema.com/shared/zNXAextC

      Any help would be appreciated, thanks!

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

        Effectively this is doing what you need, but you don't need the pink for each trade, these blocks work as part of 2, dark pink, then light pink, or a light pink inside another block. I would set up a small test project doing 1 thing, when working, I would add to my main project.

        Learn fxDreema Without the Wait!

        My comprehensive book, available on Amazon, is packed with examples and invaluable insights to help you fast-track your learning journey.

        The paperback and hardback editions include MT4 & MT5 QR codes for easy access to all prebuilt projects and robots, including my latest gold trading robot!

        Don’t miss out

        Click here➡️ https://mybook.to/fxDreema to get your copy today!

        Enjoy! 😊

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

          Yeah, thanks jstap.

          I tried everything! I tried removing the pink blocks 'for each trade'. I tried using blocks 'if trade', still no success. And I tried just having the condition, Then linked the close trade command. I'm still getting the same errors in the backtester. For some reason it just doesn't like the MA crossover condition for closing the trade.

          Can you please suggest any other option to get this working?

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

            Try this, set up a cross to open a trade, then set up a cross to close the trade, nothing more, run this on back test, and watch what happens, I don't use this, but I have and worked for me,

            Learn fxDreema Without the Wait!

            My comprehensive book, available on Amazon, is packed with examples and invaluable insights to help you fast-track your learning journey.

            The paperback and hardback editions include MT4 & MT5 QR codes for easy access to all prebuilt projects and robots, including my latest gold trading robot!

            Don’t miss out

            Click here➡️ https://mybook.to/fxDreema to get your copy today!

            Enjoy! 😊

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

              No, jstap,

              Sorry to say it but I created this test EA, very simple. I still have the same errors:

              https://fxdreema.com/shared/1GK404ATc

              MA-cross-error-closing-trades.jpg

              I would highly appreciate anyone that can solve this issue. And why in the error log, so many decimal places for the EURJPY? Also I notice when I use default project rule settings, it doesn't work properly with my broker on YEN pairs. I have to modify the rules to ?JPY = 0.01 every time.
              @fxDreema your help is much appreciated, thankyou

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

                You didn't set buy and sell in close: this works: https://fxdreema.com/shared/OC9QWN4bd
                MA cross test.ex4

                Learn fxDreema Without the Wait!

                My comprehensive book, available on Amazon, is packed with examples and invaluable insights to help you fast-track your learning journey.

                The paperback and hardback editions include MT4 & MT5 QR codes for easy access to all prebuilt projects and robots, including my latest gold trading robot!

                Don’t miss out

                Click here➡️ https://mybook.to/fxDreema to get your copy today!

                Enjoy! 😊

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

                  Thanks jstap, yes I fixed them but forgot to save.

                  No I'm still getting constant errors here:
                  https://fxdreema.com/shared/CB9VJjOJb

                  It must only be happening with my broker then? Is that possible? It's a very frustrating problem. Strange because it recognises the command to open a trade but all sorts of problems closing it using the exact same logic

                  1 Reply Last reply Reply Quote 0
                  • I
                    Ipod last edited by

                    If you share the mql4 I can probably fix it for you, or someone will find it easier to fix than just going by the project blocks.

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

                      Thanks Ipod, I think the problem is with my data. I think there are inconsistencies. I've had to change the code entirely to remove that issue. The TP worked as as virtual one when certain conditions were met. Now I've just changed it to a fixed TP. Once my research is done I'll try to simulate the issue and get back to you

                      1 Reply Last reply Reply Quote 0
                      • I
                        Ipod last edited by

                        Sounds odd though, defo something going on with the logic you have created.

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

                        Online Users

                        S
                        O
                        K
                        M
                        M
                        C

                        32
                        Online

                        146.7k
                        Users

                        22.4k
                        Topics

                        122.6k
                        Posts

                        Powered by NodeBB Forums | Contributors