Hi,
This is the combination of the 5 different strategies for the DAX which vschmitt Artificall has previously openly shared. I have simply combined them into one strategy, with some additional code kindly provided by robertogozzi
The majority of the performance comes from the Momentum strategy however, the others smooth out the equity curve through their smaller contributions to the overall performance.
//================================================
// Code: _PRD DAX Combi
// Source: https://artificall.com
// Author: Vivien Schmitt
// Version 2
// Index: DAX
// TF: 10 min
// Notes: v1.1 Momentum only
// Notes: v2 Portfolio of multi strategies
// robertogozzi provided position mgt logic
// v2.1 Added Trend Following
// v2.2 Added Double Bottom
// v2.3 Added Green Hammer
// v2.4 Added Counter Trend
// v2.5 Tested Day of Week - ignore
// v2.5 Optimised position size logic
//================================================
DEFPARAM CUMULATEORDERS = TRUE // only one trade in the same time
DEFPARAM FLATBEFORE = 090000 // avoide entry opening before this hour
DEFPARAM FLATAFTER = 213000 // close entry at this hour
IF NOT OnMarket THEN //Make sure you reset these variables to ZERO when not trading
P1 = 0
P2 = 0
P3 = 0
P4 = 0
P5 = 0
ENDIF
//RISK MANAGEMENT
PositionSize=1
//===================================== MOMENTUM STRATEGY ================================================
//MOMENTUM STRATEGY
// MARKET TREND USING LINEAR REGRESSION
// Set of technical indicators to test
IF P1 < 1 THEN
m10 = momentum[10](close)
m20 = momentum[20](close)
m50 = momentum[50](close)
m100 = momentum[100](close)
m300 = momentum[300](close)
m800 = momentum[800](close)
cM1 = (m10[0]-m10[1]) > 0
cM2 = (m20[0]-m20[1]) > 0
cM3 = (m50[0]-m50[1]) > 0
cM4 = (m100[0]-m100[1]) > 0
cM5 = (m300[0]-m300[1]) > 0
cM6 = (m800[0]-m800[1]) > 0
//--------------------------------------------------------------------------
// ENTRY POINT
//#13
conditionMomentumM = cM1 AND cM2 AND cM3 AND NOT cM4 AND cM5 AND NOT cM6
//--------------------------------------------------------------------------
// MARKET VOLATILITY USING STANDARD DEVIATION
volatility100MaxM = 50
volatility100MinM = 1
volatility100M = STD[100] (close)
conditionMarketVolatilityM = volatility100M < volatility100MaxM AND volatility100M > volatility100MinM
//conditionMarketVolatility=1
//--------------------------------------------------------------------------
// OPEN A LONG ENTRY
IF conditionMomentumM AND conditionMarketVolatilityM THEN
PSTOPLOSSMO = 100
PTARGETMO = PSTOPLOSSMO * 2
SET STOP pLOSS PSTOPLOSSMO
SET TARGET pPROFIT PTARGETMO
BUY PositionSize CONTRACT AT MARKET
P1 = 1
ENDIF
//SHORT ENTRY CONDITIONS
s1 = (m10[0]-m10[1]) < 0
s2 = (m20[0]-m20[1]) < 0
s3 = (m50[0]-m50[1]) < 0
s4 = (m100[0]-m100[1]) < 0
s5 = (m300[0]-m300[1]) < 0
s6 = (m800[0]-m800[1]) < 0
conditionSellMomentum = s1 AND s2 AND s3 AND NOT s4 AND s5 AND NOT s6
// OPEN A SHORT ENTRY
IF conditionSellMomentum AND conditionMarketVolatilityM THEN
PSTOPLOSS = 100
PTARGET = PSTOPLOSS * 2
SET STOP pLOSS PSTOPLOSS
SET TARGET pPROFIT PTARGET
SELLSHORT PositionSize CONTRACT AT MARKET
P1 = 1
ENDIF
ENDIF
//===================================== TREND FOLLOWING ================================================
//TREND FOLLOWING
// MARKET TREND USING LINEAR REGRESSION
IF P2 < 1 THEN
DRL100 = average[10](LinearRegression[100])
slope100 = DRL100[0] - DRL100[1]
DRL300 = average[10](LinearRegression[300])
slope300 = DRL300[0] - DRL300[1]
DRL600 = average[10](LinearRegression[600])
slope600 = DRL600[0] - DRL600[1]
conditionMarketTrend = slope100 > 0 OR slope300 > 0 OR slope600 > 0
//--------------------------------------------------------------------------
// MARKET VOLATILITY USING STANDARD DEVIATION
volatility100Max = 11
volatility100Min = 1
volatility100 = STD[100] (close)
conditionMarketVolatility = volatility100 < volatility100Max AND volatility100 > volatility100Min
//--------------------------------------------------------------------------
// ENTRY POINT
rsi14 = RSI[14] > 30
macd12 = MACD [12,26,9] > 0
stocha10 = Stochastic[10,3](close) > 0
conditionEntryPoint = rsi14 AND macd12 AND stocha10
//--------------------------------------------------------------------------
// OPEN A LONG ENTRY
//IF NOT LongOnMarket AND conditionMarketTrend AND conditionMarketVolatility AND conditionEntryPoint THEN
IF conditionMarketTrend AND conditionMarketVolatility AND conditionEntryPoint THEN
PSTOPLOSSMT = 100
PTARGETMT = PSTOPLOSSMT * 2
SET STOP pLOSS PSTOPLOSSMT
SET TARGET pPROFIT PTARGETMT
BUY PositionSize CONTRACT AT MARKET
P2 = 1
ENDIF
ENDIF
//===================================== DOUBLE BOTTOM RECOGNITION ================================================
// DOUBLE BOTTOM RECOGNITION
IF P3 < 1 THEN
ONCE period = 10
ONCE correlation = 0.8
R = 0
x1 = 10
x2 = 9
x3 = 8
x4 = 9
x5 = 10
x6 = 10
x7 = 9
x8 = 8
x9 = 9
x10 = 10
xBar=(x1+x2+x3+x4+x5+x6+x7+x8+x9+x10)/period
varianceX=(SQUARE(x1-xBar)+SQUARE(x2-xBar)+SQUARE(x3-xBar)+SQUARE(x4-xBar)+SQUARE(x5-xBar)+SQUARE(x6-xBar)+SQUARE(x7-xBar)+SQUARE(x8-xBar)+SQUARE(x9-xBar)+SQUARE(x10-xBar))/(period-1)
ecarTypeX=SQRT(varianceX)
y1 = MAX(Open[9], Close[9])
y2 = MAX(Open[8], Close[8])
y3 = MAX(Open[7], Close[7])
y4 = MAX(Open[6], Close[6])
y5 = MAX(Open[5], Close[5])
y6 = MAX(Open[4], Close[4])
y7 = MAX(Open[3], Close[3])
y8 = MAX(Open[2], Close[2])
y9 = MAX(Open[1], Close[1])
y10 = MAX(Open[0], Close[0])
yBar=Average[period](Close)
ecarTypeY=STD[period](Close)
covarianceXY=((x1-xBar)*(y1-yBar)+(x2-xBar)*(y2-yBar)+(x3-xBar)*(y3-yBar)+(x4-xBar)*(y4-yBar)+(x5-xBar)*(y5-yBar)+(x6-xBar)*(y6-yBar)+(x7-xBar)*(y7-yBar)+(x8-xBar)*(y8-yBar)+(x9-xBar)*(y9-yBar)+(x10-xBar)*(y10-yBar))/(period-1)
R=covarianceXY/(ecarTypeX*ecarTypeY)
IF R < correlation THEN
R = 0
ENDIF
//RETURN R AS "R"
closeY1 = Close[9]
highY5 = high[5]
closeY10 = Close[0]
neckLine = closeY10 => closeY1 AND closeY10 => highY5
conditionDoubleBottom = R AND neckLine
//--------------------------------------------------------------------------
// OPEN A LONG ENTRY
//IF NOT LongOnMarket AND conditionDoubleBottom THEN
IF conditionDoubleBottom THEN
PSTOPLOSSDB = 100
PTARGETDB = PSTOPLOSSDB * 2
SET STOP pLOSS PSTOPLOSSDB
SET TARGET pPROFIT PTARGETDB
BUY PositionSize CONTRACT AT MARKET
P3 = 1
ENDIF
ENDIF
//===================================== GREEN HAMMER ================================================
//GREEN HAMMER
// MARKET VOLATILITY USING STANDARD DEVIATION
IF P4 < 1 THEN
volatility100MaxGH = 20
volatility100MinGH = 1
volatility100GH = STD[100] (close)
conditionMarketVolatilityGH = volatility100GH < volatility100MaxGH AND volatility100GH > volatility100MinGH
//conditionMarketVolatility=1
//--------------------------------------------------------------------------
// ENTRY POINT
// Strategy of the Doji Hammer
hammerBody = high = close AND open < close
hammerTail = low < open AND (open - low) > ((high - open) * 1.5)
dojiHammer = hammerBody AND hammerTail
//--------------------------------------------------------------------------
// OPEN A LONG ENTRY
//IF NOT LongOnMarket AND conditionMarketVolatility AND dojiHammer THEN
IF conditionMarketVolatilityGH AND dojiHammer THEN
PSTOPLOSSGH = 80
PTARGETGH = PSTOPLOSSGH * 2
SET STOP pLOSS PSTOPLOSSGH
SET TARGET pPROFIT PTARGETGH
BUY PositionSize CONTRACT AT MARKET
P4 = 1
ENDIF
ENDIF
//===================================== COUNTERTREND ================================================
//COUNTERTREND
// MARKET TREND USING LINEAR REGRESSION
// Set of technical indicators to test
IF P5 < 1 THEN
c1 = LinearRegressionSlope[10](close) > 0
c2 = LinearRegressionSlope[20](close) > 0
c3 = LinearRegressionSlope[50](close) > 0
c4 = LinearRegressionSlope[100](close) > 0
c5 = LinearRegressionSlope[300](close) > 0
c6 = LinearRegressionSlope[800](close) > 0
//--------------------------------------------------------------------------
// ENTRY POINT
//#13
conditionCounterTrend1 = NOT c1 AND NOT c2 AND c3 AND c4 AND NOT c5 AND NOT c6
conditionCounterTrend = conditionCounterTrend1
//--------------------------------------------------------------------------
// MARKET VOLATILITY USING STANDARD DEVIATION
volatility100MaxCT = 50
volatility100MinCT = 1
volatility100CT = STD[100] (close)
conditionMarketVolatilityCT = volatility100CT < volatility100MaxCT AND volatility100CT > volatility100MinCT
//conditionMarketVolatility=1
//--------------------------------------------------------------------------
// OPEN A LONG ENTRY
//IF NOT LongOnMarket AND conditionCounterTrend AND conditionMarketVolatility THEN
IF conditionCounterTrend AND conditionMarketVolatilityCT THEN
PSTOPLOSS = 100
PTARGET = PSTOPLOSS * 2
SET STOP pLOSS PSTOPLOSS
SET TARGET pPROFIT PTARGET
BUY PositionSize CONTRACT AT MARKET
P5 = 1
ENDIF
ENDIF
ONCE P1 = 0
ONCE P2 = 0
ONCE P3 = 0
ONCE P4 = 0
ONCE P5 = 0
Thanks for ur contribution. Where is the original thread?
I have been using this in a modified form since 08/20. But even the original system still works flawlessly today.
Long only strategy with the TMA channel
Thanks phoentzs.
Something is wrong with ur link.
Whats the different between the orginal and ur modified version? Would be great if u post ur modified version in the linked thread.
Looks like the word “only” dropped from the URL and doesn’t get copied with a straight copy paste from the page, we’ll look at it
Sorry, here is a new link. The link points to the original version, which works fine. I’ll keep my version to myself for now. 😉
Long only strategy with the TMA channel
The link doesn’t work either. Why?
Ok, it’s a known website bug on a very small number of old links apparently, but a tough one to understand why as previous investigations didn’t solve it. Sorry.
As a workaround please click on the faulty link anyway, and in the address box at top of the page, add with keyboard the word “only” in the middle of … long- -strategy … to make it the normal text: … long-only-strategy …
In my opinion should all strategys have their own thread. A better way of discussion and improvements. Maybe coder JohnScher or phoentzs can start one. If not i will tonight.
Or copy the link above and paste direct into browser address bar.
tough one to understand
Links to Topics that don’t work may be due to the Title / Subject of the Topic having been changed after the original link was created (i.e. before the Topic title was changed).
In this particular case it’s a library topic and title wasn’t changed, but I don’t know much more about the subject, it’s in Nicolas’ hands. Also, yes your copy-paste of the “texted” link in the address bar rather than clicking on it would work too.
@samsanpop – regarding _PRD DAX Combi strategy:
Removing or commenting out the sellshort function, essentially making it a long only strategy, creates slightly better results. Thanks for sharing!
Remove this:
//SHORT ENTRY CONDITIONS
s1 = (m10[0]–m10[1]) < 0
s2 = (m20[0]–m20[1]) < 0
s3 = (m50[0]–m50[1]) < 0
s4 = (m100[0]–m100[1]) < 0
s5 = (m300[0]–m300[1]) < 0
s6 = (m800[0]–m800[1]) < 0
conditionSellMomentum = s1 AND s2 AND s3 AND NOT s4 AND s5 AND NOT s6
// OPEN A SHORT ENTRY
IF conditionSellMomentum AND conditionMarketVolatilityM THEN
PSTOPLOSS = 100
PTARGET = PSTOPLOSS * 2
SET STOP pLOSS PSTOPLOSS
SET TARGET pPROFIT PTARGET
SELLSHORT PositionSize CONTRACT AT MARKET
P1 = 1
ENDIF
thanked this post
Hi, Anyone can convert “GBPJPY MINI M15” code itf file in Metatrader 4 file Expert Advisor?
Defparam cumulateorders = false
// TAILLE DES POSITIONS
n = 1
// PARAMETRES
// high ratio = few positions
// AUD/JPY : ratio = 0.5 / SL = 0.8 / TP = 1.2 / Period = 12
// EUR/JPY : ratio = 0.6 / SL = 1 / TP = 0.8 / Period = 8
// GBP/JPY : ratio = 0.5 / SL = 0.6 / TP = 1 / Period = 8
// USD/JPY : ratio = 0.5 / SL = 1 / TP = 0.8 / Period = 12
ratio = 0.6
period = 8
// HORAIRES
startTime = 210000
endTime = 231500
exitLongTime = 210000
exitShortTime = 80000
// BOUGIE REFERENCE à StartTime
if time = startTime THEN
amplitude = highest[Period](high) - lowest[Period](low)
ouverture = close
endif
// LONGS & SHORTS : every day except Fridays
// entre StartTime et EndTime
if time >= startTime and time <= endTime and dayOfWeek <> 5 then
buy n shares at ouverture - amplitude*ratio limit
sellshort n shares at ouverture + amplitude*ratio limit
endif
// Stop Loss & Take Profit
// Stop e target
SET STOP PLOSS 25
SET TARGET PPROFIT 13 //395
//
//trailing stop function
//************************************************************************
// trailing stop function
trailingstart = 19 //10 trailing will start @trailinstart points profit
trailingstep = 24 //5 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 HIGH-tradeprice(1)>=trailingstart*pipsize THEN //close --> HIGH
newSL = tradeprice(1)+trailingstep*pipsize
// new coding
IF newSL > close THEN //if current closing price is < new SL then exit IMMEDIATELY!
SELL AT newSL LIMIT
ENDIF
// end new coding
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
// new coding
IF newSL > close THEN //if current closing price is < new SL then exit IMMEDIATELY!
SELL AT newSL LIMIT
ENDIF
// end new coding
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-LOW>=trailingstart*pipsize THEN //close --> LOW
newSL = tradeprice(1)-trailingstep*pipsize
// new coding
IF newSL < close THEN //if current closing price is > new SL then exit IMMEDIATELY!
EXITSHORT AT newSL LIMIT
ENDIF
// end new coding
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
// new coding
IF newSL < close THEN //if current closing price is > new SL then exit IMMEDIATELY
EXITSHORT AT MARKET
ENDIF
// end new coding
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT MARKET
ENDIF
// Exit Time
if time = exitLongTime then
sell at market
endif
if time = exitShortTime then
exitshort at market
endif