Indicateur “Breakout Probability” TV à Traduire
Forums › ProRealTime forum Français › Support ProBuilder › Indicateur “Breakout Probability” TV à Traduire
- This topic has 1 reply, 2 voices, and was last updated 2 days ago by
Iván.
Viewing 2 posts - 1 through 2 (of 2 total)
-
-
09/08/2025 at 11:33 AM #250495
Bonjour,
Voici un indicateur que j’ai récupéré sur Trading View et que je souhaiterai faire traduire en ProBuilder.
Il s’appelle “Breakout Probability” et a été créé par Zeiierman.
Il a l’air de plutôt bien fonctionné.
En vous souhaitant une très bonne journée !
// © Zeiierman//@version=5indicator(“Breakout Probability (Expo)”,overlay=true,max_bars_back=5000)// ~~ Tooltips {t1 = “The space between the levels can be adjusted with a percentage step. 1% means that each level is located 1% above/under the previous one.”t2 = “Set the number of levels you want to display.”t3 = “If a level got 0 % likelihood of being hit, the level is not displayed as default. Enable the option if you want to see all levels regardless of their values.”t4 = “Enable this option if you want to display the backtest statistics for that a new high or low is made.”string [] tbl_tips = array.from(“Number of times price has reached the first highest percentage level”,“Number of times price failed to reach the first highest percentage level”,“Win/Loss ratio”)//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Inputs {perc = input.float(1.0,title=”Percentage Step”,step=.1,minval=0,group=”Settings”,tooltip=t1)nbr = input.int(5, title=”Number of Lines”,maxval=5,minval=1,group=”Settings”,tooltip=t2)upCol = input.color(color.new(color.green,0),title=””,inline=”col”),dnCol=input.color(color.new(color.red,0),title=””,inline=”col”),fill=input.bool(true,title=”BG Color”,inline=”col”)var bool [] bools = array.from(input.bool(true,title=”Disable 0.00%”,group=”Settings”,tooltip=t3),input.bool(true, title=”Show Statistic Panel”,group=”Settings”,tooltip=t4))var bool [] alert_bool = array.from(input.bool(true,title=”Ticker ID”,group=”Any alert() function call”),input.bool(true,title=”High/Low Price”,group=”Any alert() function call”),input.bool(true,title=”Bullish/Bearish Bias”,group=”Any alert() function call”),input.bool(true,title=”Bullish/Bearish Percentage”,group=”Any alert() function call”))//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Variables {b = bar_indexo = openh = highl = lowc = closestep = c*(perc/100)//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Save Values In Matrix {var total = matrix.new<int>(7,4,0)var vals = matrix.new<float>(5,4,0.0)var lines = matrix.new<line>(1,10,line(na))var labels = matrix.new<label>(1,10,label(na))var tbl = matrix.new<table>(1,1,table.new(position.top_right,2,3,frame_color=color.new(color.gray,50),frame_width=3,border_color=chart.bg_color,border_width=-2))//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Save Number Of Green & Red Candles {green = c[1]>o[1]red = c[1]<o[1]if greenprev = matrix.get(total,5,0)matrix.set(total,5,0,prev+1)if redprev = matrix.get(total,5,1)matrix.set(total,5,1,prev+1)//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Functions {//LinesCreateLine(p,i,c)=>prevLine = matrix.get(lines,0,i)line.delete(prevLine)li = line.new(b[1],p,b,p,color=c,width=2)matrix.set(lines,0,i,li)//LabelsCreateLabel(p,i,c,r,v)=>prevLabel = matrix.get(labels,0,i)label.delete(prevLabel)la = label.new(b+1,p,text=str.tostring(matrix.get(vals,r,v),format.percent),style=label.style_label_left,color=color.new(color.black,100),textcolor=c)matrix.set(labels,0,i,la)//Score CalculationScore(x,i)=>ghh = matrix.get(total,i,0)gll = matrix.get(total,i,1)rhh = matrix.get(total,i,2)rll = matrix.get(total,i,3)gtotal = matrix.get(total,5,0)rtotal = matrix.get(total,5,1)hh = h>=h[1] + xll = l<=l[1] – xif green and hhmatrix.set(total,i,0,ghh+1)matrix.set(vals,i,0,math.round(((ghh+1)/gtotal)*100,2))if green and llmatrix.set(total,i,1,gll+1)matrix.set(vals,i,1,math.round(((gll+1)/gtotal)*100,2))if red and hhmatrix.set(total,i,2,rhh+1)matrix.set(vals,i,2,math.round(((rhh+1)/rtotal)*100,2))if red and llmatrix.set(total,i,3,rll+1)matrix.set(vals,i,3,math.round(((rll+1)/rtotal)*100,2))//BacktestBacktest(v)=>p1 = matrix.get(total,6,0)p2 = matrix.get(total,6,1)if v==h[1]if h>=vmatrix.set(total,6,0,p1+1)elsematrix.set(total,6,1,p2+1)elseif l<=vmatrix.set(total,6,0,p1+1)elsematrix.set(total,6,1,p2+1)//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Code {//Run Score FunctionScore(0,0)Score(step,1)Score(step*2,2)Score(step*3,3)Score(step*4,4)//Fetch Score Valuesa1 = matrix.get(vals,0,0)b1 = matrix.get(vals,0,1)a2 = matrix.get(vals,0,2)b2 = matrix.get(vals,0,3)//Lines & Labels & Alertsfor i=0 to nbr-1hide = array.get(bools,0)if not hide or (hide and (green?math.min(matrix.get(vals,i,0),matrix.get(vals,i,1))>0:math.min(matrix.get(vals,i,2),matrix.get(vals,i,3))>0))hi = h[1]+(step*i)lo = l[1]-(step*i)//Plot LinesCreateLine(hi,i,upCol)CreateLine(lo,5+i,dnCol)//Plot Labelsif greenCreateLabel(hi,i,upCol,i,0)CreateLabel(lo,5+i,dnCol,i,1)elseCreateLabel(hi,i,upCol,i,2)CreateLabel(lo,5+i,dnCol,i,3)//Create Alertif array.includes(alert_bool, true)s1 = str.tostring(syminfo.ticker)s2 = “High Price: “+str.tostring(math.round_to_mintick(h[1]))+” | Low Price: “+str.tostring(math.round_to_mintick(l[1]))s3 = green?(math.max(a1,b1)==a1?”BULLISH”:”BEARISH”):(math.max(a2,b2)==a2?”BULLISH”:”BEARISH”)s4 = green?(math.max(a1,b1)==a1?a1:b1):(math.min(a2,b2)==a2?a2:b2)s5 = red ?(math.max(a2,b2)==a2?a2:b2):(math.min(a1,b1)==a1?a1:b1)string [] str_vals = array.from(s1,s2,”BIAS: “+s3,“Percentage: High: “+str.tostring(s4,format.percent)+” | Low: “+str.tostring(s5,format.percent))output = array.new_string()for x=0 to array.size(alert_bool)-1if array.get(alert_bool,x)array.push(output,array.get(str_vals,x))//Alert Is Triggered On Every Bar Open With Bias And Percentage Ratioalert(array.join(output,’\n’),alert.freq_once_per_bar)else//Delete Old Lines & Labelsline.delete(matrix.get(lines,0,i))line.delete(matrix.get(lines,0,5+i))label.delete(matrix.get(labels,0,i))label.delete(matrix.get(labels,0,5+i))//Run Backtest FunctionBacktest(green?(math.max(a1,b1)==a1?h[1]:l[1]):(math.max(a2,b2)==a2?h[1]:l[1]))//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Linefill {if fillvar filler = linefill(na)for i=0 to 8get = matrix.get(lines,0,i)get1= matrix.get(lines,0,i+1)col = i>4?color.new(dnCol,80) : i==4?color.new(color.gray,100) : color.new(upCol,80)filler := linefill.new(get,get1,color=col)linefill.delete(filler[1])//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}// ~~ Table {if barstate.islast and array.get(bools,1)//Calulate WinRatioW = matrix.get(total,6,0)L = matrix.get(total,6,1)WR = math.round(W/(W+L)*100,2)string [] tbl_vals = array.from(“WIN: “+str.tostring(W),“LOSS: “+str.tostring(L),“Profitability: “+str.tostring(WR,format.percent))color [] tbl_col = array.from(color.green,color.red,chart.fg_color)for i=0 to 2table.cell(matrix.get(tbl,0,0),0,i,array.get(tbl_vals,i),text_halign=text.align_center,bgcolor=chart.bg_color,text_color=array.get(tbl_col,i),text_size=size.auto,tooltip=array.get(tbl_tips,i))//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}09/08/2025 at 1:05 PM #250505voici
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248//-------------------------------------------------------------// PRC_Breakout Probability (Expo) by Zeiierman// version = 0// 08.09.25// Iván González @ www.prorealcode.com// Sharing ProRealTime knowledge//-------------------------------------------------------------defparam drawonlastbaronly=true//-------------------------------------------------------------// --- Inputs//-------------------------------------------------------------perc = 1.0 // Percentage step between levelsnbr = 5 // Number of lines to display (maximum 5)fill = 1 // 1 to fill the background between lines, 0 to disablehideZero = 1 // 1 to hide levels with 0% probability, 0 to show them//-------------------------------------------------------------ONCE totalGreenCandles = 0ONCE totalRedCandles = 0// Emulating the 'total' matrix using arrays for counters// $total[row][column] -> $totalRow[column]ONCE $total0[3] = 0 // Row 0: ghh, gll, rhh, rllONCE $total1[3] = 0 // Row 1ONCE $total2[3] = 0 // Row 2ONCE $total3[3] = 0 // Row 3ONCE $total4[3] = 0 // Row 4// Emulating the 'vals' matrix using arrays for percentagesONCE $vals0[3] = 0.0 // Row 0: ghh%, gll%, rhh%, rll%ONCE $vals1[3] = 0.0 // Row 1ONCE $vals2[3] = 0.0 // Row 2ONCE $vals3[3] = 0.0 // Row 3ONCE $vals4[3] = 0.0 // Row 4//-------------------------------------------------------------// --- Main logic (runs on each bar)//-------------------------------------------------------------IF barindex > 1 THEN// Determine whether the previous candle was green or redgreen = close[1] > open[1]red = close[1] < open[1]// Tally total green and red candlesIF green THENtotalGreenCandles = totalGreenCandles + 1ENDIFIF red THENtotalRedCandles = totalRedCandles + 1ENDIF// Compute step based on the previous closestep = close[1] * (perc / 100)//-------------------------------------------------------------// --- Inlined 'Score' logic for 5 levels ---//-------------------------------------------------------------// Level 0 (no step)x0 = 0hh0 = high >= high[1] + x0ll0 = low <= low[1] - x0IF green AND hh0 THEN$total0[0] = $total0[0] + 1ENDIFIF green AND ll0 THEN$total0[1] = $total0[1] + 1ENDIFIF red AND hh0 THEN$total0[2] = $total0[2] + 1ENDIFIF red AND ll0 THEN$total0[3] = $total0[3] + 1ENDIF// Level 1 (step * 1)x1 = stephh1 = high >= high[1] + x1ll1 = low <= low[1] - x1IF green AND hh1 THEN$total1[0] = $total1[0] + 1ENDIFIF green AND ll1 THEN$total1[1] = $total1[1] + 1ENDIFIF red AND hh1 THEN$total1[2] = $total1[2] + 1ENDIFIF red AND ll1 THEN$total1[3] = $total1[3] + 1ENDIF// Level 2 (step * 2)x2 = step * 2hh2 = high >= high[1] + x2ll2 = low <= low[1] - x2IF green AND hh2 THEN$total2[0] = $total2[0] + 1ENDIFIF green AND ll2 THEN$total2[1] = $total2[1] + 1ENDIFIF red AND hh2 THEN$total2[2] = $total2[2] + 1ENDIFIF red AND ll2 THEN$total2[3] = $total2[3] + 1ENDIF// Level 3 (step * 3)x3 = step * 3hh3 = high >= high[1] + x3ll3 = low <= low[1] - x3IF green AND hh3 THEN$total3[0] = $total3[0] + 1ENDIFIF green AND ll3 THEN$total3[1] = $total3[1] + 1ENDIFIF red AND hh3 THEN$total3[2] = $total3[2] + 1ENDIFIF red AND ll3 THEN$total3[3] = $total3[3] + 1ENDIF// Level 4 (step * 4)x4 = step * 4hh4 = high >= high[1] + x4ll4 = low <= low[1] - x4IF green AND hh4 THEN$total4[0] = $total4[0] + 1ENDIFIF green AND ll4 THEN$total4[1] = $total4[1] + 1ENDIFIF red AND hh4 THEN$total4[2] = $total4[2] + 1ENDIFIF red AND ll4 THEN$total4[3] = $total4[3] + 1ENDIF// Recompute percentages on each barIF totalGreenCandles > 0 THEN$vals0[0] = ($total0[0] / totalGreenCandles)$vals0[1] = ($total0[1] / totalGreenCandles)$vals1[0] = ($total1[0] / totalGreenCandles)$vals1[1] = ($total1[1] / totalGreenCandles)$vals2[0] = ($total2[0] / totalGreenCandles)$vals2[1] = ($total2[1] / totalGreenCandles)$vals3[0] = ($total3[0] / totalGreenCandles)$vals3[1] = ($total3[1] / totalGreenCandles)$vals4[0] = ($total4[0] / totalGreenCandles)$vals4[1] = ($total4[1] / totalGreenCandles)ENDIFIF totalRedCandles > 0 THEN$vals0[2] = ($total0[2] / totalRedCandles)$vals0[3] = ($total0[3] / totalRedCandles)$vals1[2] = ($total1[2] / totalRedCandles)$vals1[3] = ($total1[3] / totalRedCandles)$vals2[2] = ($total2[2] / totalRedCandles)$vals2[3] = ($total2[3] / totalRedCandles)$vals3[2] = ($total3[2] / totalRedCandles)$vals3[3] = ($total3[3] / totalRedCandles)$vals4[2] = ($total4[2] / totalRedCandles)$vals4[3] = ($total4[3] / totalRedCandles)ENDIFENDIF//-------------------------------------------------------------// --- Drawing of Lines, Labels and Fill//-------------------------------------------------------------// We use a temporary array to store levels and ease the fillingONCE $hiLevels[4] = 0.0ONCE $loLevels[4] = 0.0if islastbarupdate thenFOR i = 0 TO nbr - 1// Fetch the proper percentages depending on the previous candle (green or red)myProbUp = 0myProbDown = 0IF green THENIF i = 0 THENmyProbUp = $vals0[0]myProbDown = $vals0[1]ELSIF i = 1 THENmyProbUp = $vals1[0]myProbDown = $vals1[1]ELSIF i = 2 THENmyProbUp = $vals2[0]myProbDown = $vals2[1]ELSIF i = 3 THENmyProbUp = $vals3[0]myProbDown = $vals3[1]ELSIF i = 4 THENmyProbUp = $vals4[0]myProbDown = $vals4[1]ENDIFELSE // if previous candle is redIF i = 0 THENmyProbUp = $vals0[2]myProbDown = $vals0[3]ELSIF i = 1 THENmyProbUp = $vals1[2]myProbDown = $vals1[3]ELSIF i = 2 THENmyProbUp = $vals2[2]myProbDown = $vals2[3]ELSIF i = 3 THENmyProbUp = $vals3[2]myProbDown = $vals3[3]ELSIF i = 4 THENmyProbUp = $vals4[2]myProbDown = $vals4[3]ENDIFENDIF// Condition to hide levels with 0%showLevel = (hideZero = 0) OR (hideZero = 1 AND myProbUp > 0 AND myProbDown > 0)IF showLevel THEN// Compute price levelshiLevel = high[1] + (step * i)loLevel = low[1] - (step * i)// Save into arrays for filling$hiLevels[i] = hiLevel$loLevels[i] = loLevel// Draw linesDRAWSEGMENT(barindex[1], hiLevel, barindex, hiLevel) COLOURED("green") STYLE(Line, 2)DRAWSEGMENT(barindex[1], loLevel, barindex, loLevel) COLOURED("red") STYLE(Line, 2)// Draw text labelsprobUp=myProbUp*100ProbDown=myProbDown * 100DRAWTEXT("#probUp# %", barindex + 1, hiLevel, Dialog, Standard, 10) ANCHOR(TOPLEFT, INDEX, VALUE) COLOURED("green")DRAWTEXT("#ProbDown# %", barindex + 1, loLevel, Dialog, Standard, 10) ANCHOR(TOPLEFT, INDEX, VALUE) COLOURED("red")ELSE // If not shown, clear levels arrays$hiLevels[i] = UNDEFINED$loLevels[i] = UNDEFINEDENDIFNEXTendif//-------------------------------------------------------------RETURN -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
Find exclusive trading pro-tools on
Similar topics: