fxDreema

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

    Two Condition Trees but if both are true only one of them should trigger a trade

    Questions & Answers
    3
    11
    1659
    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.
    • A
      aramsamsam69 last edited by

      My problem is that the EA always opens the trades two times if both "Condition Trees" are true.

      I don't know how to code that in the Condition block for "If" rules. Or is there maybe a block where I dont have to code anything?

      Condition Tree 1 : If Price crosses Moving Average to the upside enter a Long Trade.
      Condition Tree 2 : If the Two Lines Indicator crossed and gave me a Long Signal enter a Long Trade.

      Now the Problem is that I trade the Daily chart and it often happened that Condition Tree 1 and 2 were both true at the same time.
      Logically it opens two trades. But I want that it opens only one Trade.

      Like : "If Condition Tree 1 and 2 is true, then only open a trade on the Condition Tree which was first".

      Is that possible?

      Thanks in advance

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

        @aramsamsam69
        Hmm, maybe it's easiest to put some filter before the trade block:
        0_1569527671320_089f4354-79bc-46d7-9601-d7e7047bb608-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 0
        • A
          aramsamsam69 last edited by aramsamsam69

          @roar but that would still trigger both, or am I wrong?

          Edit: Aaah no sry, I misunderstood.

          Condition 8 would go through first and after that the tree is done, because it only runs through once a day.

          Good Idea thank you mate.

          1 Reply Last reply Reply Quote 1
          • A
            aramsamsam69 last edited by

            @roar sorry to bother you again.

            How can I build this.

            Condition 1 : If Price has crossed Moving Average to the upside, then enter Long.

            Conditon 2 : But only if the 2 Lines Indicator also has crossed above, doesnt matter if it happened at the same time. But the Crossing shouldnt be older than 7 Candles.

            roar 1 Reply Last reply Reply Quote 0
            • C
              cesardefez last edited by

              Hola.
              si pones una función "0" ?
              si (condición 1) ó (condición 2) entonces largo
              se abrirá una operación después de chequear las dos condiciones y una o las dos se cumplen.
              Ojo, si en la siguiente vela o al siguiente tic, sigue cumpliendo alguna de las dos condiciones, volvería a entrar.
              para solucionar esto yo , a los comercios con estas condiciones le configuraría el grupo ( ejemplo "1") a la hora de comprar o vender en el box de compra -venta.
              y antes de este box ( comprar / vender) color un filtro (verificación de oficios y pedidos/if trader), de forma que si no existe grupo 1, brir la operación, y si existe, pues no la abre.
              espero que te sirva

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

                @aramsamsam69 said in Two Condition Trees but if both are true only one of them should trigger a trade:

                @roar sorry to bother you again.

                How can I build this.

                Condition 1 : If Price has crossed Moving Average to the upside, then enter Long.

                Conditon 2 : But only if the 2 Lines Indicator also has crossed above, doesnt matter if it happened at the same time. But the Crossing shouldnt be older than 7 Candles.

                For this, I'd introduce a loop logic. Its a bit more advanced thing, but not too complicated.

                • First, check that MA cross

                • Next, we are going to check two lines indicator 6 times in a row (I don't have that indicator, so using simple MA in the example). Each time we check the indicator, we use a different candle for the measurement. That is accomplished by the candle ID setting. ID 0 is current candle, ID 1 is last completed candle, ID 2 is 2nd completed candle etc.

                • I created a variable for the ID setting, called ID_var

                • This variable is set to 0 at the beginning of work, and each of the 6 iterations it is increased by 1.

                • Now the loop cycles setting will determine how old the 2line crossing can be - you can change the number at your will

                https://fxdreema.com/shared/Lxyio0Gbd
                0_1569577881680_1a77a2dc-d043-48f9-b4f0-8e57f2831a9b-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 0
                • roar
                  roar last edited by

                  Finally, we should take care of the fact that this loop system could find multiple crossings, so it would open multiple trades.
                  If this is not what we want, just put a loop break block after the buy - loop will stop at that point.
                  0_1569579262762_fe74a333-d494-4040-ae91-7c1595c9dcce-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 0
                  • A
                    aramsamsam69 last edited by aramsamsam69

                    @roar hmm. Maybe I did something wrong but it doesnt work for me,.
                    It only opened one trade in 6 years.

                    0_1569610720796_Two Lines and Moving Average.PNG

                    I show you an example, those Candles I circled, have crosses the Moving Average.
                    So it gave me two buy signals. But the crossing of the indicator below has happened way sooner.
                    The first Candle cross was 3 Candles too late and the second one was 7 Candles too late.
                    Means that my Algo shouldnt take those trades.

                    For the EA part, I did it like this :
                    0_1569611034342_Ma Two Lines Test.PNG

                    Did I make a mistake?

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

                      @aramsamsam69 said in Two Condition Trees but if both are true only one of them should trigger a trade:

                      Did I make a mistake?

                      Yes, a tiny one 😉

                      0_1569611818461_a4e1d903-ba15-48ab-b00a-769d566067fd-image.png

                      We must reset the ID_var to 0 before the loop work begins. If we don't reset it, the variable will remember its previous value from some earlier calculations: at the end of your test period, ID_var is probably something like 2458 😄

                      So, put 0 to the white field 🙂

                      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 0
                      • A
                        aramsamsam69 last edited by aramsamsam69

                        @roar I have changed it to zero in both windows, but it still opens one trade and then nothing.

                        Do i need to change the "int" ID_var to a "double" ID_var?

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

                          @aramsamsam69
                          No need for that... int means whole numbers, double means numbers with decimals, candle ID is whole number.

                          I'm not sure what is wrong here.. Try troubleshooting piece by piece:

                          • Maybe the "(loop) break" causes some bug, originally it's not really meant for this purpose
                          • Maybe there is something wrong with the custom indicators, try some simple default indicator
                          • Your top block "Once per tick" is useless, if you are on the OnTick event in the first place:
                            0_1569614827314_3f64c4ce-fc28-4f3d-82fa-2fffa2382d8e-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 0
                          • 1 / 1
                          • First post
                            Last post

                          Online Users

                          E
                          A
                          E
                          E
                          T
                          M
                          X
                          A
                          D
                          S
                          A
                          S
                          E
                          E
                          J

                          26
                          Online

                          146.8k
                          Users

                          22.4k
                          Topics

                          122.6k
                          Posts

                          Powered by NodeBB Forums | Contributors