Just to add som information to this thread, I have been running this algo live since mid May. The results are attached in a PDF.
This is the version I have been running, Maz version (I have not done any manual interference):
// ADX-Bollinger Mean Reversion v 1.12
// Version 0.23
// https://www.prorealcode.com/topic/scalping-eurusd/
DEFPARAM cumulateOrders = false
DEFPARAM preloadBars = 300
once GMTOffset = 2 // Your time zone reletive to +/- GMT (in hours) 0=GMT | 1=CET
once optimization = 1
// -- Optimizations selection --
if optimization = 1 then // USD_JPY :: M5 (Jan 2016- Apr 2017)
startTime = 090000 // 100000
endTime = 230000 // 240000
fridayEndTime = 225000 //
bolUpPeriod = 20
bolDnPeriod = 20
maShrtPeriod = 8
maLongPeriod = 200
adxPeriod = 21
adxThreshold = 22
stopLossMode = 3 // 1: Static | 2: Dynamic | 3: Trailing1 | 4: Trailing2
stopLoss = 67 // For Static stop
slATRmultiple = 5 // For Dynamic stop
targetATRmultiple = 7 // For Dynamic target
//tslATRmultiple = 8 // For Dynamic trailing stop, also try 5 and 3
moneymgmt = 1 // 1: Fixt position size | 2: Increasing position size
elsif optimization = 2 then
startTime = 090000 // 100000
endTime = 230000 // 240000
fridayEndTime = 225000 //
bolUpPeriod = 20
bolDnPeriod = 20
maShrtPeriod = 8
maLongPeriod = 200
adxPeriod = 21
adxThreshold = 22
stopLossMode = 3 // 1: Static | 2: Dynamic | 3and4: Trailing stops
stopLoss = 70 // For Static stop
slATRmultiple = 5 // For Dynamic stop
moneymgmt = 1 // 1: Fixt position size | 2: Increasing position size
// elsif optimization = 3 then // ... and so on
endif
// Money mgmt
IF moneymgmt = 1 then
positionSize = 1
elsif moneymgmt = 2 then
REM Money Management
Capital = 10000
Risk = 0.2
Sl = 70 // Could be our variable X
REM Calculate contracts
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
PositionSize = abs(round((maxrisk/Sl)/PointValue)*pipsize)
endif
// -- Time zone adjustments --
startTime = startTime + ( GMTOffset * 10000 )
endTime = endTime + ( GMTOffset * 10000 )
fridayEndTime = fridayEndTime + ( GMTOffset * 10000 )
// -- Indicators -----
bLow = BollingerDown[bolUpPeriod]
bHigh = BollingerUp[bolDnPeriod]
MA1 = average[maShrtPeriod]
MA2 = average[maLongPeriod]
ad = adx[adxPeriod]
atr = averageTrueRange[40]
// -- Entry conditions -----
// -- Common Conditions (for both long and short) --
isTradingTime = (currenttime > startTime and currenttime < endTime)
atADXLevel = (ad > adxThreshold)
isLateFriday = (dayOfWeek = 5 and time >= fridayEndTime)
if isTradingTime and atADXLevel then
// -- long conditions only --
bc1 = not longOnMarket //and isTradingTime and atADXLevel
bc1 = bc1 and (max(low, close) < bLow) //(low < bLow and close < bLow)
bc1 = bc1 and (MA1 > MA2) //and (MA2 > MA2[1])
// -- Short conditions only --
sc1 = not shortOnMarket //and isTradingTime and atADXLevel
sc1 = sc1 and (min(high, close) > bHigh) //(high > bHigh and close > bHigh)
sc1 = sc1 and (MA1 < MA2) //and (MA2 < MA2[1])
else
bc1 = 0
sc1 = 0
endif
if onMarket then
// -- Long EXIT conditions only --
le1 = longOnMarket and ( (close > bHigh) or isLateFriday )
// -- Short EXIT conditions only --
se1 = shortOnMarket and ( (close < bLow) or isLateFriday )
else
le1 = 0
se1 = 0
endif
// -- Execution Handlers -----
if bc1 then
buy positionSize contract at market
elsif sc1 then
sellShort positionSize contract at market
elsif le1 then
sell at market
elsif se1 then
exitshort at market
endif
SET TARGET pPROFIT (atr * targetATRmultiple)/pointsize //dynamic ATR based target
if stopLossMode = 1 then // static stop loss
SET STOP pLOSS stopLoss
elsif stopLossMode = 2 then // dynamic ATR based stop loss
SET STOP pLOSS (atr * slATRmultiple)/pointsize
elsif stopLossMode = 3 then // trailing stop 1
SET STOP pLOSS stoploss
//trailingstop = (atr * tslATRmultiple)/pointsize
trailingstop = 30
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE (Maximum favorable excursion) of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
elsif stopLossMode = 4 then // trailing stop 2
SET STOP pLOSS stoploss
trailingstart = 30 //trailing will start @trailinstart points profit
trailingstep = 10 //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
ENDIF
Hi Ronny! Thanks for sharing! I tested this strategy mostly on demo and after letting it run for some time and a few tries on backtest I decided not to run it live. The main problem that I found was trades it got into when the short term trend was turning around ( same problem as with all mean-rev.) However on such short timeframe I found it hard to determinate if it was possible to get a long term edge and not just a short term curve fit.
I can understand that this one easily gets curve fitted. It’s a pity actually, I like the idea behind it. Looking at the equity curve, it has a quite stable downwards movement. Maybe it could tell us that it’s something there to explore 🙂 Anyway 55 trades is not representative, but I get a feeling that I should shut it down. I like testing the strategys with small amounts in live trade, more than demotrading.