ProRealCode - Trading & Coding with ProRealTime™
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
// Sonarlabs - Order Block Finder
// converted from TradingView
// Lower the sensitivity to show more order blocks. A higher sensitivity will show less order blocks
defparam drawonlastbaronly=true
//Transparency = 80
//sens = 28
once obcreatedbear = 0
once obcreatedbull = 0
once crossindexbear = 0
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/100
OBBullMitigation = 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 OB
if pc crosses under -sens then
obcreatedbear = 1
crossindexbear = barindex
endif
// If the ROC crossover our Sensitivty input - Then create a Bullish Order Block
if pc crosses over sens then
obcreatedbull = 1
crossindexbull = barindex
endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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
lastgreen = 0
hhighest = 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
if close[i] > open[i] then
lastgreen = 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 data
break
endif
next
endif
// -------------------------------
// 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
lastred = 0
hhighest = 0
// Loop through the most recent candles and find the first RED (Beaarish) candle. We will place our OB here.
for ibull = 4 to 15
if close[ibull] < open[ibull] then
lastred = 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 data
break
endif
next
endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Cleanup
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Clean up Bearish OB boxes
if plot>0 then
for j = plot-1 downto 0 //0 to plot-1
// If the two last closes are above the high of the bearish OB - Remove the OB
if $left[j]>0 then //check if the zone still exist
itop = $top[j]
breakout = summation[max(1,barindex-$left[j])](OBBearMitigation>itop)>=1 //2
if breakout then
$left[j]=0
endif
endif
next
endif
// Clean up Bullish OB boxes
if plotbull>0 then
for jbull = plotbull-1 downto 0 //0 to plotbull-1
// If the two last closes are below the low of the bullish OB - Remove the OB
if $leftbull[jbull]>0 then //check if the zone still exist
ibot = $bottombull[jbull]
breakoutbull = summation[max(1,barindex-$leftbull[jbull])](OBBullMitigation<ibot)>=1
if breakoutbull then
$leftbull[jbull]=0
endif
endif
next
endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Drawing
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if islastbarupdate then
//plot the Bearish boxes
if plot>0 then //islastbarupdate and
for j = plot-1 downto 0 //0 to plot-1
if $left[j]>0 then
drawrectangle($left[j],$top[j],barindex,$bottom[j]) coloured("red",Transparency)bordercolor("red",Transparency)
endif
next
endif
//plot the Bullish boxes
if plotbull>0 then //islastbarupdate and
for jbull = plotbull-1 downto 0 //0 to plotbull-1
if $leftbull[jbull]>0 then
drawrectangle($leftbull[jbull],$bottombull[jbull],barindex,$topbull[jbull]) coloured("green",Transparency)bordercolor("green",Transparency)
endif
next
endif
endif
return
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ClayeWeight
//@version=5
indicator(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
// OB
OBMitigationType = 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] : low
OBBearMitigation = OBMitigationType=="Close" ? close[1] : high
//OB Colors
col_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")
// Alerts
buy_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 Variables
bool ob_created = false
bool ob_created_bull = false
var int cross_index = na
// Declaring Box Arrays
var box drawlongBox = na
var longBoxes = array.new_box()
var box drawShortBox = na
var 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 OB
if ta.crossunder(pc, -sens)
ob_created := true
cross_index := bar_index
cross_index
// If the ROC crossover our Sensitivty input - Then create an Order Block
if ta.crossover(pc, sens)
ob_created_bull := true
cross_index := bar_index
cross_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] > 5
float last_green = 0
float 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 1
if close[i] > open[i]
last_green := i
break
// 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] > 5
float last_red = 0
float 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 1
if close[i] < open[i]
last_red := i
break
// 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 alerts
if array.size(shortBoxes) > 0
for i = array.size(shortBoxes) - 1 to 0 by 1
sbox = 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 OB
if OBBearMitigation > top
array.remove(shortBoxes, i)
box.delete(sbox)
// Alerts
if high > bot and sell_alert
alert('Price inside Bearish OB', alert.freq_once_per_bar)
// ----------------- Bullish Clean Up -------------------
// Clean up OB boxes and place alerts
if array.size(longBoxes) > 0
for i = array.size(longBoxes) - 1 to 0 by 1
sbox = 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 OB
if OBBullMitigation < bot
array.remove(longBoxes, i)
box.delete(sbox)
// Alerts
if low < top and buy_alert
alert('Price inside Bullish OB', alert.freq_once_per_bar)
Les rectangles qui vont au fond du graphique sont ceux de tradingwiew (tracé à la main).
Les autres ceux de PRT.
Salut… 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
On attends la publication
Vous 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.
Druby
// Sonarlabs - Order Block Finder
// converted from TradingView
// Lower the sensitivity to show more order blocks. A higher sensitivity will show less order blocks
defparam drawonlastbaronly=true
Transparency = 80
Transparency = abs(max(0,min(255,Transparency))) // input gaurd +0-255
sens = 28
sens = abs(max(1,sens)) // input guard +1-?
obcreatedbear = 0 // once obcreatedbear = 0 // variables need to reset every time
obcreatedbull = 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/100
OBBullMitigation = 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 OB
if pc crosses under -sens then
obcreatedbear = 1
crossindexbear = barindex
//crossindex = barindex
endif
// If the ROC crossover our Sensitivty input - Then create a Bullish Order Block
if pc crosses over sens then
obcreatedbull = 1
crossindexbull = barindex
//crossindex = barindex
endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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 then
lastgreen = 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 15
if close[i] > open[i] then
lastgreen = 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 data
break
endif
next
endif
// -------------------------------
// 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 then
lastred = 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 15
if close[ibull] < open[ibull] then
lastred = 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 data
break
endif
next
endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Cleanup
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Clean up Bearish OB boxes
if plot>0 then
for j = plot-1 downto 0 //0 to plot-1
// If the two last closes are above the high of the bearish OB - Remove the OB
if $left[j]>0 then //check if the zone still exist
itop = $top[j]
breakout = summation[max(1,barindex-$left[j])](OBBearMitigation>itop)>=1 //2
if breakout then
$left[j]=0
endif
endif
next
endif
// Clean up Bullish OB boxes
if plotbull>0 then
for jbull = plotbull-1 downto 0 //0 to plotbull-1
// If the two last closes are below the low of the bullish OB - Remove the OB
if $leftbull[jbull]>0 then //check if the zone still exist
ibot = $bottombull[jbull]
breakoutbull = summation[max(1,barindex-$leftbull[jbull])](OBBullMitigation<ibot)>=1
if breakoutbull then
$leftbull[jbull]=0
endif
endif
next
endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Drawing
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if islastbarupdate then
//plot the Bearish boxes
if plot>0 then //islastbarupdate and
for j = plot-1 downto 0 //0 to plot-1
if $left[j]>0 then
drawrectangle($left[j],$top[j],barindex,$bottom[j]) coloured("red",Transparency)bordercolor("red",Transparency)
endif
next
endif
//plot the Bullish boxes
if plotbull>0 then //islastbarupdate and
for jbull = plotbull-1 downto 0 //0 to plotbull-1
if $leftbull[jbull]>0 then
drawrectangle($leftbull[jbull],$bottombull[jbull],barindex,$topbull[jbull]) coloured("green",Transparency)bordercolor("green",Transparency)
endif
next
endif
endif
return
// 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 together
Y aurait-il moyen pouvoir ajouter une alerte à chaque nouveau rectangle?
ORDER BLOCK PRT TRADINGWIEW différence
This topic contains 5 replies,
has 3 voices, and was last updated by ARLEQUIN49
1 year, 10 months ago.
| Forum: | ProBuilder : Indicateurs & Outils Personnalisés |
| Language: | French |
| Started: | 03/17/2024 |
| Status: | Active |
| Attachments: | 3 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.