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

avatar
Register or
Related users ' posts
Iván
1 year ago
Madrosat Bonjour ivan Quelle différence il y a t il entre Extra trend et ultra trend lequel est le p...
MaoRai54 dear Ivan, it seems to be very interesting but please clarify what are all the lines I see i...
Iván Hi! you have the answer in the last line of code... MacdMiddle as "histo" style(histogra...
kats Le Top , a utiliser avec le nuage violet et alerte TN pour plus de précision.
Iván Hi! yes. You can ask for it here: https://www.prorealcode.com/free-code-conversion/
roccafragius Thank you so much Ivan! I created this request in english Translate from TradingView Indicat...
ipbvba Hello, Is it possible to have a screener for the various buy and sell signals?
Regisnew très bel indicateur merci
Jean2139 Bonjour Yvan, Merci pour ton indicateur que je trouve très intéressant. Je suppose que tu ...
Suffi Hier eine kleine Korrektur: //-----Inputs-----------------------------------------// MALengt...
kats Bonjour, J'ai une question etes vous trader? Je m'explique , j'ai téléchargé tous les indi...
Faisalx Hola Ivan. Thanks for your great job. I would appreciate if you have look at my request http...
roccafragius Thank you for all these useful information!! Very great job Ivan! THank you so much
geroniman Merci Ivan, super travail. On peut toujours compter sur toi pour apporter des innovations su...
Stenozar Ciao IVAN , mi da errore per la riga 49 "print tema low"; puoi suggerirmi la modifica da met...
Iván Avete provato a scaricare il file .itf?
AndyB72 Caricato ora sulla V12, nessun errore.
Iván Allora crei un nuovo post. Lo aspetterò.
Stenozar Ciao Ivan, ho inserito il post con la richiesta di traduzione. Se puoi vedere, grazie!
Iván perfect!
kats BONSOIR c bon merci j ai trouve ce weekend merci de votre reponse cdlt
the_giorgio Hi, nice work I would like to understand something about prorealtime code. With your ...
Iván Hello. When you use the drawcandle() instruction then in the configuration window you add ...
Gaspare Ciao Ivan si puo' inserire una strategia su questo indicatore per ottimizzare le variabil...
Iván
2 years ago
Iván Si lo descargas e importas en tu PRT verás que se han creado las variables para luego config...
WhyAskOZ Hi, Ivan As always you are doing great coding. The code works on my PRT, however the issu...
Iván You can delete in the last line (return) the configuration for color. Delete coloured(xx,xx,...
Bernard13 (Je réécris mon commentaire -français- en français car certains mots ne correspondaient pas ...
Iván 1000 indicateurs !!! brutaux
Iván Gracias! Para el screener sólo tienes que copiar el indicador y poner como condición de búsq...
Lean Muchas gracias Iván, ya lo he podido crear.
bertoluce Hello Ivan, thank you very much for the indicator. An observation: would it be possible (and...
Doddge Hola Iván, ¿sería posible crear un screener que indique cuándo las velas coloreadas del indi...
RTR Ivan thank you for the pro-screener. I a trying to understand how to write the signals from ...
Iván Hi, Lines 62 and 63. These lines define buy and sell conditions.
Iván Hi You should delete from the indicator code all drawing functions and all variables not us...
Iván I've created a screener to show [longcondition or shortcondition]
Chrisinobi Hallo Ivan, Danke das ist Perfekt !! Kannst du bitte in der Screener-Bibliothek die itf. hoc...
MaoRai54 Thanks, now it's OK. in your first code at line 15-16 it's missing.
Madrosat Hello Ivan Did you try a strategy with this indicator
Iván Hi. No I didn't. This is a code translation requested by an user a few days ago.
Iván
2 years ago
cjr30 Simplemente modifica las lineas 19 y 21 por las siguientes: drawtext("▲",barindex,low-0.1*a...
groelandes Gracias!!
WhyAskOZ i copied the code into strategy and it gives error on line 21 and 23. it says " Line 1: ...
Iván
2 years ago
Madrosat Hello Ivan You have interesting topics on indicators , smart supertrend, optimised trend t...
Iván Hi! thanks. All of these codes are translations requested in the forum. I've on mind to back...
Raspete01 Buenos días Iván, estoy intentando llevar el código eliminando los colores y pasando un Back...

Top