Vidya Quantile Bands
Forums › ProRealTime forum Français › Support ProBuilder › Vidya Quantile Bands
- This topic has 2 replies, 2 voices, and was last updated 1 month ago by
Bateson.
Viewing 3 posts - 1 through 3 (of 3 total)
-
-
02/23/2025 at 12:39 PM #244218
Bonjour
Je suis en train de finir l’étude de la Vidya et j’aurai besoin d’un dernier coup de main pour traduire le code Trading View ci-dessous.
Merci d’avance !Vidya Quantile123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © loxx//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0///@version=5indicator('STD-Stepped VIDYA w/ Quantile Bands [Loxx]',shorttitle = "STDDVIDYAQB [Loxx]",overlay = true,timeframe="",timeframe_gaps=true)import loxx/loxxexpandedsourcetypes/3greencolor = #2DD204redcolor = #D2042DSM02 = 'Slope'SM03 = 'Middle Crossover'SM04 = 'Levels Crossover'_filt(src, len, filter)=>price = srcfiltdev = filter * ta.stdev(src, len)price := math.abs(price - price[1]) < filtdev ? price[1] : pricepricesmthtype = input.string("Kaufman", "Heikin-Ashi Better Caculation Type", options = ["AMA", "T3", "Kaufman"], group = "Basic Settings")srcin = input.string("Close", "Source", group= "Basic Settings",options =["Close", "Open", "High", "Low", "Median", "Typical", "Weighted", "Average", "Average Median Body", "Trend Biased", "Trend Biased (Extreme)","HA Close", "HA Open", "HA High", "HA Low", "HA Median", "HA Typical", "HA Weighted", "HA Average", "HA Average Median Body", "HA Trend Biased", "HA Trend Biased (Extreme)","HAB Close", "HAB Open", "HAB High", "HAB Low", "HAB Median", "HAB Typical", "HAB Weighted", "HAB Average", "HAB Average Median Body", "HAB Trend Biased", "HAB Trend Biased (Extreme)"])per = input(9, 'Period', group= "Basic Settings")histPer = input(30, 'Hist Period', group= "Basic Settings")filterop = input.string("Both", "Filter Options", options = ["Price", "VIDYA", "Both"], group= "Filter Settings")filter = input.float(0, "Filter Devaitions", minval = 0, group= "Filter Settings")filterperiod = input.int(1, "Filter Period", minval = 0, group= "Filter Settings")FlPeriod = input.int(25, "Levels Period", group = "Levels Settings")FlUp = input.float(80 , "Up Level", group = "Levels Settings")FlDn = input.float(20 , "Down Level", group = "Levels Settings")sigtype = input.string(SM03, "Signal type", options = [SM02, SM03, SM04], group = "Signal Settings")colorbars = input.bool(false, "Color bars?", group = "UI Options")showsignals = input.bool(false, "Show signals?", group = "UI Options")kfl=input.float(0.666, title="* Kaufman's Adaptive MA (KAMA) Only - Fast End", group = "Moving Average Inputs")ksl=input.float(0.0645, title="* Kaufman's Adaptive MA (KAMA) Only - Slow End", group = "Moving Average Inputs")amafl = input.int(2, title="* Adaptive Moving Average (AMA) Only - Fast", group = "Moving Average Inputs")amasl = input.int(30, title="* Adaptive Moving Average (AMA) Only - Slow", group = "Moving Average Inputs")haclose = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)haopen = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)hahigh = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)halow = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)hamedian = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hl2)hatypical = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hlc3)haweighted = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hlcc4)haaverage = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, ohlc4)src = switch srcin"Close" => loxxexpandedsourcetypes.rclose()"Open" => loxxexpandedsourcetypes.ropen()"High" => loxxexpandedsourcetypes.rhigh()"Low" => loxxexpandedsourcetypes.rlow()"Median" => loxxexpandedsourcetypes.rmedian()"Typical" => loxxexpandedsourcetypes.rtypical()"Weighted" => loxxexpandedsourcetypes.rweighted()"Average" => loxxexpandedsourcetypes.raverage()"Average Median Body" => loxxexpandedsourcetypes.ravemedbody()"Trend Biased" => loxxexpandedsourcetypes.rtrendb()"Trend Biased (Extreme)" => loxxexpandedsourcetypes.rtrendbext()"HA Close" => loxxexpandedsourcetypes.haclose(haclose)"HA Open" => loxxexpandedsourcetypes.haopen(haopen)"HA High" => loxxexpandedsourcetypes.hahigh(hahigh)"HA Low" => loxxexpandedsourcetypes.halow(halow)"HA Median" => loxxexpandedsourcetypes.hamedian(hamedian)"HA Typical" => loxxexpandedsourcetypes.hatypical(hatypical)"HA Weighted" => loxxexpandedsourcetypes.haweighted(haweighted)"HA Average" => loxxexpandedsourcetypes.haaverage(haaverage)"HA Average Median Body" => loxxexpandedsourcetypes.haavemedbody(haclose, haopen)"HA Trend Biased" => loxxexpandedsourcetypes.hatrendb(haclose, haopen, hahigh, halow)"HA Trend Biased (Extreme)" => loxxexpandedsourcetypes.hatrendbext(haclose, haopen, hahigh, halow)"HAB Close" => loxxexpandedsourcetypes.habclose(smthtype, amafl, amasl, kfl, ksl)"HAB Open" => loxxexpandedsourcetypes.habopen(smthtype, amafl, amasl, kfl, ksl)"HAB High" => loxxexpandedsourcetypes.habhigh(smthtype, amafl, amasl, kfl, ksl)"HAB Low" => loxxexpandedsourcetypes.hablow(smthtype, amafl, amasl, kfl, ksl)"HAB Median" => loxxexpandedsourcetypes.habmedian(smthtype, amafl, amasl, kfl, ksl)"HAB Typical" => loxxexpandedsourcetypes.habtypical(smthtype, amafl, amasl, kfl, ksl)"HAB Weighted" => loxxexpandedsourcetypes.habweighted(smthtype, amafl, amasl, kfl, ksl)"HAB Average" => loxxexpandedsourcetypes.habaverage(smthtype, amafl, amasl, kfl, ksl)"HAB Average Median Body" => loxxexpandedsourcetypes.habavemedbody(smthtype, amafl, amasl, kfl, ksl)"HAB Trend Biased" => loxxexpandedsourcetypes.habtrendb(smthtype, amafl, amasl, kfl, ksl)"HAB Trend Biased (Extreme)" => loxxexpandedsourcetypes.habtrendbext(smthtype, amafl, amasl, kfl, ksl)=> hacloseprice = filterop == "Both" or filterop == "Price" and filter > 0 ? _filt(src, filterperiod, filter) : srck = ta.stdev(price, per) / ta.stdev(price, histPer)sc = 2 / (per + 1)vidya = 0.0vidya := nz(k * sc * price + (1 - k * sc) * vidya[1], 0)out = filterop == "Both" or filterop == "VIDYA" and filter > 0 ? _filt(vidya, filterperiod, filter) : vidyasig = out[1]flhi = ta.percentile_linear_interpolation(out, FlPeriod, FlUp)mid = ta.percentile_linear_interpolation(out, FlPeriod, (FlUp+FlDn)/2.0)fllo = ta.percentile_linear_interpolation(out, FlPeriod, FlDn)state = 0.if sigtype == SM02if (out<sig)state :=-1if (out>sig)state := 1else if sigtype == SM03if (out<mid)state :=-1if (out>mid)state := 1else if sigtype == SM04if (out<fllo)state :=-1if (out>flhi)state := 1colorfish = state == -1 ? redcolor : state == 1 ? greencolor : color.grayplot(out, color= colorfish, title="Fisher", linewidth = 3)plot(flhi, "High Level", color = color.gray)plot(fllo, "Low Level" ,color = color.gray)plot(mid, "Middle", color = color.white)barcolor(colorbars ? colorfish : na)goLong = sigtype == SM02 ? ta.crossover(out, sig) : sigtype == SM03 ? ta.crossover(out, mid) : ta.crossover(out, flhi)goShort = sigtype == SM02 ? ta.crossunder(out, sig) : sigtype == SM03 ? ta.crossunder(out, mid) : ta.crossunder(out, fllo)plotshape(goLong and showsignals, title = "Long", color = color.yellow, textcolor = color.yellow, text = "L", style = shape.triangleup, location = location.belowbar, size = size.tiny)plotshape(goShort and showsignals, title = "Short", color = color.fuchsia, textcolor = color.fuchsia, text = "S", style = shape.triangledown, location = location.abovebar, size = size.tiny)alertcondition(goLong, title="Long", message="STD-Stepped VIDYA w/ Quantile Bands [Loxx]: Long\nSymbol: {{ticker}}\nPrice: {{close}}")alertcondition(goShort, title="Short", message="STD-Stepped VIDYA w/ Quantile Bands [Loxx]: Short\nSymbol: {{ticker}}\nPrice: {{close}}")02/24/2025 at 12:25 PM #244281Voici ce que vous avez :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198//-------------------------------------------------////PRC_Vidya Quantile Bands//version = 0//24.02.25//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//-------------------------------------------------//// PARAMETERS & CONFIGURATIONS//-------------------------------------------------//// VIDYA calculation periodsPer = 9 // VIDYA calculation periodHistPer = 30 // Historical period for standard deviation// Quantile levels settingsFlPeriod = 25 // Period for quantile levels calculationFlUp = 80 // Upper quantile level (80%)FlDn = 20 // Lower quantile level (20%)// Filter settingsFilterOp = 1 // 1 = Price, 2 = VIDYA, 3 = BothFilter = 2FilterPeriod = 1// Source type selection (1 = Close, 2 = Open, 3 = High, 4 = Low, 5 = Heikin-Ashi Close)srcType = 1// Signal type selection (1 = Slope, 2 = Middle Crossover, 3 = Levels Crossover)SigType = 2 // Default: Middle Crossover// Enable or disable signal plotting on chartShowSignals = 1//-------------------------------------------------//// HEIKIN-ASHI CANDLE CALCULATION//-------------------------------------------------//once haopen = openhaclose = (open + close + high + low) / 4IF barindex > 0 THENhaopen = (haopen + haclose[1]) / 2ENDIFhalow = min(low, min(haclose, haopen))hahigh = max(high, max(haclose, haopen))//-------------------------------------------------//// SELECT DATA SOURCE//-------------------------------------------------//IF srcType = 1 THENsrc = CloseELSIF srcType = 2 THENsrc = OpenELSIF srcType = 3 THENsrc = HighELSIF srcType = 4 THENsrc = LowELSIF srcType = 5 THENsrc = HACloseELSEsrc = CloseENDIF//-------------------------------------------------//// VIDYA CALCULATION//-------------------------------------------------//once vidya = 0IF barindex > max(Per, HistPer) THEN// ------------------------------// PRICE FILTERING// ------------------------------IF FilterOp = 3 OR (FilterOp = 1 AND Filter > 0) THENiPrice = srcStdDevFilter = Filter * STD[FilterPeriod](src)IF ABS(iPrice - iPrice[1]) < StdDevFilter THENiPrice = iPrice[1]ELSEiPrice = iPriceENDIFELSEiPrice = srcENDIF// ------------------------------// VIDYA COMPUTATION// ------------------------------k = STD[Per](iPrice) / STD[HistPer](iPrice)sc = 2 / (Per + 1)vidya = k * sc * iPrice + (1 - k * sc) * vidya[1]// ------------------------------// VIDYA FILTERING FOR OUTPUT// ------------------------------IF FilterOp = 3 OR (FilterOp = 2 AND Filter > 0) THENOut = vidyaStdDevFilterVIDYA = Filter * STD[FilterPeriod](vidya)IF ABS(Out - Out[1]) < StdDevFilterVIDYA THENOut = Out[1]ELSEOut = OutENDIFELSEOut = vidyaENDIFENDIFSig = Out[1]//-------------------------------------------------//// QUANTILE LEVELS CALCULATION//-------------------------------------------------//// Store last <code>FlPeriod</code> values of <code>OutFOR i = 0 TO FlPeriod - 1 DO$OutArray[i] = Out[i]NEXT// Sort array in descending orderArraySort($OutArray, DESCEND)// Extract percentile levelsflhi = $OutArray[ROUND(FlPeriod * (FlUp / 100))] // 80% percentile (upper level)mid = $OutArray[ROUND(FlPeriod * ((FlUp + FlDn) / 200))] // 50% percentile (middle level)fllo = $OutArray[ROUND(FlPeriod * (FlDn / 100))] // 20% percentile (lower level)//-------------------------------------------------//// TREND STATE DETERMINATION//-------------------------------------------------//state = 0IF SigType = 1 THENIF Out < Sig THENstate = -1ELSIF Out > Sig THENstate = 1ENDIFELSIF SigType = 2 THENIF Out < mid THENstate = -1ELSIF Out > mid THENstate = 1ENDIFELSIF SigType = 3 THENIF Out < FlDn THENstate = -1ELSIF Out > FlUp THENstate = 1ENDIFENDIF//-------------------------------------------------//// COLOR ASSIGNMENT BASED ON TREND STATE//-------------------------------------------------//IF state = -1 THENr = 210g = 4b = 45 // Red for downtrendELSIF state = 1 THENr = 45g = 210b = 4 // Green for uptrendELSEr = 123g = 123b = 123 // Gray for neutral trendENDIF//-------------------------------------------------//// SIGNAL GENERATION (ENTRY & EXIT)//-------------------------------------------------//IF SigType = 1 THENgoLong = Out CROSSES OVER SiggoShort = Out CROSSES UNDER SigELSIF SigType = 2 THENgoLong = Out CROSSES OVER midgoShort = Out CROSSES UNDER midELSIF SigType = 3 THENgoLong = Out CROSSES OVER flhigoShort = Out CROSSES UNDER flloENDIF//-------------------------------------------------//// SIGNAL DISPLAY ON CHART//-------------------------------------------------//atr = averagetruerange[14](close)IF goLong AND ShowSignals THENDRAWTEXT("▲", BarIndex, Low - 0.5 * atr, Dialog, Bold, 10) COLOURED(0, 0, 255) // Blue for long entryELSIF goShort AND ShowSignals THENDRAWTEXT("▼", BarIndex, High + 0.5 * atr, Dialog, Bold, 10) COLOURED(255, 0, 255) // Fuchsia for short entryENDIF//-------------------------------------------------//RETURN Out COLOURED(r, g, b) STYLE(LINE, 3),flhi COLOURED("grey"),fllo COLOURED("grey"),mid COLOURED("orange")02/24/2025 at 1:28 PM #244283Bonjour Ivan
Vraiment un très grand merci pour le code qui fonctionne parfaitement.
Le code est vraiment très “propre”, c’est du très bon travail !
Le fait d’avoir bien séparé et décrit les différentes “modules” de calcul dans le code va me permettre de faire quelques modifications ciblées.
Encore un très grand merci pour votre contribution -
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)