Close trades under condition once certain profit reached
-
Hi guys, here is what I would like to do: I have an EA where only one trade at a time can be open. Once the trade reaches 100% of stop loss distance, I want a permanent (on tick) condition which closes the trade if price crosses the 50 MA. So the trade doesn't have a fix take profit. I have tried various things but can't really solve the issue. The thing is, I don't only want the trade to close when price crosses the MA while it is still 100% in profit (of SL). It should just activate that rule no matter what happens with the price later. Kind of like a trailing stop, where the stop is the crossing of the 50 MA.
Is there anyone who can help with this?
-
@sirluk Not sure I fully understand. Which of those conditions is supposed to be the top priority? If you set your trade to be closed when in profit at 100% Sl distnace, it close no matter what. Could you please be more specific?
-
@l-andorrà Ok, let's make an example. I have a trade with a 20 pips stop loss. Now, what I want is the following: Once my trade is 20 pips in profit (which is 100% of the SL), I want the trade to close whenever price crosses (on close) the 50 MA. So once condition A (trade in profit 100% of SL) it triggers B (close if 50 MA crossed). Is that more clear?
-
@sirluk Ok That is more clear now. Now the problem is 'price crossing 50 MA'. Is that corssing supposed to happen immediately it is confirmed on candle ID 0 or you need to be confirmed at the close of candle ID 1?
-
Hi, I just put something together not sure if it works but it should work. I used a variable called "trailingactive" which becomes true if price was 200% pips away from current trade. Then I used this variable as starting condition for the price is below 50 ma for buys or above the 50 ma for sells.
https://fxdreema.com/shared/i6Qs3nyLc
Let me know if this worked. I couldn't test it myself because I didn't get the code and I'm too busy to put one together myself right now.
Cheers.
-
@l-andorrà at the close of the candle. So ID 1.