Traduction Premium/discount zone
Forums › ProRealTime forum Français › Support ProBuilder › Traduction Premium/discount zone
- This topic has 5 replies, 2 voices, and was last updated 3 weeks ago by Iván.
-
-
11/06/2024 at 11:46 AM #240028
Bonjour à tous et principalement à Nicolas et Ivan qui font un superbe travail sur ce site.
Je voudrais traduire un code que je trouve très intéressant sur Tradingview. Je pense que ce serait un indicateur très utile à tous sur le site.
Cet indicateur permet d’identifier des zones discount et premium + des macro zones plus long terme.
Le détail du code est expliqué dans ce lien :
Ci-dessous le code en version pinescript :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199// This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International// © BigBeluga//@version=5indicator("Premium & Discount Delta Volume [BigBeluga]",overlay = true, max_lines_count = 2, max_boxes_count = 3)// INPUTS --------------------------------------------------------------------------------------------------------------// @variable: Toggle to show Support and Resistance levelsbool showSR = input.bool(true, "", inline = "0")// @variable: Lookback period for calculating Support and Resistanceint srPeriod = input.int(50, "Premium & Discount Lookback Period", minval = 10, step = 10, inline = "0",tooltip = "Lookback period for Premium & Discount Levels with Delta Volume")// @variable: Toggle to show macro High and Low levelsbool showMacro = input.bool(true, "", inline = "1")// @variable: Lookback period for calculating macro Highs and Lowsint macroPeriod = input.int(200, "Macro Lookback Period", minval = 10, step = 10, inline = "1",tooltip = "Lookback period for Macro Highs/Lows and Delta Volume")// Color variables for trendscolor upColor = input.color(#79c1f1, "Discount", inline = "col", group = "Color")color downColor = input.color(#f19579, "Premium", inline = "col", group = "Color")// ARRAYS FOR STORING DATA ---------------------------------------------------------------------------------------------// Arrays to store high/low data for S/R levelsvar float[] srHighs = array.new_float(srPeriod, 0.)var float[] srLows = array.new_float(srPeriod, 0.)// Arrays to store high/low data for Macro levelsvar float[] macroHighs = array.new_float(macroPeriod, 0.)var float[] macroLows = array.new_float(macroPeriod, 0.)// Arrays to store delta volume datavar float[] posVolSR = array.new_float(srPeriod, 0.)var float[] negVolSR = array.new_float(srPeriod, 0.)var float[] posVolMacro = array.new_float(macroPeriod, 0.)var float[] negVolMacro = array.new_float(macroPeriod, 0.)// VARIABLES FOR DELTA VOLUME CALCULATIONS -----------------------------------------------------------------------------// Variables to store delta volume percentages for S/R and Macro periodsvar float deltaVolSR = navar float deltaVolMacro = na// VARIABLES FOR BOX DRAWING --------------------------------------------------------------------------------------------// Variables for box indices for both S/R and Macro periodsint srStartIdx = bar_index - srPeriodint srEndIdx = bar_index + 50int macroStartIdx = bar_index - macroPeriodint macroEndIdx = bar_index + 70// Variables for box drawingvar box srUpperBox = navar box srLowerBox = navar box macroUpperBox = navar box macroLowerBox = navar box midBox = na// ATR for box scalingfloat atrValue = ta.atr(200)*0.8// VOLUME DELTA CALCULATIONS -------------------------------------------------------------------------------------------// @description: Calculate the delta volume for Macro periodif barstate.islast and showMacrofor int i = 0 to macroPeriod - 1array.push(macroHighs, high[i])array.push(macroLows, low[i])// Store positive and negative volume based on candle directionif close[i] > open[i]posVolMacro.set(i, volume[i])if close[i] < open[i]negVolMacro.set(i, -volume[i])// Calculate Macro Delta VolumedeltaVolMacro := (negVolMacro.avg() / posVolMacro.avg() + 1) * 100deltaVolMacro := math.min(math.max(deltaVolMacro, -100), 100) // Cap delta volume between -100 and 100// Calculate the delta volume for S/R periodif barstate.islast and showSRfor int i = 0 to srPeriod - 1array.push(srHighs, high[i])array.push(srLows, low[i])// Store positive and negative volume based on candle directionif close[i] > open[i]posVolSR.set(i, volume[i])if close[i] < open[i]negVolSR.set(i, -volume[i])// Calculate S/R Delta VolumedeltaVolSR := (negVolSR.avg() / posVolSR.avg() + 1) * 100deltaVolSR := math.min(math.max(deltaVolSR, -100), 100) // Cap delta volume between -100 and 100// BOX HANDLING AND UPDATING -------------------------------------------------------------------------------------------// Update and manage boxes based on crossover conditionsif ta.crossover(low, srUpperBox.get_top()) or ta.crossunder(high, srLowerBox.get_bottom()) or bar_index % 100 == 0// Set new bounds for S/R and Macro boxessrUpperBox.set_top(srHighs.max() + atrValue)srUpperBox.set_bottom(srHighs.min())srLowerBox.set_top(srLows.min())srLowerBox.set_bottom(srLows.min() - atrValue)macroUpperBox.set_top(macroHighs.max() + atrValue)macroUpperBox.set_bottom(macroHighs.min())macroLowerBox.set_top(macroLows.min())macroLowerBox.set_bottom(macroLows.min() - atrValue)// Delete previous boxesbox.delete(srUpperBox[1])box.delete(srLowerBox[1])box.delete(macroUpperBox[1])box.delete(macroLowerBox[1])// DRAW AND UPDATE BOXES ------------------------------------------------------------------------------------------------// Draw and update lower box if not initialized for S/R periodif na(srLowerBox) and barstate.islast and showSRsrLowerBox := box.new(srStartIdx, srLows.min(), srEndIdx, srLows.min() - atrValue,upColor, 1,bgcolor = color.new(upColor, 100),text = "DISCOUNT: " + str.tostring(posVolSR.sum(), format.volume),text_size = size.small,text_color= chart.fg_color, force_overlay = true)elsesrLowerBox.set_text("DISCOUNT: " + str.tostring(posVolSR.sum(), format.volume))box.set_left(srLowerBox, srStartIdx)box.set_right(srLowerBox, srEndIdx)array.clear(srLows)// Draw and update upper box if not initialized for S/R periodif na(srUpperBox) and barstate.islast and showSRsrUpperBox := box.new(srStartIdx, srHighs.max() + atrValue, srEndIdx, srHighs.max(),downColor, 1,bgcolor = color.new(downColor, 100),text = "PREMIUM: " + str.tostring(negVolSR.sum(), format.volume),text_size = size.small,text_color= chart.fg_color, force_overlay = true)elsesrUpperBox.set_text("PREMIUM: " + str.tostring(negVolSR.sum(), format.volume))box.set_left(srUpperBox, srStartIdx)box.set_right(srUpperBox, srEndIdx)array.clear(srHighs)// DRAW BOXES FOR MACRO PERIOD ------------------------------------------------------------------------------------------// Draw and update upper box for Macro periodif na(macroUpperBox) and barstate.islast and showMacromacroUpperBox := box.new(macroStartIdx, macroHighs.max() + atrValue, macroEndIdx, macroHighs.max(),downColor, 0,bgcolor = color.new(downColor, 60),text = str.tostring(negVolMacro.sum(), format.volume),text_size = size.small,text_color = chart.fg_color,text_halign= showSR ? text.align_right : text.align_center)elsemacroUpperBox.set_text(str.tostring(negVolMacro.sum(), format.volume))box.set_left(macroUpperBox, macroStartIdx)box.set_right(macroUpperBox, macroEndIdx)array.clear(macroHighs)// Draw and update lower box for Macro periodif na(macroLowerBox) and barstate.islast and showMacromacroLowerBox := box.new(macroStartIdx, macroLows.min(), macroEndIdx, macroLows.min() - atrValue,upColor, 0,bgcolor = color.new(upColor, 60),text = str.tostring(posVolMacro.sum(), format.volume),text_size = size.small,text_color = chart.fg_color,text_halign= showSR ? text.align_right : text.align_center)elsemacroLowerBox.set_text(str.tostring(posVolMacro.sum(), format.volume))box.set_left(macroLowerBox, macroStartIdx)box.set_right(macroLowerBox, macroEndIdx)array.clear(macroLows)// ADDITIONAL PLOTTING --------------------------------------------------------------------------------------------------// Draw line for equilibrium and box for delta volume displayif barstate.islast and showSRfloat mid = math.avg(srLowerBox.get_top(), srUpperBox.get_bottom())line.delete(line.new(srStartIdx, mid, srEndIdx, mid, color=chart.fg_color, style=line.style_dashed)[1])midBox := box.new(srStartIdx, srUpperBox.get_bottom(), srEndIdx, srLowerBox.get_top(),na, 0,bgcolor = color.new(deltaVolSR > 0 ? upColor : downColor, 93),text = "Delta Volume\n" + str.tostring(deltaVolSR, format.percent),text_size = size.normal, text_color=deltaVolSR > 0 ? upColor : downColor,text_halign = text.align_right, text_valign=text.align_bottom)box.delete(midBox[1])// If only macro levels are shown, handle box and line drawingif not showSR and showMacro and barstate.islastfloat midMacro = math.avg(macroLowerBox.get_top(), macroUpperBox.get_bottom())line.delete(line.new(macroStartIdx, midMacro, macroEndIdx, midMacro,color=chart.fg_color, style=line.style_dashed)[1])// Display Macro Delta Volume as a tableif showMacro and barstate.islastvar table deltaTable = table.new(position.top_right, 5, 5)table.cell(deltaTable, 0, 0,text = "Macro\n Delta Volume:\n" + str.tostring(deltaVolMacro, format.percent),text_color = deltaVolMacro > 0 ? upColor : downColor,text_size = size.large)11/06/2024 at 4:54 PM #240032Bonnes! Ici, ils ont été traduits :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101//-------------------------------------------////PRC_Premium and Discount Delta Volume//version = 0//06.11.2024//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//-------------------------------------------//// Inputs//-------------------------------------------//defparam drawonlastbaronly=trueshowSR=1srPeriod=50showMacro=1macroPeriod=200//-------------------------------------------//// Variables for Delta Volume Calculation//-------------------------------------------//once deltaVolSR=undefinedonce deltaVolMacro=undefined//-------------------------------------------//// Variables for BOX Drawing//-------------------------------------------////Box indicessrStartIdx=barindex-srPeriodsrEndIdx=barindex+50macroStartIdx=barindex-macroPeriodmacroEndIdx=barindex+70//ATR for box scalingatrValue=averagetruerange[200](close)*0.8//-------------------------------------------//// Volume Delta Calculations//-------------------------------------------////Calculate Delta Volume for macro periodif islastbarupdate and showMacro thencumPosVolMacro=0countPosVolMacro=0cumNegVolMacro=0countNegVolMacro=0for i=0 to macroPeriod-1 do//Store positive negative volume based on candle directionif close[i]>open[i] thencumPosVolMacro=cumPosVolMacro+volume[i]countPosVolMacro=countPosVolMacro+1elsif close[i]<open[i] thencumNegVolMacro=cumNegVolMacro-volume[i]countNegVolMacro=countNegVolMacro+1endifnext//Calculate Macro Delta VolumeAvgPosVolMacro=cumPosVolMacro/countPosVolMacroAvgNegVolMacro=cumNegVolMacro/countNegVolMacrodeltaVolMacro=(AvgNegVolMacro/AvgPosVolMacro+1)*100//Delta volume between -100 and 100deltaVolMacro=round(min(max(deltaVolMacro,-100),100),2)drawtext("Macro Delta Volume:",-100,-100)anchor(topright,xshift,yshift)drawtext("#deltaVolMacro#%",-100,-120)anchor(topright,xshift,yshift)drawrectangle(macroStartIdx,lowest[macroPeriod](low),macroEndIdx,lowest[macroPeriod](low)-atrValue)coloured("blue",0)fillcolor("blue",30)drawtext("#cumPosVolMacro#",macroEndIdx,lowest[macroPeriod](low)-0.5*atrValue)drawrectangle(macroStartIdx,highest[macroPeriod](high),macroEndIdx,highest[macroPeriod](high)+atrValue)coloured("red",0)fillcolor("red",30)drawtext("#cumNegVolMacro#",macroEndIdx,highest[macroPeriod](high)+0.5*atrValue)endif//Calculate Delta Volume for S/R periodif islastbarupdate and showSR thencumPosVolsr=0countPosVolsr=0cumNegVolsr=0countNegVolsr=0for i=0 to srPeriod-1 do//Store positive negative volume based on candle directionif close[i]>open[i] then//$posVolsr[i]=volume[i]cumPosVolsr=cumPosVolsr+volume[i]countPosVolsr=countPosVolsr+1elsif close[i]<open[i] thencumNegVolsr=cumNegVolsr-volume[i]countNegVolsr=countNegVolsr+1endifnext//Calculate SR Delta VolumeAvgPosVolsr=cumPosVolsr/countPosVolsrAvgNegVolsr=cumNegVolsr/countNegVolsrdeltaVolsr=(AvgNegVolsr/AvgPosVolsr+1)*100//Delta volume between -100 and 100deltaVolsr=round(min(max(deltaVolsr,-100),100),2)drawtext("Delta Volume:",srEndIdx,lowest[srPeriod](low)+1.5*atrValue)drawtext("#deltaVolsr#%",srEndIdx,lowest[srPeriod](low)+1.0*atrValue)drawrectangle(srStartIdx,lowest[srPeriod](low),srEndIdx,lowest[srPeriod](low)-atrValue)coloured("blue")drawtext("DISCOUNT: #cumPosVolsr#",barindex,lowest[srPeriod](low)-0.5*atrValue)drawrectangle(srStartIdx,highest[srPeriod](high),srEndIdx,highest[srPeriod](high)+atrValue)coloured("red")drawtext("PREMIUM: #cumNegVolsr#",barindex,highest[srPeriod](high)+0.5*atrValue)drawrectangle(srStartIdx,highest[srPeriod](high),srEndIdx,lowest[srPeriod](low))coloured("orange",0)fillcolor("orange",10)midSR=(highest[srPeriod](high)+lowest[srPeriod](low))/2drawsegment(srStartIdx,midSR,srEndIdx,midSR)style(dottedline)endif//-------------------------------------------//return11/06/2024 at 6:35 PM #240036Bonjour Ivan et merci pour ton travail.
Je pense qu’il y a un petit bug car les zones de l’indicateur sont copiées de période en période au lieu de bouger sans être copiée (je ne suis pas sûr d’être clair).
Voir image ci-dessous, on voit que lorsqu’on laisse l’indicateur sur un timeframe, ici 2 minutes, les zones et textes sont copiés à chaque nouvelle unité de temps.11/06/2024 at 9:40 PM #24004111/28/2024 at 9:26 AM #240840Bonjour Ivan, ce code fonctionne bien et m’est très utile. J’aimerais me créer des alertes pour mon confort de trading mais ne sais pas les coder.
Mon idée est un histogramme avec :
– Signal=1 si prix > ou = à la ligne basse de la zone Premium,
– Signal=-1 si prix < ou = à la ligne haute de la zone discount. Pouvez-vous coder cet histogramme, dérivée de l'indicateur ? Vous remerciant pour votre super boulot sur le site11/28/2024 at 9:55 AM #240841Bonjour. La zone premium et discount n’est qu’une ligne haute et une ligne basse. Dans le code indicateur ci-dessus, ils sont définis par
srPeriod
.12345678910111213141516srPeriod=50lmax=highest[srPeriod](high)lmin=lowest[srPeriod](low)if high=lmax thensignal=1r=0g=255elsif low=lmin thensignal=-1r=255g=0elsesignal=0endifreturn signal style(histogram) coloured(r,g,0) -
AuthorPosts
Find exclusive trading pro-tools on