ORDER BLOCK PRT TRADINGWIEW différence
Forums › ProRealTime forum Français › Support ProBuilder › ORDER BLOCK PRT TRADINGWIEW différence
- This topic has 5 replies, 3 voices, and was last updated 8 months ago by ARLEQUIN49.
-
-
03/17/2024 at 6:13 PM #229924
Bonjour,
Voici ci dessous les codes ORDER BLOCK créé sur tradingwiew par sonarlab et transcrit sur PRT dans la bibliothèque.
Malheureusement, ces deux codes ne sont pas équivalents dans les deux plateformes.(voir pièces jointes).On note une sur-multiplication de rectangle coté PRT.
Certainement du à un petit oublie. Le sens est équivalent de chaque coté (25) et la sensitivité ne concerne que la couleur des rectangles.
Merci à vous
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147// Sonarlabs - Order Block Finder// converted from TradingView// Lower the sensitivity to show more order blocks. A higher sensitivity will show less order blocksdefparam drawonlastbaronly=true//Transparency = 80//sens = 28once obcreatedbear = 0once obcreatedbull = 0once crossindexbear = 0once crossindexbull = 0// Custom Rate of Change (ROC) calculation. This is to calculate high momentum moves in the market.pc = ((open - open[4]) / open[4]) * 100// -----------------sens = sens/100 //ExponentialAverage[8](pc) //sens/100OBBullMitigation = close[1]OBBearMitigation = close[1]// If the ROC crossover our Sensitivty input - Then create a Bearish Order Block// Sensitivty is negative as this is a Bearish OBif pc crosses under -sens thenobcreatedbear = 1crossindexbear = barindexendif// If the ROC crossover our Sensitivty input - Then create a Bullish Order Blockif pc crosses over sens thenobcreatedbull = 1crossindexbull = barindexendif////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Calculation////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -------------------------------// Bearish OB Creation// -------------------------------// Check if we should create a OB. Also check if we haven't created an OB in the last 5 candles.if obcreatedbear and (crossindexbear - crossindexbear[1]) > 5 thenlastgreen = 0hhighest = 0// Loop through the most recent candles and find the first GREEN (Bullish) candle. We will place our OB here.for i = 4 to 15if close[i] > open[i] thenlastgreen = i//populate the arrays of order block to draw them later$left[plot]= barindex[lastgreen]$top[plot]=high[lastgreen]$bottom[plot]=low[lastgreen]$right[plot]=barindex[lastgreen]plot=plot+1 //increase the array column for next databreakendifnextendif// -------------------------------// Bullish OB Creation// -------------------------------// Check if we should create a OB, Also check if we haven't created an OB in the last 5 candles.if obcreatedbull and (crossindexbull - crossindexbull[1]) > 5 thenlastred = 0hhighest = 0// Loop through the most recent candles and find the first RED (Beaarish) candle. We will place our OB here.for ibull = 4 to 15if close[ibull] < open[ibull] thenlastred = ibull//populate the arrays of order block to draw them later$leftbull[plotbull]= barindex[lastred]$topbull[plotbull]=high[lastred]$bottombull[plotbull]=low[lastred]$rightbull[plotbull]=barindex[lastred]plotbull=plotbull+1 //increase the array column for next databreakendifnextendif////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Cleanup////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Clean up Bearish OB boxesif plot>0 thenfor j = plot-1 downto 0 //0 to plot-1// If the two last closes are above the high of the bearish OB - Remove the OBif $left[j]>0 then //check if the zone still existitop = $top[j]breakout = summation[max(1,barindex-$left[j])](OBBearMitigation>itop)>=1 //2if breakout then$left[j]=0endifendifnextendif// Clean up Bullish OB boxesif plotbull>0 thenfor jbull = plotbull-1 downto 0 //0 to plotbull-1// If the two last closes are below the low of the bullish OB - Remove the OBif $leftbull[jbull]>0 then //check if the zone still existibot = $bottombull[jbull]breakoutbull = summation[max(1,barindex-$leftbull[jbull])](OBBullMitigation<ibot)>=1if breakoutbull then$leftbull[jbull]=0endifendifnextendif////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Drawing////////////////////////////////////////////////////////////////////////////////////////////////////////////////if islastbarupdate then//plot the Bearish boxesif plot>0 then //islastbarupdate andfor j = plot-1 downto 0 //0 to plot-1if $left[j]>0 thendrawrectangle($left[j],$top[j],barindex,$bottom[j]) coloured("red",Transparency)bordercolor("red",Transparency)endifnextendif//plot the Bullish boxesif plotbull>0 then //islastbarupdate andfor jbull = plotbull-1 downto 0 //0 to plotbull-1if $leftbull[jbull]>0 thendrawrectangle($leftbull[jbull],$bottombull[jbull],barindex,$topbull[jbull]) coloured("green",Transparency)bordercolor("green",Transparency)endifnextendifendifreturn123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © ClayeWeight//@version=5indicator(title='Sonarlab - Order Blocks', shorttitle='Sonarlab - OB', overlay=true, max_boxes_count=20)_v = input.string("1.0.2", title="Version", options=["1.0.2"], group="Version")sens = input.int(28, minval=1, title='Sensitivity', group='Order Block', tooltip='Lower the sensitivity to show more order blocks. A higher sensitivity will show less order blocks.')sens /= 100// OBOBMitigationType = input.string("Close", title="OB Mitigation Type", options=["Close", "Wick"], group="Order Block", tooltip="Choose how Order Blocks are mitigated")OBBullMitigation = OBMitigationType=="Close" ? close[1] : lowOBBearMitigation = OBMitigationType=="Close" ? close[1] : high//OB Colorscol_bullish = input.color(#5db49e, title="Bullish OB Border", inline="a", group="Order Block")col_bullish_ob = input.color(color.new(#64C4AC, 85), title="Background", inline="a", group="Order Block")col_bearish = input.color(#4760bb, title="Bearish OB Border", inline="b", group="Order Block")col_bearish_ob = input.color(color.new(#506CD3, 85), title="Background", inline="b", group="Order Block")// Alertsbuy_alert = input.bool(title='Buy Signal', defval=true, group='Alerts', tooltip='An alert will be sent when price goes below the top of a bullish order block.')sell_alert = input.bool(title='Sell Signal', defval=true, group='Alerts', tooltip='An alert will be sent when price goes above the bottom of a bearish order block.')// Delacring Variablesbool ob_created = falsebool ob_created_bull = falsevar int cross_index = na// Declaring Box Arraysvar box drawlongBox = navar longBoxes = array.new_box()var box drawShortBox = navar shortBoxes = array.new_box()// Custom Rate of Change (ROC) calculation. This is to calculate high momentum moves in the market.pc = (open - open[4]) / open[4] * 100// If the ROC crossover our Sensitivty input - Then create an Order Block// Sensitivty is negative as this is a Bearish OBif ta.crossunder(pc, -sens)ob_created := truecross_index := bar_indexcross_index// If the ROC crossover our Sensitivty input - Then create an Order Blockif ta.crossover(pc, sens)ob_created_bull := truecross_index := bar_indexcross_index// -------------------------------// Bearish OB Creation// -------------------------------// Check if we should create a OB, Also check if we haven't created an OB in the last 5 candles.if ob_created and cross_index - cross_index[1] > 5float last_green = 0float highest = 0// Loop through the most recent candles and find the first GREEN (Bullish) candle. We will place our OB here.for i = 4 to 15 by 1if close[i] > open[i]last_green := ibreak// Draw our OB on that candle - then push the box into our box arrays.drawShortBox := box.new(left=bar_index[last_green], top=high[last_green], bottom=low[last_green], right=bar_index[last_green], bgcolor=col_bearish_ob, border_color=col_bearish, extend=extend.right)array.push(shortBoxes, drawShortBox)// -------------------------------// Bullish OB Creation// -------------------------------// Check if we should create a OB, Also check if we haven't created an OB in the last 5 candles.if ob_created_bull and cross_index - cross_index[1] > 5float last_red = 0float highest = 0// Loop through the most recent candles and find the first RED (Bearish) candle. We will place our OB here.for i = 4 to 15 by 1if close[i] < open[i]last_red := ibreak// Draw our OB on that candle - then push the box into our box arrays.drawlongBox := box.new(left=bar_index[last_red], top=high[last_red], bottom=low[last_red], right=bar_index[last_red], bgcolor=col_bullish_ob, border_color=col_bullish, extend=extend.right)array.push(longBoxes, drawlongBox)// ----------------- Bearish Order Block -------------------// Clean up OB boxes and place alertsif array.size(shortBoxes) > 0for i = array.size(shortBoxes) - 1 to 0 by 1sbox = array.get(shortBoxes, i)top = box.get_top(sbox)bot = box.get_bottom(sbox)// If the two last closes are above the high of the bearish OB - Remove the OBif OBBearMitigation > toparray.remove(shortBoxes, i)box.delete(sbox)// Alertsif high > bot and sell_alertalert('Price inside Bearish OB', alert.freq_once_per_bar)// ----------------- Bullish Clean Up -------------------// Clean up OB boxes and place alertsif array.size(longBoxes) > 0for i = array.size(longBoxes) - 1 to 0 by 1sbox = array.get(longBoxes, i)bot = box.get_bottom(sbox)top = box.get_top(sbox)// If the two last closes are below the low of the bullish OB - Remove the OBif OBBullMitigation < botarray.remove(longBoxes, i)box.delete(sbox)// Alertsif low < top and buy_alertalert('Price inside Bullish OB', alert.freq_once_per_bar)03/17/2024 at 6:17 PM #229926Les rectangles qui vont au fond du graphique sont ceux de tradingwiew (tracé à la main).
Les autres ceux de PRT.
03/18/2024 at 12:08 AM #229932Salut… En regardant le code PRC…
La variable ‘obcreatedbear’ est définie sur ‘1’, mais n’est pas réinitialisée. La même chose pour ‘taureau obcréé’. Je pense que lorsque vous utilisez « une fois », cette variable n’est exécutée qu’une seule fois. Le mot-clé ‘once’ doit être supprimé afin que chaque fois que le code s’exécute, dans chaque barre, les variables soient réinitialisées en premier et définies uniquement dans des conditions vraies.
En comparant TV et PRC, la variable « crossindex » de TV semble être la même dans les deux opérations haussière/ourse, alors qu’en RPC, elles sont séparées.
Je ne connais pas le code TV pour savoir si les noms de variables sont traités de la même manière ou séparément lorsqu’ils sont définis. Re: ‘ta.’
Mais cela m’amène à la question suivante : lorsque le code vérifie si un OB a été créé, recherche-t-il spécifiquement un OB haussier ou baissier respectivement, ou simplement n’importe quel OB créé dans les 5 dernières barres.
Je ne connais pas la réponse à cette question, cela dépend de l’intention de conception et des résultats si vous les modifiez de la même manière. J’ai mis des lignes alternatives dans le code alors vous essayez.
Je publierai une version éditée.
Cordialement Druby
03/18/2024 at 4:58 PM #229964On attends la publication
03/19/2024 at 7:47 AM #229990Vous pouvez importer le fichier .itf au bas du message précédent. Vous ne le verrez peut-être pas si vous n’êtes pas connecté.
Voici une version copier/coller en cas de problème.
Druby123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151// Sonarlabs - Order Block Finder// converted from TradingView// Lower the sensitivity to show more order blocks. A higher sensitivity will show less order blocksdefparam drawonlastbaronly=trueTransparency = 80Transparency = abs(max(0,min(255,Transparency))) // input gaurd +0-255sens = 28sens = abs(max(1,sens)) // input guard +1-?obcreatedbear = 0 // once obcreatedbear = 0 // variables need to reset every timeobcreatedbull = 0 // once obcreatedbull = 0//once crossindexbear = 0 // variable auto default to '0' at start//once crossindexbull = 0// Custom Rate of Change (ROC) calculation. This is to calculate high momentum moves in the market.pc = ((open - open[4]) / open[4]) * 100// -----------------sens = sens/100 //ExponentialAverage[8](pc) //sens/100OBBullMitigation = close[1]OBBearMitigation = close[1]// If the ROC crossover our Sensitivty input - Then create a Bearish Order Block// Sensitivty is negative as this is a Bearish OBif pc crosses under -sens thenobcreatedbear = 1crossindexbear = barindex//crossindex = barindexendif// If the ROC crossover our Sensitivty input - Then create a Bullish Order Blockif pc crosses over sens thenobcreatedbull = 1crossindexbull = barindex//crossindex = barindexendif////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Calculation////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -------------------------------// Bearish OB Creation// -------------------------------// Check if we should create a OB. Also check if we haven't created an OB in the last 5 candles.if obcreatedbear and (crossindexbear - crossindexbear[1]) > 5 then//if obcreatedbear and (crossindex - crossindex [1]) > 5 thenlastgreen = 0// hhighest = 0 // not used// Loop through the most recent candles and find the first GREEN (Bullish) candle. We will place our OB here.for i = 4 to 15if close[i] > open[i] thenlastgreen = i//populate the arrays of order block to draw them later$left[plot]= barindex[lastgreen]$top[plot]=high[lastgreen]$bottom[plot]=low[lastgreen]$right[plot]=barindex[lastgreen]plot=plot+1 //increase the array column for next databreakendifnextendif// -------------------------------// Bullish OB Creation// -------------------------------// Check if we should create a OB, Also check if we haven't created an OB in the last 5 candles.if obcreatedbull and (crossindexbull - crossindexbull[1]) > 5 then//if obcreatedbull and (crossindex - crossindex[1]) > 5 thenlastred = 0// hhighest = 0 // not used// Loop through the most recent candles and find the first RED (Beaarish) candle. We will place our OB here.for ibull = 4 to 15if close[ibull] < open[ibull] thenlastred = ibull//populate the arrays of order block to draw them later$leftbull[plotbull]= barindex[lastred]$topbull[plotbull]=high[lastred]$bottombull[plotbull]=low[lastred]$rightbull[plotbull]=barindex[lastred]plotbull=plotbull+1 //increase the array column for next databreakendifnextendif////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Cleanup////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Clean up Bearish OB boxesif plot>0 thenfor j = plot-1 downto 0 //0 to plot-1// If the two last closes are above the high of the bearish OB - Remove the OBif $left[j]>0 then //check if the zone still existitop = $top[j]breakout = summation[max(1,barindex-$left[j])](OBBearMitigation>itop)>=1 //2if breakout then$left[j]=0endifendifnextendif// Clean up Bullish OB boxesif plotbull>0 thenfor jbull = plotbull-1 downto 0 //0 to plotbull-1// If the two last closes are below the low of the bullish OB - Remove the OBif $leftbull[jbull]>0 then //check if the zone still existibot = $bottombull[jbull]breakoutbull = summation[max(1,barindex-$leftbull[jbull])](OBBullMitigation<ibot)>=1if breakoutbull then$leftbull[jbull]=0endifendifnextendif////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Drawing////////////////////////////////////////////////////////////////////////////////////////////////////////////////if islastbarupdate then//plot the Bearish boxesif plot>0 then //islastbarupdate andfor j = plot-1 downto 0 //0 to plot-1if $left[j]>0 thendrawrectangle($left[j],$top[j],barindex,$bottom[j]) coloured("red",Transparency)bordercolor("red",Transparency)endifnextendif//plot the Bullish boxesif plotbull>0 then //islastbarupdate andfor jbull = plotbull-1 downto 0 //0 to plotbull-1if $leftbull[jbull]>0 thendrawrectangle($leftbull[jbull],$bottombull[jbull],barindex,$topbull[jbull]) coloured("green",Transparency)bordercolor("green",Transparency)endifnextendifendifreturn// Note: should the 'crossindex....' variables be the same for bull and bear rather than different!...,// so when it check for OB within 5 bars , current repectively bull or bear OB,// or should it be any OB? Would this avoid bull/bear OB's being close together03/19/2024 at 8:58 AM #229991Y aurait-il moyen pouvoir ajouter une alerte à chaque nouveau rectangle?
-
AuthorPosts
Find exclusive trading pro-tools on