Help for the translation from trading view
Forums › ProRealTime English forum › ProRealTime platform support › Help for the translation from trading view
- This topic has 3 replies, 2 voices, and was last updated 2 days ago by Annchow8052014.
Viewing 4 posts - 1 through 4 (of 4 total)
-
-
04/24/2024 at 4:32 AM #231868
Hi All,
I would like to ask for help to translate a script from tradingview as below with thanks in advance
AI Trend Navigator by Zeiierma04/24/2024 at 10:50 AM #23188204/24/2024 at 11:49 AM #231885AI Trend Navigator123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/// © Zeiierman {//@version=5indicator('AI Trend Navigator', overlay=true)// ~~ Tooltips {t1 ="PriceValue selects the method of price computation. \n\nSets the smoothing period for the PriceValue. \n\nAdjusting these settings will change the input values for the K-Nearest Neighbors algorithm, influencing how the trend is calculated."t2 = "TargetValue specifies the target to evaluate. \n\nSets the smoothing period for the TargetValue."t3 ="numberOfClosestValues sets the number of closest values that are considered when calculating the KNN Moving Average. Adjusting this number will affect the sensitivity of the trend line, with a higher value leading to a smoother line and a lower value resulting in a line that is more responsive to recent price changes."t4 ="smoothingPeriod sets the period for the moving average applied to the KNN classifier. Adjusting the smoothing period will affect how rapidly the trend line responds to price changes, with a larger smoothing period leading to a smoother line that may lag recent price movements, and a smaller smoothing period resulting in a line that more closely tracks recent changes."t5 ="This option controls the background color for the trend prediction. Enabling it will change the background color based on the prediction, providing visual cues on the direction of the trend. A green color indicates a positive prediction, while red indicates a negative prediction."//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Inputs {PriceValue = input.string("hl2", options = ["hl2","VWAP", "sma", "wma", "ema", "hma"], group="", inline="Value")maLen = input.int(5, minval=2, maxval=200, title="", group="", inline="Value", tooltip=t1)TargetValue = input.string("Price Action", options = ["Price Action","VWAP", "Volatility", "sma", "wma", "ema", "hma"], group="", inline="Target")maLen_ = input.int(5, minval=2, maxval=200, title="", group="", inline="Target", tooltip=t2)// Input parameters for the KNN Moving AveragenumberOfClosestValues = input.int(3, "Number of Closest Values", 2, 200, tooltip=t3)smoothingPeriod = input.int(50, "Smoothing Period", 2, 500, tooltip=t4)windowSize = math.max(numberOfClosestValues, 30)// knn ColorUpknn_col = input.color(color.lime, title="", group="KNN Color", inline="knn col")Dnknn_col = input.color(color.red, title="", group="KNN Color", inline="knn col")Neuknn_col = input.color(color.orange, title="", group="KNN Color", inline="knn col")// MA knn ColorMaknn_col = input.color(color.teal, title="", group="MA KNN Color", inline="MA knn col")// BG Colorbgcolor = input.bool(false, title="Trend Prediction Color", group="BG Color", inline="bg", tooltip=t5)Up_col = input.color(color.lime, title="", group="BG Color", inline="bg")Dn_col = input.color(color.red, title="", group="BG Color", inline="bg")//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ kNN Classifier {value_in = switch PriceValue"hl2" => ta.sma(hl2,maLen)"VWAP" => ta.vwap(close[maLen])"sma" => ta.sma(close,maLen)"wma" => ta.wma(close,maLen)"ema" => ta.ema(close,maLen)"hma" => ta.hma(close,maLen)meanOfKClosest(value_,target_) =>closestDistances = array.new_float(numberOfClosestValues, 1e10)closestValues = array.new_float(numberOfClosestValues, 0.0)for i = 1 to windowSizevalue = value_[i]distance = math.abs(target_ - value)maxDistIndex = 0maxDistValue = closestDistances.get(0)for j = 1 to numberOfClosestValues - 1if closestDistances.get(j) > maxDistValuemaxDistIndex := jmaxDistValue := closestDistances.get(j)if distance < maxDistValueclosestDistances.set(maxDistIndex, distance)closestValues.set(maxDistIndex, value)closestValues.sum() / numberOfClosestValues// Choose the target input based on user selectiontarget_in = switch TargetValue"Price Action" => ta.rma(close,maLen_)"VWAP" => ta.vwap(close[maLen_])"Volatility" => ta.atr(14)"sma" => ta.sma(close,maLen_)"wma" => ta.wma(close,maLen_)"ema" => ta.ema(close,maLen_)"hma" => ta.hma(close,maLen_)knnMA = meanOfKClosest(value_in,target_in)//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ kNN Prediction {// Function to calculate KNN Classifierprice = math.avg(knnMA, close)c = ta.rma(knnMA[1], smoothingPeriod)o = ta.rma(knnMA, smoothingPeriod)// Defines KNN function to perform classificationknn(price) =>Pos_count = 0Neg_count = 0min_distance = 10e10nearest_index = 0for j = 1 to 10distance = math.sqrt(math.pow(price[j] - price, 2))if distance < min_distancemin_distance := distancenearest_index := jNeg = c[nearest_index] > o[nearest_index]Pos = c[nearest_index] < o[nearest_index]if PosPos_count += 1if NegNeg_count += 1output = Pos_count>Neg_count?1:-1// Calls KNN function and smooths the predictionknn_prediction_raw = knn(price)knn_prediction = ta.wma(knn_prediction_raw, 3)//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Plots {// Plots for display on the chartknnMA_ = ta.wma(knnMA,5)knnMA_col = knnMA_>knnMA_[1]?Upknn_col:knnMA_<knnMA_[1]?Dnknn_col:Neuknn_colClassifier_Line = plot(knnMA_,"Knn Classifier Line", knnMA_col)MAknn_ = ta.rma(knnMA, smoothingPeriod)plot(MAknn_,"Average Knn Classifier Line" ,Maknn_col)green = knn_prediction < 0.5red = knn_prediction > -0.5bgcolor( green and bgcolor? color.new(Dn_col,80) :red and bgcolor ? color.new(Up_col,80) : na)//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Alerts {knnMA_cross_Over_Ma = ta.crossover(knnMA_,MAknn_)knnMA_cross_Under_Ma = ta.crossunder(knnMA_,MAknn_)knnMA_cross_Over_Close = ta.crossover(knnMA_,close)knnMA_cross_Under_Close = ta.crossunder(knnMA_,close)knnMA_Switch_Up = knnMA_[1]<knnMA_ and knnMA_[1]<=knnMA_[2]knnMA_Switch_Dn = knnMA_[1]>knnMA_ and knnMA_[1]>=knnMA_[2]knnMA_Neutral = knnMA_col==Neuknn_col and knnMA_col[1]!=Neuknn_colgreenBG = green and not green[1]redBG = red and not red[1]alertcondition(knnMA_cross_Over_Ma, title = "Knn Crossover Average Knn", message = "Knn Crossover Average Knn")alertcondition(knnMA_cross_Under_Ma, title = "Knn Crossunder Average Knn", message = "Knn Crossunder Average Knn")alertcondition(knnMA_cross_Over_Close, title = "Knn Crossover Close", message = "Knn Crossover Close")alertcondition(knnMA_cross_Under_Close, title = "Knn Crossunder Close", message = "Knn Crossunder Close")alertcondition(knnMA_Switch_Up, title = "Knn Switch Up", message = "Knn Switch Up")alertcondition(knnMA_Switch_Dn, title = "Knn Switch Dn", message = "Knn Switch Dn")alertcondition(knnMA_Neutral, title = "Knn is Neutral", message = "Knn is Neutral")alertcondition(greenBG, title = "Positive Prediction", message = "Positive Prediction")alertcondition(redBG, title = "Negative Prediction", message = "Negative Prediction")//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}Hi GraHal,
Noted with thanks for your reminding.
Here above is the code, please help me for the translation in your convenience with thanks.
05/03/2024 at 5:33 PM #232290Hi All,
Can anyone help me to convert the above indicator with thanks.
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
Find exclusive trading pro-tools on
Similar topics: