ATR Stop Loss Finder
Forums › ProRealTime forum Français › Support ProBuilder › ATR Stop Loss Finder
- This topic has 2 replies, 2 voices, and was last updated 2 years ago by
achraf.
-
-
07/19/2022 at 5:25 PM #197514
bonjour
je sais pas si je suis sur le bon forum, je cherche a convertir cet indicateur ATR STOP LOSS FINDER version tradingview en version prorealtime.
voici le code :
//@version=4
study(title=”Average True Range Stop Loss Finder”, shorttitle=”ATR”, overlay=true)
length = input(title=”Length”, defval=14, minval=1)
smoothing = input(title=”Smoothing”, defval=”RMA”, options=[“RMA”, “SMA”, “EMA”, “WMA”])
m = input(1.5, “Multiplier”)
src1 = input(high)
src2 = input(low)
pline = input(true, “Show Price Lines”)
col1 = input(color.blue, “ATR Text Color”)
col2 = input(color.teal, “Low Text Color”,inline =”1″)
col3 = input(color.red, “High Text Color”,inline =”2″)collong = input(color.teal, “Low Line Color”,inline =”1″)
colshort = input(color.red, “High Line Color”,inline =”2″)ma_function(source, length) =>
if smoothing == “RMA”
rma(source, length)
else
if smoothing == “SMA”
sma(source, length)
else
if smoothing == “EMA”
ema(source, length)
else
wma(source, length)a = ma_function(tr(true), length) * m
x = ma_function(tr(true), length) * m + src1
x2 = src2 – ma_function(tr(true), length) * mp1 = plot(x, title = “ATR Short Stop Loss”, color= colshort, transp=20, trackprice = pline ? true : false)
p2 = plot(x2, title = “ATR Long Stop Loss”, color= collong, transp=20, trackprice = pline ? true : false)var table Table = table.new(position.bottom_center, 3, 1, border_width = 3)
f_fillCell(_table, _column, _row, _value, _timeframe) =>
_cellText = _timeframe+ tostring(_value, “#.#”)
table.cell(_table, _column, _row, _cellText, text_color = col1)
table.cell_set_text_color(Table, 1, 0, color.new(col3, transp = 0))
table.cell_set_text_color(Table, 2, 0, color.new(col2, transp = 0))if barstate.islast
f_fillCell(Table, 0, 0, a, “ATR: ” )
f_fillCell(Table, 1, 0, x, “H: ” )
f_fillCell(Table, 2, 0, x2, “L: ” )07/20/2022 at 4:26 PM #197580BJ…
Quelque part, j’ai entendu le nom “Trading View” et le langage de codage “pin”. Mais c’est pour ça.
En regardant le code, cela ne semblait pas si compliqué d’après ma connaissance des choses, alors j’ai décidé de relever le défi.
Ci-dessous le fruit de mon travail. Ce n’est qu’une version de base pour prouver le concept et ne fait que la moyenne “RMA” avec une fonctionnalité limitée.
Si vous copiez le code, vous devez configurer les variables dynamiques répertoriées en haut du fichier de code.
L’importation du fichier à partir du bas doit inclure ces paramètres.
La couleur/le style de la ligne peut être défini dans les paramètres de l’indicateur.Faites-moi savoir quelles autres moyennes et/ou fonctionnalités vous souhaitez être accordées.
La lampe ne demande qu’à être frottée
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960// HstopL v1 20-07-2022 druby//// Dynamic variable settings// NAME Type Default (comment)// -------------------------------------------------------------------// Period integer 14 lookback range// Mul Decimal 1.5 multiply the ATR value by:defparam drawonlastbaronly = true// input limiters - limit the range of values used in code calculationsperiod = max(min(Period,barindex),1) // (1 to barindex)mul = max(min(Mul,10),0) // (0 to 10)//true range calculationtr1 = abs(high - low)tr2 = abs(high - close[1])tr3 = abs(low - close[1])trf = max(tr3,max(tr1,tr2)) // absolute maximum of (tr1,tr2,tr3)if barindex > period then // delay average calculations till enough bars avaliable// manual RMA calculationk= 1/(period)RMA = range * k + RMA[1] * (1-k)xma = RMA// Atr, HLline calculations// Atr valuea = xma * mul// Atr +/- high/low valuesx = xma * mul + highx2 = low - xma * mulendif // barindex > period// Drawing main text and valuesDrawtext("ATR: #a#",-255,10,dialog,bold,20)anchor(bottom) coloured ("dodgerblue")Drawtext("H: #x#", -70,10,dialog,bold,20)anchor(bottom) coloured ("red")Drawtext("L: #x2#", 100,10,dialog,bold,20)anchor(bottom) coloured ("teal")// draw averageType labelDrawtext("RMA",40,10,dialog,bold,20)anchor(bottomLeft) coloured ("grey")// return (atr * mul) high and low linesreturn x as"Hstop",x2 as"Lstop"// Known limitations not limited to:// There's 'NO' feedback between, the changing of the value a dynamic variable from its// default value and what value is used in the executing code if changed internally.// It is permitted to change the value of dynamic variables while the code is being// executed, however setting a value outside a valid range, suitable for the// application at hand, could lead to erroneous data or the indicator to crash.// Though some input limiting is done above, a value outside the valid range will adopt// the closest valid value and will 'not' issue any error or notification. Also an// 'out of range' value other than appearing in the indicator settings will also// appear in the indicator label box on the chart panel and in the cursor info label(s).//// Feedback Welcome!12/03/2022 at 4:42 PM #205226 -
AuthorPosts
Find exclusive trading pro-tools on