New Text Document (2) (1)
New Text Document (2) (1)
//
-----------------------------------------------------------------------------------
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
----------------------------------}
//
-----------------------------------------------------------------------------------
----------------------------------{
float source = input(hlc3, title='Source', group = "Settings")
int length = input.int(60, title="MA's Length", group = "Settings")
int gap_length = input.int(20, "Gap Length Between Fast And Slow MA's",
tooltip = "Determines the difference in lengths
between the slow and fast moving averages.
A higher gap length will increase the difference,
potentially identifying stronger trend signals"
)
int gap = input.int(10, "Gap Signals", minval = 10,
tooltip = "Defines the gap used for the smoothed
gradient signal function.
This parameter affects the sensitivity of the trend
signals by setting the number of bars used in the signal calculations."
)
// FUNCTIONS
//@function This function forces the current timeframe on inputs that shouldn't
take lower timeframes
FORCE_CTF(str_tf) =>
i_tf_sec = timeframe.in_seconds(str_tf)
ctf_sec = timeframe.in_seconds('')
// INPUTS
ha_htf = FORCE_CTF(input.timeframe('', 'Timeframe', tooltip="This timeframe must be
equal to or greater than the chart's timeframe", group="HA Market Bias"))
ha_len = input(100, 'Period', group="HA Market Bias")
ha_len2 = input(100, 'Smoothing', group="HA Market Bias")
//@function Handles the import of data from other timeframes, while preventing
repainting
//@param _resolution (str) : This is the timeframe to import data from.
//@param _expression (float | int) : This is the data to be imported
f_no_repaint_request(string _resolution, _expression) =>
request.security(syminfo.tickerid, _resolution, _expression[indexHighTF])
[indexCurrTF]
//#endregion
//
-----------------------------------------------------------------------------------
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
----------------------------------}
//
-----------------------------------------------------------------------------------
----------------------------------{
// Calculate moving averages
ema_ = ta.ema(source, length)
sma_ = ta.sma(source, length)
dema_ = ta.ema(2 * ta.ema(source, length) - ta.ema(ta.ema(source, length), length),
length)
vwma_ = ta.vwma(source, length)
if na(posterior_up)
posterior_up := 0
sigcolor = switch
(osc_bias > 0) and (osc_bias >= osc_smooth) => color.new(col_bull, 35)
(osc_bias > 0) and (osc_bias < osc_smooth) => color.new(col_bull, 75)
(osc_bias < 0) and (osc_bias <= osc_smooth) => color.new(col_bear, 35)
(osc_bias < 0) and (osc_bias > osc_smooth) => color.new(col_bear, 75)
=> color(na)
// }
//
-----------------------------------------------------------------------------------
----------------------------------}
// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
//
-----------------------------------------------------------------------------------
----------------------------------{
// Bar Color Trend
trend_col = posterior_up < 0.48
? color.from_gradient(posterior_up, 0, 0.48, colorDn, color.new(chart.bg_color,
20))
: posterior_up > 0.52 ? color.from_gradient(posterior_up, 0.52, 1,
color.new(chart.bg_color, 20), colorUp)
: chart.bg_color
// Plots
p_h = plot(h2, "Bias High", color=color(na), display=display.data_window,
editable=false)
p_l = plot(l2, "Bias Low", color=color(na), display=display.data_window,
editable=false)
p_avg = plot(ha_avg, "Bias Avergae", color=color(na), display=display.data_window,
editable=false)
fill(p_l, p_h, show_mb ? sigcolor : na)
// Signals
plotchar(ta.crossover(posterior_up, 0.5),
char = "◆",
location = location.belowbar,
size = size.tiny,
color = color.new(colorUp, 5)
)
plotchar(ta.crossunder(posterior_up, 0.5),
char = "◆",
location = location.abovebar,
size = size.tiny,
color = color.new(colorDn, 5)
)
// Alerts
// Bullish Trend Switch (Bearish -> Bullish)
alertcondition(ta.change(ta.change(math.sign(osc_bias)) > 0),
'Bullish Trend Switch (Bearish -> Bullish)', '{{exchange}}:{{ticker}}: Trend is
now Bullish.')
// CUSTOM ALERTS : To enable this functionality, Select and uncomment (Cmd (or
Ctrl) + /) the following code block, starting from the next line.
// // {
// use_custom_alerts = input.bool(false, 'Use Custom Alert Messages', group='Alert
Messages', display=display.none)
// i_alert_bull_trend_switch = input.text_area('New Bullish Trend', 'Bullish Trend
Switch', group='Alert Messages', display=display.none)
// i_alert_bull_trend_strengthen = input.text_area('New Strong Bullish Trend',
'Bullish Trend Strengthens', group='Alert Messages', display=display.none)
// i_alert_bull_trend_weaken = input.text_area('New Weak Bullish Trend', 'Bullish
Trend Weakens', group='Alert Messages', display=display.none)
// i_alert_bear_trend_switch = input.text_area('New Bearish Trend', 'Bearish Trend
Switch', group='Alert Messages', display=display.none)
// i_alert_bear_trend_strengthen = input.text_area('New Strong Bearish Trend',
'Bearish Trend Strengthens', group='Alert Messages', display=display.none)
// i_alert_bear_trend_weaken = input.text_area('New Weak Bearish Trend', 'Bearish
Trend Weakens', group='Alert Messages', display=display.none)
//
-----------------------------------------------------------------------------------
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
---------------------------------}
//
-----------------------------------------------------------------------------------
---------------------------------{
int len = input.int(100, "Swing Length")
bool hide_h_l = input.bool(true, "Levels", inline = "lvl", group =
"Levels")
bool broken_levels = input.bool(false, "Broken Levels", inline = "lvl", group =
"Levels")
bool history_levels = input.bool(false, "History Levels", inline = "lvl", group
= "Levels")
// Declare variables
var int index_h = na
var int index_l = na
var bool trend = false
//
-----------------------------------------------------------------------------------
//
-----------------------------------------------------------------------------------
---------------------------------{
float upper = ta.highest(len)
float lower = ta.lowest(len)
if upper_trigger
index_h := time[1]
if lower_trigger
index_l := time[1]
if high == upper
trend := true
if low == lower
trend := false
if not history_levels
line.delete(line_h[1])
line.delete(line_h1[1])
if not history_levels
line.delete(line_l[1])
line.delete(line_l1[1])
line_z.set_style(line.style_dashed)
line_l.set_x2(time)
line_l1.set_x2(time)
line_h.set_x2(time)
line_h1.set_x2(time)
bool cross_over = ta.crossover(low, line_h.get_y1())
bool cross_under = ta.crossunder(high, line_l.get_y1())
if barstate.islast
if trend != trend[1]
line.delete(line_up)
line.delete(line_dn)
label.delete(lbl_h)
label.delete(lbl_l)
if hide_h_l
lbl_h := label.new(bar_index
, line_h.get_y1()
, str.tostring(line_h.get_y1()
, "Swing H (#,###.####)")
, style = label.style_label_left
, color = color.new(upper_col, 50)
, textcolor = chart.fg_color)
lbl_l := label.new(bar_index
, line_l.get_y1()
, str.tostring(line_l.get_y1()
, "Swing L (#,###.####)")
, style = label.style_label_left
, color = color.new(lower_col, 50)
, textcolor = chart.fg_color)
label.delete(lbl_h[1])
label.delete(lbl_l[1])
line.delete(line_dn[1])
line.delete(line_up[1])
var tbl = table.new(position.top_right, 10, 10)
tbl.cell(0,0,"Swing Direction: ", text_color = chart.fg_color)
tbl.cell(1,0, (trend ? "⬈" : "⬊"), text_color = trend ? lower_col : upper_col,
text_size = size.huge)
if not hide_h_l
label.new(line_h.get_x1(), line_h.get_y2(), "", xloc = xloc.bar_time, color =
upper_col)
label.new(line_l.get_x1(), line_l.get_y2(), "", xloc = xloc.bar_time, style =
label.style_label_up, color = lower_col)