AI Trend Navigator

AI Trend Navigator

This article provides a comprehensive guide to the AI Trend Navigator, an advanced technical indicator that leverages a K-Nearest Neighbors (KNN) machine learning logic to identify market trends and predict potential reversals directly within ProRealTime.

What is the AI Trend Navigator?

The AI Trend Navigator is designed to filter market noise by comparing current price action against a historical “window” of data. Unlike standard moving averages that simply lag behind the price, this tool uses a KNN Classifier to find the most similar historical data points (the “neighbors”) and uses their average to project a cleaner, more responsive trend line.

The indicator is highly versatile, allowing users to choose between various calculation methods such as VWAP, Exponential Moving Averages (EMA), and Hull Moving Averages (HMA) for both the data database and the current target.

How It Works: Technical Insights

The core of this indicator is a learning loop that performs the following steps:

  • Database Creation (valueIn): The script calculates a series of historical values based on your chosen source (e.g., Mid-Price, VWAP, or SMA).

  • Target Comparison (targetIn): It identifies the current market state using a separate target calculation.

  • Distance Calculation: For every bar in the historical window (default is 30 bars), the script calculates the absolute “distance” between the current target and past values.

  • KNN Averaging: It identifies the K (number of closest values) smallest distances and averages their corresponding prices to produce the Knn Classifier Line.

  • AI Prediction: It looks back at the 10 most recent patterns to see if similar price movements historically resulted in a bullish or bearish shift, which is then visualized via the background color.

Key Visual Elements

1. The Knn Classifier Line (Thick Line)

This is your primary trend signal. It is dynamically colored based on its slope:

  • Green: The KNN line is rising, indicating a bullish trend.

  • Red: The KNN line is falling, indicating a bearish trend.

  • Orange: The line is neutral or flat.

2. Average Knn Classifier Line (Thin Teal Line)

This line acts as a long-term baseline (smoothed by a Wilder Average). It helps traders distinguish between minor fluctuations and major trend shifts.

3. Predictive Background (Optional)

If enabled, the background provides a visual “forecast” from the AI logic:

  • Green Background: The AI logic predicts a higher probability of an upward move.

  • Red Background: The AI logic predicts a higher probability of a downward move.

Configuration & Settings

You can customize the indicator through the Variables menu in ProBuilder without touching the code.

Input Variable Default Description
priceValue 0

Source for the “Database” (0=HL2, 1=VWAP, 2=SMA, 4=EMA, etc.)

maLen 5

The period used to calculate the database values.

targetValue 0 The current target for comparison (0=Wilder, 1=VWAP, etc.).
numberOfClosestValues 3 The “K” in KNN. Higher values result in more smoothing.
smoothingPeriod 50

Long-term smoothing for the baseline and AI logic.

bgColour 0

Toggle (0 or 1) to enable/disable the predictive background.

ProBuilder Code

The following code should be pasted into the ProBuilder editor. Ensure you define the variables listed above in the “Variables” section of the indicator settings to enable full customization.

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. adeelq79 • 17 hours ago #

    Nice indicator. Works well when combined with 9EMA and other indicators.

  2. hartgeld • 2 hours ago #

    Hallo Ivan, leider lässt sich die Datei nicht importieren…..(Fehler im Dateiformat sagt PRT)…

avatar
Register or

Likes

avatar avatar
Related users ' posts
Nicolas
8 years ago
Nicolas https://www.prorealcode.com/topic/ayuda-screener-indicador-perfect-trend-line/#post-51291
Manu L. Bonjour Nicolas, suite a une de mes precedentes demande dans le forum indicateur, j'ai touv...
AntoGH C'est selon moi le meilleur indicateur, que j'ai vu, si vous trouvez mieux dîtes moi car dif...
Jiacky mma = average[per,1](close) should be mma = average[per,1](close * 1000). Otherwise TDF will...
bolsatrilera Hi Nicolas, I have this version of the True Balance Power ,created by eykpunter on Tradingvi...
bolsatrilera and the code : REM TRUE BALANCE OF POWER // código original de eykpunter para la plataform...
Steven Bahia Hi Nicolas - great indicator - is there a way to place a alert when the Oscillator crosses ...
Nicolas Alerts can't be programmed, you have to set them yourself with the Alert tool of the platfor...
Steven Bahia just to add to this would there be a way to establish a entry price from the Oscillator
juanj Hi Nicolas, this is very interesting. Do you mind maybe providing some more information on h...
avatar
fabioerliam Hi Nicolas...I don't know where to post my request.....sorry!!!! Can you tell me in a gener...
Nicolas Hi, please post your question in the ProOrder section of the forum.
juanj And the point of violation is the close of the candle that violates the line by generating a...
juanj For the latest version of the strategy or to follow updates and developments see the thread ...
phanz i backtested it with 10K units of EURUSD 1 hour i get an equity curve that is going one way ...
Wing Not yet but I plan to.
Leo Have a look in this Forum, I got something interesting for you... https://www.prorealcode.co...
Dávid Gyalus Dear Wing, As I am a daytrader, and one of my best friend is a programmer we think your a...
EchnatonX Hallo Im Demomodus bei IG habe ich das Problem, dass oft keine Orders ausgeführt werden kön...
Jan EchnatonX, nice late answer of me: Make the stop loss a percentage of the close, like 100/...
guleny Hello I made some optimization to make it better. But there are 5 transacttion which incr...
stratobast Good afternoon everyone. Thanks Doctrading for your work. I have an issue while using this ...
stratobast My bad guys. I understood what was the problem. The indicator uses highs and lows for the Re...
samwarduk Has anyone tried this on Bitcoin GBP1? The results look amazing but every time mine trie...
Kris75 Hi Bolsatrilera, I love this indicator! Thanks; => did you develop a strategy around...
Doctrading AH ok, I think the ca3 is the same : ca3 = pB[1] < 0.2 and pB < 0.2 Best regards,
chromosome21 Hello everybody, First, thank you so much for all your advices, I'm a begginer in trading a...
bertrandpinoy bonjour j ai un probleme avec ce code modifié, apparement PRT ne veut pas...avez vous une so...
rispardin no entiendo como funciana este indicador, por favor alguien podria explicar como utilizarlo???
AVT No se trata de un solo indicador, pero cada linea muestra otra información, de abajo hacia ...
IV Mcm Your indicator is interesting, I evaluated its relevance with the squeeze to detect the phas...
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?

Top