Hi all, I am looking for a way to temporarily stop the strategy from trading once losses have reached a certain amount for a certain amount of time without using QUIT and having to restart the strategy again. The strategy runs on a 5min timeframe.
The workaround I was trying was to use was to go onto a higher timeframe of 1h and add strategyprofit for the last 3 hours and make “AND NOT pause” a condition to open trades. If strategy profit for the last 3 bars is below a certain number, e.g. -500, it should not open new positions. In my mind, it should then start trading again after a while since strategyprofit[3], [2] and [1] should all be 0.
However, this does not work.
Does anyone know how to solve the issue?
Thanks!
<!–more–>
timeframe(1 hour, updateonclose)
SP3 = strategyprofit[3]
SP2 = strategyprofit[2]
SP1 = strategyprofit[1]
SumSP = p1 + p2 + p3
pause = (SumSP <= -500)
timeframe(default)
<!–more–>
Try this one (it will pause 1 hour after a big loss):
DEFPARAM CumulateOrders = False
//
timeframe(1 hour, updateonclose)
ONCE MyProfit = 0
pause = 0
IF Not OnMarket THEN
MyProfit = StrategyProfit
SumSP = StrategyProfit - MyProfit[1]
pause = (SumSP <= -500)
ENDIF
//
timeframe(default)
IF close CROSSES OVER average[200] AND Not OnMarket AND Not Pause THEN
BUY AT MARKET
ENDIF
SET TARGET pPROFIT 50
SET STOP pLOSS 20
graph pause
graph SumSP
Link to above added as Log 325 here …
Snippet Link Library
This is exactly what I was looking for – thanks! 🙂
Just a quick question for my understanding: Why are we subtracting MyProfit[1] instead of adding it? If MyProfit is negative, e.g. -100, would using subtraction not lead to SumSP be “higher” than it actually is?
Example:
- StrategyProfit of previous 1h close was -500 -> MyProfit = StrategyProfit[1] = -500
- StrategyProfit = 0
- SumSP = 0 – -500 = 500 instead of -500?
The two last GRAPH lines will show the answer.