Close position when next candle close [SOLVED]
-
Hi all!
I'm trying to make my first EA with fxdreema and I have a doubt.
My EA is very simple: if a condition is true (candle size) when a candle close, I will open a position on the opening of the new candle, and I will close it when this new candle close. But when I test it in MT4, every time the condition is true, the position opens and closes at the same time and I lose the commissions... Anyone could help me? Thanks in advance.
https://fxdreema.com/shared/wyDwe6Axd -
@felixnr Is this the whole EA? I don't see any cinditions for closing a trade so they shouldn't be closed except if hitting a SL.
-
Hi @l-andorrà, the condition to close is on the TP. I put it on the close of the next candle. Can I do that? Thanks for your response.
-
@felixnr Ok. The problem is that you selected the current price as your TP. This is why it is closed as soon as it opens. You shoyld select another TP level different from current price.
-
Hi @l-andorrà. Thank you again for your help. I have selected "Candle Close" as parameter. Why take the current price as TP?
-
@felixnr Candle close on 0 happens as candle becomes 1, but candle close on 1 has already happened until it becomes 2.
-
@jstap Than you in advance. I understand your explanation, but I don't know why am I wrong... If conditions on candle 1 are true, I'll buy on the open of candle 0, so, I want to sell when this candle close (or candle -1 opens). How would you do it?
-
@felixnr If your conditions check candle 1, then as a new 0 opens candle 1 is checked.
-
@l-andorrà @jstap It's what I am doing... isn't it? I checked candle 1, if true, I open order on 0. It works...
The part that produces me a headache is that I want to close this position when candle 0 close, but it closes as soon as the order is on market... -
@felixnr I would set the current timeframe to a variable, then use this in the expiration field.

-
@jstap @l-andorrà SOLVED.
After reading a reply on another post (thank you @jerkha) I just modified the structure and now the EA makes what I expected!
Thank you all for your support.I post the final structure in case it's usefull for anyone around here:
https://fxdreema.com/shared/nLUoK22Ed -
@felixnr Thank you for sharing.
-
@felixnr You're welcome. Glad I could help!