NASDAQ Mean Reversion

Viewing 15 posts - 16 through 30 (of 38 total)
  • Author
    Posts
  • #176079 quote
    murre87
    Participant
    Senior

    Attach BT for DAX 5M

    BT-1.jpg BT-1.jpg
    #176081 quote
    deletedaccount051022
    Participant
    New

    Am working on a Low Volume Reversal next, will post a new thread for that one  🙂

    murre87, Midlanddave and @AlgoHunter1 thanked this post
    #176129 quote
    murre87
    Participant
    Senior

    One 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).

    I tried to optomize the strategy with B1 and B2.
    I attach the results

    TEST-KD_MeanReverting-v1.4-2.jpg TEST-KD_MeanReverting-v1.4-2.jpg TEST-KD_MeanReverting-v1.4.jpg TEST-KD_MeanReverting-v1.4.jpg
    #176691 quote
    MauroPro
    Participant
    Veteran
    This 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.
    
    

    //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

    //—————————————————————————————————————————————–

     
    paisantrader thanked this post
    #176692 quote
    MauroPro
    Participant
    Veteran
    Test over a period of 200K.
    
    On the left side: the basic version 1.3
    On the right side: the new version 2.1[attachment file="176693"]
    
    
    Image-001.jpg Image-001.jpg
    #176695 quote
    MauroPro
    Participant
    Veteran

    This 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

    Midlanddave and thanked this post
    #176702 quote
    deletedaccount051022
    Participant
    New

    This 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.

    #176890 quote
    murre87
    Participant
    Senior

    Great strategy.  Anyone got further with short?

    #191005 quote
    fifi743
    Participant
    Master
    #191030 quote
    Madrosat
    Participant
    Master

    Hello Fifi

    What is your simple modification???

    #191031 quote
    fifi743
    Participant
    Master

    For me the range is the highest and lowest, not the opening and closing.
    Line 103: I modify the range by: abs(high-low)>rangeok

    Line 40: my opening must be above the 50 moving average and above the opening of the day
    That’s it

    thanked this post
    #191126 quote
    Madrosat
    Participant
    Master

    Thank you Fifi  I try to rectfy

    #191141 quote
    fifi743
    Participant
    Master

    I removed the TP too

    #191279 quote
    ullle73
    Participant
    Senior

    Fifi, could you post the itf file? did not get the same results.

    #191460 quote
    fifi743
    Participant
    Master

    Yes, here is the code.
    I added an output with the rsi in overbuy

    //================================================
    //   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 Management
    PositionSize=10
    
    //=== Entry Filter ===
    //Filter 1
    indicator1=average[150,7]
    F1 = close>indicator1
    
    
    //Range Parameters
    Nbars=15
    Pbars=10
    
    //Entry Criteria
    indicator1 = Volume
    c1 = (indicator1 < indicator1[Nbars])
    MM=average[50]
    
    
    // Conditions to enter long positions
    If close > lowest[Pbars](low) and c1 and opendayofweek <> 5 and F1 and OPEN>MM and dopen(0)<close then
    Buy PositionSize CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    //IF rrange>2*stdrange+avgrange and close<close[10] THEN
    //SELLSHORT PositionSize CONTRACTS AT MARKET
    //ENDIF
    
    // Stops and targets
    SET STOP LOSS 100     //50
    //SET TARGET PROFIT 175  //50
    
    //FOR STOPLOSS MANNGEMENT
    // Conditions to enter long positions
    startBreakeven = 30
    PointsToKeep = 12
    
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
    
    // --- BUY SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
     
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    
    //************************************************************************
    IF longonmarket and barindex-tradeindex>1600 and close<positionprice then
    sell at market
    endif
    IF shortonmarket and barindex-tradeindex>1800 and close>positionprice then
    exitshort at market
    endif
    
    //===================================
    myrsiM5=rsi[14](close)
    //
    if myrsiM5<30 and barindex-tradeindex>1 and longonmarket and close>positionprice then
    sell at market
    endif
    if myrsiM5>70 and barindex-tradeindex>1 and shortonmarket and close<positionprice then
    exitshort at market
    endif
    //===================================
    
    once openStrongLong = 0
    once openStrongShort = 0
    if (time <= 090000 or time >= 210000) then
    openStrongLong = 0
    openStrongShort = 0
    endif
    
    //detect strong direction for market open
    once rangeOK = 30
    once tradeMin = 2500
    IF (time >= 090500) AND (time <= 090500 + tradeMin) AND ABS(high - low) > rangeOK THEN
    IF close > open and close > open[1] THEN
    openStrongLong = 1
    openStrongShort = 0
    ENDIF
    IF close < open and close < open[1] THEN
    openStrongLong = 0
    openStrongShort = 1
    ENDIF
    ENDIF
    
    once bollperiod = 20
    once bollMAType = 1
    once s = 2
    
    bollMA = average[bollperiod, bollMAType](close)
    STDDEV = STD[bollperiod]
    bollUP = bollMA + s * STDDEV
    bollDOWN = bollMA - s * STDDEV
    IF bollUP = bollDOWN THEN
    bollPercent = 50
    ELSE
    bollPercent = 100 * (close - bollDOWN) / (bollUP - bollDOWN)
    ENDIF
    
    once trendPeriod = 80
    once trendPeriodResume = 10
    once trendGap = 4
    once trendResumeGap = 4
    if not onmarket then
    fullySupported = 0
    fullyResisteded = 0
    endif
    //Market supported in the wrong direction
    IF shortonmarket AND fullySupported = 0 AND summation[trendPeriod](bollPercent > 50) >= trendPeriod - trendGap THEN
    fullySupported = 1
    ENDIF
    
    //Market pull back but continue to be supported
    IF shortonmarket AND fullySupported = 1 AND bollPercent[trendPeriodResume + 1] < 0 AND summation[trendPeriodResume](bollPercent > 50) >= trendPeriodResume - trendResumeGap THEN
    exitshort at market
    ENDIF
    
    //Market resisted in wrong direction
    IF longonmarket AND fullyResisteded = 0 AND summation[trendPeriod](bollPercent < 50) >= trendPeriod - trendGap THEN
    fullyResisteded = 1
    ENDIF
    
    //Market pull back but continue to be resisted
    IF longonmarket AND fullyResisteded = 1 AND bollPercent[trendPeriodResume + 1] > 100 AND summation[trendPeriodResume](bollPercent < 50) >= trendPeriodResume - trendResumeGap THEN
    sell at market
    ENDIF
    
    //Started real wrong direction
    once strongTrend = 60
    once strongPeriod = 4
    once strongTrendGap = 2
    IF shortonmarket and openStrongLong and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent > strongTrend) = strongPeriod - strongTrendGap then
    exitshort at market
    ENDIF
    
    IF longonmarket and openStrongShort and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent < 100 - strongTrend) = strongPeriod - strongTrendGap then
    sell at market
    ENDIF
    //====ajouté par fifi
    if longonmarket and close>positionprice and RSI[14](close)>70 and  close-open>100 then
    sell at market
    ENDIF
    
    
    Midlanddave and ichimoku18 thanked this post
Viewing 15 posts - 16 through 30 (of 38 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

NASDAQ Mean Reversion


ProOrder: Automated Strategies & Backtesting

New Reply
Summary

This topic contains 37 replies,
has 14 voices, and was last updated by MauroPro
4 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/23/2021
Status: Active
Attachments: 14 files
Logo Logo
Loading...