Trend Follower Strategy

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #191526 quote
    Kanamax
    Participant
    Junior

    Hi All,

    I try to use « trend follower” indicator posted by robertogozzi as a simple strategy.

    Original Indicator link : https://www.prorealcode.com/prorealtime-indicators/trend-follower/

    Strategy is based on “trend > 0” for BUY signal and “trend < 0” for SELL signal. Strategy is coded to be LONG or SHORT.

    You’ll find below the strategy, however back test result shows entry and close position don’t follow the indicator. See sceenshot also attached.

    Any idea?

    Thank you.

    I run with PRTV11

     

    // Trend Follower
    //
    // https://it.tradingview.com/script/o0ZOSVHj-Trend-Follower/
    //
    MAtype    = 1        //1=Ema
    TrendP    = 20       //20 periods to check trend
    MAperiods = 20       //20 periods for MA
    TrendRate = 1        //1%  trend channel rate
    UseLR     = 1        //1=use Linear Regression,  0=do not use LR
    LRperiods = 5        //5  periods for Linear Regression
    RangeP    = 1      //300 period for the range
    MAtype    = max(0,min(8,MAtype))
    TrendP    = max(1,min(999,TrendP))
    MAperiods = max(1,min(999,MAperiods))
    TrendRate = max(0.00001,min(99,TrendRate))
    RangeP    = max(1,min(999,RangeP))
    //
    RateMult  = TrendRate / 100
    PriceRange= highest[RangeP](high) - lowest[RangeP](low)
    MyChannel = PriceRange * RateMult
    MyMA      = average[MAperiods,MAtype](close)
    IF UseLR THEN
    MyMA   = LinearRegression[LRperiods](close)
    ENDIF
    hh        = highest[TrendP](MyMA)
    ll        = lowest[TrendP](MyMA)
    diff      = abs(hh - ll)
    x         = 0
    IF diff > MyChannel THEN
    IF MyMA > (ll + MyChannel) THEN
    x   = 1
    ELSE
    IF MyMA < (hh - MyChannel) THEN
    x = -1
    ENDIF
    ENDIF
    ENDIF
    Trend = x * diff / MyChannel
    IF Trend> 0 THEN
    r = 0
    g = 255
    b = 0
    t = 255
    IF Trend < Trend[1] THEN
    g = 128
    t = 180
    ENDIF
    ELSE
    r = 255
    g = 0
    b = 0
    t = 255
    IF Trend > Trend[1] THEN
    r = 139
    g = 0
    b = 0
    t = 255
    ENDIF
    ENDIF
    
    // "LONG" trend open
    if not onmarket and trend > 0 then
    BUY 1 CONTRACTS AT MARKET
    endif
    
    // "LONG" trend closed
    if longonmarket and trend < 0 then
    SELL AT MARKET
    ENDIF
     
     
    // "SHORT" trend open
    if not onmarket and trend < 0 then
    SELLSHORT 1 CONTRACTS AT MARKET
    endif
     
    // "SHORT" trend closed
    if shortonmarket and trend > 0 then
    EXITSHORT AT MARKET
    ENDIF
    
    Trend-Follower-Poition-error.jpg Trend-Follower-Poition-error.jpg
    #191556 quote
    pableitor
    Participant
    Master

    Are you sure that the indicator and system parameters have the same value?  Check RangeP

    #191602 quote
    JS
    Participant
    Senior
    Hi @Kanamax, Pableitor is right, your system parameters (1 20 20 1 t 5 1) don’t match with your indicator parameters (1 20 20 1 f 5 300)
    Schermafbeelding-2022-04-11-om-23.47.58.png Schermafbeelding-2022-04-11-om-23.47.58.png
    #191626 quote
    Kanamax
    Participant
    Junior
    Hi Pableitor and JS, you are right, I tested this morning with with the right ones and that works. I’ll be more careful next time. Thank you for your help.
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Trend Follower Strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Kanamax @kanamax Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by Kanamax
3 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/10/2022
Status: Active
Attachments: 2 files
Logo Logo
Loading...