You are on page 1of 3

instrument { name = "pdv_Trailing Stops", overlay = true }

period = input (20, "front.period", input.integer, 1)


shift = input (5, "front.newind.offset", input.double, 0.01, 300, 0.01)
fn = input (averages.ema, "front.newind.average", input.string_selection,
averages.titles)
input_group {
"front.top line",
upper_line_visible = input { default = true, type = input.plot_visibility },
upper_line_color = input { default = "#25FC13", type = input.color },
upper_line_width = input { default = 2, type = input.line_width }
}

input_group {
"front.bottom line",
lower_line_visible = input { default = true, type = input.plot_visibility },
lower_line_color = input { default = "#FA0A53", type = input.color },
lower_line_width = input { default = 2, type = input.line_width }
}

input_group {
"front.newind.adx.fill",
fill_visible = input { default = true, type = input.plot_visibility },
fill_color = input { default = rgba(226, 0, 255, 0.12), type = input.color },
}
local averageFunction = averages [fn]
middle = averageFunction (hlc3, period)
offset = rma(tr, period) * shift
upper = middle + offset
lower = middle - offset
if fill_visible then
fill { first = upper, second = lower, color = fill_color }
end
if upper_line_visible then
plot (upper, "Upper", upper_line_color, upper_line_width, 0, style.dash_line)
end
if lower_line_visible then
plot (lower, "Lower", lower_line_color, lower_line_width, 0, style.dash_line)
end

instrument { name = "pdv_Trailing Stops", overlay = true, icon="indicators:ATR" }


period = input (14, "front.period", input.integer, 1 )
multiplier = input (2, "front.newind.multiplier", input.double, 1 )
high_low = input (false, "HighLow", input.boolean)
input_group {
"front.newind.colors",
up = input { default = "#2CAC40", type = input.color },
down = input { default = "#DB4931", type = input.color },
width = input { default = 8, type = input.line_width }
}
atr = rma (tr, period) * multiplier
h = iff (high_low, high, close)
l = iff (high_low, low, close)
atr_ts = iff(close > nz(atr_ts[1], 0) and close[1] > nz(atr_ts[1], 0),
max(nz(atr_ts[1]), h - atr),
iff(close < nz(atr_ts[1], 0) and close[1] < nz(atr_ts[1], 0), min(nz(atr_ts[1]), l
+ atr),
iff(close > nz(atr_ts[1], 0), h - atr, l + atr)))
pos = iff(close[1] < nz(atr_ts[1], 0) and close > nz(atr_ts[1], 0), 1,
iff(close[1] > nz(atr_ts[1], 0) and close < nz(atr_ts[1], 0), -1, nz(pos[1], 0)))
plot (atr_ts, "", pos < 0 and down or up , width, 0, style.crosses)

instrument { name = "pdv_Trailing Stops", icon="jpg", overlay = true }

input_group {
"MACD",
"Slow and fast EMA periods, used in MACD calculation",
fast = input (12, "front.platform.fast period", input.integer, 1, 250),
slow = input (26, "front.platform.fast period", input.integer, 1, 250)
}
input_group {
"front.platform.signal-line",
"Reference signal series period",
signal_period = input (9, "front.period", input.integer, 1, 250)
}
input_group {
"front.newind.emaperiod",
ema_period = input (13, "front.period", input.integer, 1, 250)
}
input_group {
"front.newind.barcolors",
positive = input { default = "#00ff00", type = input.color },
neutral = input { default = "#ffffff", type = input.color },
negative = input { default = "#FF0000", type = input.color },
}
fastMA = ema(close, fast)
slowMA = ema(close, slow)
macd = fastMA - slowMA
signal = sma(macd, signal_period)
hist = macd - signal
ema13 = ema (close, ema_period)
local bar_color
if ema13 > ema13 [1] and hist > hist [1] then
bar_color = positive
elseif ema13 < ema13 [1] and hist < hist [1] then
bar_color = negative
else
bar_color = neutral
end
plot_candle (open, high, low, close, "ES", bar_color)
instrument { name = "pdv_Trailing Stops", icon="jpg", overlay = true }

input_group {
"MACD",
"Slow and fast EMA periods, used in MACD calculation",
fast = input (12, "front.platform.fast period", input.integer, 1, 250),
slow = input (26, "front.platform.fast period", input.integer, 1, 250)
}
input_group {
"front.platform.signal-line",
"Reference signal series period",
signal_period = input (9, "front.period", input.integer, 1, 250)
}
input_group {
"front.newind.emaperiod",
ema_period = input (13, "front.period", input.integer, 1, 250)
}
input_group {
"front.newind.barcolors",
positive = input { default = "#00ff00", type = input.color },
neutral = input { default = "#ffffff", type = input.color },
negative = input { default = "#FF0000", type = input.color },
}
fastMA = ema(close, fast)
slowMA = ema(close, slow)
macd = fastMA - slowMA
signal = sma(macd, signal_period)
hist = macd - signal
ema13 = ema (close, ema_period)
local bar_color
if ema13 > ema13 [1] and hist > hist [1] then
bar_color = positive
elseif ema13 < ema13 [1] and hist < hist [1] then
bar_color = negative
else
bar_color = neutral
end
plot_candle (open, high, low, close, "ES", bar_color)

You might also like