0% found this document useful (0 votes)
26 views2 pages

atr level

indicator

Uploaded by

yas4mrh1402
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

atr level

indicator

Uploaded by

yas4mrh1402
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// © stupean

//@version=5
indicator("ATRLevels 1.0.0", overlay = true)

int atrLength = input.int(defval = 17, title = "Daily ATR length", minval = 1)


color defaultColorres = input.color(defval = color.new(#ff0000, 0), title = "Up")
color defaultColor0 = input.color(defval = color.new(color.white, 0), title = "0
Level")
color defaultColorsup = input.color(defval = color.new(#00ff00, 0), title = "down")

type LevelOption
float ratio
color lvlColor
string style = line.style_dotted
int width = 1

type Options
array<LevelOption> levelOptions

type Level
line ln
label lb

type ATRLevels
array<Level> levels
Options options

createDefaultLevelsOptions() =>
array.from(
LevelOption.new(1.618, defaultColorres),
LevelOption.new(1.5, defaultColorres),
LevelOption.new(1.236, defaultColorres),
LevelOption.new(1, defaultColorres),
LevelOption.new(0.786, defaultColorres),
LevelOption.new(0.618, defaultColorres),
LevelOption.new(0.5, defaultColorres),
LevelOption.new(0.236, defaultColorres),
LevelOption.new(0, defaultColor0),
LevelOption.new(-0.236, defaultColorsup),
LevelOption.new(-0.5, defaultColorsup),
LevelOption.new(-0.618, defaultColorsup),
LevelOption.new(-0.786, defaultColorsup),
LevelOption.new(-1, defaultColorsup),
LevelOption.new(-1.236, defaultColorsup),
LevelOption.new(-1.5, defaultColorsup),
LevelOption.new(-1.618, defaultColorsup))

enrichOptions(Options options) =>


options.levelOptions := na(options.levelOptions) ? createDefaultLevelsOptions()
: options.levelOptions

newInstance(Options options = na) =>


Options _options = na(options) ? Options.new() : options
enrichOptions(_options)
array<Level> levels = array.new<Level>()
for i = 0 to _options.levelOptions.size() - 1
LevelOption lvlOption = _options.levelOptions.get(i)
line ln = line.new(bar_index, close[1], bar_index, close[1], color =
lvlOption.lvlColor,style= line.style_dotted)
label lb = label.new(bar_index, close[1], str.format("{0,number,percent}",
lvlOption.ratio), style = label.style_none, textcolor =
lvlOption.lvlColor,size=size.tiny)
Level lvl = Level.new(ln, lb)
levels.push(lvl)
ATRLevels.new(levels = levels, options = _options)

method update(ATRLevels this, float atr) =>


float priceStep = atr / 4
for i = 0 to this.levels.size() - 1
Level lvl = this.levels.get(i)
LevelOption lvlOption = this.options.levelOptions.get(i)
line ln = lvl.ln
label lb = lvl.lb
ln.set_x2(bar_index + 300)
if session.isfirstbar_regular
float price = close[1] + (lvlOption.ratio * atr)
ln.set_x1(timeframe.isminutes ? bar_index : na)
ln.set_y1(timeframe.isminutes ? price :na)
ln.set_y2(timeframe.isminutes ? price : na)
lb.set_x(timeframe.isminutes ? bar_index : na)
lb.set_y(timeframe.isminutes ? price :na)

// main
var Options options = Options.new(levelOptions = createDefaultLevelsOptions())
var ATRLevels atrLevels = newInstance(options)
float atr = request.security(syminfo.tickerid, "D", ta.atr(atrLength))[1]
atrLevels.update(atr)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy