VWAP ANCHORED ;tendance haute et basse
Forums › ProRealTime forum Français › Support ProBuilder › VWAP ANCHORED ;tendance haute et basse
- This topic has 5 replies, 2 voices, and was last updated 1 year ago by larouedegann.
-
-
06/23/2023 at 4:10 PM #216668
Bonjour,
Voici un code mis en ligne par liquid-trader sur tradingview.
Ce script trace et met à jour automatiquement 3 VWAP distincts : un VWAP traditionnel, un VWAP ancré à une tendance haute et une autre ancrée à une tendance basse.
Les VWAP et les VWAP ancrés sont couramment utilisés par les institutions responsables de la majorité du volume du marché un jour donné. Citadel Trading, par exemple, représente environ 35 % de l’ensemble du volume de vente au détail coté aux États-Unis , en grande partie effectuée par le biais de transactions programmées au cours d’une journée, d’une semaine ou d’ un mois.
Étant donné que VWAP est un outil de création de marché de premier plan pour l’exécution de transactions importantes, les day traders peuvent l’utiliser pour mieux anticiper les tendances, le retour à la moyenne et les cassures.
Ceci est particulièrement utile sur les graphiques avec des délais intrajournaliers (1 minute, 5 minutes, etc.) couramment utilisés pour le day trading. Ce n’est pas idéal pour les périodes plus longues (1 heure ou plus) couramment utilisées pour le swing trading ou l’identification de tendances plus importantes.
N’étant pas programmeur, je vous joint le script ci-dessous.
Merci
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196//@version=5indicator("Anchored VWAP (Auto High & Low)", "AVWAP (Auto Hi / Lo)", overlay=true, max_bars_back=1440), max_bars_back(time, 1440)// Base Colorsnone = color.new(color.black, 100)clr1 = color.aquaclr2 = color.blue// VWAP Settingsvar shoVWAP = input.bool(true, "VWAP", "The Volume Weighted Average Price is reset at the beginning of each session.", inline="vwap")var vwapClr = input.color(clr2, "", inline="vwap")var vWidth = input.int(2, "", 1, inline="vwap")// High Anchorvar shoHiA = input.bool(true, "High Anchor", "VWAP anchored and weighted to trend highs.", inline="hi")var hiAnClr = input.color(clr1, "", inline="hi")var hiWidth = input.int(2, "", 1, inline="hi")// Low Anchorvar shoLoA = input.bool(true, "Low Anchor", "VWAP anchored and weighted to trend lows.", inline="lo")var loAnClr = input.color(clr1, "", inline="lo")var loWidth = input.int(2, "", 1, inline="lo")// Average of Anchorsvar shoMid = input.bool(true, "Average of Anchors", "The mean (average) between the high and low anchored VWAP's", inline="mid")var midClr = input.color(color.new(clr1, 50), "", inline="mid")var mWidth = input.int(2, "", 1, inline="mid")// Quarter levelsvar shoQrt = input.bool(true, "Quarter values", "The median (middle) value between the mean (average) and high / low anchors.", inline="quarter")var qrtClr = input.color(color.new(clr1, 80), "", inline="quarter")var qWidth = input.int(1,"", 1, inline="quarter")// Eight levels with fillvar shoFil = input.bool(true, "Interim Bands", "The ", inline="fill")var ethClr = input.color(color.new(clr1, 93), "", inline="fill")var filClr = input.color(color.new(clr1, 97), "", inline="fill")// Smooth Average of Anchorsvar shoMA = input.bool(false, "Smooth Average", inline="smooth")var maLen = input.int(3, "", 1, inline="smooth")var maSrc = input.string("SMMA (RMA)", "", ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "Linear Regression"], inline="smooth")// Define new sessions.newSession = timeframe.isdwm ? false : session.isfirstbar// Put common price calls into variables.o = open, h = high, l = low, c = close, index = bar_index// Define candle patterns and parts.candleBody = c > o ? c - o : o - crising = c > ofalling = o > cupWick = rising ? h - c : h - odnWick = falling ? c - l : o - ldoji = (upWick >= candleBody or dnWick >= candleBody) and (h != o and h != c and l != o and l != c)higher = o > o[1] and c > c[1]lower = o < o[1] and c < c[1]risingHigher = rising and higherfallingLower = falling and lower// Anchor variables.var hi = h, var lo = l, var anchoredHi = h, var anchoredLo = l, var resetHiAnchor = false, var resetLoAnchor = falsevar lastResetLo = indexvar lastResetHi = indexvar bullish = falsevar bearish = false// Logic for what qualifies as "breaking" the previous anchors.breakingHigher = rising and (c > hi or (c[1] > anchoredHi and c > h[1] and o > anchoredHi and not doji))breakingLower = falling and (c < lo or (c[1] < anchoredLo and c < l[1] and o < anchoredLo and not doji))// Logic for when to reset anchors.if newSessionhi := hlo := lresetHiAnchor := trueresetLoAnchor := truebullish := truebearish := truelastResetHi := not doji ? index : lastResetHilastResetLo := not doji ? index : lastResetLoelse if breakingHigherhi := hresetHiAnchor := truebullish := truelastResetHi := indexelse if breakingLowerlo := lresetLoAnchor := truebearish := truelastResetLo := indexelseresetHiAnchor := falseresetLoAnchor := false// Get how many number of bars have passed since the last reset.hiResetIndex = index - lastResetHiloResetIndex = index - lastResetLo// Set the Anchored VWAP, and their average.anchoredHi := ta.vwap(h, resetHiAnchor)anchoredLo := ta.vwap(l, resetLoAnchor)anchoredMean = math.avg(anchoredHi, anchoredLo)// Smooth the average according to the traders settings.if shoMAanchoredMean := switch maSrc"SMA" => ta.sma(anchoredMean, maLen)"EMA" => ta.ema(anchoredMean, maLen)"SMMA (RMA)" => ta.rma(anchoredMean, maLen)"WMA" => ta.wma(anchoredMean, maLen)"VWMA" => ta.vwma(anchoredMean, maLen)"Linear Regression" => ta.linreg(anchoredMean, maLen, 0)// Set the anchored quarter values.avg75 = math.avg(anchoredHi, anchoredMean), avg87 = math.avg(anchoredHi, avg75), avg62 = math.avg(avg75, anchoredMean)avg25 = math.avg(anchoredLo, anchoredMean), avg12 = math.avg(anchoredLo, avg25), avg42 = math.avg(anchoredMean, avg25)// VWAPvwapColor = newSession ? none : vwapClrvar showHideVWAP = shoVWAP ? display.pane : display.noneplot(ta.vwap(hlc3, timeframe.change("1D")), "VWAP", vwapColor, vWidth, plot.style_linebr, false, na, na, na, false, na, showHideVWAP)// Determine if a plot should display, based on the traders settings.displayPlot(ifTrue) =>_return_ = ifTrue ? display.pane : display.nonevar showHideH = displayPlot(shoHiA)var showHideL = displayPlot(shoLoA)var showHideM = displayPlot(shoMid)var showHideTopQ = displayPlot(shoHiA and shoQrt)var showHideBotQ = displayPlot(shoLoA and shoQrt)var showHideTopE = displayPlot(shoHiA and shoFil)var showHideBotE = displayPlot(shoLoA and shoFil)// Function defining abnormal candle move continuation.moveCont(a) =>switch a"higher" => hiResetIndex <= 5 and anchoredHi > anchoredHi[1]"lower" => loResetIndex <= 5 and anchoredLo < anchoredLo[1]// Function defining candle consolidation, relative to the previous anchor.consolidating(i) =>_return_ = o <= h[i] and c <= h[i] and o >= l[i] and c >= l[i]// Function to set the plot and fill colors.clr(a, c) =>ifTrue = switch a"top" => bullish and (resetHiAnchor or moveCont("higher") or consolidating(hiResetIndex))"bot" => bearish and (resetLoAnchor or moveCont("lower") or consolidating(loResetIndex))=> false_return_ = newSession ? none : ifTrue ? color.new(c, 75) : c// Set the plot and fill colors.tClr = clr("top", hiAnClr)bClr = clr("bot", loAnClr)mClr = clr("", midClr)qClr = clr("", qrtClr)fClr = clr("", filClr)eClr = clr("", ethClr)// Toggle the colors reset to be false, if it has been reset back to the user specified color.bullish := tClr == hiAnClr ? false : bullishbearish := bClr == loAnClr ? false : bearish// Plot the top, bottom, and average anchor values.top = plot(anchoredHi, "High Anchor", tClr, hiWidth, plot.style_linebr, false, na, na, na, false, na, showHideH)bot = plot(anchoredLo, "Low Anchor", bClr, loWidth, plot.style_linebr, false, na, na, na, false, na, showHideL)mid = plot(anchoredMean, "Average of Anchors", mClr, mWidth, plot.style_linebr, false, na, na, na, false, na, showHideM)// Plot 1/4 values (half way between average and anchor).t25 = plot(avg75, "Top 25% Line", qClr, qWidth, plot.style_linebr, false, na, na, na, false, na, showHideTopQ)b25 = plot(avg25, "Bottom 25% Line", qClr, qWidth, plot.style_linebr, false, na, na, na, false, na, showHideBotQ)// Plot 1/8 values.t12 = plot(avg87, "Top 12.5% Line",eClr, 1, plot.style_linebr, false, na, na, na, false, na, showHideTopE)t252 = plot(avg75, "Top 25% Line", eClr, 1, plot.style_linebr, false, na, na, na, false, na, showHideTopE)t42 = plot(avg62, "Top 42.5% Line",eClr, 1, plot.style_linebr, false, na, na, na, false, na, showHideTopE)b42 = plot(avg42, "Bottom 42.5% Line",eClr, 1, plot.style_linebr, false, na, na, na, false, na, showHideBotE)b252 = plot(avg25, "Bottom 25% Line", eClr, 1, plot.style_linebr, false, na, na, na, false, na, showHideBotE)b12 = plot(avg12, "Bottom 12.5% Line",eClr, 1, plot.style_linebr, false, na, na, na, false, na, showHideBotE)// Determine if the fill should display, based on the traders settings.displayFill(ifTrue) =>_return_ = ifTrue ? display.all : display.nonevar showHideF = displayFill(shoFil)var showHideTopF = displayFill(shoHiA and shoFil)var showHideBotF = displayFill(shoLoA and shoFil)// Plot fill.fill(top, t12, fClr, "Top 12.5% Fill", false, display = showHideTopF)fill(top, t25, fClr, "Top 25% Fill", false, display = showHideTopF)fill(top, t42, fClr, "Top 42.5% Fill", false, display = showHideTopF)fill(bot, b42, fClr, "Bottom 42.5% Fill", false, display = showHideBotF)fill(bot, b25, fClr, "Bottom 25% Fill", false, display = showHideBotF)fill(bot, b12, fClr, "Bottom 12.5% Fill", false, display = showHideBotF)06/29/2023 at 10:41 AM #216972Toujours personne ?
06/29/2023 at 1:25 PM #216983Selon la description d’origine: on trace un VWAP ordinaire (voir indicateur de base dans la plateforme) et 1 VWAP ancré à un sommet de tendance, et un autre ancré à un creux de tendance.
Le code ci-dessous trace les VWAP High et Low ancrés sur les bougies qui respectent les conditions décrites dans le code original:
1234567891011121314151617181920212223242526272829303132333435363738394041424344candleBody = abs(open-close)c=closeo=openrising = c > ofalling = o > cnewsession = intradaybarindex=0//upWick = rising ? h - c : h - oif rising thenupwick = high-closeelseupwick=high-openendif//dnWick = falling ? c - l : o - lif falling thendnwick=close-lowelsednwick=open-lowendifdoji = (upWick >= candleBody or dnWick >= candleBody) and (high <> o and high <> c and low <> o and low <> c)// Logic for what qualifies as "breaking" the previous anchors.breakingHigher = rising and (c[1] > anchoredHi and c > high[1] and o > anchoredHi and not doji)breakingLower = falling and (c[1] < anchoredLo and c < low[1] and o < anchoredLo and not doji)if breakinghigher or newsession thenhibar=barindexanchoredhi=highendifif breakinglower or newsession thenlobar=barindexanchoredlo=lowendifperiodhi = max(1,barindex-hibar)vwaphi = SUMMATION[periodhi](volume*high)/SUMMATION[periodhi](volume)periodlo = max(1,barindex-lobar)vwaplo = SUMMATION[periodlo](volume*low)/SUMMATION[periodlo](volume)return vwaphi, vwaplo06/29/2023 at 8:53 PM #217004Merci pour ton travail.
Voilà ce que j’obtiens avec l’indicateur et j’ai fais un imprime écran de trading view.
On s’aperçoit qu’ il manque quelque lignes suiveuses peut-être du au PLOT 1/4 values et PLOT 1/8 values ou PLOT fill.
Quant à la phrase “Determine if a plot should display, based on the trader settings” AUCUNE IDEE.
il manque pas grand chose, je pense pour atteindre le but
MERCI
06/30/2023 at 7:56 AM #217027Oui, je n’ai pas codé ces lignes, ce sont de simples divisions entre les VWAP haut et bas: par exemple pour la 1/4: soit prendre la distance entre vwap high et vwap low et ajouter 1/4 à celle du bas (vwaplow + 0.25*distance qui les sépare)
Je pense que tu devrais pouvoir atteindre ce but rapidement, j’ai pour le moment d’autres sujets bien plus complexe 🙂
06/30/2023 at 11:43 AM #217067OK MERCI pour ton travail
-
AuthorPosts
Find exclusive trading pro-tools on