fxDreema

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

    EA to buy and sell after MACD cross confirmation

    Questions & Answers
    2
    20
    5711
    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.
    • R
      ryry last edited by

      Hi ,
      would it be possible for my EA to place the order once the MACD has crossed?
      Screen Shot 2016-01-19 at 15.31.27.png
      Like it is shown in the image above I need an order to be placed once the MACD has crossed as confirmation after the Stochastic has crossed. I have made an EA already however it only places orders when both indicators line up and both cross around the same time instead of waiting a while for the confirmation of the MACD.
      What would you advise?

      ......
      Screen Shot 2016-01-19 at 15.31.27.png

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

        Use two "Condition" blocks with crossovers inside. If both indicators cross at the same candle, there should be no problem. But first try with one of them and then add the other.

        1 Reply Last reply Reply Quote 0
        • R
          ryry last edited by

          Thanks for replying. I have created the EA with two condition blocks consisting of the stochastic cross and macd cross, however when i test the EA it doesn't place orders where I would like them to be as the EA only places an order when both Stochastic and MACD cross at the same time, however would it be possible if the EA was to wait a few bars for the MACD to cross after the Stochastic has already crossed and then place an order instead of being placed when they both have crossed in the same place.
          Link to the EA- https://fxdreema.com/shared/Luu4RR3Ed

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

            Check this answer: post/11275

            1 Reply Last reply Reply Quote 0
            • R
              ryry last edited by

              I have checked out the project advised and it seems its a similar issue. I have given it a try using the same principle in the other project and come up with this- https://fxdreema.com/shared/v52Gk2Hid

              I have ran it through mt4 ea tester and it seems to work however in some places where they both cross, orders aren't being placed but the majority of the time they are in the right place. Would you be able to take a look to check to see if it is ok. Also would I need to add 'once per bar' block to prevent multiple orders happening on the same candle.

              Many thanks for your help!

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

                I always try to explain how things work in general, I never want to make whole projects. I was just showing the idea. And the idea is that the EA uses temporary memory (Variables) to hold some information about it's current state. It's just some example and no one says that this is exactly the way it must be done. The Variable that is used in my case is "int", but it can be also other type, like "string".

                What is missing in your copy is the check of the Variable before going to Buy or Sell. Again, this Variable holds information about the current state of the logic and I was using the value of 1 to say that the EA is ready to Buy. Value -1 to say if the EA is ready to Sell. But you are not checking whether the Variable is 1 or -1.

                1 Reply Last reply Reply Quote 0
                • R
                  ryry last edited by

                  How would I begin to program the variable so the EA will check before buy and sell, that the MACD has crossed. Im not used to coding so I'm not really sure how to do this. Would you be able to give me an example of how the variable should be?

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

                    This was the example. Look at my example in the other topic and you will see that there are 2 extra blocks.

                    Variables are just values with name. Some name that holds a value. There are different types of values, different data types.

                    bool = boolean, either true or false, which is similar to 1 or 0
                    int = integer, whole values like 1, 2, 3, 4
                    double = floating numbers like 1.2345 and 48.39327
                    string - texts like Hello, World

                    bool, int and double can be mixed most of the time. It's actually possible to define string variable and use it as a number later... sometimes.

                    Again, variables are just some kind of objects that have name and the person can recognize, and they contain some data. In the deepest level they are addresses on the RAM. They can be read or modified.

                    in fxDreema Variables are global - they can be accessed from everywhere in the project.

                    1 Reply Last reply Reply Quote 0
                    • R
                      ryry last edited by

                      I believe I have now fixed the issue i had earlier with the EA. However i now face another problem and I have no idea why it is doing it but I have added the condition so trades will close once they have reached a certain amount however when a buy order closes for example it opens a sell order and closes straight away causing a loss of a small amount. Also the EA terminates itself for no reason. Could you please help and advise, I have no idea whats going wrong. Sorry for being a pain and thanks for your help so far!

                      https://fxdreema.com/shared/DoQqqyqae
                      Screen Shot 2016-01-25 at 14.33.54.png
                      Screen Shot 2016-01-25 at 14.54.17.png
                      Also above shows orders closing at one point instead individually closing when they all have reached there level of profit?

                      ......
                      Screen Shot 2016-01-25 at 14.33.54.png
                      Screen Shot 2016-01-25 at 14.54.17.png

                      1 Reply Last reply Reply Quote 0
                      • R
                        ryry last edited by

                        Never mind, I was playing around with it today and figured it out.

                        1 Reply Last reply Reply Quote 0
                        • R
                          ryry last edited by

                          Hi there,
                          Is there a block that will continue to take trades while there is an open order waiting to be closed in profit, as the EA currently stops taking anymore trades until the current open one has closed. The trades that are open have been set to only close once in profit, which can go on for ages, that is why I was wondering if more trades could be opened?

                          Any ideas or advise would be greatly appreciated.
                          Many thanks.

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

                            "Buy now" and "Sell now" will open a new trade every time they run. "No trade" is just one block that prevents them from running all the time, but it's not mandatory to use it. You can limit runs by time with blocks such as "Once per bar" or other blocks. It depends.

                            1 Reply Last reply Reply Quote 0
                            • R
                              ryry last edited by

                              Thanks for the response, I have played around with it and it doesn't seem to go my way, so I was wondering if I could close trades after 2 days instead of letting it run for ages. I have went through the time filters but it doesn't seem to work.
                              Maybe im doing it wrong, can you help please?

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

                                There are expiration settings. But note that for trades these work because of the EA - those trades will only be closed if the EA works, it's not like how it happens for pending orders.

                                The other way is of course to check the age of trades and close them, but this is what happens with the expiration settings.

                                1 Reply Last reply Reply Quote 0
                                • R
                                  ryry last edited by

                                  Hi again,
                                  I have started to test my EA on demo and discovered that after a few hours it decides to randomly close any open trade, causing me to lose money when I wanted the trade to go on until it came back into profit. I don't have and expiration settings or anything that would cause it to close. What do you reckon could be the problem, would you be able to help me please?

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

                                    If you placed trades with expiration settings, these will eventually be closed by the EA. Because I use the comment attribute to write information about the expiration and then the EA works with that comment attribute, which cannot be changed with the EA again.

                                    But if you create trades without expiration, I don't see reason for them to be closed by expiration. Maybe you have other blocks that are used to close trades by some condition.

                                    1 Reply Last reply Reply Quote 0
                                    • R
                                      ryry last edited by

                                      I haven't been using any expiration settings in my EA and I have also double checked everything to see if it would cause my EA to randomly close out open trades and found nothing. However looking through this forum I found one person who had the similar problem ( viewtopic.php?f=3&t=2600&p=6932&hilit=closing#p6932 ) and you said it could be the 'Virtual Stops' enabled in the coding. I checked that and it said (bool USE_VIRTUAL_STOPS = VIRTUAL_STOPS_ENABLED; ) so I then changed it to false, hopefully this will work.
                                      Many Thanks for your help!

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

                                        But Virtual stops are disabled by default. So, everything works now?

                                        1 Reply Last reply Reply Quote 0
                                        • R
                                          ryry last edited by

                                          Im going to let it run for a day and see if it continues to close trades randomly.

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

                                          Online Users

                                          J
                                          E
                                          A
                                          L

                                          15
                                          Online

                                          146.8k
                                          Users

                                          22.4k
                                          Topics

                                          122.6k
                                          Posts

                                          Powered by NodeBB Forums | Contributors