This is a reworking of TREND CHASER v2.0 posted by Mike GC (he also did a v3, so mine is v4). I added a trailing stop and some other tweaks, then thought to replace cumulateorders = true with money management. That went well enough, but then I thought, why not have both cumulateorders and MM? Is this a bad idea? It seems to work (+1400% over ~4 years) and is certainly in keeping with what I would do in real world trading. Off to a good start in demo over the past week…
Of course, when I get results like this, my first assumption is that I’ve probably blundered somewhere and it’s all TG2Btrue. I’d be most grateful if someone could take a look to confirm this, just to put my mind to rest. Thanks.
See attached for WF results.
DEFPARAM CumulateOrders = true // Cumulating positions activated
MoneyManagement = 1
//MoneyManagement = Set to 0 for level stakes. Set to 1 for increasing stake size as profits increase and decreasing stake size as profits decrease. Set to 2 for increasing stake size as profits increase with stake size never being decreased.
Capital = 10000
MinSize = 1
//MinSize = The minimum position size allowed for the instrument.
Equity = Capital + StrategyProfit
IF MoneyManagement = 1 THEN
PositionSize = Max(MinSize, Equity * (MinSize/Capital))
ENDIF
IF MoneyManagement = 2 THEN
PositionSize = Max(LastSize, Equity * (MinSize/Capital))
LastSize = PositionSize
ENDIF
IF MoneyManagement <> 1 and MoneyManagement <> 2 THEN
PositionSize = MinSize
ENDIF
PositionSize = Round(PositionSize)
// Size of POSITIONS
PositionSizeLong = 1 * positionsize
PositionSizeShort = 1 * positionsize
// Indicators
COI = WEIGHTEDAVERAGE[10](ROC[14] +ROC[11])
MAC = MACDline[12,26,9](close)
STO = Stochastic[14,3](close)
ST = Supertrend[8,16]
// Conditions to enter long positions
c1 = COI > COI[1] AND COI < 0
c2 = MAC > MAC[1] AND MAC < 0
c3 = STO > 23 AND STO < 44
IF Not ShortOnMarket AND c1 AND c2 AND c3 THEN
BUY PositionSizeLong CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
c4 = close crosses over ST
IF c4 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
c5 = COI < COI[1] AND COI > 0
c6 = MAC < MAC[1] AND MAC > 0
c7 = STO < 74 AND STO > 58
IF Not LongOnMarket AND c5 AND c6 AND c7 THEN
SELLSHORT PositionSizeShort CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
c8 = close crosses under ST
IF c8 THEN
EXITSHORT AT MARKET
ENDIF
//trailing stop function
trailingstart = 43 //trailing will start @trailinstart points profit
trailingstep = 3 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
You should never walk forward test with money management turned on. Walk forward tests should always be carried out with level stakes unless the money management is part of the strategy where position size is altered up and down based on some sort of trade risk calculation.
Personally I like to forward demo test with level stakes too because then I can easily compare like for like all the strategies on forward test. If one is good enough to go live then I would put it live with level stakes for a short while just to double check that it behaves itself before turning money management on to try to maximise returns.
Being in a rush to get rich can often lead to a rush towards being poor!
My last post just gave me a coding idea. It would be good to add a trade count to the money management and then automate the switch from trading without money management to trading with it. We could have the code check that say 100 trades (or the quantity of your choice) have taken place and that we are in say 5% profit and then turn it on. This would mean that we don’t have to stop strategies and modify them thus losing the trading results when we start the strategy again. It is also one more decision that is automated for those of us who hate making trading decisions!
Vonasi wrote:
Walk forward tests should always be carried out with level stakes
I agree and should have mentioned that I had already done that. Attached are the WF results with no MM, cumulateorders true and false. As one would expect, level stakes gives the smoothest curve.
I couldn’t face WF … so tediously slow at the weekend!!??
So here is an alternative view attached … opti over 100k bars and I …
- Added a filter on the shorts (Close < MA(750) – lower curve.
- Vonasi MM code – upper curve.
I’m hoping if Vonasi adds code to cease MM after losses then we might see that dip at the end of 2019 reduce somewhat?
One thing I don’t understand about this code are the exit lines 49 and 66. Sounds wrong to have a long position close when it crosses over the SuperTrend and short to close when crossing under. To my mind it should be the opposite, but that doesn’t work at all.
@GraHal, what’s the actual line of code you added?
With MoneyManagement = 1 it should reduce position size as profit falls.
@GraHal, what’s the actual line of code you added?
I added the MA as a Filter to Line 66
IF Not LongOnMarket AND c5 AND c6 AND c7 and Close < Average[A66](close) THEN
SELLSHORT PositionSizeShort CONTRACT AT MARKET
ENDIF
PaulParticipant
Master
@nonetheless If there is not long or not short onmarket position in your entry criteria then it ignores an opposite signal. In an optimisation process however I think it should be possible to revert straight to another direction.
If you have it like it is as right now, maybe it’s better to run the optimisation for long & short separate?
maybe it’s better to run the optimisation for long & short separate?
Thanks Paul, I’ll try that.
Following @Paul worthy observations … I deleted not longonmarket and not shortonmarket from the entry criteria and re-optimised and ended up with even bigger profit (top curve)! 🙂
PaulParticipant
Master
@GraHal very nice!
Then there’s another issue, the correct settings for the trailing stop. Because now the trailingstop doesn’t reset properly.
It’s this part
IF NOT ONMARKET THEN
newSL=0
ENDIF
first line replaced with
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
In a strategy on the dow, it appeared that some trades had 0 bars which isn’t good. Didn’t happend on the dax. Found the cause the be the exit on the trailing stop.
Separating the exit fixed that problem. Like this;
So instead of this
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
use
if longonmarket then
if newSL>0 then
sell at newSL stop
endif
endif
if shortonmarket then
if newSL>0 then
exitshort at newSL stop
endif
endif
Small things, I think it’s correct with above. Maybe it doesn’t matter much at all, but it could be your new optimised results go down a bit 🙂
Did you add more variables to your optimization? What do the last 4 numbers in the brackets refer to: 6,250 50 2 ?
Is this with MM=0 and cumalateorders = False ?
What do the last 4 numbers in the brackets refer to: 6,250 50 2 ?
See attached .itf.
You have prob gathered by now … I use line numbers as variable names. When I add code then the line numbers get out of synch with the Lines in the code. but the descriptor is still valid, e.g. A23 may end up on Line 26.
It does seem very versatile this System … got rid of the drop at the end of 2019 and got a superlative set of performance results … Image 2 relates to the top curve. Profit has dropped but so has the drawdown!
It now all needs WF (tomorrow when WF is faster!) as most of the money was made up to 1st Qtr of 2018.
Now to look at Paul’s latest suggestion! 🙂
Ok, got it. So you’re running MM=1 and CumulateOrders = False. But if it’s one or the other, CumulateOrders = true seems to have the more dramatic effect on profit.
CumulateOrders = true seems to have the more dramatic effect on profit.
Yeah but could I go to sleep at night knowing that I might wake up to having 15 positions on the Dow?? 🙂