Hi all!
Im wondering if someone could help me with a, probably, small problem.
in one of my strategies i see that alot of the loosing trades never make any profit at all (meaning after trade is activated the market just keeps going down (long trades only)
Is there a way to code in the following: “If no profit has been made (if the trade does not go into profit-making) within X candles, stop trade” ?
edit: or maybe even better: “If trade has not generated X amounts of pips within X amounts of candles, close trade”
This could potentially save me from some of the stop losses! 🙂
Big thanks!
Edit: I think ive seen it on this forum before but now i cant find it. Is it possible to code the following: “If MFE >= 25 (or X) pips then stop trade if it falls below 0 pips in profit.” ?
In other words: if a trade goes to 50$ profit active trade, i dont want to see -50$ closed trade 🙂 If it goes to 50$ then to 0$ i want to close it there.
What you describe sounds like a trailing SL to me. If there is x amount of profit, set the SL to breakeven. There are several trailing SL codes in the forum, also using MFE.
Hi Despair, thanks for the reply.
So yea, it is indeed trailing stop, i just dont know how to code them.
Idea #1: “If trade has not generated X amounts of pips, within X amounts of candles, close trade”
Idea #2: “If there is x amount of profit, set the SL to breakeven.”
I know i’ve seen a post regarding idea #2, but i cant recall which post or what words i can use to search for it. I believe it was mixed in someones code for some strategy, no idea which one.
Nicolas posted a whole article on trailing SL. There you will find code you can use.
As for breakeven (Idea #2), there’s Nicolas‘s code here that is ready to be included in your code:https://www.prorealcode.com/blog/learning/breakeven-code-automated-trading-strategy/
As for Idea #1 you may try this one (I haven’t tested it):
ONCE MyPips = 5 //5 pips at least after...
ONCE MyBars = 20 //20 bars have elapsed
IF OnMarket THEN
MyProfit = (close - tradeprice) * pipsize
IF (MyProfit < MyPips) AND (BarIndex - TradeIndex) >= MyBars THEN
SELL AT MARKET //close long trades as well as...
EXITSHORT AT MARKET //... short ones
ENDIF
ENDIF
Roberto