Looking for Momentum

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #175806 quote
    deletedaccount051022
    Participant
    New

    Hi,

    Attached is a strategy from Kevin Davey, Momentum and Big Range.  Very simple  entry code which I really like.  With help from JC_bywan, thank you.  What I notice is the significant  uptick in performance from 2017 onward.  Therefore, there must be a filter to say when this market condition will change or end?  Any ideas would be greatly appreciated.  Have yet to try to adapt to other indices or CCY pairs.

    (Also – PRT seems to think it is in the market for an infinite period of time!  Not sure what’s happening there.)

    Thank you very much,

    S

    //================================================
    //   Code:    TEST KD1 MomtRange v1
    //   Source:  https://www.youtube.com/watch?v=D_P_XqB5nHs
    //            Entry Strategy #1 Momentum and Big Range
    //   Author:  Kevin Davey
    //   Version  1
    //   Index:   NASDAQ
    //   TF:      15 min
    //   Notes:   v1.1 Square root calc
    //   Notes:   v1.2 Swaped Square for Sandard Deviation  - thanks to JC_bywan
    //   Notes:   v1.3 Tried timeframes 1m, 3m, 5m, 10m and 30m - poor performance
    //   Notes:   v1.4 Tested different day of week combos - poorreduced overfall performance
    //   Notes:   v1.5 Added Break Even Trailing Stop from KISS strategy
    //================================================
    
    //Risk Management
    PositionSize=1
    
    //Range Parameters
    Nbars=5
    Pbars=10
    rrange=high-low
    stdrange=2*std[Nbars](range)  //square
    avgrange=rrange[Nbars]
    
    // Conditions to enter long positions
    If rrange>stdrange+avgrange and close>close[Pbars] 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(close - open) > 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
    
    //SET STOP $LOSS stoploss
    
    @AlgoHunter1 and Player8520 thanked this post
    KD-MomtRange.png KD-MomtRange.png TEST-KD-MomtRange-v1.5.itf
    #175812 quote
    JC_Bywan
    Moderator
    Master

    At line 24, your “avgrange” variable is made equal to rrange Nbars ago, if that’s you wanted then ok… but just in case, with the name suggesting it might be an average, if what you wanted is the average of rrange over Nbars, then it would be:

    avgrange=average[Nbars](rrange)

     

     

    #175815 quote
    nonetheless
    Participant
    Master

    is that backtest for long only? short entry is //

    #175816 quote
    deletedaccount051022
    Participant
    New

    At line 24, your “avgrange” variable is made equal to rrange Nbars ago, if that’s you wanted then ok… but just in case, with the name suggesting it might be an average, if what you wanted is the average of rrange over Nbars, then it would be:

    Thank you, my error.  I also see I hadn’t copied over the “DEFPARAM CUMULATEORDERS = FALSE” at the start.

    @AlgoHunter1 thanked this post
    #175817 quote
    deletedaccount051022
    Participant
    New

    is that backtest for long only? short entry is //

    Hello – This is a long only strategy for now.  I have left the short side in but commented out for now, as I plan to add it in for the next version.

    @AlgoHunter1 thanked this post
    #175818 quote
    nonetheless
    Participant
    Master

    I also see I hadn’t copied over the “DEFPARAM CUMULATEORDERS = FALSE”

    I was about to say that. makes a rather large difference, but i guess you’ve seen that now.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Looking for Momentum


ProOrder: Automated Strategies & Backtesting

New Reply
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by nonetheless
4 years, 6 months ago.

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