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
Nicolas Il doit s'agir d'un mauvais copier/coller. Je suggère de télécharger le fichier itf contenu ...
Bard Hello @Nicolas, I can get this to display in a separate indicator panel but not on Price as ...
Stenozar Hi @Nicolas, how can I put the bands on price? Thanks, Stefano
Guillaume Mcm I gave the above message fix ;)
Tradingrob Is it possible to put the itf-file in the right way here in Prorealcode? so the right 'trend...
Guillaume Mcm Update link ;) https://www.prorealcode.com/topic/trend-histogramme-cci-mise-a-jour-suite-...
Screw27 Hi man, I installed the indicator and i don't know why but my graph it is so big
HelixKing sounds interesting I'll take a look
Godo Bonjour Souhait Sam, Après de nombreux essais pour le mettre en format afin d'utiliser ce c...
Nicolas Il faut supprimer celles qui existent dans la fenêtre d'optimisation et les créer en dur dan...
crusoe76 hi there, anyone can help making this strategy work, i have a message saying replace variabl...
Screw27 Salut nicolas j'aimerais savoir tes résulats grace a cettte methode
eva.g.forsgren It dose not work, I get a strap instead of candels???????????????????????????????????????????
Nicolas That indicator is the one below the chart. The indicator to put on the price chart is this o...
pyhrus P.S : IG , que j'ai contacté ,m'indique que la version V11 , ne sera pas disponible avant un...
Hasardeur Dear Nicolas, is there someting at the arry to modify in order to run the trend at the actu...
MALIMALO Dear Nicolas, just try touse your indicator with backtest but it's not working. is anybody...
ribes65 Bonjour Nicolas, Merci pour votre travail. Est-il envisageable de créer un screener pour ...
Nicolas Bien sûr, merci de formuler une demande dans le forum des screeners pour prorealtime. En res...
ipbvba Est il possible de le transformer en indicateur (pour ne plus avoir les lignes mais uniqueme...
supertiti Bonjour Nicolas, Je ne comprend pas bien , le trend change de couleur quand les prix sont a...
Nicolas Oui ce serait possible, cependant l'indicateur est bien prévu pour conserver la couleur de l...
supertiti Quand tu pourras si tu peux nous coder la troisième couleur cela améliorerait les trades cou...
Nicolas How to import file page: in the help section of the website explains howto
kenssa import through the indicator page/window in the Proreal time
chicoteca Buenas, no consigo que se me muestre en el chart de DAX. ¿Cómo procedo? Gracias.-
frenqle Hi There.. It seems the TSL stop loss is not working.. it does not respond is that correct?
Ciccarelli Franco Per lasciare che la strategia venga eseguita (dopo aver importato il file): Basta eliminare...
JADINVEST Hello Jan, hello everyone, Thanks Jan for this strategy! Since 2020, have any of you found a...
Stockastiss Can this code be simply transferred into Backtestingcode so one doesnt need to use call ? (i...
Vonasi Sorry for the late reply. Add the code to your strategy and remove line 5 and line 39. Chang...
viktorthunss Hi! How many averages are there? Can I see the somewhere?
leofi https://www.prorealcode.com/topic/simple-average-with-visual-color/
leofi Go visit www.prorealcode.com/topic/simple-average-with-visual-color/ and watch 2em post
Dritan Hi,I am new on Prorealtime and coding.I downloaded the indi but I have it on a separate wind...
Nicolas Just add it on the price series.
yomisadiku Hello Nicolas, Can I use high and low price at lines hh=max(hh,close) and ll=min(ll,close) ...
Nicolas Yes you can do that, the impact will be that the trailing stop line will be much close to th...
Byggtrader Hi Nicolas! How do I get the indicator in the price chart? It only stays under i new chart.
Nicolas Just add it on the price chart by using the wrench on the left upper side of the chart (pric...
Dom Hello, hello....je commence le trading et découvre par la même occasion le codage....et ce n...
Nicolas Merci, ça fait plaisir !
Be-n Bonjour tout le monde ! Dans l'indicateur de tendance, j'ai du mal à saisir la nuance entre ...
Globalmarkets79 Thank you Vonasi for the answer. I have an other question. When i tried to run the indicator...
Vonasi Lines is either 0 or 1 to turn on or off the drawing of them. Once again if you download and...
Globalmarkets79 Thank you Vonasi, this indicator is very helpful!!!
Nicolas
5 years ago
Bateson Merci pour la réponse Nicolas. C'est bien ce que j'ai fait mais ça ne fonctionne toujours pa...
Enzo Paliotti Veramente ottimo, era quello che cercavo, si potrebbe modificare inserendo come variazione a...
Nicolas Perché no, chiedetelo con una descrizione dettagliata nel forum degli indicatori, per favore!
jiddan78 how to convert to afl amibroker ?
Nicolas We do not supply free coding assistance for AFL Amibroker on the website. You can ask for pa...
Ngomsi @ Vonasi, how to use timeframe , 13 minutes ,21 minutes, 34 minutes,et 55 minutes with this...

Top