Two Condition Trees but if both are true only one of them should trigger a trade
-
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
-
@aramsamsam69
Hmm, maybe it's easiest to put some filter before the trade block:

-
@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.
-
@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.
-
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 -
@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
-
-
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.

-
@roar hmm. Maybe I did something wrong but it doesnt work for me,.
It only opened one trade in 6 years.
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 :

Did I make a mistake?
-
@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


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

-
@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?
-
@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:

