Will keep you all posted.
Feel free to share as far as you have got … others may think of improvements you may not think of … then we all benefit? 🙂
//-------------------------------------------------------------------------
// Codice principale : 1secondo
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// Code principal : CANDLE
//-------------------------------------------------------------------------
Defparam cumulateorders = false
n = 10
//Conditions to enter long positions
TIMEFRAME(24 minutes,updateonclose)
Period= 22 //optimize
inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
HULLa = weightedaverage[round(sqrt(Period))](inner)
tc1 = HULLa > HULLa[1]
//tc2 = HULLa < HULLa[1]
indicator101 = SuperTrend[4,4] //optimize
tc3 = (close > indicator101)
//tc4 = (close < indicator101)
ma = average[40,4](close) //optimize
tc11 = ma > ma[1]
//tc12 = ma < ma[1]
timeframe(10 minute,updateonclose)
c160m = open > open[1] and close > close[1] and close > open
timeframe(2 minute,updateonclose)
c11m = open > open[1] and close > close[1]
c21m = abs(close-open) >= 17
c31m = abs(close[1]-open[1])
c41m = c31m > c21m
timeframe(default)
c1def = open > open[1] and close > close[1]
c2def = abs(close-open) >= 1
IF not longonmarket and c1def and c11m and c21m and c41m and c2def and c1def and c160m AND tc1 AND tc3 AND tc11 then
BUY N contracts at market
set stop ploss 300
ENDIF
//if longonmarket and close crosses under st then
//sell at market
//endif
//************************************************************************
//trailing stop function
trailingstart = 19 //trailing will start @trailinstart points profit
trailingstep = 7 //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
//***
This code yields the following results
This is a combination of ideas posted by various helpful people (nonetheless, GraHal, Nicolas to name but a few)
That looks highly optimized to me, anyway i think it’s a MAKSIDE code idea.
You tell us – it’s your code just with a higher time frame filter added…
Attached is the 200 k backtest
Out of interest I changed TF’s to M25, M10 and M5 and ran it on DJI on M1 TF with spread = 4.
Attached are results over 100K bars.
I have reservations about the MAE … on nearly every winning trade the MAE is Losing X multiples times the eventual Gain.
The MFE spends a lot of time way in excess of the eventual gain.
Maybe above means there is plenty of scope for improvement?
As you can see from the equity curve (gaps in positions) … the strategy (Long only) does stay out of the market during extended down periods … so that is good!
To save any confusion …
My results on DJI are with position Size = 1.
samsampop results on DAX are with position size = 10.
thanked this post
Apologies Francesco, thanks for clarifying
Morning – I have added a short entry criteria as well and re-ran the back test on 100k, to include the down turn in Feb-Mar of this year.
//-------------------------------------------------------------------------
// Codice principale : 1secondo
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// Code principal : CANDLE
//-------------------------------------------------------------------------
Defparam cumulateorders = false
n =5
timeframe(10 minute,updateonclose)
c160m = open > open[1] and close > close[1] and close > open
sc1 = open < open[1] and close < close[1] and close < open
timeframe(2 minute,updateonclose)
c11m = open > open[1] and close > close[1]
c21m = abs(close-open) >= 17
c31m = abs(close[1]-open[1])
c41m = c31m > c21m
sc2 = open < open[1] and close < close[1]
sc3 = abs(close-open) <= 17 //see below
sc4 = abs(close[1]-open[1]) //these may need to be same as bove, and sc5 stays <
sc5 = sc3 < sc4
timeframe(default)
c1def = open > open[1] and close > close[1]
c2def = abs(close-open) >= 1
sc6 = open < open[1] and close < close[1]
sc7 = abs(open-close) <= 1
IF not longonmarket and c1def and c11m and c21m and c41m and c2def and c1def and c160m then
BUY N contracts at market
set stop ploss 300
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
IF not shortonmarket and sc1 and sc2 and sc3 and sc4 and sc5 and sc6 and sc7 then
SELLSHORT N contracts at market
set stop ploss 300
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
//if longonmarket and close crosses under st then
//sell at market
//endif
//************************************************************************
//trailing stop function
trailingstart = 19 //trailing will start @trailinstart points profit
trailingstep = 7 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//***
I’m running this on the DAX on a 2 min time frame. Initial Capital of 5,000 and trading 5 per point. I am using a Spread of 2, but may need to increase this as it trades around the clock.
I would still add a VDAX filter for this strategy, so that it didn’t trade if volatility on the DAX > than say 40. Anyone know how this can be achieved?