EA for SMA crossing
-
Hi all,
I am trying to build an EA that enters a trade when the 100 SMA > 200 SMA and when the Stochastic crosses the 25 level from below. Let's suppose I set a fixed TP and SL, each of 100 pips. How can you stop the EA from entering a new trade when the SL or TP are reached and the SMAs still have not crossed over?
I.e. I would like the EA to enter just one trade per SMA crossovers...
Many thanks!!! -
try "once per bar" block
-
@miro1360 once per bar does not work. the following example could clarify a bit:
- SMA cross on bar 0
- stochastic gives signal on bar 2 and trade is entered
- trade exit at bat 10
- at bar 12 the stochastic gives another entry signal and the trade is entered
- trade exit at bar 20
- SMA cross again at bat 22
I am trying to find a way to block the EA from entering the trade at bar 12 - i.e. any trade triggered after the first trade and before the SMA cross in the opposite direction of the first trade... hope it makes sense...
-
Normally you check bunch of conditions at the current moment and decide what to do. It's good that you have information from the past - MetaTrader knows OHLC levels of many candles in the past => indicator values can be calculated => many values from the past can be used from the past. And this is how things work most of the time - you check something NOW using current or past data and you do something (buy, sell, close) now.
The reverse way is not very easy. You want to remember that something happened, so you probably need to use Variables to save the current state of the strategy in them. To deal with that I made this functionality: https://fxdreema.com/demo/mt4-wait-crossovers But to be honest, after I made this, I realized that it's not that easy to use it as I was initially expecting.
-
@fxDreema Thanks! I will try to make it work with the example you provided

-
@fxDreema Hey! I've tried to apply what you suggested but I cannot seem to figure out how to configure it properly.
Isn't there another way of telling the indicator to "stop entering trades until X condition is met"? the X condition being that the SMA must crossover in the opposite direction. -
I have best experience with variables (Flag) ... but sometimes it is hard to do and need a lot of testing ...
-
try this:
Set a new Variable (as 0) - for this example I will use 'RunOnce'
Add a condition to run your EA only if RunOnce == 0
After your BUY or SELL - set RunOnce to 1
Add an extra condition to set RunOnce to 0 once the Opposite Cross Over happens againSee screenshot