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/24/2021 at 12:54 PM #17607908/24/2021 at 1:06 PM #176081
Am working on a Low Volume Reversal next, will post a new thread for that one 🙂
3 users thanked author for this post.
08/24/2021 at 7:22 PM #176129One 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 marketendifendifI tried to optomize the strategy with B1 and B2.
I attach the results09/02/2021 at 9:51 PM #17669112345<span style="color: #202124;"><span style="font-family: inherit;"><span style="font-size: large;">This is a simplified and clean version (v2.1) of the trading system:</span></span></span><span style="color: #202124;"><span style="font-family: inherit;"><span style="font-size: large;"><span lang="en-US">TEST-KD Mean Reverting version (v1.3).</span></span></span></span><span style="color: #202124;"><span style="font-family: inherit;"><span style="font-size: large;"><span lang="en-US">I have optimized the trailing stop, added a splitPosition (thanks to Roberto Gozzi's code) and added an additional filter for the exit.</span></span></span></span>//TS KD Mean Reverting v2.1 – Nasdaq 15 min – cfd 1 contract
// spread 2 points
DEFPARAM CUMULATEORDERS = FALSE
PositionSize=1
//——————————————————– SETUP
avgHull=average[150,7] //150-7
volBars=15 //15
vol = Volume
lowBars=10 //10
c1 = close>avgHull // average Hull (filter)
c2 = vol < vol[volBars] // volume
c3 = close > lowest [lowBars] (low) // close – lowest low
If c1 and c2 and c3 and openDayOfWeek <> 5 and tradeAllowed=1 then //TS LONG ONLY ENTRY
Buy PositionSize CONTRACTS AT MARKET
ENDIF
//——————————————————— ADDED EXIT FILTERS
myrsiM5=rsi[14](close)
if myrsiM5<30 and longonmarket and close>positionprice then //RSI Exit
sell at market
endif
if myrsiM5>70 and shortonmarket and close<positionprice then
exitshort at market
endif
//—————————————————————-
maxDailyLoss = 250 // Max Loss Intraday Exit (Euro)
realPosition=positionPerf*positionPrice/pointSize*pointValue
once tradeAllowed = 1
if intradayBarIndex=0 then
myProfit=strategyProfit
tradeAllowed=1
endif
if (strategyProfit+realPosition) <= (myProfit-maxDailyLoss) then
tradeAllowed=0
endif
///——————————————————— MONEY MANAGEMENT
SET STOP pLOSS 130 //SL 100 //SL (stop loss) – TP (take profit)
SET TARGET pPROFIT 190 //TP 175
//———————————————————
pointToReachLong=35*pointSize // 30 //TrP (trailingProfit)
pointToKeepLong=10*pointSize // 12
If not onMarket then
newSL=0
endif
If longOnMarket then
If newSL=0 and high-tradePrice(1)>pointToReachLong then
newSL=tradePrice(1)+ pointToKeepLong
endif
If newSL>0 and close-newSL>pointToReachLong then
newSL = newSL+pointToKeepLong
endif
endif
If newSL>0 then
sell at newSL STOP
endif
//————————————————————- SPLIT winning position
once partialcloseGain = 1
If partialcloseGain then
ONCE PerCent = 0.5 //close 1/2 size
PipsGain = 160 //PositionPrice * PerCentGain / PipSize
ONCE MinLotSize = 0.5
ExitQuantity = abs(CountOfPosition) * PerCent
LeftQty = max(MinLotSize,abs(CountOfPosition) – ExitQuantity)
CloseQuantity = max(0,abs(CountOfPosition) – LeftQty)
TempGain = PositionPerf * PositionPrice / PipSize
IF Not OnMarket THEN
Flag = 1
ENDIF
IF partialcloseGain AND LongOnMarket and TempGain >= PipsGain*pipsize AND Flag THEN
SELL CloseQuantity Contracts AT Market
Flag = 0
endif
IF partialcloseGain AND ShortOnMarket and TempGain >= PipsGain*pipsize AND Flag THEN
exitshort CloseQuantity Contracts AT Market
Flag = 0
endif
endif
//—————————————————————————————————————————————–
1<span style="color: #202124;"><span style="font-family: inherit;"><span style="font-size: large;"><span lang="en-US"> </span></span></span></span>1 user thanked author for this post.
09/02/2021 at 9:52 PM #1766921234<span style="color: #202124;"><span style="font-family: inherit;"><span style="font-size: large;">Test over a period of 200K.</span></span></span><span style="color: #202124;"><span style="font-family: inherit;"><span style="font-size: large;"><span lang="en-US">On the left side: the basic version 1.3</span></span></span></span><span style="color: #202124;"><span style="font-family: inherit;"><span style="font-size: large;"><span lang="en-US">On the right side: the new version 2.1</span></span></span></span><a class="gdbbx-bbcode-attachment" target="_blank" title="Image-001" href="https://www.prorealcode.com/wp-content/uploads/2021/09/Image-001.jpg"><img decoding="async" class="gdbbx-bbcode-attachment-image" alt="Image-001" src="https://www.prorealcode.com/wp-content/uploads/2021/09/Image-001.jpg" /></a>09/02/2021 at 9:57 PM #176695This is a simplified and clean version of the tradingsystem : TEST-KD Mean Reverting version 1,3
Test over 200k:
on the leftside the basic version 1,3
on the right side the new version 2,1
2 users thanked author for this post.
09/03/2021 at 6:44 AM #176702This is a simplified and clean version (v2.1) of the trading system: TEST-KD Mean Reverting version (v1.3). I have optimized the trailing stop, added a splitPosition (thanks to Roberto Gozzi’s code) and added an additional filter for the exit.
Thank you very much MauroPro, that’s such a great improvement. And there are so many useful snippets of code in your version, such as averaging out of a position. Brilliant work.
09/06/2021 at 5:06 PM #17689004/01/2022 at 8:40 PM #19100504/02/2022 at 8:57 AM #19103004/02/2022 at 9:09 AM #191031For me the range is the highest and lowest, not the opening and closing.
Line 103: I modify the range by: abs(high-low)>rangeokLine 40: my opening must be above the 50 moving average and above the opening of the day
That’s it1 user thanked author for this post.
04/04/2022 at 8:00 AM #19112604/04/2022 at 9:57 AM #19114104/05/2022 at 9:29 PM #19127904/08/2022 at 6:51 PM #191460Yes, here is the code.
I added an output with the rsi in overbuy123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170//================================================// 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=10//=== Entry Filter ===//Filter 1indicator1=average[150,7]F1 = close>indicator1//Range ParametersNbars=15Pbars=10//Entry Criteriaindicator1 = Volumec1 = (indicator1 < indicator1[Nbars])MM=average[50]// Conditions to enter long positionsIf close > lowest[Pbars](low) and c1 and opendayofweek <> 5 and F1 and OPEN>MM and dopen(0)<close 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 //50//SET 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(high - low) > 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//====ajouté par fifiif longonmarket and close>positionprice and RSI[14](close)>70 and close-open>100 thensell at marketENDIF3 users thanked author for this post.
-
AuthorPosts