ค้นหาในสคริปต์สำหรับ "富时中国50期指"
EMA Crossover Strategy (15m)50 and 200 ema crossing when leaving anchor. when 50 and 200 crosses will give you direction of where market is going. wait for a pull back and take trade. sl on highest or lowest point of apex tp open . when you see multiple equal ( low or High) get put of trade.
The Lazy Trader - Index (ETF) Trend Following Robot50/150 moving average, index (ETF) trend following robot. Coded for people who cannot psychologically handle dollar-cost-averaging through bear markets and extreme drawdowns (although DCA can produce better results eventually), this robot helps you to avoid bear markets. Be a fair-weathered friend of Mr Market, and only take up his offer when the sun is shining! Designed for the lazy trader who really doesn't care...
Recommended Chart Settings:
Asset Class: ETF
Time Frame: Daily
Necessary ETF Macro Conditions:
a) Country must have healthy demographics, good ratio of young > old
b) Country population must be increasing
c) Country must be experiencing price-inflation
Default Robot Settings:
Slow Moving Average: 50 (integer) //adjust to suit your underlying index
Fast Moving Average: 150 (integer) //adjust to suit your underlying index
Bullish Slope Angle: 5 (degrees) //up angle of moving averages
Bearish Slope Angle: -5 (degrees) //down angle of moving averages
Average True Range: 14 (integer) //input for slope-angle formula
Risk: 100 (%) //100% risk means using all equity per trade
ETF Test Results (Default Settings):
SPY (1993 to 2020, 27 years), 332% profit, 20 trades, 6.4 profit factor, 7% drawdown
EWG (1996 to 2020, 24 years), 310% profit, 18 trades, 3.7 profit factor, 10% drawdown
EWH (1996 to 2020, 24 years), 4% loss, 26 trades, 0.9 profit factor, 36% drawdown
QQQ (1999 to 2020, 21 years), 232% profit, 17 trades, 3.6 profit factor, 2% drawdown
EEM (2003 to 2020, 17 years), 73% profit, 17 trades, 1.1 profit factor, 3% drawdown
GXC (2007 to 2020, 13 years), 18% profit, 14 trades, 1.3 profit factor, 26% drawdown
BKF (2009 to 2020, 11 years), 11% profit, 13 trades, 1.2 profit factor, 33% drawdown
A longer time in the markets is better, with the exception of EWH. 6 out of 7 tested ETFs were profitable, feel free to test on your favourite ETF (default settings) and comment below.
Risk Warning:
Not tested on commodities nor other financial products like currencies (code will not work), feel free to leave comments below.
Moving Average Slope Angle Formula:
Reproduced and modified from source:
50-Minute Opening Range BreakoutThis is a test of the opening range with Bearish/Bullish confirmation
50-Line Oscillator // (\_/)
// ( •.•)
// (")_(")
25-Line Oscillator
Description:
The 25-Line Oscillator is a sophisticated technical analysis tool designed to visualize market trends through the use of multiple Simple Moving Averages (SMAs). This indicator computes a series of 26 SMAs, incrementally increasing the base length, providing traders with a comprehensive view of price dynamics.
Features:
Customizable Base Length: Adjust the base length of the SMAs according to trading preferences, enhancing versatility for different market conditions.
Rainbow Effect: The indicator employs a visually appealing rainbow color scheme to differentiate between the various trend lines, making it easy to identify crossovers and momentum shifts.
Crossovers Detection: The script includes logic to detect crossover events between consecutive trend lines, which can serve as signals for potential entry or exit points in trading.
Clear Visualization: Suitable for both novice and seasoned traders, the plots enable quick interpretation of trends and market behavior.
How to Use:
Add the indicator to your chart and customize the base length as desired.
Observe the rainbow-colored lines for trend direction.
Look for crossover events between the SMAs as potential trading signals.
Application: This indicator is particularly useful for swing traders and trend followers who aim to capitalize on market momentum and identify reversals. By monitoring the behavior of multiple SMAs, traders can gain insights into the strength and direction of price movements over various time frames.
AK Simple Moving Average 50 days Simple Moving average suitable for Intraday on 1Hr,30Min.15Min Time frames
1. When candle crossing above SMA Line - Go for Long Entries
2. When candle crossing below SMA Line - Go for short Entries
50 SMA / 200 EMA / 128EMA Moving Average CrossFound success using 50SMA vs 200EMA.
128 EMA also charted for it's BTC relevance.
50/100/200 Moving Averages (Pine Script For Copy)by fresca
SCRIPT LANGUAGE
Copy script below and adjust based on your preferences.
-function (change function from "sma" to "ema", "wma" and more)
-length (25 Day, 150 Day or add more averages to the three in this script.)
-color, (red, yellow, etc. or use color hex codes i.e. #FEDA15, #FFAD8F, etc.)
-transparency (set to desired level 1-100)
Or add more options.
RESOURCES
Color hex codes site: www.canva.com
Trading View Pine Script Editor Reference Guide: www.tradingview.com
Taint's Multi Time Frame MA50-100-200 SMA with two 200 EMA's all with the ability choose a time frame for each.
ICT Killzones & FVG// This source code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org
// © Mutharasan12
//@version=5
indicator("ICT Killzones & FVG", "ICT Killzones & FVG", overlay = true, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500)
// ---------------------------------------- Constant Functions --------------------------------------------------
get_line_type(_style) =>
result = switch _style
'Solid' => line.style_solid
'Dotted' => line.style_dotted
'Dashed' => line.style_dashed
result
get_size(x) =>
result = switch x
'Auto' => size.auto
'Tiny' => size.tiny
'Small' => size.small
'Normal' => size.normal
'Large' => size.large
'Huge' => size.huge
get_table_pos(pos) =>
result = switch pos
"Bottom Center" => position.bottom_center
"Bottom Left" => position.bottom_left
"Bottom Right" => position.bottom_right
"Middle Center" => position.middle_center
"Middle Left" => position.middle_left
"Middle Right" => position.middle_right
"Top Center" => position.top_center
"Top Left" => position.top_left
"Top Right" => position.top_right
get_font_style(s) =>
result = switch s
'Monospace' => font.family_monospace
'Default' => font.family_default
// ---------------------------------------- Constant Functions --------------------------------------------------
// ---------------------------------------- Inputs --------------------------------------------------
gmt_tz = input.string('America/New_York', "Timezone", options = , tooltip = "Note GMT is not adjusted to reflect Daylight Saving Time changes", group = 'Time Zone')
DWM_profile = input.bool(true,"Show All Profile",inline="Show",group = 'Profile')
D_profile = input.bool(true,"Show Daily",inline = "Show",group = 'Profile')
hide_lines_DO = input.timeframe("60","Daily:",inline = "Hide",group = 'Hide Above')
W_profile = input.bool(true,"Weekly",inline="Show",group = 'Profile')
hide_lines_WO = input.timeframe("240","Weekly:",inline="Hide",group = 'Hide Above')
M_profile = input.bool(true,"Monthly",inline="Show",group = 'Profile')
hide_lines_MO = input.timeframe("1D","Monthly:",inline="Hide",group = 'Hide Above')
show_kz = input.bool(false, "Show Killzone Boxes", inline = "skz", group = 'Hide KillZone')
var g_SETTINGS = "Settings"
max_days = input.int(60, "Drawing Limit", 1, inline = 'dl', tooltip = "Only this many drawings will be kept on the chart, for each selected drawing type (killzone boxes, pivot lines, open lines, etc.)", group = g_SETTINGS)
tf_limit = input.timeframe("30", "Timeframe Limit", inline = 'dl', tooltip = "Drawings will not appear on timeframes greater than or equal to this", group = g_SETTINGS)
lbl_size = get_size(input.string('Tiny', "Label Size", inline = 'sc', options = , tooltip = "The size of all labels", group = g_SETTINGS))
font_style = get_font_style(input.string('Monospace', "Font Style", inline = 'sc', group = g_SETTINGS, options = ))
txt_color = input.color(#000000, "Text Color", inline = 'sc', tooltip = "The color of all label and table text", group = g_SETTINGS)
use_cutoff = input.bool(true, "Drawing Cutoff Time", inline = "CO", tooltip = "When enabled, all pivots and open price lines will stop extending at this time", group = g_SETTINGS)
cutoff = input.session("1700-1701", "", inline = "CO", group = g_SETTINGS)
var g_KZ = "Killzones"
show_kz_text = input.bool(false, "Display Text", inline = "KZ", group = g_KZ)
box_transparency = input.int(85, "Box Transparency", 0, 100, group = g_KZ)
text_transparency = input.int(50, "Text Transparency", 0, 100, group = g_KZ)
use_asia = input.bool(true, "", inline = "ASIA", group = g_KZ)
as_txt = input.string("ASIA", "", inline = "ASIA", group = g_KZ)
asia = input.session("2000-0000", "", inline = "ASIA", group = g_KZ)
as_color = input.color(#9598a1, "", inline = "ASIA", group = g_KZ)
use_london = input.bool(true, "", inline = "LONDON", group = g_KZ)
lo_txt = input.string("OPEN", "", inline = "LONDON", group = g_KZ)
london = input.session("0200-0500", "", inline = "LONDON", group = g_KZ)
lo_color = input.color(#9598a1, "", inline = "LONDON", group = g_KZ)
use_nyam = input.bool(true, "", inline = "NYAM", group = g_KZ)
na_txt = input.string("NYAM", "", inline = "NYAM", group = g_KZ)
nyam = input.session("0700-1000", "", inline = "NYAM", group = g_KZ)
na_color = input.color(#9598a1, "", inline = "NYAM", group = g_KZ)
use_nylu = input.bool(false, "", inline = "NYLU", group = g_KZ)
nl_txt = input.string("Lunch", "", inline = "NYLU", group = g_KZ)
nylu = input.session("1200-1300", "", inline = "NYLU", group = g_KZ)
nl_color = input.color(#9598a1, "", inline = "NYLU", group = g_KZ)
use_nypm = input.bool(false, "", inline = "NYPM", group = g_KZ)
np_txt = input.string("NYPM", "", inline = "NYPM", group = g_KZ)
nypm = input.session("1300-1600", "", inline = "NYPM", group = g_KZ)
np_color = input.color(#9598a1, "", inline = "NYPM", group = g_KZ)
use_loop = input.bool(true, "", inline = "LOOP", group = g_KZ)
op_txt = input.string("CBDR", "", inline = "LOOP", group = g_KZ)
loop = input.session("1400-2000", "", inline = "LOOP", group = g_KZ)
op_color = input.color(#9598a1, "", inline = "LOOP", group = g_KZ)
use_locl = input.bool(true, "", inline = "LOCL", group = g_KZ)
cl_txt = input.string("CLOSE", "", inline = "LOCL", group = g_KZ)
locl = input.session("1000-1200", "", inline = "LOCL", group = g_KZ)
cl_color = input.color(#9598a1, "", inline = "LOCL", group = g_KZ)
use_sb1 = input.bool(false, "", inline = "SB1", group = g_KZ)
m1_txt = input.string("London SB", "", inline = "SB1", group = g_KZ)
sb1 = input.session("0300-0400", "", inline = "SB1", group = g_KZ)
m1_color = input.color(#9598a1, "", inline = "SB1", group = g_KZ)
use_sb2 = input.bool(false, "", inline = "SB2", group = g_KZ)
m2_txt = input.string("NewYork AM SB", "", inline = "SB2", group = g_KZ)
sb2 = input.session("1000-1100", "", inline = "SB2", group = g_KZ)
m2_color = input.color(#9598a1, "", inline = "SB2", group = g_KZ)
use_sb3 = input.bool(false, "", inline = "SB3", group = g_KZ)
m3_txt = input.string("NewYork PM SB", "", inline = "SB3", group = g_KZ)
sb3 = input.session("1400-1500", "", inline = "SB3", group = g_KZ)
m3_color = input.color(#9598a1, "", inline = "SB3", group = g_KZ)
var g_LABELS = "Killzone Pivots"
use_alerts = input.bool(false, "Alert Broken Pivots", inline = "PV", group = g_LABELS)
show_pivots = input.bool(false, "Show Pivots", inline = "SV", group = g_LABELS)
show_labels = input.bool(false, "Pivots Labels", inline = "SV", group = g_LABELS)
show_midpoints = input.bool(false, "Pivots Midpoints",inline = "SV", group = g_LABELS)
ext_pivots = input.string("Until Mitigated", "Extend Pivots...", options = , group = g_LABELS)
ext_which = input.string("Most Recent", "...From Which Sessions", options = , group = g_LABELS)
ash_str = input.string("AS.H", "Killzone 01 Labels", inline = "L_AS", group = g_LABELS)
asl_str = input.string("AS.L", "", inline = "L_AS", group = g_LABELS)
loh_str = input.string("LO.H", "Killzone 02 Labels", inline = "L_LO", group = g_LABELS)
lol_str = input.string("LO.L", "", inline = "L_LO", group = g_LABELS)
nah_str = input.string("NYAM.H", "Killzone 03 Labels", inline = "L_NA", group = g_LABELS)
nal_str = input.string("NYAM.L", "", inline = "L_NA", group = g_LABELS)
nlh_str = input.string("NYL.H", "Killzone 04 Labels", inline = "L_NL", group = g_LABELS)
nll_str = input.string("NYL.L", "", inline = "L_NL", group = g_LABELS)
nph_str = input.string("NYPM.H", "Killzone 05 Labels", inline = "L_NP", group = g_LABELS)
npl_str = input.string("NYPM.L", "", inline = "L_NP", group = g_LABELS)
oph_str = input.string("LOOP.H", "Killzone 06 Labels", inline = "L_OP", group = g_LABELS)
opl_str = input.string("LOOP.L", "", inline = "L_OP", group = g_LABELS)
clh_str = input.string("LOCL.H", "Killzone 07 Labels", inline = "L_CL", group = g_LABELS)
cll_str = input.string("LOCL.L", "", inline = "L_CL", group = g_LABELS)
m1h_str = input.string("SB1.H", "Killzone 08 Labels", inline = "L_M1", group = g_LABELS)
m1l_str = input.string("SB1.L", "", inline = "L_M1", group = g_LABELS)
m2h_str = input.string("SB2.H", "Killzone 09 Labels", inline = "L_M2", group = g_LABELS)
m2l_str = input.string("SB2.L", "", inline = "L_M2", group = g_LABELS)
m3h_str = input.string("SB3.H", "Killzone 10 Labels", inline = "L_M3", group = g_LABELS)
m3l_str = input.string("SB3.L", "", inline = "L_M3", group = g_LABELS)
kzp_style = get_line_type(input.string(defval = 'Solid', title = "Pivot Style", options = , inline = "KZP", group = g_LABELS))
kzp_width = input.int(1, "", inline = "KZP", group = g_LABELS)
kzm_style = get_line_type(input.string(defval = 'Dotted', title = "Midpoint Style", options = , inline = "KZM", group = g_LABELS))
kzm_width = input.int(1, "", inline = "KZM", group = g_LABELS)
var g_RNG = "Killzone Range"
show_range = input.bool(false, "Show Killzone Range", tooltip = "Show the most recent ranges of each selected killzone, from high to low", group = g_RNG)
show_range_avg = input.bool(true, "Show Average", tooltip = "Show the average range of each selected killzone", group = g_RNG)
range_avg = input.int(5, "Average Length", 0, tooltip = "This many previous sessions will be used to calculate the average. If there isn't enough data on the current chart, it will use as many sessions as possible", group = g_RNG)
range_pos = get_table_pos(input.string('Top Right', "Table Position", options = , group = g_RNG))
range_size = get_size(input.string('Normal', "Table Size", options = , group = g_RNG))
var g_DWM = "Day - Week - Month"
dow_labels = input.bool(false, "Day of Week Labels", inline = "DOW", group = g_DWM)
dow_yloc = input.string('Bottom', "", options = , inline = "DOW", group = g_DWM)
dow_xloc = input.string('Midnight', "", options = , inline = "DOW", group = g_DWM)
sep_unlimited = input.bool(true, "Unlimited", tooltip = "Unlimited will show as many of the selected lines as possible. Otherwise, the session drawing limit will be used", group = g_DWM)
show_d_open = input.bool(true, "D Open", inline = "DO", group = g_DWM)
dhl = input.bool(true, "High/Low", inline = "DO", tooltip = "", group = g_DWM)
ds = input.bool(true, "Separators", inline = "DO", tooltip = "Mark where a new day begins", group = g_DWM)
d_color = input.color(color.blue, "", inline = "DO", group = g_DWM)
show_w_open = input.bool(true, "W Open", inline = "WO", group = g_DWM)
whl = input.bool(true, "High/Low", inline = "WO", tooltip = "", group = g_DWM)
ws = input.bool(true, "Separators", inline = "WO", tooltip = "Mark where a new week begins", group = g_DWM)
w_color = input.color(#089981, "", inline = "WO", group = g_DWM)
show_m_open = input.bool(true, "M Open", inline = "MO", group = g_DWM)
mhl = input.bool(true, "High/Low", inline = "MO", tooltip = "", group = g_DWM)
ms = input.bool(true, "Separators", inline = "MO", tooltip = "Mark where a new month begins", group = g_DWM)
m_color = input.color(color.red, "", inline = "MO", group = g_DWM)
htf_style = get_line_type(input.string(defval = 'Dotted', title = "Style", options = , inline = "D0", group = g_DWM))
htf_width = input.int(1, "", inline = "D0", group = g_DWM)
var g_OPEN = "Opening Prices"
open_unlimited = input.bool(true, "Unlimited", tooltip = "Unlimited will show as many of the selected lines as possible. Otherwise, the session drawing limit will be used", group = g_OPEN)
hide_hline = input.bool(true,"Show Opening Price",group = g_OPEN)
hide_lines_h = input.timeframe("60","Hide Above Time Frame",group = g_OPEN)
use_h1 = input.bool(true, "", inline = "H1", group = g_OPEN)
h1_text = input.string("00:00", "", inline = "H1", group = g_OPEN)
h1 = input.session("0000-0001", "", inline = "H1", group = g_OPEN)
h1_color = input.color(#000000, "", inline = "H1", group = g_OPEN)
use_h2 = input.bool(true, "", inline = "H2", group = g_OPEN)
h2_text = input.string("08:30", "", inline = "H2", group = g_OPEN)
h2 = input.session("0830-0831", "", inline = "H2", group = g_OPEN)
h2_color = input.color(#000000, "", inline = "H2", group = g_OPEN)
use_h3 = input.bool(false, "", inline = "H3", group = g_OPEN)
h3_text = input.string("10:00", "", inline = "H3", group = g_OPEN)
h3 = input.session("1000-1001", "", inline = "H3", group = g_OPEN)
h3_color = input.color(#000000, "", inline = "H3", group = g_OPEN)
use_h4 = input.bool(false, "", inline = "H4", group = g_OPEN)
h4_text = input.string("14:00", "", inline = "H4", group = g_OPEN)
h4 = input.session("1400-1401", "", inline = "H4", group = g_OPEN)
h4_color = input.color(#000000, "", inline = "H4", group = g_OPEN)
hz_style = get_line_type(input.string(defval = 'Dotted', title = "Style", options = , inline = "H0", group = g_OPEN))
hz_width = input.int(1, "", inline = "H0", group = g_OPEN)
var g_VERTICAL = "Timestamps"
hide_vline = input.bool(true,"Show Timestamp",group = g_VERTICAL)
hide_lines_v = input.timeframe("60","Hide Above Time Frame",group = g_VERTICAL)
use_v1 = input.bool(true, "", inline = "V1", group = g_VERTICAL)
v1 = input.session("0000-0001", "", inline = "V1", group = g_VERTICAL)
v1_color = input.color(#000000, "", inline = "V1", group = g_VERTICAL)
use_v2 = input.bool(false, "", inline = "V2", group = g_VERTICAL)
v2 = input.session("0800-0801", "", inline = "V2", group = g_VERTICAL)
v2_color = input.color(#000000, "", inline = "V2", group = g_VERTICAL)
use_v3 = input.bool(false, "", inline = "V3", group = g_VERTICAL)
v3 = input.session("1000-1001", "", inline = "V3", group = g_VERTICAL)
v3_color = input.color(#000000, "", inline = "V3", group = g_VERTICAL)
use_v4 = input.bool(false, "", inline = "V4", group = g_VERTICAL)
v4 = input.session("1200-1201", "", inline = "V4", group = g_VERTICAL)
v4_color = input.color(#000000, "", inline = "V4", group = g_VERTICAL)
vl_style = get_line_type(input.string(defval = 'Dotted', title = "Style", options = , inline = "V0", group = g_VERTICAL))
vl_width = input.int(1, "", inline = "V0", group = g_VERTICAL)
// ---------------------------------------- Inputs --------------------------------------------------
// ---------------------------------------- Variables & Constants --------------------------------------------------
type kz
string _title
box _box
line _hi_line
line _md_line
line _lo_line
label _hi_label
label _lo_label
bool _hi_valid
bool _md_valid
bool _lo_valid
float _range_store
float _range_current
type hz
line LN
label LB
bool CO
type dwm_hl
line hi_line
line lo_line
label hi_label
label lo_label
type dwm_info
string tf
float o = na
float h = na
float l = na
float ph = na
float pl = na
var as_kz = kz.new(as_txt, array.new_box(), array.new_line(), array.new_line(), array.new_line(), array.new_label(), array.new_label(), array.new_bool(), array.new_bool(), array.new_bool(), array.new_float())
var lo_kz = kz.new(lo_txt, array.new_box(), array.new_line(), array.new_line(), array.new_line(), array.new_label(), array.new_label(), array.new_bool(), array.new_bool(), array.new_bool(), array.new_float())
var na_kz = kz.new(na_txt, array.new_box(), array.new_line(), array.new_line(), array.new_line(), array.new_label(), array.new_label(), array.new_bool(), array.new_bool(), array.new_bool(), array.new_float())
var nl_kz = kz.new(nl_txt, array.new_box(), array.new_line(), array.new_line(), array.new_line(), array.new_label(), array.new_label(), array.new_bool(), array.new_bool(), array.new_bool(), array.new_float())
var np_kz = kz.new(np_txt, array.new_box(), array.new_line(), array.new_line(), array.new_line(), array.new_label(), array.new_label(), array.new_bool(), array.new_bool(), array.new_bool(), array.new_float())
var op_kz = kz.new(op_txt, array.new_box(), array.new_line(), array.new_line(), array.new_line(), array.new_label(), array.new_label(), array.new_bool(), array.new_bool(), array.new_bool(), array.new_float())
var cl_kz = kz.new(cl_txt, array.new_box(), array.new_line(), array.new_line(), array.new_line(), array.new_label(), array.new_label(), array.new_bool(), array.new_bool(), array.new_bool(), array.new_float())
var m1_kz = kz.new(m1_txt, array.new_box(), array.new_line(), array.new_line(), array.new_line(), array.new_label(), array.new_label(), array.new_bool(), array.new_bool(), array.new_bool(), array.new_float())
var m2_kz = kz.new(m2_txt, array.new_box(), array.new_line(), array.new_line(), array.new_line(), array.new_label(), array.new_label(), array.new_bool(), array.new_bool(), array.new_bool(), array.new_float())
var m3_kz = kz.new(m3_txt, array.new_box(), array.new_line(), array.new_line(), array.new_line(), array.new_label(), array.new_label(), array.new_bool(), array.new_bool(), array.new_bool(), array.new_float())
var hz_1 = hz.new(array.new_line(), array.new_label(), array.new_bool())
var hz_2 = hz.new(array.new_line(), array.new_label(), array.new_bool())
var hz_3 = hz.new(array.new_line(), array.new_label(), array.new_bool())
var hz_4 = hz.new(array.new_line(), array.new_label(), array.new_bool())
var d_hl = dwm_hl.new(array.new_line(), array.new_line(), array.new_label(), array.new_label())
var w_hl = dwm_hl.new(array.new_line(), array.new_line(), array.new_label(), array.new_label())
var m_hl = dwm_hl.new(array.new_line(), array.new_line(), array.new_label(), array.new_label())
var d_info = dwm_info.new("D")
var w_info = dwm_info.new("W")
var m_info = dwm_info.new("M")
t_as = not na(time("", asia, gmt_tz))
t_lo = not na(time("", london, gmt_tz))
t_na = not na(time("", nyam, gmt_tz))
t_nl = not na(time("", nylu, gmt_tz))
t_np = not na(time("", nypm, gmt_tz))
t_op = not na(time("", loop, gmt_tz))
t_cl = not na(time("", locl, gmt_tz))
t_m1 = not na(time("", sb1, gmt_tz))
t_m2 = not na(time("", sb2, gmt_tz))
t_m3 = not na(time("", sb3, gmt_tz))
t_co = not na(time("", cutoff, gmt_tz))
t_h1 = not na(time("", h1, gmt_tz))
t_h2 = not na(time("", h2, gmt_tz))
t_h3 = not na(time("", h3, gmt_tz))
t_h4 = not na(time("", h4, gmt_tz))
t_v1 = not na(time("", v1, gmt_tz))
t_v2 = not na(time("", v2, gmt_tz))
t_v3 = not na(time("", v3, gmt_tz))
t_v4 = not na(time("", v4, gmt_tz))
var d_sep_line = array.new_line()
var w_sep_line = array.new_line()
var m_sep_line = array.new_line()
var d_line = array.new_line()
var w_line = array.new_line()
var m_line = array.new_line()
var d_label = array.new_label()
var w_label = array.new_label()
var m_label = array.new_label()
var v1_line = array.new_line()
var v2_line = array.new_line()
var v3_line = array.new_line()
var v4_line = array.new_line()
var transparent = #ffffff00
var ext_current = ext_which == 'Most Recent'
var ext_past = ext_pivots == 'Past Mitigation'
update_dwm_info(dwm_info n) =>
if timeframe.change(n.tf)
n.ph := n.h
n.pl := n.l
n.o := open
n.h := high
n.l := low
else
n.h := math.max(high, n.h)
n.l := math.min(low, n.l)
if dhl or show_d_open
update_dwm_info(d_info)
if whl or show_w_open
update_dwm_info(w_info)
if mhl or show_m_open
update_dwm_info(m_info)
// ---------------------------------------- Variables & Constants --------------------------------------------------
// ---------------------------------------- Functions --------------------------------------------------
get_box_color(color c) =>
result = color.new(c, box_transparency)
get_text_color(color c) =>
result = color.new(c, text_transparency)
// ---------------------------------------- Functions --------------------------------------------------
// ---------------------------------------- Core Logic --------------------------------------------------
dwm_sep(string tf, bool use, line arr, color col) =>
if use
if timeframe.change(tf)
arr.unshift(line.new(bar_index, high*1.0001, bar_index, low, style = htf_style, width = htf_width, extend = extend.both, color = col))
if not sep_unlimited and arr.size() > max_days
arr.pop().delete()
dwm_open(string tf, bool use, line lns, label lbls, dwm_info n, color col) =>
if use
if timeframe.change(tf)
lns.unshift(line.new(time, n.o, time, n.o, xloc = xloc.bar_time, style = htf_style, width = htf_width, color = col))
lbls.unshift(label.new(time, n.o, tf + " OPEN", xloc = xloc.bar_time, style = label.style_label_left, color = transparent, textcolor = txt_color, size = lbl_size, text_font_family = font_style))
if not sep_unlimited and lns.size() > max_days
lns.pop().delete()
lbls.pop().delete()
else if lns.size() > 0
lns.get(0).set_x2(time)
lbls.get(0).set_x(time)
dwm_hl(string tf, bool use, dwm_hl hl, dwm_info n, color col) =>
if use
if timeframe.change(tf)
hl.hi_line.unshift(line.new(time, n.ph, time, n.ph, xloc = xloc.bar_time, style = htf_style, width = htf_width, color = col))
hl.lo_line.unshift(line.new(time, n.pl, time, n.pl, xloc = xloc.bar_time, style = htf_style, width = htf_width, color = col))
hl.hi_label.unshift(label.new(time, n.ph, "P"+tf+"H", xloc = xloc.bar_time, style = label.style_label_left, color = transparent, textcolor = txt_color, size = lbl_size, text_font_family = font_style))
hl.lo_label.unshift(label.new(time, n.pl, "P"+tf+"L", xloc = xloc.bar_time, style = label.style_label_left, color = transparent, textcolor = txt_color, size = lbl_size, text_font_family = font_style))
if not sep_unlimited and hl.hi_line.size() > max_days
hl.hi_line.pop().delete()
hl.lo_line.pop().delete()
hl.hi_label.pop().delete()
hl.lo_label.pop().delete()
else if hl.hi_line.size() > 0
hl.hi_line.get(0).set_x2(time)
hl.lo_line.get(0).set_x2(time)
hl.hi_label.get(0).set_x(time)
hl.lo_label.get(0).set_x(time)
dwm() =>
//if timeframe.in_seconds() <= hide_lines_sessions *60
if DWM_profile
if D_profile and timeframe.in_seconds("") <= timeframe.in_seconds(hide_lines_DO)
// Draw Daily separators, open lines, and high/low lines
dwm_sep("D", ds, d_sep_line, d_color)
dwm_open("D", show_d_open, d_line, d_label, d_info, d_color)
dwm_hl("D", dhl, d_hl, d_info, d_color)
// Draw Weekly and Monthly only if Daily profile allows it
if W_profile and timeframe.in_seconds("") <= timeframe.in_seconds(hide_lines_WO)
dwm_sep("W", ws, w_sep_line, w_color)
dwm_open("W", show_w_open, w_line, w_label, w_info, w_color)
dwm_hl("W", whl, w_hl, w_info, w_color)
if M_profile and timeframe.in_seconds("") <= timeframe.in_seconds(hide_lines_MO)
dwm_sep("M", ms, m_sep_line, m_color)
dwm_open("M", show_m_open, m_line, m_label, m_info, m_color)
dwm_hl("M", mhl, m_hl, m_info, m_color)
else if W_profile and timeframe.in_seconds("") <= timeframe.in_seconds(hide_lines_WO)
// Draw Weekly separators, open lines, and high/low lines
dwm_sep("W", ws, w_sep_line, w_color)
dwm_open("W", show_w_open, w_line, w_label, w_info, w_color)
dwm_hl("W", whl, w_hl, w_info, w_color)
// Draw Monthly only if Weekly profile allows it
if M_profile and timeframe.in_seconds("") <= timeframe.in_seconds(hide_lines_MO)
dwm_sep("M", ms, m_sep_line, m_color)
dwm_open("M", show_m_open, m_line, m_label, m_info, m_color)
dwm_hl("M", mhl, m_hl, m_info, m_color)
else if M_profile and timeframe.in_seconds("") <= timeframe.in_seconds(hide_lines_MO)
// Draw Monthly separators, open lines, and high/low lines
dwm_sep("M", ms, m_sep_line, m_color)
dwm_open("M", show_m_open, m_line, m_label, m_info, m_color)
dwm_hl("M", mhl, m_hl, m_info, m_color)
vline(bool use, bool t, line arr, color col) =>
if use
if t and not t
arr.unshift(line.new(bar_index, high*1.0001, bar_index, low, style = vl_style, width = vl_width, extend = extend.both, color = col))
vlines() =>
if hide_vline
if timeframe.in_seconds("") <= timeframe.in_seconds(hide_lines_v)
vline(use_v1, t_v1, v1_line, v1_color)
vline(use_v2, t_v2, v2_line, v2_color)
vline(use_v3, t_v3, v3_line, v3_color)
vline(use_v4, t_v4, v4_line, v4_color)
hz_line(bool use, bool t, hz hz, string txt, color col) =>
if use
if t and not t
hz.LN.unshift(line.new(bar_index, open, bar_index, open, style = hz_style, width = hz_width, color = col))
hz.LB.unshift(label.new(bar_index, open, txt, style = label.style_label_left, color = transparent, textcolor = txt_color, size = lbl_size, text_font_family = font_style))
array.unshift(hz.CO, false)
if not open_unlimited and hz.LN.size() > max_days
hz.LN.pop().delete()
hz.LB.pop().delete()
hz.CO.pop()
if not t and hz.CO.size() > 0
if not hz.CO.get(0)
hz.LN.get(0).set_x2(bar_index)
hz.LB.get(0).set_x(bar_index)
if (use_cutoff ? t_co : false)
hz.CO.set(0, true)
hz_lines() =>
if hide_hline
if timeframe.in_seconds("") <= timeframe.in_seconds(hide_lines_h)
hz_line(use_h1, t_h1, hz_1, h1_text, h1_color)
hz_line(use_h2, t_h2, hz_2, h2_text, h2_color)
hz_line(use_h3, t_h3, hz_3, h3_text, h3_color)
hz_line(use_h4, t_h4, hz_4, h4_text, h4_color)
del_kz(kz k) =>
if k._box.size() > max_days
k._box.pop().delete()
if k._hi_line.size() > max_days
k._hi_line.pop().delete()
k._lo_line.pop().delete()
k._hi_valid.pop()
k._lo_valid.pop()
if show_midpoints
k._md_line.pop().delete()
k._md_valid.pop()
if k._hi_label.size() > max_days
k._hi_label.pop().delete()
k._lo_label.pop().delete()
adjust_in_kz(kz kz, bool t) =>
if t
kz._box.get(0).set_right(time)
kz._box.get(0).set_top(math.max(kz._box.get(0).get_top(), high))
kz._box.get(0).set_bottom(math.min(kz._box.get(0).get_bottom(), low))
kz._range_current := kz._box.get(0).get_top() - kz._box.get(0).get_bottom()
if show_pivots and kz._hi_line.size() > 0
if high > kz._hi_line.get(0).get_y1()
kz._hi_line.get(0).set_xy1(time, high)
kz._hi_line.get(0).set_xy2(time, high)
if low < kz._lo_line.get(0).get_y1()
kz._lo_line.get(0).set_xy1(time, low)
kz._lo_line.get(0).set_xy2(time, low)
if show_midpoints
kz._md_line.get(0).set_xy1(time, math.avg(kz._hi_line.get(0).get_y2(), kz._lo_line.get(0).get_y2()))
kz._md_line.get(0).set_xy2(time, math.avg(kz._hi_line.get(0).get_y2(), kz._lo_line.get(0).get_y2()))
if show_labels and kz._hi_label.size() > 0
if high > kz._hi_label.get(0).get_y()
kz._hi_label.get(0).set_xy(time, high)
if low < kz._lo_label.get(0).get_y()
kz._lo_label.get(0).set_xy(time, low)
adjust_out_kz(kz kz, bool t) =>
if not t and kz._box.size() > 0
if t
array.unshift(kz._range_store, kz._range_current)
if kz._range_store.size() > range_avg
kz._range_store.pop()
if kz._box.size() > 0 and show_pivots
for i = 0 to kz._box.size() - 1
if not ext_current or (ext_current and i == 0)
if ext_past ? true : (kz._hi_valid.get(i) == true)
kz._hi_line.get(i).set_x2(time)
if high > kz._hi_line.get(i).get_y1() and kz._hi_valid.get(i) == true
if use_alerts and i == 0
alert("Broke "+kz._title+" High", alert.freq_once_per_bar)
kz._hi_valid.set(i, false)
else if (use_cutoff ? t_co : false)
kz._hi_valid.set(i, false)
if ext_past ? true : (kz._lo_valid.get(i) == true)
kz._lo_line.get(i).set_x2(time)
if low < kz._lo_line.get(i).get_y1() and kz._lo_valid.get(i) == true
if use_alerts and i == 0
alert("Broke "+kz._title+" Low", alert.freq_once_per_bar)
kz._lo_valid.set(i, false)
else if (use_cutoff ? t_co : false)
kz._lo_valid.set(i, false)
if show_midpoints
kz._md_line.get(i).set_x2(time)
else
break
manage_kz(kz kz, bool use, bool t, color c, string box_txt, string hi_txt, string lo_txt) =>
if timeframe.in_seconds("") <= timeframe.in_seconds(tf_limit) and use
if t and not t
_c = get_box_color(c)
_t = get_text_color(c)
kz._box.unshift(box.new(time, high, time, low, xloc = xloc.bar_time, border_color = show_kz ? _c : na, bgcolor = show_kz ? _c : na, text = (show_kz and show_kz_text) ? box_txt : na, text_color = _t))
if show_pivots
kz._hi_line.unshift(line.new(time, high, time, high, xloc = xloc.bar_time, style = kzp_style, color = c, width = kzp_width))
kz._lo_line.unshift(line.new(time, low, time, low, xloc = xloc.bar_time, style = kzp_style, color = c, width = kzp_width))
if show_midpoints
kz._md_line.unshift(line.new(time, math.avg(high, low), time, math.avg(high, low), xloc = xloc.bar_time, style = kzm_style, color = c, width = kzm_width))
array.unshift(kz._md_valid, true)
array.unshift(kz._hi_valid, true)
array.unshift(kz._lo_valid, true)
if show_labels
kz._hi_label.unshift(label.new(time, high, hi_txt, xloc = xloc.bar_time, color = transparent, textcolor = txt_color, style = label.style_label_down, size = lbl_size))
kz._lo_label.unshift(label.new(time, low, lo_txt, xloc = xloc.bar_time, color = transparent, textcolor = txt_color, style = label.style_label_up, size = lbl_size))
del_kz(kz)
adjust_in_kz(kz, t)
adjust_out_kz(kz, t)
manage_kz(as_kz, use_asia, t_as, as_color, as_txt, ash_str, asl_str)
manage_kz(lo_kz, use_london, t_lo, lo_color, lo_txt, loh_str, lol_str)
manage_kz(na_kz, use_nyam, t_na, na_color, na_txt, nah_str, nal_str)
manage_kz(nl_kz, use_nylu, t_nl, nl_color, nl_txt, nlh_str, nll_str)
manage_kz(np_kz, use_nypm, t_np, np_color, np_txt, nph_str, npl_str)
manage_kz(op_kz, use_loop, t_op, op_color, op_txt, oph_str, opl_str)
manage_kz(cl_kz, use_locl, t_cl, cl_color, cl_txt, clh_str, cll_str)
manage_kz(m1_kz, use_sb1, t_m1, m1_color, m1_txt, m1h_str, m1l_str)
manage_kz(m2_kz, use_sb2, t_m2, m2_color, m2_txt, m2h_str, m2l_str)
manage_kz(m3_kz, use_sb3, t_m3, m3_color, m3_txt, m3h_str, m3l_str)
dwm()
vlines()
hz_lines()
new_dow_time = dow_xloc == 'Midday' ? time - timeframe.in_seconds("D") / 2 * 1000 : time
new_day = dayofweek(new_dow_time, gmt_tz) != dayofweek(new_dow_time, gmt_tz)
var dow_top = dow_yloc == 'Top'
var sunday = "SUNDAY"
var monday = "MONDAY"
var tuesday = "TUESDAY"
var wednesday = "WEDNESDAY"
var thursday = "THURSDAY"
var friday = "FRIDAY"
plotchar(dow_labels and timeframe.isintraday and dayofweek(new_dow_time, gmt_tz) == 1 and new_day, location = dow_top ? location.top : location.bottom, char = "", textcolor = txt_color, text = sunday)
plotchar(dow_labels and timeframe.isintraday and dayofweek(new_dow_time, gmt_tz) == 2 and new_day, location = dow_top ? location.top : location.bottom, char = "", textcolor = txt_color, text = monday)
plotchar(dow_labels and timeframe.isintraday and dayofweek(new_dow_time, gmt_tz) == 3 and new_day, location = dow_top ? location.top : location.bottom, char = "", textcolor = txt_color, text = tuesday)
plotchar(dow_labels and timeframe.isintraday and dayofweek(new_dow_time, gmt_tz) == 4 and new_day, location = dow_top ? location.top : location.bottom, char = "", textcolor = txt_color, text = wednesday)
plotchar(dow_labels and timeframe.isintraday and dayofweek(new_dow_time, gmt_tz) == 5 and new_day, location = dow_top ? location.top : location.bottom, char = "", textcolor = txt_color, text = thursday)
plotchar(dow_labels and timeframe.isintraday and dayofweek(new_dow_time, gmt_tz) == 6 and new_day, location = dow_top ? location.top : location.bottom, char = "", textcolor = txt_color, text = friday)
get_min_days_stored() =>
store = array.new_int()
if as_kz._range_store.size() > 0
store.push(as_kz._range_store.size())
if lo_kz._range_store.size() > 0
store.push(lo_kz._range_store.size())
if na_kz._range_store.size() > 0
store.push(na_kz._range_store.size())
if nl_kz._range_store.size() > 0
store.push(nl_kz._range_store.size())
if np_kz._range_store.size() > 0
store.push(np_kz._range_store.size())
if op_kz._range_store.size() > 0
store.push(op_kz._range_store.size())
if cl_kz._range_store.size() > 0
store.push(cl_kz._range_store.size())
if m1_kz._range_store.size() > 0
store.push(m1_kz._range_store.size())
if m2_kz._range_store.size() > 0
store.push(m2_kz._range_store.size())
if m3_kz._range_store.size() > 0
store.push(m3_kz._range_store.size())
result = store.min()
set_table(table tbl, kz kz, int row, string txt, bool use, bool t, color col) =>
if use
table.cell(tbl, 0, row, txt, text_size = range_size, bgcolor = get_box_color(col), text_color = txt_color)
table.cell(tbl, 1, row, str.tostring(kz._range_current), text_size = range_size, bgcolor = t ? get_box_color(col) : na, text_color = txt_color)
if show_range_avg
table.cell(tbl, 2, row, str.tostring(kz._range_store.avg()), text_size = range_size, text_color = txt_color)
if show_range and barstate.islast
var tbl = table.new(range_pos, 10, 10, chart.bg_color, chart.fg_color, 2, chart.fg_color, 1)
table.cell(tbl, 0, 0, "Killzone", text_size = range_size, text_color = txt_color)
table.cell(tbl, 1, 0, "Range", text_size = range_size, text_color = txt_color)
if show_range_avg
table.cell(tbl, 2, 0, "Avg ("+str.tostring(get_min_days_stored())+")", text_size = range_size, text_color = txt_color)
set_table(tbl, as_kz, 1, as_txt, use_asia, t_as, as_color)
set_table(tbl, lo_kz, 2, lo_txt, use_london, t_lo, lo_color)
set_table(tbl, na_kz, 3, na_txt, use_nyam, t_na, na_color)
set_table(tbl, nl_kz, 4, nl_txt, use_nylu, t_nl, nl_color)
set_table(tbl, np_kz, 5, np_txt, use_nypm, t_np, np_color)
set_table(tbl, op_kz, 6, op_txt, use_loop, t_op, op_color)
set_table(tbl, cl_kz, 7, cl_txt, use_locl, t_cl, cl_color)
set_table(tbl, m1_kz, 8, m1_txt, use_sb1, t_m1, m1_color)
set_table(tbl, m2_kz, 9, m2_txt, use_sb2, t_m2, m2_color)
set_table(tbl, m3_kz, 10, m3_txt, use_sb3, t_m3, m3_color)
// ---------------------------------------- Core Logic --------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------------------------------//
// This source code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org
// ©Mutharasan2
// Prev Published: 608
// Curr Published: 907
//@version=5
//2nd indicator("ICT HTF Candles (fadi)", overlay=true, max_boxes_count = 500, max_lines_count = 500, max_bars_back = 5000)
type Candle
float o
float c
float h
float l
int o_idx
int c_idx
int h_idx
int l_idx
box body
line wick_up
line wick_down
type Trace
line o
line c
line h
line l
label o_l
label c_l
label h_l
label l_l
type Imbalance
box b
int idx
type CandleSettings
bool show
string htf
int max_display
type Settings
int max_sets
color bull_body
color bull_border
color bull_wick
color bear_body
color bear_border
color bear_wick
int offset
int buffer
int htf_buffer
int width
bool trace_show
color trace_o_color
string trace_o_style
int trace_o_size
color trace_c_color
string trace_c_style
int trace_c_size
color trace_h_color
string trace_h_style
int trace_h_size
color trace_l_color
string trace_l_style
int trace_l_size
string trace_anchor
bool label_show
color label_color
string label_size
bool fvg_show
color fvg_color
bool vi_show
color vi_color
bool htf_label_show
color htf_label_color
string htf_label_size
bool htf_timer_show
color htf_timer_color
string htf_timer_size
string level
string liquidity_open_style
string liquidity_claimed_style
color liquidity_open_color
color liquidity_claimed_color
int liquidity_open_size
int liquidity_claimed_size
int max_lines
int extend
type CandleSet
Candle candles
Imbalance imbalances
CandleSettings settings
label tfName
label tfTimer
type Helper
string name = "Helper"
Settings settings = Settings.new()
var CandleSettings SettingsHTF1 = CandleSettings.new()
var CandleSettings SettingsHTF2 = CandleSettings.new()
var CandleSettings SettingsHTF3 = CandleSettings.new()
var CandleSettings SettingsHTF4 = CandleSettings.new()
var CandleSettings SettingsHTF5 = CandleSettings.new()
var CandleSettings SettingsHTF6 = CandleSettings.new()
var Candle candles_1 = array.new(0)
var Candle candles_2 = array.new(0)
var Candle candles_3 = array.new(0)
var Candle candles_4 = array.new(0)
var Candle candles_5 = array.new(0)
var Candle candles_6 = array.new(0)
var Imbalance imbalances_1 = array.new()
var Imbalance imbalances_2 = array.new()
var Imbalance imbalances_3 = array.new()
var Imbalance imbalances_4 = array.new()
var Imbalance imbalances_5 = array.new()
var Imbalance imbalances_6 = array.new()
var CandleSet htf1 = CandleSet.new()
htf1.settings := SettingsHTF1
htf1.candles := candles_1
htf1.imbalances := imbalances_1
var CandleSet htf2 = CandleSet.new()
htf2.settings := SettingsHTF2
htf2.candles := candles_2
htf2.imbalances := imbalances_2
var CandleSet htf3 = CandleSet.new()
htf3.settings := SettingsHTF3
htf3.candles := candles_3
htf3.imbalances := imbalances_3
var CandleSet htf4 = CandleSet.new()
htf4.settings := SettingsHTF4
htf4.candles := candles_4
htf4.imbalances := imbalances_4
var CandleSet htf5 = CandleSet.new()
htf5.settings := SettingsHTF5
htf5.candles := candles_5
htf5.imbalances := imbalances_5
var CandleSet htf6 = CandleSet.new()
htf6.settings := SettingsHTF6
htf6.candles := candles_6
htf6.imbalances := imbalances_6
//+------------------------------------------------------------------------------------------------------------+//
//+--- Settings ---+//
//+------------------------------------------------------------------------------------------------------------+//
htf1.settings.show := input.bool(false, "HTF 1 ", inline="htf1")
htf_1 = input.timeframe("60", "", inline="htf1")
htf1.settings.htf := htf_1
htf1.settings.max_display := input.int(1, "", inline="htf1")
htf2.settings.show := input.bool(false, "HTF 2 ", inline="htf2")
htf_2 = input.timeframe("240", "", inline="htf2")
htf2.settings.htf := htf_2
htf2.settings.max_display := input.int(1, "", inline="htf2")
htf3.settings.show := input.bool(true, "HTF 3 ", inline="htf3")
htf_3 = input.timeframe("1D", "", inline="htf3")
htf3.settings.htf := htf_3
htf3.settings.max_display := input.int(1, "", inline="htf3")
htf4.settings.show := input.bool(true, "HTF 4 ", inline="htf4")
htf_4 = input.timeframe("1W", "", inline="htf4")
htf4.settings.htf := htf_4
htf4.settings.max_display := input.int(1, "", inline="htf4")
htf5.settings.show := input.bool(true, "HTF 5 ", inline="htf5")
htf_5 = input.timeframe("1M", "", inline="htf5")
htf5.settings.htf := htf_5
htf5.settings.max_display := input.int(1, "", inline="htf5")
htf6.settings.show := input.bool(false, "HTF 6 ", inline="htf6")
htf_6 = input.timeframe("3M", "", inline="htf6")
htf6.settings.htf := htf_6
htf6.settings.max_display := input.int(1, "", inline="htf6")
settings.max_sets := input.int(6, "Limit to next HTFs only", minval=1, maxval=6)
settings.bull_body := input.color(color.rgb(76, 175, 80), "Body ", inline="body")
settings.bear_body := input.color(color.rgb(0, 0, 0), "", inline="body")
settings.bull_border := input.color(color.rgb(93, 96, 107), "Borders", inline="borders")
settings.bear_border := input.color(color.rgb(0, 0, 0), "", inline="borders")
settings.bull_wick := input.color(color.rgb(93, 96, 107), "Wick ", inline="wick")
settings.bear_wick := input.color(color.rgb(93, 96, 107), "", inline="wick")
settings.offset := input.int(10, "padding from current candles", minval = 1)
settings.buffer := input.int(1, "space between candles", minval = 1, maxval = 4)
settings.htf_buffer := input.int(10, "space between Higher Timeframes", minval = 1, maxval = 10)
settings.width := input.int(4, "Candle Width", minval = 1, maxval = 10)*2
settings.htf_label_show := input.bool(false, "HTF Label ", inline="HTFlabel")
settings.htf_label_color := input.color(color.rgb(0, 0, 0), "", inline='HTFlabel')
settings.htf_label_size := input.string(size.tiny, "", , inline="HTFlabel")
settings.htf_timer_show := input.bool(false, "Remaining time ", inline="timer")
settings.htf_timer_color := input.color(color.rgb(0, 0, 0), "", inline='timer')
settings.htf_timer_size := input.string(size.tiny, "", , inline="timer")
settings.fvg_show := input.bool(true, "Fair Value Gap ", group="Imbalance", inline="fvg")
settings.fvg_color := input.color(color.new(color.gray, 80), "", inline='fvg', group="Imbalance")
settings.vi_show := input.bool(true, "Volume Imbalance", group="Imbalance", inline="vi")
settings.vi_color := input.color(color.new(color.red, 50), "", inline='vi', group="Imbalance")
settings.trace_show := input.bool(false, "Trace lines", group="trace")
settings.trace_o_color := input.color(color.rgb(0, 0, 0), "Open ", inline='1', group="trace")
settings.trace_o_style := input.string('····', '', options = , inline='1', group="trace")
settings.trace_o_size := input.int(1, '', options = , inline='1', group="trace")
settings.trace_c_color := input.color(color.rgb(0, 0, 0), "Close ", inline='2', group="trace")
settings.trace_c_style := input.string('····', '', options = , inline='2', group="trace")
settings.trace_c_size := input.int(1, '', options = , inline='2', group="trace")
settings.trace_h_color := input.color(color.rgb(0, 0, 0), "High ", inline='3', group="trace")
settings.trace_h_style := input.string('····', '', options = , inline='3', group="trace")
settings.trace_h_size := input.int(1, '', options = , inline='3', group="trace")
settings.trace_l_color := input.color(color.rgb(0, 0, 0), "Low ", inline='4', group="trace")
settings.trace_l_style := input.string('····', '', options = , inline='4', group="trace")
settings.trace_l_size := input.int(1, '', options = , inline='4', group="trace")
settings.trace_anchor := input.string("First Timeframe", "Anchor to", options= , group="trace")
settings.label_show := input.bool(false, "Price Label ", inline="label")
settings.label_color := input.color(color.rgb(0, 0, 0), "", inline='label')
settings.label_size := input.string(size.small, "", , inline="label")
//+------------------------------------------------------------------------------------------------------------+//
//+--- Variables ---+//
//+------------------------------------------------------------------------------------------------------------+//
Helper helper = Helper.new()
var Trace trace = Trace.new()
color color_transparent = #ffffff00
//+------------------------------------------------------------------------------------------------------------+//
//+--- Internal Functions ---+//
//+------------------------------------------------------------------------------------------------------------+//
method LineStyle(Helper helper, string style) =>
helper.name := style
out = switch style
'----' => line.style_dashed
'····' => line.style_dotted
=> line.style_solid
method ValidTimeframe(Helper helper, string HTF) =>
helper.name := HTF
if timeframe.in_seconds(HTF) >= timeframe.in_seconds("D") and timeframe.in_seconds(HTF) > timeframe.in_seconds()
true
else
n1 = timeframe.in_seconds()
n2 = timeframe.in_seconds(HTF)
n3 = n1 % n2
(n1 < n2 and math.round(n2/n1) == n2/n1)
method RemainingTime(Helper helper, string HTF) =>
helper.name := HTF
if barstate.isrealtime
timeRemaining = (time_close(HTF) - timenow)/1000
days = math.floor(timeRemaining / 86400)
hours = math.floor((timeRemaining - (days*86400)) / 3600)
minutes = math.floor((timeRemaining - (days*86400) - (hours*3600))/ 60)
seconds = math.floor(timeRemaining - (days*86400) - (hours*3600) - (minutes*60))
r = str.tostring(seconds, "00")
if minutes > 0 or hours > 0 or days > 0
r := str.tostring(minutes, "00") + ":" + r
if hours > 0 or days > 0
r := str.tostring(hours, "00") + ":" + r
if days > 0
r := str.tostring(days) + "D " + r
r
else
"n/a"
method HTFName(Helper helper, string HTF) =>
helper.name := "HTFName"
formatted = HTF
seconds = timeframe.in_seconds(HTF)
if seconds < 60
formatted := str.tostring(seconds) + "s"
else if (seconds / 60) < 60
formatted := str.tostring((seconds/60)) + "m"
else if (seconds/60/60) < 24
formatted := str.tostring((seconds/60/60)) + "H"
formatted
method HTFEnabled(Helper helper) =>
helper.name := "HTFEnabled"
int enabled =0
enabled += htf1.settings.show ? 1 : 0
enabled += htf2.settings.show ? 1 : 0
enabled += htf3.settings.show ? 1 : 0
enabled += htf4.settings.show ? 1 : 0
enabled += htf5.settings.show ? 1 : 0
enabled += htf6.settings.show ? 1 : 0
int last = math.min(enabled, settings.max_sets)
last
method CandleSetHigh(Helper helper, Candle candles, float h) =>
helper.name := "CandlesSetHigh"
float _h = h
if array.size(candles) > 0
for i = 0 to array.size(candles)-1
Candle c = array.get(candles, i)
if c.h > _h
_h := c.h
_h
method CandlesHigh(Helper helper, Candle candles) =>
helper.name := "CandlesHigh"
h = 0.0
int cnt = 0
int last = helper.HTFEnabled()
if htf1.settings.show and helper.ValidTimeframe(htf1.settings.htf)
h := helper.CandleSetHigh(htf1.candles, h)
cnt += 1
if htf2.settings.show and helper.ValidTimeframe(htf2.settings.htf) and cnt < last
h := helper.CandleSetHigh(htf2.candles, h)
cnt +=1
if htf3.settings.show and helper.ValidTimeframe(htf3.settings.htf) and cnt < last
h := helper.CandleSetHigh(htf3.candles, h)
cnt += 1
if htf4.settings.show and helper.ValidTimeframe(htf4.settings.htf) and cnt < last
h := helper.CandleSetHigh(htf4.candles, h)
cnt += 1
if htf5.settings.show and helper.ValidTimeframe(htf5.settings.htf) and cnt < last
h := helper.CandleSetHigh(htf5.candles, h)
cnt += 1
if htf6.settings.show and helper.ValidTimeframe(htf6.settings.htf) and cnt < last
h := helper.CandleSetHigh(htf6.candles, h)
h
if array.size(candles) > 0
for i = 0 to array.size(candles)-1
Candle c = array.get(candles, i)
if c.h > h
h := c.h
h
method Reorder(CandleSet candleSet, int offset) =>
size = candleSet.candles.size()
if size > 0
for i = size-1 to 0
Candle candle = candleSet.candles.get(i)
t_buffer = offset + ((settings.width+settings.buffer)*(size-i-1))
box.set_left(candle.body, bar_index + t_buffer)
box.set_right(candle.body, bar_index + settings.width + t_buffer)
line.set_x1(candle.wick_up, bar_index+((settings.width)/2) + t_buffer)
line.set_x2(candle.wick_up, bar_index+((settings.width)/2) + t_buffer)
line.set_x1(candle.wick_down, bar_index+((settings.width)/2) + t_buffer)
line.set_x2(candle.wick_down, bar_index+((settings.width)/2) + t_buffer)
candleSet
top = helper.CandlesHigh(candleSet.candles)
left = bar_index + offset + ((settings.width+settings.buffer)*(size-1))/2
if settings.htf_label_show
var label l = candleSet.tfName
string lbl = helper.HTFName(candleSet.settings.htf)
if settings.htf_timer_show
lbl += "\n"
if not na(l)
label.set_xy(l, left, top)
else
l := label.new(left, top, lbl, color=color_transparent, textcolor = settings.htf_label_color, style=label.style_label_down, size = settings.htf_label_size)
if settings.htf_timer_show
var label t = candleSet.tfTimer
string tmr = "(" + helper.RemainingTime(candleSet.settings.htf) + ")"
if not na(t)
label.set_xy(t, left, top)
else
t := label.new(left, top, tmr, color=color_transparent, textcolor = settings.htf_timer_color, style=label.style_label_down, size = settings.htf_timer_size)
candleSet
method FindImbalance(CandleSet candleSet) =>
if barstate.isrealtime or barstate.islast
if candleSet.imbalances.size() > 0
for i = candleSet.imbalances.size()-1 to 0
Imbalance del = candleSet.imbalances.get(i)
box.delete(del.b)
candleSet.imbalances.pop()
if candleSet.candles.size() > 3 and settings.fvg_show
for i = 1 to candleSet.candles.size() -3
candle1 = candleSet.candles.get(i)
candle2 = candleSet.candles.get(i+2)
candle3 = candleSet.candles.get(i+1)
if (candle1.l > candle2.h and math.min(candle1.o, candle1.c) > math.max(candle2.o, candle2.c))
Imbalance imb = Imbalance.new()
imb.b := box.new(box.get_left(candle2.body), candle2.h, box.get_right(candle1.body), candle1.l, bgcolor=settings.fvg_color, border_color = color_transparent, xloc=xloc.bar_index)
candleSet.imbalances.push(imb)
if (candle1.h < candle2.l and math.max(candle1.o, candle1.c) < math.min(candle2.o, candle2.c))
Imbalance imb = Imbalance.new()
imb.b := box.new(box.get_right(candle1.body), candle1.h, box.get_left(candle2.body), candle2.l, bgcolor=settings.fvg_color, border_color = color_transparent)
candleSet.imbalances.push(imb)
box temp = box.copy(candle3.body)
box.delete(candle3.body)
candle3.body := temp
if candleSet.candles.size() > 2 and settings.vi_show
for i = 1 to candleSet.candles.size() -2
candle1 = candleSet.candles.get(i)
candle2 = candleSet.candles.get(i+1)
if (candle1.l < candle2.h and math.min(candle1.o, candle1.c) > math.max(candle2.o, candle2.c))
Imbalance imb = Imbalance.new()
imb.b := box.new(box.get_left(candle2.body), math.min(candle1.o, candle1.c), box.get_right(candle1.body), math.max(candle2.o, candle2.c), bgcolor=settings.vi_color, border_color = color_transparent)
candleSet.imbalances.push(imb)
if (candle1.h > candle2.l and math.max(candle1.o, candle1.c) < math.min(candle2.o, candle2.c))
Imbalance imb = Imbalance.new()
imb.b := box.new(box.get_right(candle1.body), math.min(candle2.o, candle2.c), box.get_left(candle2.body), math.max(candle1.o, candle1.c), bgcolor=settings.vi_color, border_color = color_transparent)
candleSet.imbalances.push(imb)
candleSet
method Monitor(CandleSet candleSet) =>
HTFBarTime = time(candleSet.settings.htf)
isNewHTFCandle = ta.change(HTFBarTime)
if isNewHTFCandle
Candle candle = Candle.new()
candle.o := open
candle.c := close
candle.h := high
candle.l := low
candle.o_idx := bar_index
candle.c_idx := bar_index
candle.h_idx := bar_index
candle.l_idx := bar_index
bull = candle.c > candle.o
candle.body := box.new(bar_index, math.max(candle.o, candle.c), bar_index+2, math.min(candle.o, candle.c), bull ? settings.bull_border : settings.bear_border, 1, bgcolor = bull ? settings.bull_body : settings.bear_body)
candle.wick_up := line.new(bar_index+1, candle.h, bar_index, math.max(candle.o, candle.c), color=bull ? settings.bull_wick : settings.bear_wick)
candle.wick_down := line.new(bar_index+1, math.min(candle.o, candle.c), bar_index, candle.l, color=bull ? settings.bull_wick : settings.bear_wick)
candleSet.candles.unshift(candle)
if candleSet.candles.size() > candleSet.settings.max_display
Candle delCandle = array.pop(candleSet.candles)
box.delete(delCandle.body)
line.delete(delCandle.wick_up)
line.delete(delCandle.wick_down)
candleSet
method Update(CandleSet candleSet, int offset, bool showTrace) =>
if candleSet.candles.size() > 0
Candle candle = candleSet.candles.first()
candle.h_idx := high > candle.h ? bar_index : candle.h_idx
candle.h := high > candle.h ? high : candle.h
candle.l_idx := low < candle.l ? bar_index : candle.l_idx
candle.l := low < candle.l ? low : candle.l
candle.c := close
candle.c_idx := bar_index
bull = candle.c > candle.o
box.set_top(candle.body, candle.o)
box.set_bottom(candle.body, candle.c)
box.set_bgcolor(candle.body, bull ? settings.bull_body : settings.bear_body)
box.set_border_color(candle.body, bull ? settings.bull_border : settings.bear_border)
line.set_color(candle.wick_up, bull ? settings.bull_wick : settings.bear_wick)
line.set_color(candle.wick_down, bull ? settings.bull_wick : settings.bear_wick)
line.set_y1(candle.wick_up, candle.h)
line.set_y2(candle.wick_up, math.max(candle.o, candle.c))
line.set_y1(candle.wick_down, candle.l)
line.set_y2(candle.wick_down, math.min(candle.o, candle.c))
if barstate.isrealtime or barstate.islast
candleSet.Reorder(offset)
if settings.trace_show and showTrace
if bar_index - candle.o_idx < 5000
if na(trace.o)
trace.o := line.new(candle.o_idx, candle.o, box.get_left(candle.body), candle.o, xloc= xloc.bar_index, color=settings.trace_o_color, style= helper.LineStyle(settings.trace_o_style), width=settings.trace_o_size)
else
line.set_xy1(trace.o, candle.o_idx, candle.o)
line.set_xy2(trace.o, box.get_left(candle.body), candle.o)
if settings.label_show
if na(trace.o_l)
trace.o_l := label.new(box.get_right(candle.body), candle.o, str.tostring(candle.o), textalign = text.align_center, style=label.style_label_left, size=settings.label_size, color=color_transparent, textcolor=settings.label_color)
else
label.set_xy(trace.o_l, box.get_right(candle.body), candle.o)
label.set_text(trace.o_l, str.tostring(candle.o))
if bar_index - candle.c_idx < 5000
if na(trace.c)
trace.c := line.new(candle.c_idx, candle.c, box.get_left(candle.body), candle.c, xloc= xloc.bar_index, color=settings.trace_c_color, style=helper.LineStyle(settings.trace_c_style), width=settings.trace_c_size)
else
line.set_xy1(trace.c, candle.c_idx, candle.c)
line.set_xy2(trace.c, box.get_left(candle.body), candle.c)
if settings.label_show
if na(trace.c_l)
trace.c_l := label.new(box.get_right(candle.body), candle.c, str.tostring(candle.c), textalign = text.align_center, style=label.style_label_left, size=settings.label_size, color=color_transparent, textcolor=settings.label_color)
else
label.set_xy(trace.c_l, box.get_right(candle.body), candle.c)
label.set_text(trace.c_l, str.tostring(candle.c))
if bar_index - candle.h_idx < 5000
if na(trace.h)
trace.h := line.new(candle.h_idx, candle.h, line.get_x1(candle.wick_up), candle.h, xloc= xloc.bar_index, color=settings.trace_h_color, style=helper.LineStyle(settings.trace_h_style), width=settings.trace_h_size)
else
line.set_xy1(trace.h, candle.h_idx, candle.h)
line.set_xy2(trace.h, line.get_x1(candle.wick_up), candle.h)
if settings.label_show
if na(trace.h_l)
trace.h_l := label.new(box.get_right(candle.body), candle.h, str.tostring(candle.h), textalign = text.align_center, style=label.style_label_left, size=settings.label_size, color=color_transparent, textcolor=settings.label_color)
else
label.set_xy(trace.h_l, box.get_right(candle.body), candle.h)
label.set_text(trace.h_l, str.tostring(candle.o))
if bar_index - candle.l_idx < 5000
if na(trace.l)
trace.l := line.new(candle.l_idx, candle.l, line.get_x1(candle.wick_down), candle.l, xloc= xloc.bar_index, color=settings.trace_l_color, style=helper.LineStyle(settings.trace_l_style), width=settings.trace_l_size)
else
line.set_xy1(trace.l, candle.l_idx, candle.l)
line.set_xy2(trace.l, line.get_x1(candle.wick_down), candle.l)
if settings.label_show
if na(trace.l_l)
trace.l_l := label.new(box.get_right(candle.body), candle.l, str.tostring(candle.l), textalign = text.align_center, style=label.style_label_left, size=settings.label_size, color=color_transparent, textcolor=settings.label_color)
else
label.set_xy(trace.l_l, box.get_right(candle.body), candle.l)
label.set_text(trace.l_l, str.tostring(candle.o))
candleSet
int cnt = 0
int last = helper.HTFEnabled()
int offset = settings.offset
if htf1.settings.show and helper.ValidTimeframe(htf1.settings.htf)
bool showTrace = false
if settings.trace_anchor == "First Timeframe"
showTrace := true
if settings.trace_anchor == "Last Timeframe" and settings.max_sets == 1
showTrace := true
htf1.Monitor().Update(offset, showTrace).FindImbalance()
cnt +=1
offset += cnt > 0 ? (htf1.candles.size() * settings.width) + (htf1.candles.size() > 0 ? htf1.candles.size()-1 * settings.buffer : 0) + settings.htf_buffer : 0
if htf2.settings.show and helper.ValidTimeframe(htf2.settings.htf) and cnt < last
bool showTrace = false
if settings.trace_anchor == "First Timeframe" and cnt == 0
showTrace := true
if settings.trace_anchor == "Last Timeframe" and cnt == last-1
showTrace := true
htf2.Monitor().Update(offset, showTrace).FindImbalance()
cnt+=1
offset += cnt > 0 ? (htf2.candles.size() * settings.width) + (htf2.candles.size() > 0 ? htf2.candles.size()-1 * settings.buffer : 0) + settings.htf_buffer : 0
if htf3.settings.show and helper.ValidTimeframe(htf3.settings.htf) and cnt < last
bool showTrace = false
if settings.trace_anchor == "First Timeframe" and cnt == 0
showTrace := true
if settings.trace_anchor == "Last Timeframe" and cnt == last-1
showTrace := true
htf3.Monitor().Update(offset, showTrace).FindImbalance()
cnt+=1
offset += cnt > 0 ? (htf3.candles.size() * settings.width) + (htf3.candles.size() > 0 ? htf3.candles.size()-1 * settings.buffer : 0) + settings.htf_buffer : 0
if htf4.settings.show and helper.ValidTimeframe(htf4.settings.htf) and cnt < last
bool showTrace = false
if settings.trace_anchor == "First Timeframe" and cnt == 0
showTrace := true
if settings.trace_anchor == "Last Timeframe" and cnt == last-1
showTrace := true
htf4.Monitor().Update(offset, showTrace).FindImbalance()
cnt+=1
offset += cnt > 0 ? (htf4.candles.size() * settings.width) + (htf4.candles.size() > 0 ? htf4.candles.size()-1 * settings.buffer : 0) + settings.htf_buffer : 0
if htf5.settings.show and helper.ValidTimeframe(htf5.settings.htf) and cnt < last
bool showTrace = false
if settings.trace_anchor == "First Timeframe" and cnt == 0
showTrace := true
if settings.trace_anchor == "Last Timeframe" and cnt == last-1
showTrace := true
htf5.Monitor().Update(offset, showTrace).FindImbalance()
cnt+=1
offset += cnt > 0 ? (htf5.candles.size() * settings.width) + (htf5.candles.size() > 0 ? htf5.candles.size()-1 * settings.buffer : 0) + settings.htf_buffer : 0
if htf6.settings.show and helper.ValidTimeframe(htf6.settings.htf) and cnt < last
bool showTrace = false
if settings.trace_anchor == "First Timeframe" and cnt == 0
showTrace := true
if settings.trace_anchor == "Last Timeframe"
showTrace := true
htf6.Monitor().Update(offset, showTrace).FindImbalance()
//------------------------------------------------------------------------------------------------//
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org
// ©Mutharasan12
//@version=5
//indicator("Notes, Watermark",overlay = true)
// STICKY NOTES #BEGIN --------------------------------------------------------------------------------------------------------------------------------------------------------//
var StickyNote_settings = "STICKY NOTES --------------------------------------------------"
showStickyNotes = input.bool(false, "Show Sticky Notes?", group = StickyNote_settings)
if showStickyNotes
stickynote01 = input.text_area("Your Note Here","NOTES",group = StickyNote_settings)
tl1 = input.string("top", title = "Sticky Note Position (Vertical)", options = , group = StickyNote_settings)
tl2 = input.string("right", title = "Sticky Note Position (Horizontal)", options = , group = StickyNote_settings)
font_size = input.string("Normal", title = "Sticky Note Text Size", options = , group = StickyNote_settings)
font_type = input.string("Default", title = "Font Type", options = , group = StickyNote_settings)
font_color = input.color(color.rgb(0,0,0,0), title = "Note Color", inline = 'nc', group = StickyNote_settings)
note_color = input.color(color (color.rgb(0,0,0,100)), title = "Note Background", inline='nc', group = StickyNote_settings)
selected_font = font_type == "Default" ? font.family_default : font.family_monospace
selected_size = font_size == "Auto" ? size.auto : font_size == "Huge" ? size.huge : font_size == "Large" ? size.large : font_size == "Normal" ? size.normal : font_size == "Small" ? size.small : font_size == "Tiny" ? size.tiny : na
var table t1 = table.new(tl1 + "_" + tl2, 1, 10)
if barstate.islast
if not na(stickynote01) and stickynote01 != ""
table.cell(t1,0,0, text = stickynote01 , bgcolor = note_color, text_color = font_color, text_halign = text.align_left, text_size = selected_size, text_font_family = selected_font)
// STICKY NOTES #END ----------------------------------------------------------------------------------------------------------------------------------------------------------//
// WATERMARK #BEGIN --
ADR levels+// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org
// © notprofessorgreen
//@version=5
indicator("ADR levels", shorttitle = 'ADR', overlay=true, max_bars_back=5000, max_lines_count=500)
// Error catching
if (timeframe.in_seconds() >= timeframe.in_seconds('D'))
runtime.error('Timeframe cannot be greater than Daily')
// Inputs
adr_days = input.int(10, title = 'Days', maxval=250, minval = 1)
std_x = input.float(1.0, "Scale Factor")
width = input.int(1, "Line Width")
// ADR line inputs
adr_color = input.color(color.gray, "ADR Color")
adr_style = input.string("solid", "ADR Style", options= )
// Standard deviation inputs
std_dev_0_5 = input.float(0.5, "Std Dev 1 Multiplier", minval=0.1, maxval=5.0)
std_0_5_show = input.bool(true, "Show Std Dev 1", inline="std1")
std_0_5_color = input.color(color.gray, "Std Dev 1 Color", inline="std1")
std_0_5_style = input.string("dotted", "Std Dev 1 Style", options= , inline="std1")
std_dev_1 = input.float(1.0, "Std Dev 2 Multiplier", minval=0.1, maxval=5.0)
std_1_show = input.bool(true, "Show Std Dev 2", inline="std2")
std_1_color = input.color(color.gray, "Std Dev 2 Color", inline="std2")
std_1_style = input.string("dotted", "Std Dev 2 Style", options= , inline="std2")
std_dev_2 = input.float(2.0, "Std Dev 3 Multiplier", minval=0.1, maxval=5.0)
std_2_show = input.bool(true, "Show Std Dev 3", inline="std3")
std_2_color = input.color(color.gray, "Std Dev 3 Color", inline="std3")
std_2_style = input.string("dotted", "Std Dev 3 Style", options= , inline="std3")
// Fibonacci inputs
fib_1_level = input.float(0.3, "Fib Level 1", minval=0, maxval=2.0)
fib_1_show = input.bool(true, "Show Fib 1", inline="fib1")
fib_1_color = input.color(color.blue, "Fib 1 Color", inline="fib1")
fib_1_style = input.string("dashed", "Fib 1 Style", options= , inline="fib1")
fib_2_level = input.float(0.5, "Fib Level 2", minval=0, maxval=2.0)
fib_2_show = input.bool(true, "Show Fib 2", inline="fib2")
fib_2_color = input.color(color.blue, "Fib 2 Color", inline="fib2")
fib_2_style = input.string("dashed", "Fib 2 Style", options= , inline="fib2")
fib_3_level = input.float(0.7, "Fib Level 3", minval=0, maxval=2.0)
fib_3_show = input.bool(true, "Show Fib 3", inline="fib3")
fib_3_color = input.color(color.blue, "Fib 3 Color", inline="fib3")
fib_3_style = input.string("dashed", "Fib 3 Style", options= , inline="fib3")
show_labels = input.bool(true, "Show Labels")
// Stats table inputs
show_stats = input.bool(true, "Show Table")
sample_size = input.bool(true, "Show Sample Sizes")
tbl_loc = input.string('Bottom Right', "Table", options = )
tbl_size = input.string('Tiny', "", options = )
rch_color = input.color(color.rgb(3, 131, 99, 70), "Reached ")
csd_color = input.color(color.rgb(127, 1, 185, 70), "Closed Through ")
// Function to convert style string to line style
get_line_style(string style) =>
switch style
"solid" => line.style_solid
"dashed" => line.style_dashed
"dotted" => line.style_dotted
// Variables
reset = session.islastbar_regular
var float track_highs = 0.00
var float track_lows = 0.00
var float today_adr = 0.00
var adrs = array.new_float(adr_days, 0.00)
var line adr_pos = na
var line adr_neg = na
var line fib_1_pos = na
var line fib_1_neg = na
var line fib_2_pos = na
var line fib_2_neg = na
var line fib_3_pos = na
var line fib_3_neg = na
var line std_0_5_pos = na
var line std_0_5_neg = na
var line std_1_pos = na
var line std_1_neg = na
var line std_2_pos = na
var line std_2_neg = na
var label fib_1_pos_lbl = na
var label fib_1_neg_lbl = na
var label fib_2_pos_lbl = na
var label fib_2_neg_lbl = na
var label fib_3_pos_lbl = na
var label fib_3_neg_lbl = na
var label adr_pos_lbl = na
var label adr_neg_lbl = na
var label std_0_5_pos_lbl = na
var label std_0_5_neg_lbl = na
var label std_1_pos_lbl = na
var label std_1_neg_lbl = na
var label std_2_pos_lbl = na
var label std_2_neg_lbl = na
// ADR calculation
track_highs := reset ? high : math.max(high, track_highs )
track_lows := reset ? low : math.min(low, track_lows )
if reset
array.unshift(adrs, math.round_to_mintick(track_highs - track_lows ))
if array.size(adrs) > adr_days
array.pop(adrs)
today_adr := math.round_to_mintick(array.avg(adrs))
// Delete previous lines and labels
line.delete(adr_pos )
line.delete(adr_neg )
line.delete(fib_1_pos )
line.delete(fib_1_neg )
line.delete(fib_2_pos )
line.delete(fib_2_neg )
line.delete(fib_3_pos )
line.delete(fib_3_neg )
line.delete(std_0_5_pos )
line.delete(std_0_5_neg )
line.delete(std_1_pos )
line.delete(std_1_neg )
line.delete(std_2_pos )
line.delete(std_2_neg )
label.delete(fib_1_pos_lbl )
label.delete(fib_1_neg_lbl )
label.delete(fib_2_pos_lbl )
label.delete(fib_2_neg_lbl )
label.delete(fib_3_pos_lbl )
label.delete(fib_3_neg_lbl )
label.delete(adr_pos_lbl )
label.delete(adr_neg_lbl )
label.delete(std_0_5_pos_lbl )
label.delete(std_0_5_neg_lbl )
label.delete(std_1_pos_lbl )
label.delete(std_1_neg_lbl )
label.delete(std_2_pos_lbl )
label.delete(std_2_neg_lbl )
// Draw ADR lines
adr_pos := line.new(bar_index, open + today_adr, bar_index+50, open + today_adr,
width=width, color=adr_color, style=get_line_style(adr_style))
adr_neg := line.new(bar_index, open - today_adr, bar_index+50, open - today_adr,
width=width, color=adr_color, style=get_line_style(adr_style))
// Draw ADR labels
if show_labels
adr_pos_lbl := label.new(bar_index+50, open + today_adr, "ADR High (" + str.tostring(adr_days) + "D)",
xloc=xloc.bar_index, textalign=text.align_left, textcolor=adr_color, color=color.new(color.blue, 90), style=label.style_none)
adr_neg_lbl := label.new(bar_index+50, open - today_adr, "ADR Low (" + str.tostring(adr_days) + "D)",
xloc=xloc.bar_index, textalign=text.align_left, textcolor=adr_color, color=color.new(color.red, 90), style=label.style_none)
// Calculate deviations
var float half_dev = na
var float one_dev = na
var float two_dev = na
half_dev := today_adr * std_dev_0_5
one_dev := today_adr * std_dev_1
two_dev := today_adr * std_dev_2
// Draw standard deviation lines (with show/hide options)
if std_0_5_show
std_0_5_pos := line.new(bar_index, (open + today_adr) + half_dev, bar_index+50, (open + today_adr) + half_dev,
width=width, color=std_0_5_color, style=get_line_style(std_0_5_style))
std_0_5_neg := line.new(bar_index, (open - today_adr) - half_dev, bar_index+50, (open - today_adr) - half_dev,
width=width, color=std_0_5_color, style=get_line_style(std_0_5_style))
if show_labels
std_0_5_pos_lbl := label.new(bar_index+50, (open + today_adr) + half_dev, "Std " + str.tostring(std_dev_0_5),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=std_0_5_color, color=color.new(#000000,100), style=label.style_none)
std_0_5_neg_lbl := label.new(bar_index+50, (open - today_adr) - half_dev, "Std -" + str.tostring(std_dev_0_5),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=std_0_5_color, color=color.new(#000000,100), style=label.style_none)
if std_1_show
std_1_pos := line.new(bar_index, (open + today_adr) + one_dev, bar_index+50, (open + today_adr) + one_dev,
width=width, color=std_1_color, style=get_line_style(std_1_style))
std_1_neg := line.new(bar_index, (open - today_adr) - one_dev, bar_index+50, (open - today_adr) - one_dev,
width=width, color=std_1_color, style=get_line_style(std_1_style))
if show_labels
std_1_pos_lbl := label.new(bar_index+50, (open + today_adr) + one_dev, "Std " + str.tostring(std_dev_1),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=std_1_color, color=color.new(#000000,100), style=label.style_none)
std_1_neg_lbl := label.new(bar_index+50, (open - today_adr) - one_dev, "Std -" + str.tostring(std_dev_1),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=std_1_color, color=color.new(#000000,100), style=label.style_none)
if std_2_show
std_2_pos := line.new(bar_index, (open + today_adr) + two_dev, bar_index+50, (open + today_adr) + two_dev,
width=width, color=std_2_color, style=get_line_style(std_2_style))
std_2_neg := line.new(bar_index, (open - today_adr) - two_dev, bar_index+50, (open - today_adr) - two_dev,
width=width, color=std_2_color, style=get_line_style(std_2_style))
if show_labels
std_2_pos_lbl := label.new(bar_index+50, (open + today_adr) + two_dev, "Std " + str.tostring(std_dev_2),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=std_2_color, color=color.new(#000000,100), style=label.style_none)
std_2_neg_lbl := label.new(bar_index+50, (open - today_adr) - two_dev, "Std -" + str.tostring(std_dev_2),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=std_2_color, color=color.new(#000000,100), style=label.style_none)
// Draw Fibonacci lines
if fib_1_show
fib_1_pos := line.new(bar_index, open + today_adr * fib_1_level, bar_index+50, open + today_adr * fib_1_level,
width=width, color=fib_1_color, style=get_line_style(fib_1_style))
fib_1_neg := line.new(bar_index, open - today_adr * fib_1_level, bar_index+50, open - today_adr * fib_1_level,
width=width, color=fib_1_color, style=get_line_style(fib_1_style))
if show_labels
fib_1_pos_lbl := label.new(bar_index+50, open + today_adr * fib_1_level, "Fib " + str.tostring(fib_1_level),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=fib_1_color, color=color.new(#000000,100), style=label.style_none)
fib_1_neg_lbl := label.new(bar_index+50, open - today_adr * fib_1_level, "Fib -" + str.tostring(fib_1_level),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=fib_1_color, color=color.new(#000000,100), style=label.style_none)
if fib_2_show
fib_2_pos := line.new(bar_index, open + today_adr * fib_2_level, bar_index+50, open + today_adr * fib_2_level,
width=width, color=fib_2_color, style=get_line_style(fib_2_style))
fib_2_neg := line.new(bar_index, open - today_adr * fib_2_level, bar_index+50, open - today_adr * fib_2_level,
width=width, color=fib_2_color, style=get_line_style(fib_2_style))
if show_labels
fib_2_pos_lbl := label.new(bar_index+50, open + today_adr * fib_2_level, "Fib " + str.tostring(fib_2_level),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=fib_2_color, color=color.new(#000000,100), style=label.style_none)
fib_2_neg_lbl := label.new(bar_index+50, open - today_adr * fib_2_level, "Fib -" + str.tostring(fib_2_level),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=fib_2_color, color=color.new(#000000,100), style=label.style_none)
if fib_3_show
fib_3_pos := line.new(bar_index, open + today_adr * fib_3_level, bar_index+50, open + today_adr * fib_3_level,
width=width, color=fib_3_color, style=get_line_style(fib_3_style))
fib_3_neg := line.new(bar_index, open - today_adr * fib_3_level, bar_index+50, open - today_adr * fib_3_level,
width=width, color=fib_3_color, style=get_line_style(fib_3_style))
if show_labels
fib_3_pos_lbl := label.new(bar_index+50, open + today_adr * fib_3_level, "Fib " + str.tostring(fib_3_level),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=fib_3_color, color=color.new(#000000,100), style=label.style_none)
fib_3_neg_lbl := label.new(bar_index+50, open - today_adr * fib_3_level, "Fib -" + str.tostring(fib_3_level),
xloc=xloc.bar_index, textalign=text.align_left, textcolor=fib_3_color, color=color.new(#000000,100), style=label.style_none)
else
today_adr := today_adr
line.set_x2(adr_pos, bar_index+50)
line.set_x2(adr_neg, bar_index+50)
if show_labels
label.set_x(adr_pos_lbl, bar_index+50)
label.set_x(adr_neg_lbl, bar_index+50)
if std_0_5_show
line.set_x2(std_0_5_pos, bar_index+50)
line.set_x2(std_0_5_neg, bar_index+50)
if show_labels
label.set_x(std_0_5_pos_lbl, bar_index+50)
label.set_x(std_0_5_neg_lbl, bar_index+50)
if std_1_show
line.set_x2(std_1_pos, bar_index+50)
line.set_x2(std_1_neg, bar_index+50)
if show_labels
label.set_x(std_1_pos_lbl, bar_index+50)
label.set_x(std_1_neg_lbl, bar_index+50)
if std_2_show
line.set_x2(std_2_pos, bar_index+50)
line.set_x2(std_2_neg, bar_index+50)
if show_labels
label.set_x(std_2_pos_lbl, bar_index+50)
label.set_x(std_2_neg_lbl, bar_index+50)
if fib_1_show
line.set_x2(fib_1_pos, bar_index+50)
line.set_x2(fib_1_neg, bar_index+50)
if show_labels
label.set_x(fib_1_pos_lbl, bar_index+50)
label.set_x(fib_1_neg_lbl, bar_index+50)
if fib_2_show
line.set_x2(fib_2_pos, bar_index+50)
line.set_x2(fib_2_neg, bar_index+50)
if show_labels
label.set_x(fib_2_pos_lbl, bar_index+50)
label.set_x(fib_2_neg_lbl, bar_index+50)
if fib_3_show
line.set_x2(fib_3_pos, bar_index+50)
line.set_x2(fib_3_neg, bar_index+50)
if show_labels
label.set_x(fib_3_pos_lbl, bar_index+50)
label.set_x(fib_3_neg_lbl, bar_index+50)
// Stats calculation
var float d_hi = high
var float d_lo = low
var float d_open = open
var float d_range = array.new_float()
var float adr_val = na
var float d_adr_hi = na
var float d_adr_lo = na
type adr_stats
int hit_adr_hi = 0
int hit_adr_lo = 0
int hit_adr_both = 0
int thru_adr_hi = 0
int thru_adr_lo = 0
int hit_fib_1_hi = 0
int hit_fib_1_lo = 0
int hit_fib_2_hi = 0
int hit_fib_2_lo = 0
int hit_fib_3_hi = 0
int hit_fib_3_lo = 0
int hit_std_0_5_hi = 0
int hit_std_0_5_lo = 0
int hit_std_1_hi = 0
int hit_std_1_lo = 0
int hit_std_2_hi = 0
int hit_std_2_lo = 0
int d_count = 0
var adr_sun = adr_stats.new()
var adr_mon = adr_stats.new()
var adr_tue = adr_stats.new()
var adr_wed = adr_stats.new()
var adr_thu = adr_stats.new()
var adr_fri = adr_stats.new()
var adr_sat = adr_stats.new()
if timeframe.change("D")
x = adr_mon
dow = dayofweek(time , "America/New_York")
if dow == dayofweek.tuesday
x := adr_tue
else if dow == dayofweek.wednesday
x := adr_wed
else if dow == dayofweek.thursday
x := adr_thu
else if dow == dayofweek.friday
x := adr_fri
else if dow == dayofweek.saturday
x := adr_sat
else if dow == dayofweek.sunday
x := adr_sun
if not na(adr_val)
x.d_count += 1
if d_hi > d_adr_hi
x.hit_adr_hi += 1
if d_lo < d_adr_lo
x.hit_adr_lo += 1
if d_hi > d_adr_hi and d_lo < d_adr_lo
x.hit_adr_both += 1
if close > d_adr_hi
x.thru_adr_hi += 1
if close < d_adr_lo
x.thru_adr_lo += 1
if fib_1_show
if d_hi > d_open + (adr_val * fib_1_level)
x.hit_fib_1_hi += 1
if d_lo < d_open - (adr_val * fib_1_level)
x.hit_fib_1_lo += 1
if fib_2_show
if d_hi > d_open + (adr_val * fib_2_level)
x.hit_fib_2_hi += 1
if d_lo < d_open - (adr_val * fib_2_level)
x.hit_fib_2_lo += 1
if fib_3_show
if d_hi > d_open + (adr_val * fib_3_level)
x.hit_fib_3_hi += 1
if d_lo < d_open - (adr_val * fib_3_level)
x.hit_fib_3_lo += 1
if std_0_5_show
if d_hi > d_adr_hi + (adr_val * std_dev_0_5)
x.hit_std_0_5_hi += 1
if d_lo < d_adr_lo - (adr_val * std_dev_0_5)
x.hit_std_0_5_lo += 1
if std_1_show
if d_hi > d_adr_hi + (adr_val * std_dev_1)
x.hit_std_1_hi += 1
if d_lo < d_adr_lo - (adr_val * std_dev_1)
x.hit_std_1_lo += 1
if std_2_show
if d_hi > d_adr_hi + (adr_val * std_dev_2)
x.hit_std_2_hi += 1
if d_lo < d_adr_lo - (adr_val * std_dev_2)
x.hit_std_2_lo += 1
if timeframe.change("D")
d_open := open
array.unshift(d_range, d_hi - d_lo)
if array.size(d_range) > adr_days
array.pop(d_range)
if array.size(d_range) == adr_days
adr_val := array.avg(d_range)
d_adr_hi := open + (adr_val*std_x)/2
d_adr_lo := open - (adr_val*std_x)/2
d_hi := high
d_lo := low
else
d_hi := math.max(high, d_hi)
d_lo := math.min(low, d_lo)
// Table functions
get_table_pos(pos) =>
switch pos
"Bottom Center" => position.bottom_center
"Bottom Left" => position.bottom_left
"Bottom Right" => position.bottom_right
"Middle Center" => position.middle_center
"Middle Left" => position.middle_left
"Middle Right" => position.middle_right
"Top Center" => position.top_center
"Top Left" => position.top_left
"Top Right" => position.top_right
var _loc = get_table_pos(tbl_loc)
get_table_size(size) =>
switch size
'Tiny' => size.tiny
'Small' => size.small
'Normal' => size.normal
'Large' => size.large
'Huge' => size.huge
'Auto' => size.auto
var _size = get_table_size(tbl_size)
fmt_sample(s, float pct, int count) =>
str.format("{0,number,percent}", pct) + (sample_size ? " ("+str.tostring(count)+")" : "")
// Draw table
if barstate.islast and show_stats
var tbl = table.new(_loc, 100, 100, chart.bg_color, chart.fg_color, 2, chart.fg_color, 1)
// Column headers (days + empty first cell)
table.cell(tbl, 0, 0, "Level", text_size = _size)
table.cell(tbl, 1, 0, "Mon", bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, 0, "Tue", bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, 0, "Wed", bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, 0, "Thu", bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, 0, "Fri", bgcolor = rch_color, text_size = _size)
// Row headers and data
var row = 1
table.cell(tbl, 0, row, "ADR High", text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_adr_hi / adr_mon.d_count, adr_mon.hit_adr_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_adr_hi / adr_tue.d_count, adr_tue.hit_adr_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_adr_hi / adr_wed.d_count, adr_wed.hit_adr_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_adr_hi / adr_thu.d_count, adr_thu.hit_adr_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_adr_hi / adr_fri.d_count, adr_fri.hit_adr_hi), bgcolor = rch_color, text_size = _size)
row := row + 1
table.cell(tbl, 0, row, "ADR Low", text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_adr_lo / adr_mon.d_count, adr_mon.hit_adr_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_adr_lo / adr_tue.d_count, adr_tue.hit_adr_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_adr_lo / adr_wed.d_count, adr_wed.hit_adr_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_adr_lo / adr_thu.d_count, adr_thu.hit_adr_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_adr_lo / adr_fri.d_count, adr_fri.hit_adr_lo), bgcolor = rch_color, text_size = _size)
row := row + 1
table.cell(tbl, 0, row, "ADR High (Close)", text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.thru_adr_hi / adr_mon.d_count, adr_mon.thru_adr_hi), bgcolor = csd_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.thru_adr_hi / adr_tue.d_count, adr_tue.thru_adr_hi), bgcolor = csd_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.thru_adr_hi / adr_wed.d_count, adr_wed.thru_adr_hi), bgcolor = csd_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.thru_adr_hi / adr_thu.d_count, adr_thu.thru_adr_hi), bgcolor = csd_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.thru_adr_hi / adr_fri.d_count, adr_fri.thru_adr_hi), bgcolor = csd_color, text_size = _size)
row := row + 1
table.cell(tbl, 0, row, "ADR Low (Close)", text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.thru_adr_lo / adr_mon.d_count, adr_mon.thru_adr_lo), bgcolor = csd_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.thru_adr_lo / adr_tue.d_count, adr_tue.thru_adr_lo), bgcolor = csd_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.thru_adr_lo / adr_wed.d_count, adr_wed.thru_adr_lo), bgcolor = csd_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.thru_adr_lo / adr_thu.d_count, adr_thu.thru_adr_lo), bgcolor = csd_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.thru_adr_lo / adr_fri.d_count, adr_fri.thru_adr_lo), bgcolor = csd_color, text_size = _size)
row := row + 1
if fib_1_show
table.cell(tbl, 0, row, "Fib " + str.tostring(fib_1_level), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_fib_1_hi / adr_mon.d_count, adr_mon.hit_fib_1_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_fib_1_hi / adr_tue.d_count, adr_tue.hit_fib_1_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_fib_1_hi / adr_wed.d_count, adr_wed.hit_fib_1_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_fib_1_hi / adr_thu.d_count, adr_thu.hit_fib_1_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_fib_1_hi / adr_fri.d_count, adr_fri.hit_fib_1_hi), bgcolor = rch_color, text_size = _size)
row := row + 1
table.cell(tbl, 0, row, "Fib -" + str.tostring(fib_1_level), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_fib_1_lo / adr_mon.d_count, adr_mon.hit_fib_1_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_fib_1_lo / adr_tue.d_count, adr_tue.hit_fib_1_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_fib_1_lo / adr_wed.d_count, adr_wed.hit_fib_1_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_fib_1_lo / adr_thu.d_count, adr_thu.hit_fib_1_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_fib_1_lo / adr_fri.d_count, adr_fri.hit_fib_1_lo), bgcolor = rch_color, text_size = _size)
row := row + 1
if fib_2_show
table.cell(tbl, 0, row, "Fib " + str.tostring(fib_2_level), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_fib_2_hi / adr_mon.d_count, adr_mon.hit_fib_2_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_fib_2_hi / adr_tue.d_count, adr_tue.hit_fib_2_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_fib_2_hi / adr_wed.d_count, adr_wed.hit_fib_2_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_fib_2_hi / adr_thu.d_count, adr_thu.hit_fib_2_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_fib_2_hi / adr_fri.d_count, adr_fri.hit_fib_2_hi), bgcolor = rch_color, text_size = _size)
row := row + 1
table.cell(tbl, 0, row, "Fib -" + str.tostring(fib_2_level), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_fib_2_lo / adr_mon.d_count, adr_mon.hit_fib_2_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_fib_2_lo / adr_tue.d_count, adr_tue.hit_fib_2_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_fib_2_lo / adr_wed.d_count, adr_wed.hit_fib_2_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_fib_2_lo / adr_thu.d_count, adr_thu.hit_fib_2_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_fib_2_lo / adr_fri.d_count, adr_fri.hit_fib_2_lo), bgcolor = rch_color, text_size = _size)
row := row + 1
if fib_3_show
table.cell(tbl, 0, row, "Fib " + str.tostring(fib_3_level), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_fib_3_hi / adr_mon.d_count, adr_mon.hit_fib_3_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_fib_3_hi / adr_tue.d_count, adr_tue.hit_fib_3_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_fib_3_hi / adr_wed.d_count, adr_wed.hit_fib_3_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_fib_3_hi / adr_thu.d_count, adr_thu.hit_fib_3_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_fib_3_hi / adr_fri.d_count, adr_fri.hit_fib_3_hi), bgcolor = rch_color, text_size = _size)
row := row + 1
table.cell(tbl, 0, row, "Fib -" + str.tostring(fib_3_level), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_fib_3_lo / adr_mon.d_count, adr_mon.hit_fib_3_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_fib_3_lo / adr_tue.d_count, adr_tue.hit_fib_3_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_fib_3_lo / adr_wed.d_count, adr_wed.hit_fib_3_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_fib_3_lo / adr_thu.d_count, adr_thu.hit_fib_3_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_fib_3_lo / adr_fri.d_count, adr_fri.hit_fib_3_lo), bgcolor = rch_color, text_size = _size)
row := row + 1
if std_0_5_show
table.cell(tbl, 0, row, "Std " + str.tostring(std_dev_0_5), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_std_0_5_hi / adr_mon.d_count, adr_mon.hit_std_0_5_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_std_0_5_hi / adr_tue.d_count, adr_tue.hit_std_0_5_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_std_0_5_hi / adr_wed.d_count, adr_wed.hit_std_0_5_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_std_0_5_hi / adr_thu.d_count, adr_thu.hit_std_0_5_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_std_0_5_hi / adr_fri.d_count, adr_fri.hit_std_0_5_hi), bgcolor = rch_color, text_size = _size)
row := row + 1
table.cell(tbl, 0, row, "Std -" + str.tostring(std_dev_0_5), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_std_0_5_lo / adr_mon.d_count, adr_mon.hit_std_0_5_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_std_0_5_lo / adr_tue.d_count, adr_tue.hit_std_0_5_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_std_0_5_lo / adr_wed.d_count, adr_wed.hit_std_0_5_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_std_0_5_lo / adr_thu.d_count, adr_thu.hit_std_0_5_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_std_0_5_lo / adr_fri.d_count, adr_fri.hit_std_0_5_lo), bgcolor = rch_color, text_size = _size)
row := row + 1
if std_1_show
table.cell(tbl, 0, row, "Std " + str.tostring(std_dev_1), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_std_1_hi / adr_mon.d_count, adr_mon.hit_std_1_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_std_1_hi / adr_tue.d_count, adr_tue.hit_std_1_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_std_1_hi / adr_wed.d_count, adr_wed.hit_std_1_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_std_1_hi / adr_thu.d_count, adr_thu.hit_std_1_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_std_1_hi / adr_fri.d_count, adr_fri.hit_std_1_hi), bgcolor = rch_color, text_size = _size)
row := row + 1
table.cell(tbl, 0, row, "Std -" + str.tostring(std_dev_1), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_std_1_lo / adr_mon.d_count, adr_mon.hit_std_1_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_std_1_lo / adr_tue.d_count, adr_tue.hit_std_1_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_std_1_lo / adr_wed.d_count, adr_wed.hit_std_1_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_std_1_lo / adr_thu.d_count, adr_thu.hit_std_1_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_std_1_lo / adr_fri.d_count, adr_fri.hit_std_1_lo), bgcolor = rch_color, text_size = _size)
row := row + 1
if std_2_show
table.cell(tbl, 0, row, "Std " + str.tostring(std_dev_2), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_std_2_hi / adr_mon.d_count, adr_mon.hit_std_2_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_std_2_hi / adr_tue.d_count, adr_tue.hit_std_2_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_std_2_hi / adr_wed.d_count, adr_wed.hit_std_2_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_std_2_hi / adr_thu.d_count, adr_thu.hit_std_2_hi), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_std_2_hi / adr_fri.d_count, adr_fri.hit_std_2_hi), bgcolor = rch_color, text_size = _size)
row := row + 1
table.cell(tbl, 0, row, "Std -" + str.tostring(std_dev_2), text_size = _size)
table.cell(tbl, 1, row, fmt_sample(adr_mon.d_count, adr_mon.hit_std_2_lo / adr_mon.d_count, adr_mon.hit_std_2_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 2, row, fmt_sample(adr_tue.d_count, adr_tue.hit_std_2_lo / adr_tue.d_count, adr_tue.hit_std_2_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 3, row, fmt_sample(adr_wed.d_count, adr_wed.hit_std_2_lo / adr_wed.d_count, adr_wed.hit_std_2_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 4, row, fmt_sample(adr_thu.d_count, adr_thu.hit_std_2_lo / adr_thu.d_count, adr_thu.hit_std_2_lo), bgcolor = rch_color, text_size = _size)
table.cell(tbl, 5, row, fmt_sample(adr_fri.d_count, adr_fri.hit_std_2_lo / adr_fri.d_count, adr_fri.hit_std_2_lo), bgcolor = rch_color, text_size = _size)
Multi SMA + Golden/Death + Heatmap + BB**Multi SMA (50/100/200) + Golden/Death + Candle Heatmap + BB**
A practical trend toolkit that blends classic 50/100/200 SMAs with clear crossover labels, special 🚀 Golden / 💀 Death Cross markers, and a readable candle heatmap based on a dynamic regression midline and volatility bands. Optional Bollinger Bands are included for context.
* See trend direction at a glance with SMAs.
* Get minimal, de-cluttered labels on important crosses (50↔100, 50↔200, 100↔200).
* Highlight big regime shifts with special Golden/Death tags.
* Read momentum and volatility with the candle heatmap.
* Add Bollinger Bands if you want classic mean-reversion context.
Designed to be lightweight, non-repainting on confirmed bars, and flexible across timeframes.
# What This Indicator Does (plain English)
* **Tracks trend** using **SMA 50/100/200** and lets you optionally compute each SMA on a higher or different timeframe (HTF-safe, no lookahead).
* **Prints labels** when SMAs cross each other (up or down). You can force signals only after bar close to avoid repaint.
* **Marks Golden/Death Crosses** (50 over/under 200) with special labels so major regime changes stand out.
* **Colors candles** with a **heatmap** built from a regression midline and volatility bands—greenish above, reddish below, with a smooth gradient.
* **Optionally shows Bollinger Bands** (basis SMA + stdev bands) and fills the area between them.
* **Includes alert conditions** for Golden and Death Cross so you can automate notifications.
---
# Settings — Simple Explanations
## Source
* **Source**: Price source used to calculate SMAs and Bollinger basis. Default: `close`.
## SMA 50
* **Show 50**: Turn the SMA(50) line on/off.
* **Length 50**: How many bars to average. Lower = faster but noisier.
* **Color 50** / **Width 50**: Visual style.
* **Timeframe 50**: Optional alternate timeframe for SMA(50). Leave empty to use the chart timeframe.
## SMA 100
* **Show 100**: Turn the SMA(100) line on/off.
* **Length 100**: Bars used for the mid-term trend.
* **Color 100** / **Width 100**: Visual style.
* **Timeframe 100**: Optional alternate timeframe for SMA(100).
## SMA 200
* **Show 200**: Turn the SMA(200) line on/off.
* **Length 200**: Bars used for the long-term trend.
* **Color 200** / **Width 200**: Visual style.
* **Timeframe 200**: Optional alternate timeframe for SMA(200).
## Signals (crossover labels)
* **Show crossover signals**: Prints triangle labels on SMA crosses (50↔100, 50↔200, 100↔200).
* **Wait for bar close (confirmed)**: If ON, signals only appear after the candle closes (reduces repaint).
* **Min bars between same-pair signals**: Minimum spacing to avoid duplicate labels from the same SMA pair too often.
* **Trend filter (buy: 50>100>200, sell: 50<100<200)**: Only show bullish labels when SMAs are stacked bullish (50 above 100 above 200), and only show bearish labels when stacked bearish.
### Label Offset
* **Offset mode**: Choose how to push labels away from price:
* **Percent**: Offset is a % of price.
* **ATR x**: Offset is ATR(14) × multiplier.
* **Percent of price (%)**: Used when mode = Percent.
* **ATR multiplier (for ‘ATR x’)**: Used when mode = ATR x.
### Label Colors
* **Bull color** / **Bear color**: Background of triangle labels.
* **Bull label text color** / **Bear label text color**: Text color inside the triangles.
## Golden / Death Cross
* **Show 🚀 Golden Cross (50↑200)**: Show a special “Golden” label when SMA50 crosses above SMA200.
* **Golden label color** / **Golden text color**: Styling for Golden label.
* **Show 💀 Death Cross (50↓200)**: Show a special “Death” label when SMA50 crosses below SMA200.
* **Death label color** / **Death text color**: Styling for Death label.
## Candle Heatmap
* **Enable heatmap candle colors**: Turns the heatmap on/off.
* **Length**: Lookback for the regression midline and volatility measure.
* **Deviation Multiplier**: Band width around the midline (bigger = wider).
* **Volatility basis**:
* **RMA Range** (smoothed high-low range)
* **Stdev** (standard deviation of close)
* **Upper/Middle/Lower color**: Gradient colors for the heatmap.
* **Heatmap transparency (0..100)**: 0 = solid, 100 = invisible.
* **Force override base candles**: Repaint base candles so heatmap stays visible even if your chart has custom coloring.
## Bollinger Bands (optional)
* **Show Bollinger Bands**: Toggle the overlay on/off.
* **Length**: Basis SMA length.
* **StdDev Multiplier**: Distance of bands from the basis in standard deviations.
* **Basis color** / **Band color**: Line colors for basis and bands.
* **Bands fill transparency**: Opacity of the fill between upper/lower bands.
---
# Features & How It Works
## 1) HTF-Safe SMAs
Each SMA can be calculated on the chart timeframe or a higher/different timeframe you choose. The script pulls HTF values **without lookahead** (non-repainting on confirmed bars).
## 2) Crossover Labels (Three Pairs)
* **50↔100**, **50↔200**, **100↔200**:
* **Triangle Up** label when the first SMA crosses **above** the second.
* **Triangle Down** label when it crosses **below**.
* Optional **Trend Filter** ensures only signals aligned with the overall stack (50>100>200 for bullish, 50<100<200 for bearish).
* **Debounce** spacing avoids repeated labels for the same pair too close together.
## 3) Golden / Death Cross Highlights
* **🚀 Golden Cross**: SMA50 crosses **above** SMA200 (often a longer-term bullish regime shift).
* **💀 Death Cross**: SMA50 crosses **below** SMA200 (often a longer-term bearish regime shift).
* Separate styling so they stand out from regular cross labels.
## 4) Candle Heatmap
* Builds a **regression midline** with **volatility bands**; colors candles by their position inside that channel.
* Smooth gradient: lower side → reddish, mid → yellowish, upper side → greenish.
* Helps you see momentum and “where price sits” relative to a dynamic channel.
## 5) Bollinger Bands (Optional)
* Classic **basis SMA** ± **StdDev** bands.
* Light visual context for mean-reversion and volatility expansion.
## 6) Alerts
* **Golden Cross**: `🚀 GOLDEN CROSS: SMA 50 crossed ABOVE SMA 200`
* **Death Cross**: `💀 DEATH CROSS: SMA 50 crossed BELOW SMA 200`
Add these to your alerts to get notified automatically.
---
# Tips & Notes
* For fewer false positives, keep **“Wait for bar close”** ON, especially on lower timeframes.
* Use the **Trend Filter** to align signals with the broader stack and cut noise.
* For HTF context, set **Timeframe 50/100/200** to higher frames (e.g., H1/H4/D) while you trade on a lower frame.
* Heatmap “Length” and “Deviation Multiplier” control smoothness and channel width—tune for your asset’s volatility.
RSI Overbought/Oversold + Divergence Indicator (new)//@version=5
indicator('CryptoSignalScanner - RSI Overbought/Oversold + Divergence Indicator (new)',
//---------------------------------------------------------------------------------------------------------------------------------
//--- Define Colors ---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------
vWhite = #FFFFFF
vViolet = #C77DF3
vIndigo = #8A2BE2
vBlue = #009CDF
vGreen = #5EBD3E
vYellow = #FFB900
vRed = #E23838
longColor = color.green
shortColor = color.red
textColor = color.white
bullishColor = color.rgb(38,166,154,0) //Used in the display table
bearishColor = color.rgb(239,83,79,0) //Used in the display table
nomatchColor = color.silver //Used in the display table
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- Functions--------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
TF2txt(TF) =>
switch TF
"S" => "RSI 1s:"
"5S" => "RSI 5s:"
"10S" => "RSI 10s:"
"15S" => "RSI 15s:"
"30S" => "RSI 30s"
"1" => "RSI 1m:"
"3" => "RSI 3m:"
"5" => "RSI 5m:"
"15" => "RSI 15m:"
"30" => "RSI 30m"
"45" => "RSI 45m"
"60" => "RSI 1h:"
"120" => "RSI 2h:"
"180" => "RSI 3h:"
"240" => "RSI 4h:"
"480" => "RSI 8h:"
"D" => "RSI 1D:"
"1D" => "RSI 1D:"
"2D" => "RSI 2D:"
"3D" => "RSI 2D:"
"3D" => "RSI 3W:"
"W" => "RSI 1W:"
"1W" => "RSI 1W:"
"M" => "RSI 1M:"
"1M" => "RSI 1M:"
"3M" => "RSI 3M:"
"6M" => "RSI 6M:"
"12M" => "RSI 12M:"
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- Show/Hide Settings ----------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
rsiShowInput = input(true, title='Show RSI', group='Show/Hide Settings')
maShowInput = input(false, title='Show MA', group='Show/Hide Settings')
showRSIMAInput = input(true, title='Show RSIMA Cloud', group='Show/Hide Settings')
rsiBandShowInput = input(true, title='Show Oversold/Overbought Lines', group='Show/Hide Settings')
rsiBandExtShowInput = input(true, title='Show Oversold/Overbought Extended Lines', group='Show/Hide Settings')
rsiHighlightShowInput = input(true, title='Show Oversold/Overbought Highlight Lines', group='Show/Hide Settings')
DivergenceShowInput = input(true, title='Show RSI Divergence Labels', group='Show/Hide Settings')
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- Table Settings --------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
rsiShowTable = input(true, title='Show RSI Table Information box', group="RSI Table Settings")
rsiTablePosition = input.string(title='Location', defval='middle_right', options= , group="RSI Table Settings", inline='1')
rsiTextSize = input.string(title=' Size', defval='small', options= , group="RSI Table Settings", inline='1')
rsiShowTF1 = input(true, title='Show TimeFrame1', group="RSI Table Settings", inline='tf1')
rsiTF1 = input.timeframe("15", title=" Time", group="RSI Table Settings", inline='tf1')
rsiShowTF2 = input(true, title='Show TimeFrame2', group="RSI Table Settings", inline='tf2')
rsiTF2 = input.timeframe("60", title=" Time", group="RSI Table Settings", inline='tf2')
rsiShowTF3 = input(true, title='Show TimeFrame3', group="RSI Table Settings", inline='tf3')
rsiTF3 = input.timeframe("240", title=" Time", group="RSI Table Settings", inline='tf3')
rsiShowTF4 = input(true, title='Show TimeFrame4', group="RSI Table Settings", inline='tf4')
rsiTF4 = input.timeframe("D", title=" Time", group="RSI Table Settings", inline='tf4')
rsiShowHist = input(true, title='Show RSI Historical Columns', group="RSI Table Settings", tooltip='Show the information of the 2 previous closed candles')
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- RSI Input Settings ----------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
rsiSourceInput = input.source(close, 'Source', group='RSI Settings')
rsiLengthInput = input.int(14, minval=1, title='RSI Length', group='RSI Settings', tooltip='Here we set the RSI lenght')
rsiColorInput = input.color(#26a69a, title="RSI Color", group='RSI Settings')
rsimaColorInput = input.color(#ef534f, title="RSIMA Color", group='RSI Settings')
rsiBandColorInput = input.color(#787B86, title="RSI Band Color", group='RSI Settings')
rsiUpperBandExtInput = input.int(title='RSI Overbought Extended Line', defval=80, minval=50, maxval=100, group='RSI Settings')
rsiUpperBandInput = input.int(title='RSI Overbought Line', defval=70, minval=50, maxval=100, group='RSI Settings')
rsiLowerBandInput = input.int(title='RSI Oversold Line', defval=30, minval=0, maxval=50, group='RSI Settings')
rsiLowerBandExtInput = input.int(title='RSI Oversold Extended Line', defval=20, minval=0, maxval=50, group='RSI Settings')
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- MA Input Settings -----------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
maTypeInput = input.string("EMA", title="MA Type", options= , group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
maColorInput = input.color(color.yellow, title="MA Color", group='MA Settings') //#7E57C2
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- Divergence Input Settings ---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
lbrInput = input(title="Pivot Lookback Right", defval=2, group='RSI Divergence Settings')
lblInput = input(title="Pivot Lookback Left", defval=2, group='RSI Divergence Settings')
lbRangeMaxInput = input(title="Max of Lookback Range", defval=10, group='RSI Divergence Settings')
lbRangeMinInput = input(title="Min of Lookback Range", defval=2, group='RSI Divergence Settings')
plotBullInput = input(title="Plot Bullish", defval=true, group='RSI Divergence Settings')
plotHiddenBullInput = input(title="Plot Hidden Bullish", defval=true, group='RSI Divergence Settings')
plotBearInput = input(title="Plot Bearish", defval=true, group='RSI Divergence Settings')
plotHiddenBearInput = input(title="Plot Hidden Bearish", defval=true, group='RSI Divergence Settings')
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- RSI Calculation -------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
rsi = ta.rsi(rsiSourceInput, rsiLengthInput)
rsiprevious = rsi
= request.security(syminfo.tickerid, rsiTF1, [rsi, rsi , rsi ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, rsiTF2, [rsi, rsi , rsi ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, rsiTF3, [rsi, rsi , rsi ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, rsiTF4, [rsi, rsi , rsi ], lookahead=barmerge.lookahead_on)
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- MA Calculation -------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
rsiMA = ma(rsi, maLengthInput, maTypeInput)
rsiMAPrevious = rsiMA
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- Stoch RSI Settings + Calculation --------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
showStochRSI = input(false, title="Show Stochastic RSI", group='Stochastic RSI Settings')
smoothK = input.int(title="Stochastic K", defval=3, minval=1, maxval=10, group='Stochastic RSI Settings')
smoothD = input.int(title="Stochastic D", defval=4, minval=1, maxval=10, group='Stochastic RSI Settings')
lengthRSI = input.int(title="Stochastic RSI Lenght", defval=14, minval=1, group='Stochastic RSI Settings')
lengthStoch = input.int(title="Stochastic Lenght", defval=14, minval=1, group='Stochastic RSI Settings')
colorK = input.color(color.rgb(41,98,255,0), title="K Color", group='Stochastic RSI Settings', inline="1")
colorD = input.color(color.rgb(205,109,0,0), title="D Color", group='Stochastic RSI Settings', inline="1")
StochRSI = ta.rsi(rsiSourceInput, lengthRSI)
k = ta.sma(ta.stoch(StochRSI, StochRSI, StochRSI, lengthStoch), smoothK) //Blue Line
d = ta.sma(k, smoothD) //Red Line
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- Divergence Settings ------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
bearColor = color.red
bullColor = color.green
hiddenBullColor = color.new(color.green, 50)
hiddenBearColor = color.new(color.red, 50)
//textColor = color.white
noneColor = color.new(color.white, 100)
osc = rsi
plFound = na(ta.pivotlow(osc, lblInput, lbrInput)) ? false : true
phFound = na(ta.pivothigh(osc, lblInput, lbrInput)) ? false : true
_inRange(cond) =>
bars = ta.barssince(cond == true)
lbRangeMinInput <= bars and bars <= lbRangeMaxInput
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- Define Plot & Line Colors ---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
rsiColor = rsi >= rsiMA ? rsiColorInput : rsimaColorInput
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- Plot Lines ------------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Create a horizontal line at a specific price level
myLine = line.new(bar_index , 75, bar_index, 75, color = color.rgb(187, 14, 14), width = 2)
bottom = line.new(bar_index , 50, bar_index, 50, color = color.rgb(223, 226, 28), width = 2)
mymainLine = line.new(bar_index , 60, bar_index, 60, color = color.rgb(13, 154, 10), width = 3)
hline(50, title='RSI Baseline', color=color.new(rsiBandColorInput, 50), linestyle=hline.style_solid, editable=false)
hline(rsiBandExtShowInput ? rsiUpperBandExtInput : na, title='RSI Upper Band', color=color.new(rsiBandColorInput, 10), linestyle=hline.style_dashed, editable=false)
hline(rsiBandShowInput ? rsiUpperBandInput : na, title='RSI Upper Band', color=color.new(rsiBandColorInput, 10), linestyle=hline.style_dashed, editable=false)
hline(rsiBandShowInput ? rsiLowerBandInput : na, title='RSI Upper Band', color=color.new(rsiBandColorInput, 10), linestyle=hline.style_dashed, editable=false)
hline(rsiBandExtShowInput ? rsiLowerBandExtInput : na, title='RSI Upper Band', color=color.new(rsiBandColorInput, 10), linestyle=hline.style_dashed, editable=false)
bgcolor(rsiHighlightShowInput ? rsi >= rsiUpperBandExtInput ? color.new(rsiColorInput, 70) : na : na, title="Show Extended Oversold Highlight", editable=false)
bgcolor(rsiHighlightShowInput ? rsi >= rsiUpperBandInput ? rsi < rsiUpperBandExtInput ? color.new(#64ffda, 90) : na : na: na, title="Show Overbought Highlight", editable=false)
bgcolor(rsiHighlightShowInput ? rsi <= rsiLowerBandInput ? rsi > rsiLowerBandExtInput ? color.new(#F43E32, 90) : na : na : na, title="Show Extended Oversold Highlight", editable=false)
bgcolor(rsiHighlightShowInput ? rsi <= rsiLowerBandInput ? color.new(rsimaColorInput, 70) : na : na, title="Show Oversold Highlight", editable=false)
maPlot = plot(maShowInput ? rsiMA : na, title='MA', color=color.new(maColorInput,0), linewidth=1)
rsiMAPlot = plot(showRSIMAInput ? rsiMA : na, title="RSI EMA", color=color.new(rsimaColorInput,0), editable=false, display=display.none)
rsiPlot = plot(rsiShowInput ? rsi : na, title='RSI', color=color.new(rsiColor,0), linewidth=1)
fill(rsiPlot, rsiMAPlot, color=color.new(rsiColor, 60), title="RSIMA Cloud")
plot(showStochRSI ? k : na, title='Stochastic K', color=colorK, linewidth=1)
plot(showStochRSI ? d : na, title='Stochastic D', color=colorD, linewidth=1)
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- Plot Divergence -------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
oscHL = osc > ta.valuewhen(plFound, osc , 1) and _inRange(plFound )
// Price: Lower Low
priceLL = low < ta.valuewhen(plFound, low , 1)
bullCond = plotBullInput and priceLL and oscHL and plFound
plot(
plFound ? osc : na,
offset=-lbrInput,
title="Regular Bullish",
linewidth=2,
color=(bullCond ? bullColor : noneColor)
)
plotshape(
DivergenceShowInput ? bullCond ? osc : na : na,
offset=-lbrInput,
title="Regular Bullish Label",
text=" Bull ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
oscLL = osc < ta.valuewhen(plFound, osc , 1) and _inRange(plFound )
// Price: Higher Low
priceHL = low > ta.valuewhen(plFound, low , 1)
hiddenBullCond = plotHiddenBullInput and priceHL and oscLL and plFound
plot(
plFound ? osc : na,
offset=-lbrInput,
title="Hidden Bullish",
linewidth=2,
color=(hiddenBullCond ? hiddenBullColor : noneColor)
)
plotshape(
DivergenceShowInput ? hiddenBullCond ? osc : na : na,
offset=-lbrInput,
title="Hidden Bullish Label",
text=" H Bull ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
oscLH = osc < ta.valuewhen(phFound, osc , 1) and _inRange(phFound )
// Price: Higher High
priceHH = high > ta.valuewhen(phFound, high , 1)
bearCond = plotBearInput and priceHH and oscLH and phFound
plot(
phFound ? osc : na,
offset=-lbrInput,
title="Regular Bearish",
linewidth=2,
color=(bearCond ? bearColor : noneColor)
)
plotshape(
DivergenceShowInput ? bearCond ? osc : na : na,
offset=-lbrInput,
title="Regular Bearish Label",
text=" Bear ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
oscHH = osc > ta.valuewhen(phFound, osc , 1) and _inRange(phFound )
// Price: Lower High
priceLH = high < ta.valuewhen(phFound, high , 1)
hiddenBearCond = plotHiddenBearInput and priceLH and oscHH and phFound
plot(
phFound ? osc : na,
offset=-lbrInput,
title="Hidden Bearish",
linewidth=2,
color=(hiddenBearCond ? hiddenBearColor : noneColor)
)
plotshape(
DivergenceShowInput ? hiddenBearCond ? osc : na : na,
offset=-lbrInput,
title="Hidden Bearish Label",
text=" H Bear ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- Check RSI Lineup ------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
bullTF = rsi > rsi and rsi > rsi
bearTF = rsi < rsi and rsi < rsi
bullTF1 = rsi1 > rsi1_1 and rsi1_1 > rsi1_2
bearTF1 = rsi1 < rsi1_1 and rsi1_1 < rsi1_2
bullTF2 = rsi2 > rsi2_1 and rsi2_1 > rsi2_2
bearTF2 = rsi2 < rsi2_1 and rsi2_1 < rsi2_2
bullTF3 = rsi3 > rsi3_1 and rsi3_1 > rsi3_2
bearTF3 = rsi3 < rsi3_1 and rsi3_1 < rsi3_2
bullTF4 = rsi4 > rsi4_1 and rsi4_1 > rsi4_2
bearTF4 = rsi4 < rsi4_1 and rsi4_1 < rsi4_2
bbTxt(bull,bear) =>
bull ? "BULLISH" : bear ? "BEARISCH" : 'NO LINEUP'
bbColor(bull,bear) =>
bull ? bullishColor : bear ? bearishColor : nomatchColor
newTC(tBox, col, row, txt, width, txtColor, bgColor, txtHA, txtSize) =>
table.cell(table_id=tBox,column=col, row=row, text=txt, width=width,text_color=txtColor,bgcolor=bgColor, text_halign=txtHA, text_size=txtSize)
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--- Define RSI Table Setting ----------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
width_c0 = 0
width_c1 = 0
if rsiShowTable
var tBox = table.new(position=rsiTablePosition, columns=5, rows=6, bgcolor=color.rgb(18,22,33,50), frame_color=color.black, frame_width=1, border_color=color.black, border_width=1)
newTC(tBox, 0,1,"RSI Current",width_c0,color.orange,color.rgb(0,0,0,100),'right',rsiTextSize)
newTC(tBox, 1,1,str.format(" {0,number,#.##} ", rsi),width_c0,vWhite,rsi < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
newTC(tBox, 4,1,bbTxt(bullTF, bearTF),width_c0,vWhite,bbColor(bullTF, bearTF),'center',rsiTextSize)
if rsiShowHist
newTC(tBox, 2,1,str.format(" {0,number,#.##} ", rsi ),width_c0,vWhite,rsi < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
newTC(tBox, 3,1,str.format(" {0,number,#.##} ", rsi ),width_c0,vWhite,rsi < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
if rsiShowTF1
newTC(tBox, 0,2,TF2txt(rsiTF1),width_c0,vWhite,color.rgb(0,0,0,100),'right',rsiTextSize)
newTC(tBox, 1,2,str.format(" {0,number,#.##} ", rsi1),width_c0,vWhite,rsi1 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
newTC(tBox, 4,2,bbTxt(bullTF1, bearTF1),width_c0,vWhite,bbColor(bullTF1,bearTF1),'center',rsiTextSize)
if rsiShowHist
newTC(tBox, 2,2,str.format(" {0,number,#.##} ", rsi1_1),width_c0,vWhite,rsi1_1 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
newTC(tBox, 3,2,str.format(" {0,number,#.##} ", rsi1_2),width_c0,vWhite,rsi1_2 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
if rsiShowTF2
newTC(tBox, 0,3,TF2txt(rsiTF2),width_c0,vWhite,color.rgb(0,0,0,100),'right',rsiTextSize)
newTC(tBox, 1,3,str.format(" {0,number,#.##} ", rsi2),width_c0,vWhite,rsi2 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
newTC(tBox, 4,3,bbTxt(bullTF2, bearTF2),width_c0,vWhite,bbColor(bullTF2,bearTF2),'center',rsiTextSize)
if rsiShowHist
newTC(tBox, 2,3,str.format(" {0,number,#.##} ", rsi2_1),width_c0,vWhite,rsi2_1 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
newTC(tBox, 3,3,str.format(" {0,number,#.##} ", rsi2_2),width_c0,vWhite,rsi2_2 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
if rsiShowTF3
newTC(tBox, 0,4,TF2txt(rsiTF3),width_c0,vWhite,color.rgb(0,0,0,100),'right',rsiTextSize)
newTC(tBox, 1,4,str.format(" {0,number,#.##} ", rsi3),width_c0,vWhite,rsi3 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
newTC(tBox, 4,4,bbTxt(bullTF3, bearTF3),width_c0,vWhite,bbColor(bullTF3,bearTF3),'center',rsiTextSize)
if rsiShowHist
newTC(tBox, 2,4,str.format(" {0,number,#.##} ", rsi3_1),width_c0,vWhite,rsi3_1 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
newTC(tBox, 3,4,str.format(" {0,number,#.##} ", rsi3_2),width_c0,vWhite,rsi3_2 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
if rsiShowTF4
newTC(tBox, 0,5,TF2txt(rsiTF4),width_c0,vWhite,color.rgb(0,0,0,100),'right',rsiTextSize)
newTC(tBox, 1,5,str.format(" {0,number,#.##} ", rsi4),width_c0,vWhite,rsi4 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
newTC(tBox, 4,5,bbTxt(bullTF4, bearTF4),width_c0,vWhite,bbColor(bullTF4,bearTF4),'center',rsiTextSize)
if rsiShowHist
newTC(tBox, 2,5,str.format(" {0,number,#.##} ", rsi4_1),width_c0,vWhite,rsi4_1 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
newTC(tBox, 3,5,str.format(" {0,number,#.##} ", rsi4_2),width_c0,vWhite,rsi4_2 < 50 ? bearishColor:bullishColor,'left',rsiTextSize)
//------------------------------------------------------
//--- Alerts -------------------------------------------
//------------------------------------------------------
Breadth Indicators NYSE Percent Above Moving AverageBreadth Indicators NYSE - transmits the processed data from the Barchart provider
NYSE - Breadth Indicators
S&P 500 - Breadth Indicators
DOW - Breadth Indicators
RUSSEL 1000 - Breadth Indicators
RUSSEL 2000 - Breadth Indicators
RUSSEL 3000 - Breadth Indicators
Moving Average - 5, 20, 50, 100, 150, 200
The "Percentage above 50-day SMA" indicator measures the percentage of stocks in the index trading above their 50-day moving average. It is a useful tool for assessing the general state of the market and identifying overbought and oversold conditions.
One way to use the "Percentage above 50-day SMA" indicator in a trading strategy is to combine it with a long-term moving average to determine whether the trend is bullish or bearish. Another way to use it is to combine it with a short-term moving average to identify pullbacks and rebounds within the overall trend.
The purpose of using the "Percentage above 50-day SMA" indicator is to participate in a larger trend with a better risk-reward ratio. By using this indicator to identify pullbacks and bounces, you can reduce the risk of entering trades at the wrong time.
Bull Signal Recap:
150-day EMA of $SPXA50R crosses above 52.5 and remains above 47.50 to set the bullish tone.
5-day EMA of $SPXA50R moves below 40 to signal a pullback
5-day EMA of $SPXA50R moves above 50 to signal an upturn
Bear Signal Recap:
150-day EMA of $SPXA50R crosses below 47.50 and remains below 52.50 to set the bearish tone.
5-day EMA of $SPXA50R moves above 60 to signal a bounce
5-day EMA of $SPXA50R moves below 50 to signal a downturn
Tweaking
There are numerous ways to tweak a trading system, but chartists should avoid over-optimizing the indicator settings. In other words, don't attempt to find the perfect moving average period or crossover level. Perfection is unattainable when developing a system or trading the markets. It is important to keep the system logical and focus tweaks on other aspects, such as the actual price chart of the underlying security.
What do levels above and below 50% signify in the long-term moving average?
A move above 52.5% is deemed bullish, and below 47.5% is deemed bearish. These levels help to reduce whipsaws by using buffers for bullish and bearish thresholds.
How does the short-term moving average work to identify pullbacks or bounces?
When using a 5-day EMA, a move below 40 signals a pullback, and a move above 60 signals a bounce.
How is the reversal of pullback or bounce identified?
A move back above 50 after a pullback or below 50 after a bounce signals that the respective trend may be resuming.
How can you ensure that the uptrend has resumed?
It’s important to wait for the surge above 50 to ensure the uptrend has resumed, signaling improved breadth.
Can the system be tweaked to optimize indicator settings?
While there are various ways to tweak the system, seeking perfection through over-optimizing settings is advised against. It's crucial to keep the system logical and focus tweaks on the price chart of the underlying security.
RUSSIAN \ Русская версия.
Индикатор "Процент выше 50-дневной скользящей средней" измеряет процент акций, торгующихся в индексе выше их 50-дневной скользящей средней. Это полезный инструмент для оценки общего состояния рынка и выявления условий перекупленности и перепроданности.
Один из способов использования индикатора "Процент выше 50-дневной скользящей средней" в торговой стратегии - это объединить его с долгосрочной скользящей средней, чтобы определить, является ли тренд бычьим или медвежьим. Другой способ использовать его - объединить с краткосрочной скользящей средней, чтобы выявить откаты и отскоки в рамках общего тренда.
Цель использования индикатора "Процент выше 50-дневной скользящей средней" - участвовать в более широком тренде с лучшим соотношением риска и прибыли. Используя этот индикатор для выявления откатов и отскоков, вы можете снизить риск входа в сделки в неподходящее время.
Краткое описание бычьего сигнала:
150-дневная ЕМА на уровне $SPXA50R пересекает отметку 52,5 и остается выше 47,50, что задает бычий настрой.
5-дневная ЕМА на уровне $SPXA50R опускается ниже 40, сигнализируя об откате
5-дневная ЕМА на уровне $SPXA50R поднимается выше 50, сигнализируя о росте
Обзор медвежьих сигналов:
150-дневная ЕМА на уровне $SPXA50R пересекает уровень ниже 47,50 и остается ниже 52,50, что указывает на медвежий настрой.
5-дневная ЕМА на уровне $SPXA50R поднимается выше 60, сигнализируя о отскоке
5-дневная ЕМА на уровне $SPXA50 опускается ниже 50, что сигнализирует о спаде
Корректировка
Существует множество способов настроить торговую систему, но графологам следует избегать чрезмерной оптимизации настроек индикатора. Другими словами, не пытайтесь найти идеальный период скользящей средней или уровень пересечения. Совершенство недостижимо при разработке системы или торговле на рынках. Важно поддерживать логику системы и уделять особое внимание другим аспектам, таким как график фактической цены базовой ценной бумаги.
Что означают уровни выше и ниже 50% в долгосрочной скользящей средней?
Движение выше 52,5% считается бычьим, а ниже 47,5% - медвежьим. Эти уровни помогают снизить риски, используя буферы для бычьих и медвежьих порогов.
Как краткосрочная скользящая средняя помогает идентифицировать откаты или отскоки?
При использовании 5-дневной ЕМА движение ниже 40 указывает на откат, а движение выше 60 указывает на отскок.
Как определяется разворот отката или отскока?
Движение выше 50 после отката или ниже 50 после отскока сигнализирует о возможном возобновлении соответствующего тренда.
Как вы можете гарантировать, что восходящий тренд возобновился?
Важно дождаться скачка выше 50, чтобы убедиться в возобновлении восходящего тренда, сигнализирующего о расширении диапазона.
Можно ли настроить систему для оптимизации настроек индикатора?
Хотя существуют различные способы настройки системы, не рекомендуется стремиться к совершенству с помощью чрезмерной оптимизации настроек. Крайне важно сохранить логичность системы и сфокусировать изменения на ценовом графике базовой ценной бумаги.






















