NASDAQ Mean Reversion
Forums › ProRealTime English forum › ProOrder support › NASDAQ Mean Reversion
- This topic has 37 replies, 14 voices, and was last updated 2 years ago by MauroPro.
-
-
08/23/2021 at 4:15 PM #176000
Hello,
A work in progress strategy based on a simple mean reversion idea inspired by Kevin Davey that I have adapted from a daily to a 15 minute timeframe. It looks for low volume and low price over N bars, then goes long. Only two entry criteria and one initial filter, and works well but needs improving.
The focus at this stage is to work on reducing the Drawdown, and potentially the number of trades, by use of an entry filter. Thought I would share this early version in the hope that people might have some useful ideas for a suitable filter.
NASDAQ
15m
Spread 2
Thank you,
S
7 users thanked author for this post.
08/23/2021 at 4:18 PM #176003With screenshot that was dropped
08/24/2021 at 8:19 AM #17603508/24/2021 at 8:59 AM #176043Wow. Impressing. No short entrys?
TEST KD_MeanReverting v1.3123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166//================================================// Code: TEST KD3 Mean Reverting v1// Source: https://www.youtube.com/watch?v=D_P_XqB5nHs// Entry Strategy #3 Mean REverting// Author: Kevin Davey// Version 1// Index: NASDAQ// TF: 15 min// TZ: Europe// Notes: v1.1 Long Olny// Notes: v1.2 Entry Filter (optimised to 150 MA)// Notes: v1.3 Day of week - do not trade Friday's//// Pending Test Short side// Reduce Drawdown (Long Entry Filter)//================================================DEFPARAM CUMULATEORDERS = FALSE//Risk ManagementPositionSize=1//=== Entry Filter ===//Filter 1indicator1=average[150,7]F1 = close>indicator1//Range ParametersNbars=15Pbars=10//Entry Criteriaindicator1 = Volumec1 = (indicator1 < indicator1[Nbars])// Conditions to enter long positionsIf close > lowest[Pbars](low) and c1 and opendayofweek <> 5 and F1 thenBuy PositionSize CONTRACTS AT MARKETENDIF// Conditions to enter short positions//IF rrange>2*stdrange+avgrange and close<close[10] THEN//SELLSHORT PositionSize CONTRACTS AT MARKET//ENDIF// Stops and targetsSET STOP LOSS 100 //50SET TARGET PROFIT 175 //50//FOR STOPLOSS MANNGEMENT// Conditions to enter long positionsstartBreakeven = 30PointsToKeep = 12IF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF//************************************************************************IF longonmarket and barindex-tradeindex>1600 and close<positionprice thensell at marketendifIF shortonmarket and barindex-tradeindex>1800 and close>positionprice thenexitshort at marketendif//===================================myrsiM5=rsi[14](close)//if myrsiM5<30 and barindex-tradeindex>1 and longonmarket and close>positionprice thensell at marketendifif myrsiM5>70 and barindex-tradeindex>1 and shortonmarket and close<positionprice thenexitshort at marketendif//===================================once openStrongLong = 0once openStrongShort = 0if (time <= 090000 or time >= 210000) thenopenStrongLong = 0openStrongShort = 0endif//detect strong direction for market openonce rangeOK = 30once tradeMin = 2500IF (time >= 090500) AND (time <= 090500 + tradeMin) AND ABS(close - open) > rangeOK THENIF close > open and close > open[1] THENopenStrongLong = 1openStrongShort = 0ENDIFIF close < open and close < open[1] THENopenStrongLong = 0openStrongShort = 1ENDIFENDIFonce bollperiod = 20once bollMAType = 1once s = 2bollMA = average[bollperiod, bollMAType](close)STDDEV = STD[bollperiod]bollUP = bollMA + s * STDDEVbollDOWN = bollMA - s * STDDEVIF bollUP = bollDOWN THENbollPercent = 50ELSEbollPercent = 100 * (close - bollDOWN) / (bollUP - bollDOWN)ENDIFonce trendPeriod = 80once trendPeriodResume = 10once trendGap = 4once trendResumeGap = 4if not onmarket thenfullySupported = 0fullyResisteded = 0endif//Market supported in the wrong directionIF shortonmarket AND fullySupported = 0 AND summation[trendPeriod](bollPercent > 50) >= trendPeriod - trendGap THENfullySupported = 1ENDIF//Market pull back but continue to be supportedIF shortonmarket AND fullySupported = 1 AND bollPercent[trendPeriodResume + 1] < 0 AND summation[trendPeriodResume](bollPercent > 50) >= trendPeriodResume - trendResumeGap THENexitshort at marketENDIF//Market resisted in wrong directionIF longonmarket AND fullyResisteded = 0 AND summation[trendPeriod](bollPercent < 50) >= trendPeriod - trendGap THENfullyResisteded = 1ENDIF//Market pull back but continue to be resistedIF longonmarket AND fullyResisteded = 1 AND bollPercent[trendPeriodResume + 1] > 100 AND summation[trendPeriodResume](bollPercent < 50) >= trendPeriodResume - trendResumeGap THENsell at marketENDIF//Started real wrong directiononce strongTrend = 60once strongPeriod = 4once strongTrendGap = 2IF shortonmarket and openStrongLong and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent > strongTrend) = strongPeriod - strongTrendGap thenexitshort at marketENDIFIF longonmarket and openStrongShort and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent < 100 - strongTrend) = strongPeriod - strongTrendGap thensell at marketENDIF//SET STOP $LOSS stoploss08/24/2021 at 9:37 AM #176048One thing you might want to look at is the section starting at line 73 above. In a 10 year backtest no trades have gone to 1600 bars so those values are doing nothing. This is also the case for the Breakout code you posted.
This is the snippet I use for that function, closes very long-running positions whether they’re winning or losing. You have to optimise for b1 and b2 (b3, b4 for short).
12345678910//EXIT ZOMBIE TRADEEZT = 1if EZT thenIF longonmarket and (barindex-tradeindex(1)>= b1 and positionperf>0) or (barindex-tradeindex(1)>= b2 and positionperf<0) thensell at marketendifIF shortonmarket and (barindex-tradeindex(1)>= b3 and positionperf>0) or (barindex-tradeindex(1)>= b4 and positionperf<0) thenexitshort at marketendifendif1 user thanked author for this post.
08/24/2021 at 9:49 AM #17605108/24/2021 at 10:00 AM #176052b1 if it’s winning, b2 if it’s losing.
but I should add that this isn’t always advantageous, you should also try switching it off, with some algos it’s better to just let them run.
1 user thanked author for this post.
08/24/2021 at 10:06 AM #176053B1 is for pp > 0 and B2 is for pp < 0.
I have successfully used above on several of my Algos from my early coding days, I will get back on it again, now I see you’re using it Nonetheless! 🙂
I also optimised using broad values for positionperf (in lieu of 0 as above).
2 users thanked author for this post.
08/24/2021 at 10:11 AM #176054but I should add that this isn’t always advantageous, you should also try switching it off, with some algos it’s better to just let them run.
Without this remark I already wanted to add :
I have attempted so many means of exiting because of too long “useless” trades. They always and always net lose. Otherwise this will be highly subject to curve fitting, IMO.
BUT
Only last week I applied a “strange” means for this : let shrink the SL per bar (or once in the so many, also OK). This seems counterproductive, but the contrary appears true. This starts with allowing for a higher SL (avoid peaks at entry) which is psychologically good. Next the losses because or running into the SL in practice are not that high at all. But moreover, this works out. For me it does …
Warning : I am almost sure that we should not change the StopLoss per bar because the broker may not like that. Eh, *if* possible at all. So it needs to be your own exit (like the example code in the earlier post) and NOT changing the StopLoss each time.08/24/2021 at 10:30 AM #17605508/24/2021 at 12:09 PM #176068One thing you might want to look at is the section starting at line 73 above. In a 10 year backtest no trades have gone to 1600 bars so those values are doing nothing. This is also the case for the Breakout code you posted.
This is the snippet I use for that function, closes very long-running positions whether they’re winning or losing. You have to optimise for b1 and b2 (b3, b4 for short).
12345678910//EXIT ZOMBIE TRADEEZT = 1if EZT thenIF longonmarket and (barindex–tradeindex(1)>= b1 and positionperf>0) or (barindex–tradeindex(1)>= b2 and positionperf<0) thensell at marketendifIF shortonmarket and (barindex–tradeindex(1)>= b3 and positionperf>0) or (barindex–tradeindex(1)>= b4 and positionperf<0) thenexitshort at marketendifendifThank you very much, I shall add this in and retest. Much appreciated.
1 user thanked author for this post.
08/24/2021 at 12:19 PM #17606908/24/2021 at 12:40 PM #176074I played a bit with the strategy, on DAX 1€, 200K units, 5 min-TF (mtf), changing just TP & SL and slightly the Trailing Stop to use PointsToKeep as sort of a trailing step. Performance is nice and WF is around 25%. I also commented out exiting on RSI:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179//================================================//https://www.prorealcode.com/topic/nasdaq-mean-reversion///// Code: TEST KD3 Mean Reverting v1.3// Source: https://www.youtube.com/watch?v=D_P_XqB5nHs// Entry Strategy #3 Mean REverting// Author: Kevin Davey// Version 1// Index: DAX (ex NASDAQ)// TF: 15 min// TZ: Europe// Notes: v1.1 Long Olny// Notes: v1.2 Entry Filter (optimised to 150 MA)// Notes: v1.3 Day of week - do not trade Friday's//// Pending Test Short side// Reduce Drawdown (Long Entry Filter)//================================================DEFPARAM CUMULATEORDERS = FALSETimeframe(2h,UpdateOnClose) //1h//Risk ManagementnLots=1//=== Entry Filter ===//Filter 1indicator1 = average[150,7] //150,7F1 = close>indicator1F2 = close<indicator1//Range ParametersNbars = 15 //15Pbars = 10 //10//Entry Criteriaindicator1 = Volumec1 = (indicator1 < indicator1[Nbars])// Conditions to enter long positionsIf close > lowest[Pbars](low) and c1 and opendayofweek <> 5 and F1 and Not OnMarket thenBuy nLots CONTRACTS AT MARKETENDIF// Conditions to enter short positionsIf close < highest[Pbars](high) and c1 and opendayofweek <> 5 and F2 and Not OnMarket then//SELLSHORT nLots CONTRACTS AT MARKETENDIF// Stops and targetsSET STOP pLOSS 50 //50SET TARGET pPROFIT 70 //75once openStrongLong = 0once openStrongShort = 0if (time <= 090000 or time >= 210000) then //090000 - 210000openStrongLong = 0openStrongShort = 0endif//detect strong direction for market openonce rangeOK = 30once tradeMin = 2500IF (time >= 090500) AND (time <= 090500 + tradeMin) AND ABS(close - open) > rangeOK THENIF close > open and close > open[1] THENopenStrongLong = 1openStrongShort = 0ENDIFIF close < open and close < open[1] THENopenStrongLong = 0openStrongShort = 1ENDIFENDIFonce bollperiod = 20once bollMAType = 1once s = 2bollMA = average[bollperiod, bollMAType](close)STDDEV = STD[bollperiod]bollUP = bollMA + s * STDDEVbollDOWN = bollMA - s * STDDEVIF bollUP = bollDOWN THENbollPercent = 50ELSEbollPercent = 100 * (close - bollDOWN) / (bollUP - bollDOWN)ENDIFonce trendPeriod = 80once trendPeriodResume = 10once trendGap = 4once trendResumeGap = 4if not onmarket thenfullySupported = 0fullyResisteded = 0endif//Market supported in the wrong directionIF shortonmarket AND fullySupported = 0 AND summation[trendPeriod](bollPercent > 50) >= trendPeriod - trendGap THENfullySupported = 1ENDIF//Market pull back but continue to be supportedIF shortonmarket AND fullySupported = 1 AND bollPercent[trendPeriodResume + 1] < 0 AND summation[trendPeriodResume](bollPercent > 50) >= trendPeriodResume - trendResumeGap THENexitshort at marketENDIF//Market resisted in wrong directionIF longonmarket AND fullyResisteded = 0 AND summation[trendPeriod](bollPercent < 50) >= trendPeriod - trendGap THENfullyResisteded = 1ENDIF//Market pull back but continue to be resistedIF longonmarket AND fullyResisteded = 1 AND bollPercent[trendPeriodResume + 1] > 100 AND summation[trendPeriodResume](bollPercent < 50) >= trendPeriodResume - trendResumeGap THENsell at marketENDIF//Started real wrong directiononce strongTrend = 60 //60once strongPeriod = 4 //4once strongTrendGap = 2 //2IF shortonmarket and openStrongLong and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent > strongTrend) = strongPeriod - strongTrendGap thenexitshort at marketENDIFIF longonmarket and openStrongShort and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent < 100 - strongTrend) = strongPeriod - strongTrendGap thensell at marketENDIF//SET STOP $LOSS stoplossTimeframe(default) //5 min// Breakeven & Trailing StopstartBreakeven = 25 //25PointsToKeep = 5 //5Distance = 6 //6//IF NOT ONMARKET THENbreakevenLevel=0ENDIF//// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=(startBreakeven*pipsize+PointsToKeep*pipsize) and breakevenlevel = 0 THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIFIF LONGONMARKET AND close-breakevenlevel>=(startBreakeven*pipsize) and breakevenlevel > 0 THENbreakevenLevel = breakevenlevel+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENIF close > (breakevenlevel + Distance) THENSELL AT breakevenLevel STOPIF close < (breakevenlevel - Distance) THENSELL AT breakevenLevel LIMITELSESELL AT MarketENDIFENDIFENDIF//************************************************************************ONCE MaxBars = 305 //305//IF longonmarket and barindex-tradeindex>MaxBars then//and close<positionprice thensell at marketendifIF shortonmarket and barindex-tradeindex>MaxBars then//and close>positionprice thenexitshort at marketendif//===================================myrsiM5=rsi[14](close)//if myrsiM5<30 and barindex-tradeindex>1 and longonmarket and close>positionprice then//sell at marketendifif myrsiM5>70 and barindex-tradeindex>1 and shortonmarket and close<positionprice then//exitshort at marketendif//===================================2 users thanked author for this post.
08/24/2021 at 12:43 PM #17607708/24/2021 at 12:53 PM #176078 -
AuthorPosts