How to check if EMA crosses candle body or its wick
-
I need to buy when 8 EMA crosses candle wick or body (doesnt matter wich wick), but if at the same time 21 EMA crosses same candle or tuches its wick, trade shouldn't open.
-
You can create a following condition.
[Candle crosses 8EMA and 21 EMA > candle high] or [Candle crosses 8EMA and 21 EMA < candle low] I would recommend doing everything with the previous candle to make sure it truly occurred.
You can also code a desired distance you want 21 EMA to be from the candle using formulas.
-
Will it make difference if i put [Candle crosses 8 EMA and 21 EMA >= candle high] ? Ok lets asume that wick is set up, but how about if it touches the body first without touching or crossing the wick. What should i do in this case?
-
@xexex007 If you set >= instead of > then it will make a difference. In case of >= trade will be opened when candle high = 21ema which you don't want so stick to the >.
As for your second question. You should do nothing. The condition will hold. Why? When you code an EA you need to think more in terms of numbers and mathematical expressions rather than visual representation. That is, always numerically describe your visual experience with the chart ... ok but what does that mean in this situation ? What you refereeing to as EMA "touches the body" is the event where the numerical value of EMA at the time t is smaller(higher) than or equal to the candle high(low). If you don't have a wick yet it means that the current price represents the high of the candle in the bullish candle or the low of the candle in the bearish candle. So even if it "touches the body first" the condition
[Candle crosses 8EMA and 21 EMA > candle high] or [Candle crosses 8EMA and 21 EMA < candle low] will still work. Because it does not matter whether the low/high of the candle is currently or in the prior candle(s) represented by wick or the body. Besides why not try and see it all in the chart;) -
How should i implement [Candle crosses 8EMA]?
-
@xexex007 In its simplest version https://fxdreema.com/shared/ATZXgP2pb
-
I am trying to make bot who can trade like this: https://www.youtube.com/watch?v=zhEukjCzXwM&t=627s
-
THis is how far i've got thanks to you. Can you make any suggestions or improvements? https://fxdreema.com/shared/a4RaPVdle