Trend Follower

Trend Follower

It analyses moving averages in a channel and their momentum according to the channel width.

On each bar it creates a channel by highest/lowest point of a MA. highest point is upper point and lowest point is lower point of the MA channel.

It gets highest and lowest point of last 300 bars, (say Price Channel )
If the width of MA channel is greater than certain rate of price channel then it decides there is trend.

After it decided there is trend, it calculates the rate between channel and MA. Bigger result means stronger trend.

According to rate of MA channel and the price channel , bar color becomes lighter/darker. so when you look at the bar color you can see the trend strength.

The darker the colour, the weeker the trend is.

Upon a request from user denmar (https://www.prorealcode.com/topic/help-converting-trend-follower-indicator-from-trading-view/) I converted this indicator written by LonesomeTheBlue.

Share this

Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

  1. denmar • 09/27/2021 #

    Many thanks. Highly appreciated.

  2. Kanamax • 09/27/2021 #

    Hi Roberto,
    Thanks for this indicator which is very helpful.
    I tried to use this indicator into a very simple strategy based on g > 0 –> BUY and r SELL.
    The strategy runs however entry in call and put position don’t follow the indicator. Unfortunately I can’t put sceenshot to show
    Do you have any idea why?
    FYI I run with PRTV11

    Thank you

    I share only the end of the code + position entries:

    Trend = x * diff / MyChannel
    IF Trend > 0 THEN
    r = 0
    g = 255
    b = 0
    t = 255
    IF Trend Trend[1] THEN
    r = 139
    g = 0
    b = 0
    t = 255
    ENDIF
    ENDIF

    // Conditions pour ouvrir une position acheteuse
    if not onmarket and g = 255 then
    BUY 1 CONTRACTS AT MARKET
    ENDIF

    // Conditions pour fermer une position acheteuse
    if longonmarket and r = 255 then
    SELL AT MARKET
    ENDIF

    // Conditions pour ouvrir une position en vente à découvert
    if not onmarket and r = 255 then
    SELLSHORT 1 CONTRACTS AT MARKET
    ENDIF

    // Conditions pour fermer une position en vente à découvert
    if shortonmarket and g = 255 then
    EXITSHORT AT MARKET
    ENDIF

  3. robertogozzi • 09/27/2021 #

    Don’t use colours as a signal,
    use TREND instead.
    If it’s > 0 it’s a Long signal, otherwise it’s a Short signal.

  4. Kanamax • 09/27/2021 #

    Hi Roberto,
    I did previously but same result.

  5. Kanamax • 09/27/2021 #

    Can you try on your side to check if that works properly for you?

  6. robertogozzi • 09/27/2021 #

    Post the complete code you used.

  7. Kanamax • 09/27/2021 #

    Please find herein after

    / 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 0 THEN
    r = 0
    g = 255
    b = 0
    t = 255
    IF Trend Trend[1] THEN
    r = 139
    g = 0
    b = 0
    t = 255
    ENDIF
    ENDIF

    // Conditions pour ouvrir une position acheteuse
    if not onmarket and trend > 0 then
    BUY 1 CONTRACTS AT MARKET
    endif

    // Conditions pour fermer une position acheteuse
    if longonmarket and trend < 0 then
    SELL AT MARKET
    ENDIF

    // Conditions pour ouvrir une position en vente à découvert
    if not onmarket and trend 0 then
    EXITSHORT AT MARKET
    ENDIF

  8. Kanamax • 09/27/2021 #

    It seems I had some difficulties to copy paste the complete code correctly.
    The overall code is just your indicator + the following conditions at the end:
    Read trend > 0 instead of g = 255 and trend < 0 instead of r = 255

    // Conditions pour ouvrir une position acheteuse
    if not onmarket and g = 255 then
    BUY 1 CONTRACTS AT MARKET
    ENDIF

    // Conditions pour fermer une position acheteuse
    if longonmarket and r = 255 then
    SELL AT MARKET
    ENDIF

    // Conditions pour ouvrir une position en vente à découvert
    if not onmarket and r = 255 then
    SELLSHORT 1 CONTRACTS AT MARKET
    ENDIF

    // Conditions pour fermer une position en vente à découvert
    if shortonmarket and g = 255 then
    EXITSHORT AT MARKET
    ENDIF

  9. robertogozzi • 09/27/2021 #

    I can’t understand when you want to enter/exit.
    Please start a new topic in ProOrder support and attach the ITF file of your strategy + screenshot (showing also the instrument and timeframe used).

  10. Kanamax • 09/27/2021 #

    Hi Roberto, sorry for my confusing previous posts (forget them). My request is very simple, I just want to enter/exit by using TREND signal from your indicator.
    I want entry long when trend > 0 then exit when trend 0 and exit long is not when trend < 0 (same at the opposite for short signal).
    It's why I wondered if you can test by your own and then share with me the last lines of your ProOrder code?
    Thanks for you help.

    // 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 Entry
    if not onmarket and trend > 0 then
    BUY 1 CONTRACTS AT MARKET
    ENDIF

    // Long Exit
    if longonmarket and trend < 0 then
    SELL AT MARKET
    ENDIF

    // Short Entry
    if not onmarket and trend < 0 then
    SELLSHORT 1 CONTRACTS AT MARKET
    endif

    // Short Exit
    if shortonmarket and trend > 0 then
    EXITSHORT AT MARKET
    ENDIF

  11. robertogozzi • 09/27/2021 #

    Please start a new topic in ProOrder support.

  12. Kanamax • 09/27/2021 #

    OK

avatar
Register or

Likes

avatar avatar avatar avatar avatar avatar avatar
Related users ' posts
Kris75 Hi Gabri I launched a very simple strategy based on the 3 bars trailing stop that you cre...
TimDeCat Hi. Has anyone coded a version that you could alter it to say 5 bar trailing stop? ie make ...
Nicolas Please open a new topic in forums so we can code it there, thanks.
finplus bonjour, il y a un problème à la fin du code avec elsif (close 0 then ... ne manque t il pas...
kj1988 Hello Nicolas, thank you for this useful indicator. Could you tell me how I can remove the...
Nicolas remove lines 101 to 103
GraHal Yes sorry, I set up a link to a screen shot on my google drive and then I got locked into th...
gabri Here's the thread https://www.prorealcode.com/topic/multiframe-rsi-of-rsi/
Bernard13 Bonjour Nicolas, Pourriez-vous m'indiquer si cet indicateur fonctionne avec la V11 ? Le di...
HeikinAshi Do you have an update of this indicator since you've created them, or is this still the actu...
mcha Thank you for this work. Do you try to transform/put this indicator on candlesticks and is ...
David Balance thanks for sharing this excellent indicator.  Here are some thoughts.  please ad...
reb Hello Marc your strat seems very intersting, will take a look Reb
897148 What exactly is meant by Total price? Is r1 =28 in your example the no of days for "Total P...
otty82  THX looks good!
century nice one , thank you
arvindrao01 Hey! Does anyone have a pinescript (tradingview) code for this?
imokdesign Hi Everybody, when I look at the strategy I felt the need to implement a Moneymanagement-Sy...
Inertia newlevel then multiplier=multiplier+1 oldlevel=newlevel newlevel=strategyprofit+startequi...
Inertia Hi Bjoern, I was playing around with your code this morning (EUR/USD 5'). Thank you to the...
CavalierDeCesDames Bonjour Nicolas, Thanks for your use full job. I tried this indicator on a shorter timefram...
Nicolas You are welcome. I'm glad you like it.
Bolbo It does not appear over the price indicator on V11. Thanks in advance.
bearbull As per PhilipSchultz question above, has anybody managed to add code for when it turns blue,...
Ybr35 Bonjour Nicolas, lorsque je lance l'indicateur, il m'est indiqué que je dois définir les var...
Nicolas L'idéal est de télécharger le fichier itf joint sur cette page et de l'importer dans la plat...
Nicolas Merci dans ce cas d'ouvrir un sujet dans le forum ProScreener svp.
Andrea Hi Nicolas, thx for your code. Please i need your help to understand this part of your code:...
Nicolas the MA200 is ascending since 20 periods.
Regan2020 Hi, has anybody update the above code to enable on a 15m or 5m TF?
gigi64 ik heb de code op mijn pro realtime gezet , en bij indicator staat hij erbij maar komt niet ...
gigi64 I have put the code on my pro realtime, and it is on the indicator, but it does not appear o...
supertiti Thanks you so much Lucassen
dreif123 hi, copied the above code, not working on 10.3 the system says "return can only be used at ...
LUCASSEN Hallo , i have no problem , and i have the same versie 10.3, maybe you can ask Nicolas, tha...
Krallenmann Hallo Nicolas, kannst du mir die Regeln für den Halftrend Indikator sagen? Aus dem Code kann...
davefransman Dear Nicolas, i want set a alert on the "HalfTrend "custom moving average" met Heikin Ashi w...
Nicolas Please post the question in a new forum topic, that would need custom coding I believe.
Lyam Pareil ne marche pas dommage
ahmedbouaziz89 Bonjour, quand j'ajoute le code ou le fichier dans l'outils screeners de Prorealtime je ne v...
tyvix Bonjour le code marche bien c est juste qu'il n y a pas d opportunité au moment ou vous le...
verdi55 Is there such a thing as a free lunch ?
maceng Thanks Nicolas for this great work! I would like to understand the math behind it in order t...
Nicolas Sorry I have no time to provide assistance for python programmers. Have a good day.
Maz Hi all, firstly happy to know that this is helping you. I look into updating it for PRT11 wh...
Nicolas just use 3 times a linear regression channel code you will find in the library.
leederbyshire Here's the link to alternative linear regression channel indicator Nicolas is referring to t...
Wing Yes, investigate as much as you want. For more insight, you can view the linet1, linet2 etc....
CKW Hi Wing, Thanks for your sharing. I am still trying to breakdown & understand your code...
Wing Hello CKW. No, the parameter, 7 in this case, is used when calling the RSI indicator to ide...
Nicolas Je vais faire l'indicateur et expliquer comment en même temps dans un sujet de forum. Plus s...
gregus merci nicolas toute ma gratitude est pour toi sa sera bien pratique car je pense ne pas etre...
Nicolas Ok merci donc d'ouvrir un sujet spécifique pour cette demande donc :) 
algotrader This indicator looks coolBut on attempt to use it for a strategy dev'I get an error.."The in...
dajvop @algotrader if you at the bottom of the code add: RETURN Buffer1 as "up", Buffer2 as "down",...
Bateson Si cela peut servir, l'indicateur Sadukey a été créé en utilisant un générateur de filtre ap...

Top