name
stringlengths 1
64
| url
stringlengths 44
135
| author
stringlengths 3
30
| author_url
stringlengths 34
61
| likes_count
int64 0
33.2k
| kind
stringclasses 3
values | pine_version
int64 1
5
| license
stringclasses 3
values | source
stringlengths 177
279k
|
---|---|---|---|---|---|---|---|---|
Auto Anchored Volume Weighted Average Price - Custom AVWAP | https://www.tradingview.com/script/ShppRaZB-Auto-Anchored-Volume-Weighted-Average-Price-Custom-AVWAP/ | elScipio | https://www.tradingview.com/u/elScipio/ | 461 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AJ7919
//@version=4
study("AAVWAP - AJ", overlay = true, max_bars_back=5000)
tframe = input(defval="1D", title="Timeframe", type=input.resolution, options=["1D", "1W", "1M"])
period = input(defval=90, title="Period", type=input.integer)
display_as_hline = input(defval=false, title="Display as Horizontal Line", type=input.bool)
label_offset = input(defval=50, title="Label Offset", type=input.integer)
show_low_vwap_label = input(defval=true, title="Show Low VWAP label", type=input.bool)
show_high_vwap_label = input(defval=true, title="Show High VWAP label", type=input.bool)
show_vol_vwap_label = input(defval=true, title="Show Vol VWAP label", type=input.bool)
// Var declaration
var int block_size = 1
var currentBarTime = 0
time_0 = security(syminfo.tickerid, tframe, time, barmerge.gaps_off, barmerge.lookahead_on)
time_1 = security(syminfo.tickerid, tframe, time[period], barmerge.gaps_off, barmerge.lookahead_on)
var TPeriod = 0
var chart_timeframe_minutes = 0
var indicator_timeframe_minutes = 0
var real_period = 0
// low vwap vars
var low_vwap_volume_price_summation = 0.0
var low_vwap_volume_summation = 0.0
var low_vwap_counter = 1
var float low_vwap = na
var float lowest_vwap = na
var low_vwap_color = color.fuchsia
var string low_vwap_text = na
// high vwap vars
var high_vwap_volume_price_summation = 0.0
var high_vwap_volume_summation = 0.0
var high_vwap_counter = 1
var float high_vwap = na
var float highest_vwap = na
var high_vwap_color = color.aqua
var string high_vwap_text = na
// volume vwap vars
var vol_vwap_volume_price_summation = 0.0
var vol_vwap_volume_summation = 0.0
var vol_vwap_counter = 1
var float vol_vwap = na
var float volest_vwap = na
var vol_vwap_color = color.orange
var string vol_vwap_text = na
// Labels Initialization
if (tframe == "1D")
low_vwap_text := tostring(period) + " " + "Day" + " Low"
high_vwap_text := tostring(period) + " " + "Day" + " High"
vol_vwap_text := tostring(period) + " " + "Day" + " Vol"
if (tframe == "1W")
low_vwap_text := tostring(period) + " " + "Week" + " Low"
high_vwap_text := tostring(period) + " " + "Week" + " High"
vol_vwap_text := tostring(period) + " " + "Week" + " Vol"
if (tframe == "1M")
low_vwap_text := tostring(period) + " " + "Month" + " Low"
high_vwap_text := tostring(period) + " " + "Month" + " High"
vol_vwap_text := tostring(period) + " " + "Month" + " Vol"
var low_vwap_label = label.new(na, na, low_vwap_text, xloc.bar_index)
var high_vwap_label = label.new(na, na, high_vwap_text, xloc.bar_index)
var vol_vwap_label = label.new(na, na, vol_vwap_text, xloc.bar_index)
var float delta = na
if (not na(time[period]))
delta := time_0 - time_1
for int i = 1 to 4999
if (time - time[i] > delta)
block_size := i
break
if ((timenow - time) < delta)
if (low_vwap_counter == 1)
lowest_vwap := low
low_vwap_volume_price_summation := volume * ohlc4
low_vwap_volume_summation := volume
low_vwap := low_vwap_volume_price_summation / low_vwap_volume_summation
low_vwap_counter := low_vwap_counter + 1
else
if (lowest_vwap > low)
low_vwap_color := low_vwap_color == color.fuchsia ? color.fuchsia : color.fuchsia
low_vwap_volume_price_summation := volume * ohlc4
low_vwap_volume_summation := volume
low_vwap := low_vwap_volume_price_summation / low_vwap_volume_summation
lowest_vwap := low
else
low_vwap_volume_price_summation := low_vwap_volume_price_summation + volume * ohlc4
low_vwap_volume_summation := low_vwap_volume_summation + volume
low_vwap := low_vwap_volume_price_summation / low_vwap_volume_summation
low_vwap_counter := low_vwap_counter + 1
if ((timenow - time) < delta)
if (high_vwap_counter == 1)
highest_vwap := high
high_vwap_volume_price_summation := volume * ohlc4
high_vwap_volume_summation := volume
high_vwap := high_vwap_volume_price_summation / high_vwap_volume_summation
high_vwap_counter := high_vwap_counter + 1
else
if (highest_vwap < high)
high_vwap_color := high_vwap_color == color.aqua ? color.aqua : color.aqua
high_vwap_volume_price_summation := volume * ohlc4
high_vwap_volume_summation := volume
high_vwap := high_vwap_volume_price_summation / high_vwap_volume_summation
highest_vwap := high
else
high_vwap_volume_price_summation := high_vwap_volume_price_summation + volume * ohlc4
high_vwap_volume_summation := high_vwap_volume_summation + volume
high_vwap := high_vwap_volume_price_summation / high_vwap_volume_summation
high_vwap_counter := high_vwap_counter + 1
if ((timenow - time) < delta)
if (vol_vwap_counter == 1)
volest_vwap := volume
vol_vwap_volume_price_summation := volume * ohlc4
vol_vwap_volume_summation := volume
vol_vwap := vol_vwap_volume_price_summation / vol_vwap_volume_summation
vol_vwap_counter := high_vwap_counter + 1
else
if (volest_vwap < volume)
vol_vwap_color := vol_vwap_color == color.orange ? color.orange : color.orange
vol_vwap_volume_price_summation := volume * ohlc4
vol_vwap_volume_summation := volume
vol_vwap := vol_vwap_volume_price_summation / vol_vwap_volume_summation
volest_vwap := volume
else
vol_vwap_volume_price_summation := vol_vwap_volume_price_summation + volume * ohlc4
vol_vwap_volume_summation := vol_vwap_volume_summation + volume
vol_vwap := vol_vwap_volume_price_summation / vol_vwap_volume_summation
vol_vwap_counter := vol_vwap_counter + 1
TPeriod := time - time[1]
TPeriod := na(TPeriod) ? 0 : TPeriod
// if barstate.islast
if show_low_vwap_label
label.set_xloc(low_vwap_label, time + label_offset*TPeriod, xloc.bar_time)
label.set_y(low_vwap_label, low_vwap)
label.set_style(low_vwap_label, label.style_label_left)
label.set_color(low_vwap_label, low_vwap_color)
else
label.delete(low_vwap_label)
if show_high_vwap_label
label.set_xloc(high_vwap_label, time + label_offset*TPeriod, xloc.bar_time)
label.set_y(high_vwap_label, high_vwap)
label.set_style(high_vwap_label, label.style_label_left)
label.set_color(high_vwap_label, high_vwap_color)
else
label.delete(high_vwap_label)
if show_vol_vwap_label
label.set_xloc(vol_vwap_label, time + label_offset*TPeriod, xloc.bar_time)
label.set_y(vol_vwap_label, vol_vwap)
label.set_style(vol_vwap_label, label.style_label_left)
label.set_color(vol_vwap_label, vol_vwap_color)
else
label.delete(vol_vwap_label)
plot(high_vwap, title = "Anchor: Highest candle", color = high_vwap_color, trackprice = display_as_hline, style=plot.style_circles)
plot(low_vwap, title = "Anchor: Lowest candle", color = low_vwap_color, trackprice = display_as_hline, style=plot.style_circles)
plot(vol_vwap, title = "Anchor: Highest volume candle", color = vol_vwap_color, trackprice = display_as_hline, style=plot.style_circles)
alertcondition(cross(close, high_vwap) or cross(close, low_vwap) or cross(close, vol_vwap), title="AVWAP Cross", message='Price crossing {{plot("period")}} AVWAP') |
Liquidity Levels [LuxAlgo] | https://www.tradingview.com/script/qAkfJgFu-Liquidity-Levels-LuxAlgo/ | LuxAlgo | https://www.tradingview.com/u/LuxAlgo/ | 3,930 | study | 5 | CC-BY-NC-SA-4.0 | // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
indicator("Liquidity Levels [LuxAlgo]", "LuxAlgo - Liquidity Levels",overlay = true, max_bars_back = 2000, max_lines_count = 500, max_labels_count = 500)
//-----------------------------------------------------------------------------}
//Settings
//-----------------------------------------------------------------------------{
length = input.int(20, minval = 1)
show = input.int(5,'Number Of Levels', minval = 1)
lineCol = input.string('Fixed','Levels Color Mode', options = ['Relative','Random','Fixed'])
lvlStyle = input.string('──','Levels Style', options = ['──','- - -','· · ·'])
//Levels color
relativeColUp = input(#2157f3,'', inline = 'lvlcol')
relativeColDn = input(#ff5d00,'', inline = 'lvlcol')
fixed_col = input(#2157f3,'Fixed Color', inline = 'lvlcol')
//Style
show_hist = input(true, 'Show Histogram', group = 'Histogram')
distwin = input.int(200, 'Histogram Window', maxval = 500, group = 'Histogram')
upCol = input(color.new(#2157f3,50), 'Bins Colors', group = 'Histogram', inline = 'col')
dnCol = input(color.new(#ff5d00,50), '', group = 'Histogram', inline = 'col')
//-----------------------------------------------------------------------------}
//Type
//-----------------------------------------------------------------------------{
type histbar
box bull
box bear
//-----------------------------------------------------------------------------}
//Populate arrays
//-----------------------------------------------------------------------------{
var color css = na
var lines = array.new_line(0)
var hist_bars = array.new<histbar>(0)
if barstate.isfirst
color rand_css = na
//Populate levels
for i = 0 to show-1
//Levels color
if lineCol == 'Random'
rand_css := color.rgb(math.random(0,255), math.random(0,255), math.random(0,255))
else
rand_css := fixed_col
//Line style
style = switch lvlStyle
'- - -' => line.style_dashed
'· · ·' => line.style_dotted
=> line.style_solid
lines.push(line.new(na,na,na,na
, color = rand_css
, extend = extend.left
, style = style))
//Populate histogram bars
if i < show-1 and show_hist
hist_bars.push(histbar.new(box.new(na,na,na,na,na, bgcolor = upCol), box.new(na,na,na,na,na, bgcolor = dnCol)))
//-----------------------------------------------------------------------------}
//Get liquidity levels values
//-----------------------------------------------------------------------------{
var pals = array.new<float>(0)
phv = ta.pivothigh(volume,length,length)
//On volume peak
if phv
pals.unshift(close[length])
if pals.size() > show
pals.pop()
//-----------------------------------------------------------------------------}
//Display levels/histogram
//-----------------------------------------------------------------------------{
n = bar_index
if barstate.islast
//Sort liquidity levels values (required for binary search)
pals.sort()
//Set levels
for [index, element] in pals
get = lines.get(index)
get.set_xy1(n-1, element)
get.set_xy2(n, element)
if lineCol == 'Relative'
get.set_color(close > element ? relativeColUp : relativeColDn)
//Compute histogram
bull = array.new<int>(show-1, 0)
bear = array.new<int>(show-1, 0)
if show_hist
//Iterate trough calculation window
for i = 0 to distwin-1
//Look where current close lies within liquidity levels and return index
idx = pals.binary_search_rightmost(close[i])
//Test if price lies within valid liquidity levels range and update count
if idx >= 1 and idx < show
if close[i] > open[i]
get = bull.get(idx-1)
bull.set(idx-1, get + 1)
else
get = bear.get(idx-1)
bear.set(idx-1, get + 1)
//Set histogram
for [index, element] in hist_bars
element.bull.set_rightbottom(n+bull.get(index), pals.get(index+1))
element.bull.set_lefttop(n, pals.get(index))
element.bear.set_rightbottom(n+bull.get(index)+bear.get(index), pals.get(index+1))
element.bear.set_lefttop(n+bull.get(index), pals.get(index))
//-----------------------------------------------------------------------------} |
MAD as a hatter (inspired by J. Ehlers) | https://www.tradingview.com/script/WZDH2Dxt-MAD-as-a-hatter-inspired-by-J-Ehlers/ | vsov | https://www.tradingview.com/u/vsov/ | 39 | study | 4 | MPL-2.0 | // This source code is not the subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vsov
//@version=4
f_nwma(_src, _period) =>
fast = _period/2
lambda = _period/fast
alpha = lambda * (_period - 1)/(_period - lambda)
average1 = wma(_src,_period)
average2 = wma(average1,fast)
nwma = (1+alpha)*average1 - alpha*average2
study("MAD as a hatter (inspired by J. Ehlers)", shorttitle="MADaH")
src = input(close, title="Source")
len = input(20, title="Averaging length", minval=6, step=1)
so = input(10, title="Smooth signal, 0-off", minval=0, step=1)
fast = f_nwma(src*volume, len)/f_nwma(volume, len)
slow = vwma(src, len)
MAD_=100*(fast - slow) / slow
MAD = so==0?MAD_:f_nwma(MAD_, so)
ROC_ = (len /4*math.pi) *change(MAD)
ROC = so==0?ROC_:f_nwma(ROC_, so)
hline(0.0, color=color.red)
plot(so==0?MAD:f_nwma(MAD, so), color = MAD>0?color.lime:color.maroon, linewidth=2, style=plot.style_histogram, title="MADaH")
plot(ROC, color=color.yellow, title="ROC")
|
Mannarino Market Risk Indicator | https://www.tradingview.com/script/jOSQHVjB-Mannarino-Market-Risk-Indicator/ | kevindcarr | https://www.tradingview.com/u/kevindcarr/ | 98 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kevindcarr
//@version=5
indicator(title='Mannarino Market Risk Indicator', shorttitle='MMRI', overlay=false, scale=scale.right, format=format.price)
var table risk = table.new(position=position.top_right, columns=1, rows=1)
var table data = table.new(position=position.bottom_right, columns=3, rows=3, frame_width=4, border_width=4)
lowRisk = input(title='Low Risk', defval=100)
moderateRisk = input(title='Moderate Risk', defval=200)
highRisk = input(title='High Risk', defval=300)
maLength = input(title="SMA Length", defval=50)
hideSma = input.bool(title="Hide SMA", defval=false)
hideData = input.bool(title="Hide Data", defval=false)
highlight(mmri) =>
col = color.green
if mmri > lowRisk and mmri < moderateRisk
col := color.yellow
col
if mmri >= moderateRisk and mmri < highRisk
col := color.orange
col
if mmri >= highRisk
col := color.red
col
col
riskLevel(mmri) =>
text_1 = 'Low Risk'
if mmri > lowRisk and mmri < moderateRisk
text_1 := 'Moderate Risk'
text_1
if mmri >= moderateRisk and mmri < highRisk
text_1 := 'High Risk'
text_1
if mmri >= highRisk
text_1 := 'Extreme Risk'
text_1
text_1
dollarSymbol = input.symbol(title='Dollar Symbol', defval='dxy')
yieldSymbol = input.symbol(title='Yield Symbol', defval='tnx')
oilSymbol = input.symbol(title="Oil Symbol", defval='usoil')
mmriConstant = input(title='Divisor', defval=1.61)
dxy = request.security(symbol=dollarSymbol, timeframe='D', expression=close)
yield = request.security(symbol=yieldSymbol, timeframe='D',expression=close)
mmri = dxy * yield / mmriConstant
oil = request.security(symbol=oilSymbol, timeframe='D', expression=close)
table.set_bgcolor(risk, color.new(highlight(mmri), 25))
table.cell(risk, 0, 0, str.tostring(riskLevel(mmri)))
plot(series=mmri, title="MMRI", trackprice=false, color=highlight(mmri))
plot(series=hideSma ? na : ta.sma(mmri, maLength), title="SMA", color=color.new(color.blue, 50))
highlight2(security) =>
col = color.gray
if ta.roc(security, 1) > 0
col := color.green
col
if ta.roc(security, 1) < 0
col := color.red
col
col
if not hideData
table.cell(data, 0, 0, str.tostring("10 Yr"), text_color=color.gray)
table.cell(data, 1, 0, str.format("{0,number,#.##}", yield), text_color=color.gray)
table.cell(data, 2, 0, str.format("{0,number,#.##} {1}", ta.roc(yield, 1), "%"), text_color=color.new(highlight2(yield), 25))
table.cell(data, 0, 1, str.tostring("Dollar"), text_color=color.gray)
table.cell(data, 1, 1, str.format("{0,number,#.##}", dxy), text_color=color.gray)
table.cell(data, 2, 1, str.format("{0,number,#.##} {1}", ta.roc(dxy, 1), "%"), text_color=color.new(highlight2(dxy), 25))
table.cell(data, 0, 2, str.tostring("Oil"), text_color=color.gray)
table.cell(data, 1, 2, str.format("{0,number,#.##}", oil), text_color=color.gray)
table.cell(data, 2, 2, str.format("{0,number,#.##} {1}", ta.roc(oil, 1), "%"), text_color=color.new(highlight2(oil), 25))
|
My:MANNARINO MARKET RISK INDICATOR | https://www.tradingview.com/script/sQ3QS9J5/ | Thlem | https://www.tradingview.com/u/Thlem/ | 48 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Thlem
//@version=4
study("My:MANNARINO MARKET RISK INDICATOR", "MMRI")
mode = input("Line Chart", title="Configuration mode :", options=['Line Chart', 'Table'])
isSimplified = mode == "Table"
showHist = input(false, title="Show Historic crashes")
showScale = input(false, title="Show Scale")
us10y = security("TVC:US10Y", '1D', close)
dxy = security("TVC:DXY", '1D', close)
risk = us10y * dxy / 1.61
riskLabel = if (risk <= 100)
" (Low Risk)"
else if (risk <= 200 )
" (Medium Risk)"
else if (risk <= 300 )
" (High Risk)"
else
" (Extreme Risk)"
riskColor = if (risk <= 100)
color.lime
else if (risk <= 200 )
color.yellow
else if (risk <= 300 )
color.orange
else
color.red
var table panel = table.new("bottom_right", 10, 20, border_width = 1)
if (isSimplified)
table.cell(panel, 1, 0, "Risk", bgcolor = color.green, text_size=size.auto)
table.cell(panel, 1, 1, tostring(risk, '#.#') + tostring(riskLabel), bgcolor = riskColor, text_size=size.auto)
histIndex = showHist == true and showScale == false ? 2 : 3
if (showHist)
//1987 stock market crash, this number was 488, and at the 08’ meltdown it was nearly 200. The Dot-Com bubble/crash this number was 360 As a general rule
table.cell(panel, histIndex, 0, "(488) - 1987 stock market crash", bgcolor = color.silver, text_size=size.small)
table.cell(panel, histIndex, 1, "(200) - 2008 stock market crash", bgcolor = color.silver, text_size=size.small)
table.cell(panel, histIndex, 2, "(360) - Dot-Com bubble", bgcolor = color.silver, text_size=size.small)
if (showScale)
table.cell(panel, 2, 0, "0-100 : Low Risk", bgcolor = color.lime, text_size=size.small)
table.cell(panel, 2, 1, "100-200 : Medium Risk", bgcolor = color.yellow, text_size=size.small)
table.cell(panel, 2, 2, "200-300 : High Risk", bgcolor = color.orange, text_size=size.small)
table.cell(panel, 2, 3, "> 300 : Extreme Risk", bgcolor = color.red, text_size=size.small)
plot(isSimplified ? na : risk, "Risk", style=plot.style_line, color=riskColor)
getPositive(value) => value > 0 ? '+' : ''
us10y_yesterday = security("TVC:US10Y", '1D', close[1])
dxy_yesterday = security("TVC:DXY", '1D', close[1])
risk_yesterday = us10y * dxy / 1.61
riskDailyChange = (risk - risk_yesterday) / risk_yesterday * 100
us10y_7D = security("TVC:US10Y", '1D', close[7])
dxy_7D = security("TVC:DXY", '1D', close[7])
risk_7D = us10y_7D * dxy_7D / 1.61
risk7DailyChange = (risk - risk_7D) / risk_7D * 100
us10y_30D = security("TVC:US10Y", '1D', close[30])
dxy_30D = security("TVC:DXY", '1D', close[30])
risk_30D = us10y_30D * dxy_30D / 1.61
risk30DailyChange = (risk - risk_30D) / risk_30D * 100
if (isSimplified == false)
riskLabelText = tostring(risk, '#.#') + tostring(riskLabel)
riskLabelText := riskLabelText + ' \n'
riskLabelText := riskLabelText + '1 Day : ' + tostring(getPositive(riskDailyChange)) + tostring(riskDailyChange, '#.#') + '%\n'
riskLabelText := riskLabelText + '7 Days : ' + tostring(getPositive(risk7DailyChange)) + tostring(risk7DailyChange, '#.#') + '%\n'
riskLabelText := riskLabelText + '30 Days : ' + tostring(getPositive(risk30DailyChange)) + tostring(risk30DailyChange, '#.#') + '%'
label_xloc = time_close + (( time_close - time_close[1] ) * 6 )
riskLabelTooltip = label.new(label_xloc, risk, riskLabelText , xloc.bar_time, yloc.price, color=color.teal, style=label.style_label_left, textcolor=color.white, size=size.normal )
label.delete( riskLabelTooltip[1] ) |
Bank Nifty strike price 2/3σ | https://www.tradingview.com/script/uS5F7XpT-Bank-Nifty-strike-price-2-3%CF%83/ | RajeevNaik | https://www.tradingview.com/u/RajeevNaik/ | 204 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RajeevNaik
//@version=4
study("Bank Nifty strike price 2/3σ ",overlay=true)
src = input(close, title="source")
step = input(title="strike steps", type=input.integer, defval=100)
// nearest full 100s value.
RoundTohund(value) =>
round(value / 100.0) * 100
x = RoundTohund(src)
one_day = 24 * 60 * 60 * 1000
lineColor = input(title="Strike line Colour", type=input.color, defval=color.new(color.blue, 0))
single(tkr, dte, strike) =>
if syminfo.ticker == tkr
line.new(time, strike, time + dte * one_day, strike,style=line.style_dotted, color = lineColor, xloc = xloc.bar_time)
strangle(tkr, dte, put, call) =>
single(tkr, dte, put)
single(tkr, dte, call)
if barstate.islast
exp = 1
// Bank nifty strikes
single("BANKNIFTY", exp, x+step*25)
single("BANKNIFTY", exp, x+step*24)
single("BANKNIFTY", exp, x+step*23)
single("BANKNIFTY", exp, x+step*22)
single("BANKNIFTY", exp, x+step*21)
single("BANKNIFTY", exp, x+step*20)
single("BANKNIFTY", exp, x+step*19)
single("BANKNIFTY", exp, x+step*18)
single("BANKNIFTY", exp, x+step*17)
single("BANKNIFTY", exp, x+step*16)
single("BANKNIFTY", exp, x+step*15)
single("BANKNIFTY", exp, x+step*14)
single("BANKNIFTY", exp, x+step*13)
single("BANKNIFTY", exp, x+step*12)
single("BANKNIFTY", exp, x+step*11)
single("BANKNIFTY", exp, x+step*10)
single("BANKNIFTY", exp, x+step*9)
single("BANKNIFTY", exp, x+step*8)
single("BANKNIFTY", exp, x+step*7)
single("BANKNIFTY", exp, x+step*6)
single("BANKNIFTY", exp, x+step*5)
single("BANKNIFTY", exp, x+step*4)
single("BANKNIFTY", exp, x+step*3)
single("BANKNIFTY", exp, x+step*2)
single("BANKNIFTY", exp, x+step*1)
single("BANKNIFTY", exp, x)
single("BANKNIFTY", exp, x-step*1)
single("BANKNIFTY", exp, x-step*2)
single("BANKNIFTY", exp, x-step*3)
single("BANKNIFTY", exp, x-step*4)
single("BANKNIFTY", exp, x-step*5)
single("BANKNIFTY", exp, x-step*6)
single("BANKNIFTY", exp, x-step*7)
single("BANKNIFTY", exp, x-step*8)
single("BANKNIFTY", exp, x-step*9)
single("BANKNIFTY", exp, x-step*10)
single("BANKNIFTY", exp, x-step*11)
single("BANKNIFTY", exp, x-step*12)
single("BANKNIFTY", exp, x-step*13)
single("BANKNIFTY", exp, x-step*14)
single("BANKNIFTY", exp, x-step*15)
single("BANKNIFTY", exp, x-step*16)
single("BANKNIFTY", exp, x-step*17)
single("BANKNIFTY", exp, x-step*18)
single("BANKNIFTY", exp, x-step*19)
single("BANKNIFTY", exp, x-step*20)
single("BANKNIFTY", exp, x-step*21)
single("BANKNIFTY", exp, x-step*22)
single("BANKNIFTY", exp, x-step*23)
single("BANKNIFTY", exp, x-step*24)
single("BANKNIFTY", exp, x-step*25)
//BB for 2 sigma limits
length1 = input(20, minval=1,title="BB2 length")
src2 = input(close, title="BB2 Source")
mult1 = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis1 = sma(src2, length1)
dev1 = mult1 * stdev(src2, length1)
upper1 = basis1 + dev1
lower1 = basis1 - dev1
offset1 = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
//p3 = plot(upper1, "Upper", color=color.orange, offset = offset)
//p4 = plot(lower1, "Lower", color=color.orange, offset = offset)
//2sigma bands
lineColor2 = input(title="2 sigma line Colour", type=input.color, defval=color.new(color.white, 0))
single2(tkr, dte, strike) =>
if syminfo.ticker == tkr
line.new(time, strike, time + dte * one_day, strike, style=line.style_solid, color = lineColor2, xloc = xloc.bar_time, width=1)
strangle2(tkr, dte, put, call) =>
single2(tkr, dte, put)
single2(tkr, dte, call)
if barstate.islast
exp = 1
// 2Sigma limits
strangle2("BANKNIFTY", exp, lower1, upper1)
//BB for 3 sigma limits
length = input(20, minval=1,title="BB3 length")
src1 = input(close, title="BB3 Source")
mult = input(3.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(src1, length)
dev = mult * stdev(src1, length)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
//p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
//p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
//3sigma bands
lineColor1 = input(title="3 sigma line Colour", type=input.color, defval=color.new(color.red, 0))
single1(tkr, dte, strike) =>
if syminfo.ticker == tkr
line.new(time, strike, time + dte * one_day, strike, style=line.style_solid, color = lineColor1, xloc = xloc.bar_time, width=1)
strangle1(tkr, dte, put, call) =>
single1(tkr, dte, put)
single1(tkr, dte, call)
if barstate.islast
exp = 1
// 3Sigma limits
strangle1("BANKNIFTY", exp, lower, upper)
|
Pulu's 3 Moving Averages | https://www.tradingview.com/script/nQUWquvt-Pulu-s-3-Moving-Averages/ | Pulu_ | https://www.tradingview.com/u/Pulu_/ | 29 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pulu_
//@version=5
// Pulu's 3 Moving Averages
// Release version 1.385, date 2021-11-26
indicator(title='Pulu\'s 3 Moving Averages', shorttitle='3MA', overlay=true)
strRoundValue(num) =>
strv = ''
if num >= 100000
strv := str.tostring(num/1000, '#K')
else if (num < 100000) and (num >= 100)
strv := str.tostring(num, '#')
else if (num < 100) and (num >= 1)
strv := str.tostring(num, '#.##')
else if (num < 1) and (num >= 0.01)
strv := str.tostring(num, '#.####')
else if (num < 0.01) and (num >= 0.0001)
strv := str.tostring(num, '#.######')
else if (num < 0.0001) and (num >= 0.000001)
strv := str.tostring(num, '#.########')
(strv)
defaultFunction(func, src, len, alma_offst, alma_sigma) =>
has_len = false
ma = ta.swma(close)
if func == 'ALMA'
ma := ta.alma(src, len, alma_offst, alma_sigma)
has_len := true
has_len
else if func == 'EMA'
ma := ta.ema(src, len)
has_len := true
has_len
else if func == 'RMA'
ma := ta.rma(src, len)
has_len := true
has_len
else if func == 'SMA'
ma := ta.sma(src, len)
has_len := true
has_len
else if func == 'SWMA'
ma := ta.swma(src)
has_len := false
has_len
else if func == 'VWAP'
ma := ta.vwap(src)
has_len := false
has_len
else if func == 'VWMA'
ma := ta.vwma(src, len)
has_len := true
has_len
else if func == 'WMA'
ma := ta.wma(src, len)
has_len := true
has_len
[ma, has_len]
def_fn = input.string(title='Default moving average', defval='SMA', options=['ALMA', 'EMA', 'RMA', 'SMA', 'SWMA', 'VWAP', 'VWMA', 'WMA'])
ma1_on = input.bool(inline='MA1', title='Enable moving average 1', defval=true)
ma2_on = input.bool(inline='MA2', title='Enable moving average 2', defval=true)
ma3_on = input.bool(inline='MA3', title='Enable moving average 3', defval=true)
ma1_fn = input.string(inline='MA1', title='', defval='default', options=['default', 'ALMA', 'EMA', 'RMA', 'SMA', 'SWMA', 'VWAP', 'VWMA', 'WMA'])
ma2_fn = input.string(inline='MA2', title='', defval='default', options=['default', 'ALMA', 'EMA', 'RMA', 'SMA', 'SWMA', 'VWAP', 'VWMA', 'WMA'])
ma3_fn = input.string(inline='MA3', title='', defval='default', options=['default', 'ALMA', 'EMA', 'RMA', 'SMA', 'SWMA', 'VWAP', 'VWMA', 'WMA'])
ma1_len = input.int(inline='MA1', title='', defval=30, minval=1)
ma2_len = input.int(inline='MA2', title='', defval=60, minval=1)
ma3_len = input.int(inline='MA3', title='', defval=120, minval=1)
ma1_clr = input.color(inline='MA1', title='', defval=color.orange)
ma2_clr = input.color(inline='MA2', title='', defval=color.blue)
ma3_clr = input.color(inline='MA3', title='', defval=color.fuchsia)
ma1_len_indx = ma1_len - 1
ma2_len_indx = ma2_len - 1
ma3_len_indx = ma3_len - 1
// Moving average 1 other parameters
alma1_offst = input.float(group='MA1 other settings', inline='MA11', title='ALMA offset', defval=0.85, minval=-1, maxval=1, step=0.01)
alma1_sigma = input.float(group='MA1 other settings', inline='MA11', title=', sigma', defval=6, minval=0, maxval=100, step=0.01)
ma1_src = input.source(group='MA1 other settings', inline='MA12', title='Source', defval=close)
ma1_plt_offst = input.int(group='MA1 other settings', inline='MA12', title=', plot offset', defval=0, minval=-500, maxval=500)
// Moving average 2 other parameters
alma2_offst = input.float(group='MA2 other settings', inline='MA21', title='ALMA Offset', defval=0.85, minval=-1, maxval=1, step=0.01)
alma2_sigma = input.float(group='MA2 other settings', inline='MA21', title='Sigma', defval=6, minval=0, maxval=100, step=0.01)
ma2_src = input.source(group='MA2 other settings', inline='MA22', title='Source', defval=close)
ma2_plt_offst = input.int(group='MA2 other settings', inline='MA22', title='Polt offset', defval=0, minval=-500, maxval=500)
//ma2_tag_on = input.bool(group='MA2 other settings', inline='MA23', title='enable MA2 label', defval=true)
// Moving average 3 other parameters
alma3_offst = input.float(group='MA3 other settings', inline='MA31', title='ALMA Offset', defval=0.85, minval=-1, maxval=1, step=0.01)
alma3_sigma = input.float(group='MA3 other settings', inline='MA31', title='Sigma', defval=6, minval=0, maxval=100, step=0.01)
ma3_src = input.source(group='MA3 other settings', inline='MA32', title='Source', defval=close)
ma3_plt_offst = input.int(group='MA3 other settings', inline='MA32', title='Plot offset', defval=0, minval=-500, maxval=500)
//ma3_tag_on = input.bool(group='MA3 other settings', inline='MA33', title='enable MA3 label', defval=true)
// Label
ma1_tag_on = input.bool(group='Label', inline='LBL1', title='MA1 label,', defval=true)
ma2_tag_on = input.bool(group='Label', inline='LBL1', title='MA2 label,', defval=true)
ma3_tag_on = input.bool(group='Label', inline='LBL1', title='MA3 label', defval=true)
tag_row_1 = input.string(group='Label', title='Row 1 text', defval='Price Bar', options=['Date', 'Peroid', 'Price Bar', 'Price MA', 'Type'])
tag_row_2 = input.string(group='Label', title='Row 2 text', defval='Price MA', options=['none', 'Date', 'Peroid', 'Price Bar', 'Price MA', 'Type'])
tag_row_3 = input.string(group='Label', title='Row 3 text', defval='Date', options=['none', 'Date', 'Peroid', 'Price Bar', 'Price MA', 'Type'])
tag_row_4 = input.string(group='Label', title='Row 4 text', defval='Peroid', options=['none', 'Date', 'Peroid', 'Price Bar', 'Price MA', 'Type'])
tag_row_5 = input.string(group='Label', title='Row 5 text', defval='Type', options=['none', 'Date', 'Peroid', 'Price Bar', 'Price MA', 'Type'])
// Initial moving averages
[ma1, ma1_has_len] = defaultFunction(def_fn, ma1_src, ma1_len, alma1_offst, alma1_sigma)
[ma2, ma2_has_len] = defaultFunction(def_fn, ma2_src, ma2_len, alma2_offst, alma2_sigma)
[ma3, ma3_has_len] = defaultFunction(def_fn, ma3_src, ma3_len, alma3_offst, alma3_sigma)
if ma1_fn != 'default' // if MA1 does not use default function
if ma1_fn == 'ALMA'
ma1 := ta.alma(ma1_src, ma1_len, alma1_offst, alma1_sigma)
ma1_has_len := true
else if ma1_fn == 'EMA'
ma1 := ta.ema(ma1_src, ma1_len)
ma1_has_len := true
else if ma1_fn == 'RMA'
ma1 := ta.rma(ma1_src, ma1_len)
ma1_has_len := true
else if ma1_fn == 'SMA'
ma1 := ta.sma(ma1_src, ma1_len)
ma1_has_len := true
else if ma1_fn == 'SWMA'
ma1 := ta.swma(ma1_src)
ma1_has_len := false
else if ma1_fn == 'VWAP'
ma1 := ta.vwap(ma1_src)
ma1_has_len := false
else if ma1_fn == 'VWMA'
ma1 := ta.vwma(ma1_src, ma1_len)
ma1_has_len := true
else if ma1_fn == 'WMA'
ma1 := ta.wma(ma1_src, ma1_len)
ma1_has_len := true
if ma2_fn != 'default' // if MA2 does not use default function
if ma2_fn == 'ALMA'
ma2 := ta.alma(ma2_src, ma2_len, alma2_offst, alma2_sigma)
ma2_has_len := true
else if ma2_fn == 'EMA'
ma2 := ta.ema(ma2_src, ma2_len)
ma2_has_len := true
else if ma2_fn == 'RMA'
ma2 := ta.rma(ma2_src, ma2_len)
ma2_has_len := true
else if ma2_fn == 'SMA'
ma2 := ta.sma(ma2_src, ma2_len)
ma2_has_len := true
else if ma2_fn == 'SWMA'
ma2 := ta.swma(ma2_src)
ma2_has_len := false
else if ma2_fn == 'VWAP'
ma2 := ta.vwap(ma2_src)
ma2_has_len := false
else if ma2_fn == 'VWMA'
ma2 := ta.vwma(ma2_src, ma1_len)
ma2_has_len := true
else if ma2_fn == 'WMA'
ma2 := ta.wma(ma2_src, ma2_len)
ma2_has_len := true
if ma3_fn != 'default' // if MA3 does not use default function
if ma3_fn == 'ALMA'
ma3 := ta.alma(ma3_src, ma3_len, alma3_offst, alma3_sigma)
ma3_has_len := true
else if ma3_fn == 'EMA'
ma3 := ta.ema(ma3_src, ma3_len)
ma3_has_len := true
else if ma3_fn == 'RMA'
ma3 := ta.rma(ma3_src, ma3_len)
ma3_has_len := true
else if ma3_fn == 'SMA'
ma3 := ta.sma(ma3_src, ma3_len)
ma3_has_len := true
else if ma3_fn == 'SWMA'
ma3 := ta.swma(ma3_src)
ma3_has_len := false
else if ma3_fn == 'VWAP'
ma3 := ta.vwap(ma3_src)
ma3_has_len := false
else if ma3_fn == 'VWMA'
ma3 := ta.vwma(ma3_src, ma3_len)
ma3_has_len := true
else if ma3_fn == 'WMA'
ma3 := ta.wma(ma3_src, ma3_len)
ma3_has_len := true
// Plot MA curves
plot(series=ma1_on ? ma1 : na, color=ma1_clr, trackprice=false, offset=ma1_plt_offst)
plot(series=ma2_on ? ma2 : na, color=ma2_clr, trackprice=false, offset=ma2_plt_offst)
plot(series=ma3_on ? ma3 : na, color=ma3_clr, trackprice=false, offset=ma3_plt_offst)
if ma1_on
ma1_price = line.new(x1=bar_index + 4, y1=ma1, x2=bar_index + 5, y2=ma1, xloc=xloc.bar_index, extend=extend.right, color=ma1_clr, style=line.style_dotted, width=1)
line.delete(ma1_price[1])
if ma2_on
ma2_price = line.new(x1=bar_index + 4, y1=ma2, x2=bar_index + 5, y2=ma2, xloc=xloc.bar_index, extend=extend.right, color=ma2_clr, style=line.style_dotted, width=1)
line.delete(ma2_price[1])
if ma3_on
ma3_price = line.new(x1=bar_index + 4, y1=ma3, x2=bar_index + 5, y2=ma3, xloc=xloc.bar_index, extend=extend.right, color=ma3_clr, style=line.style_dotted, width=1)
line.delete(ma3_price[1])
// Lables
rowText(name, head, fn, len, indx, src, ma) =>
row_text = ''
if name == 'Date'
if head
row_text += str.tostring(month(time[indx]))+'-'+str.tostring(dayofmonth(time[indx]))
else
row_text += '\n' + str.tostring(month(time[indx]))+'-'+str.tostring(dayofmonth(time[indx]))
else if name == 'Peroid'
if head
row_text += str.tostring(len)
else
row_text += '\n' + str.tostring(len)
else if name == 'Type'
if head
row_text += (fn == 'default' ? def_fn : fn)
else
row_text += '\n' + (fn == 'default' ? def_fn : fn)
else if name == 'Price Bar'
if head
row_text += strRoundValue(src[indx])
else
row_text += '\n' + strRoundValue(src[indx])
else if name == 'Price MA'
if head
row_text += strRoundValue(ma[indx])
else
row_text += '\n' + strRoundValue(ma[indx])
(row_text)
// Compose text for MA1 label
_row1 = rowText(tag_row_1, true, ma1_fn, ma1_len, ma1_len_indx, ma1_src, ma1)
_row2 = rowText(tag_row_2, false, ma1_fn, ma1_len, ma1_len_indx, ma1_src, ma1)
_row3 = rowText(tag_row_3, false, ma1_fn, ma1_len, ma1_len_indx, ma1_src, ma1)
_row4 = rowText(tag_row_4, false, ma1_fn, ma1_len, ma1_len_indx, ma1_src, ma1)
_row5 = rowText(tag_row_5, false, ma1_fn, ma1_len, ma1_len_indx, ma1_src, ma1)
ma1_tag_txt = _row1 + _row2 + _row3 + _row4 + _row5
// Compose text for MA2 label
_row1 := rowText(tag_row_1, true, ma2_fn, ma2_len, ma2_len_indx, ma2_src, ma2)
_row2 := rowText(tag_row_2, false, ma2_fn, ma2_len, ma2_len_indx, ma2_src, ma2)
_row3 := rowText(tag_row_3, false, ma2_fn, ma2_len, ma2_len_indx, ma2_src, ma2)
_row4 := rowText(tag_row_4, false, ma2_fn, ma2_len, ma2_len_indx, ma2_src, ma2)
_row5 := rowText(tag_row_5, false, ma2_fn, ma2_len, ma2_len_indx, ma2_src, ma2)
ma2_tag_txt = _row1 + _row2 + _row3 + _row4 + _row5
// Compose text for MA3 label
_row1 := rowText(tag_row_1, true, ma3_fn, ma3_len, ma3_len_indx, ma3_src, ma3)
_row2 := rowText(tag_row_2, false, ma3_fn, ma3_len, ma3_len_indx, ma3_src, ma3)
_row3 := rowText(tag_row_3, false, ma3_fn, ma3_len, ma3_len_indx, ma3_src, ma3)
_row4 := rowText(tag_row_4, false, ma3_fn, ma3_len, ma3_len_indx, ma3_src, ma3)
_row5 := rowText(tag_row_5, false, ma3_fn, ma3_len, ma3_len_indx, ma3_src, ma3)
ma3_tag_txt = _row1 + _row2 + _row3 + _row4 + _row5
// Iniatial global labels
var label ma1_tag = label.new(bar_index, na)
var label ma2_tag = label.new(bar_index, na)
var label ma3_tag = label.new(bar_index, na)
label.delete(ma1_tag)
label.delete(ma2_tag)
label.delete(ma3_tag)
// Tags on the start dates for last MA sets
if barstate.islast
if ma1_on and ma1_tag_on and ma1_has_len
ma1_tag := label.new(bar_index - ma1_len_indx, na, ma1_tag_txt, color=ma1_clr, textcolor=color.white, style=close[ma1_len_indx] > open[ma1_len_indx] ? label.style_label_down : label.style_label_up, yloc=close[ma1_len_indx] > open[ma1_len_indx] ? yloc.abovebar : yloc.belowbar)
if ma2_on and ma2_tag_on and ma2_has_len
ma2_tag := label.new(bar_index - ma2_len_indx, na, ma2_tag_txt, color=ma2_clr, textcolor=color.white, style=close[ma2_len_indx] > open[ma2_len_indx] ? label.style_label_down : label.style_label_up, yloc=close[ma2_len_indx] > open[ma2_len_indx] ? yloc.abovebar : yloc.belowbar)
if ma3_on and ma3_tag_on and ma3_has_len
ma3_tag := label.new(bar_index - ma3_len_indx, na, ma3_tag_txt, color=ma3_clr, textcolor=color.white, style=close[ma3_len_indx] > open[ma3_len_indx] ? label.style_label_down : label.style_label_up, yloc=close[ma3_len_indx] > open[ma3_len_indx] ? yloc.abovebar : yloc.belowbar)
|
Nifty strike price 2/3σ | https://www.tradingview.com/script/xr6FXsPu-Nifty-strike-price-2-3%CF%83/ | RajeevNaik | https://www.tradingview.com/u/RajeevNaik/ | 59 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RajeevNaik
//@version=4
study("Nifty strike price 2/3σ ",overlay=true)
src = input(close, title="source")
step = input(title="strike steps", type=input.integer, defval=50)
// nearest full 50s value.
RoundTofifty(value) =>
round(value / 50.0) * 50
x = RoundTofifty(src)
one_day = 24 * 60 * 60 * 1000
lineColor = input(title="Strike line Colour", type=input.color, defval=color.new(color.blue, 0))
single(tkr, dte, strike) =>
if syminfo.ticker == tkr
line.new(time, strike, time + dte * one_day, strike,style=line.style_dotted, color = lineColor, xloc = xloc.bar_time)
strangle(tkr, dte, put, call) =>
single(tkr, dte, put)
single(tkr, dte, call)
if barstate.islast
exp = 1
// Bank nifty strikes
single("NIFTY", exp, x+step*25)
single("NIFTY", exp, x+step*24)
single("NIFTY", exp, x+step*23)
single("NIFTY", exp, x+step*22)
single("NIFTY", exp, x+step*21)
single("NIFTY", exp, x+step*20)
single("NIFTY", exp, x+step*19)
single("NIFTY", exp, x+step*18)
single("NIFTY", exp, x+step*17)
single("NIFTY", exp, x+step*16)
single("NIFTY", exp, x+step*15)
single("NIFTY", exp, x+step*14)
single("NIFTY", exp, x+step*13)
single("NIFTY", exp, x+step*12)
single("NIFTY", exp, x+step*11)
single("NIFTY", exp, x+step*10)
single("NIFTY", exp, x+step*9)
single("NIFTY", exp, x+step*8)
single("NIFTY", exp, x+step*7)
single("NIFTY", exp, x+step*6)
single("NIFTY", exp, x+step*5)
single("NIFTY", exp, x+step*4)
single("NIFTY", exp, x+step*3)
single("NIFTY", exp, x+step*2)
single("NIFTY", exp, x+step*1)
single("NIFTY", exp, x)
single("NIFTY", exp, x-step*1)
single("NIFTY", exp, x-step*2)
single("NIFTY", exp, x-step*3)
single("NIFTY", exp, x-step*4)
single("NIFTY", exp, x-step*5)
single("NIFTY", exp, x-step*6)
single("NIFTY", exp, x-step*7)
single("NIFTY", exp, x-step*8)
single("NIFTY", exp, x-step*9)
single("NIFTY", exp, x-step*10)
single("NIFTY", exp, x-step*11)
single("NIFTY", exp, x-step*12)
single("NIFTY", exp, x-step*13)
single("NIFTY", exp, x-step*14)
single("NIFTY", exp, x-step*15)
single("NIFTY", exp, x-step*16)
single("NIFTY", exp, x-step*17)
single("NIFTY", exp, x-step*18)
single("NIFTY", exp, x-step*19)
single("NIFTY", exp, x-step*20)
single("NIFTY", exp, x-step*21)
single("NIFTY", exp, x-step*22)
single("NIFTY", exp, x-step*23)
single("NIFTY", exp, x-step*24)
single("NIFTY", exp, x-step*25)
//BB for 2 sigma limits
length1 = input(20, minval=1,title="BB2 length")
src2 = input(close, title="BB2 Source")
mult1 = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis1 = sma(src2, length1)
dev1 = mult1 * stdev(src2, length1)
upper1 = basis1 + dev1
lower1 = basis1 - dev1
offset1 = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
//p3 = plot(upper1, "Upper", color=color.orange, offset = offset)
//p4 = plot(lower1, "Lower", color=color.orange, offset = offset)
//2sigma bands
lineColor2 = input(title="2 sigma line Colour", type=input.color, defval=color.new(color.white, 0))
single2(tkr, dte, strike) =>
if syminfo.ticker == tkr
line.new(time, strike, time + dte * one_day, strike, style=line.style_solid, color = lineColor2, xloc = xloc.bar_time, width=1)
strangle2(tkr, dte, put, call) =>
single2(tkr, dte, put)
single2(tkr, dte, call)
if barstate.islast
exp = 1
// 2Sigma limits
strangle2("NIFTY", exp, lower1, upper1)
//BB for 3 sigma limits
length = input(20, minval=1,title="BB3 length")
src1 = input(close, title="BB3 Source")
mult = input(3.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(src1, length)
dev = mult * stdev(src1, length)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
//p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
//p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
//3sigma bands
lineColor1 = input(title="3 sigma line Colour", type=input.color, defval=color.new(color.red, 0))
single1(tkr, dte, strike) =>
if syminfo.ticker == tkr
line.new(time, strike, time + dte * one_day, strike, style=line.style_solid, color = lineColor1, xloc = xloc.bar_time, width=1)
strangle1(tkr, dte, put, call) =>
single1(tkr, dte, put)
single1(tkr, dte, call)
if barstate.islast
exp = 1
// 3Sigma limits
strangle1("NIFTY", exp, lower, upper)
|
Baekdoo arrows (white : long term CCI trend changing signal) | https://www.tradingview.com/script/Pvp2pQ0J-Baekdoo-arrows-white-long-term-CCI-trend-changing-signal/ | traderbaekdoosan | https://www.tradingview.com/u/traderbaekdoosan/ | 69 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © traderbaekdoosan
//@version=4
study("Baekdoo arrows", overlay=true)
//white arrow : CCI long period trend change
period=48
white=cci(close, period*5)
countBars = barssince(crossover(-100, white))
plotshape(crossover(white, -100) and countBars>=60, style=shape.arrowup, color=color.white, location=location.belowbar, size=size.tiny)
plotshape(crossover(white, -100) and countBars>=60, text="cci", style=shape.labelup, color=color.white, textcolor=color.black, location=location.belowbar, size=size.tiny)
//plotshape(crossover(white, -100), style=shape.arrowup, color=color.yellow, location=location.belowbar, size=size.tiny)
//plotshape(crossover(white, -100), text="cci", style=shape.labelup, color=color.yellow, textcolor=color.black, location=location.belowbar, size=size.tiny)
|
Baekdoo baseline | https://www.tradingview.com/script/GKQBoI14-Baekdoo-baseline/ | traderbaekdoosan | https://www.tradingview.com/u/traderbaekdoosan/ | 56 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © traderbaekdoosan
//@version=5
indicator(title="Baekdoo baseline", overlay=true)
HT1=ta.highest(volume, 5)
NewH1=ta.valuewhen(volume>HT1[1], (open+close+low+high+close)/5, 0)
result1=ta.ema(NewH1, 2)
result_shift=input(20, "shifting value")
HT2=ta.highest(volume, 20)
NewH2=ta.valuewhen(volume>HT2[1], (open+close+low+high+close)/5, 0)
result2=ta.ema(NewH2, 10)
HT3=ta.highest(volume, 125)
NewH3=ta.valuewhen(volume>HT3[1], (open+close+low+high+close)/5, 0)
result3=ta.ema(NewH3, 20)
HT4=ta.highest(volume, 250)
NewH4=ta.valuewhen(volume>HT4[1], (open+close+low+high+close)/5, 0)
result4=ta.ema(NewH4, 20)
HT5=ta.highest(volume, 500)
NewH5=ta.valuewhen(volume>HT5[1], (open+close+low+high+close)/5, 0)
result5=ta.ema(NewH5, 20)
plot(result1, color=color.lime, linewidth=1, offset=2)
plot(result2, color=color.orange, linewidth=2, offset=10)
plot(result3, color=color.red, linewidth=3, offset=result_shift)
plot(result4, color=color.white, linewidth=4, offset=result_shift)
plot(result5, color=color.purple, linewidth=5, offset=result_shift) |
Double Top/Bottom - Ultimate (OS) | https://www.tradingview.com/script/a0vTLaS6-Double-Top-Bottom-Ultimate-OS/ | Trendoscope | https://www.tradingview.com/u/Trendoscope/ | 2,703 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed
// __ __ __ __ __ __ __ __ __ __ __ _______ __ __ __
// / | / | / | _ / |/ | / \ / | / | / \ / | / | / \ / \ / | / |
// $$ | $$ | ______ $$ | / \ $$ |$$ |____ ______ $$ \ /$$ | __ __ _______ _$$ |_ $$ \ $$ | ______ _$$ |_ $$$$$$$ | ______ $$ \ $$ | ______ _____ ____ ______ ____$$ |
// $$ |__$$ | / \ $$ |/$ \$$ |$$ \ / \ $$$ \ /$$$ |/ | / | / |/ $$ | $$$ \$$ | / \ / $$ | $$ |__$$ | / \ $$$ \$$ | / \ / \/ \ / \ / $$ |
// $$ $$ |/$$$$$$ |$$ /$$$ $$ |$$$$$$$ |/$$$$$$ |$$$$ /$$$$ |$$ | $$ |/$$$$$$$/ $$$$$$/ $$$$ $$ |/$$$$$$ |$$$$$$/ $$ $$< /$$$$$$ |$$$$ $$ | $$$$$$ |$$$$$$ $$$$ |/$$$$$$ |/$$$$$$$ |
// $$$$$$$$ |$$ $$ |$$ $$/$$ $$ |$$ | $$ |$$ | $$ |$$ $$ $$/$$ |$$ | $$ |$$ \ $$ | __ $$ $$ $$ |$$ | $$ | $$ | __ $$$$$$$ |$$ $$ |$$ $$ $$ | / $$ |$$ | $$ | $$ |$$ $$ |$$ | $$ |
// $$ | $$ |$$$$$$$$/ $$$$/ $$$$ |$$ | $$ |$$ \__$$ |$$ |$$$/ $$ |$$ \__$$ | $$$$$$ | $$ |/ |$$ |$$$$ |$$ \__$$ | $$ |/ |$$ |__$$ |$$$$$$$$/ $$ |$$$$ |/$$$$$$$ |$$ | $$ | $$ |$$$$$$$$/ $$ \__$$ |
// $$ | $$ |$$ |$$$/ $$$ |$$ | $$ |$$ $$/ $$ | $/ $$ |$$ $$/ / $$/ $$ $$/ $$ | $$$ |$$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$$ |$$ $$ |$$ | $$ | $$ |$$ |$$ $$ |
// $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ $$$$$$$/ $$$$/ $$/ $$/ $$$$$$/ $$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$$$$/
//
//
//
//@version=4
study("Double Top/Bottom - Ultimate (OS)", shorttitle="W/M - Ultimate(OS)", overlay=true, max_lines_count=500, max_labels_count=500, max_bars_back=1000)
length = input(10, step=5, minval=5)
showZigzag = input(false)
showPivots = input(true)
showStats = input(true)
bullishColor = input(color.green)
bullTrapColor = input(color.orange)
bearishColor = input(color.red)
bearTrapColor = input(color.lime)
textColor = input(color.black)
MaxRiskPerReward = input(30, step=5, minval=5, maxval=100)
DisplayRiskPerReward = input(true)
var zigzagvalues = array.new_float(0)
var zigzagindexes = array.new_int(0)
var zigzagdir = array.new_int(0)
var doubleTopBottomValues = array.new_float(3)
var doubleTopBottomIndexes = array.new_int(3)
var doubleTopBottomDir = array.new_int(3)
int max_array_size = 10
max_bars_back(high, 1000)
max_bars_back(low, 1000)
var lineArray = array.new_line(0)
var labelArray = array.new_label(0)
pivots(length)=>
float ph = highestbars(high, length) == 0 ? high : na
float pl = lowestbars(low, length) == 0 ? low : na
dir = 0
dir := iff(ph and na(pl), 1, iff(pl and na(ph), -1, dir[1]))
[dir, ph, pl]
add_to_array(value, index, dir)=>
mult = array.size(zigzagvalues) < 2? 1 :
(dir*value > dir*array.get(zigzagvalues,1))? 2 : 1
array.unshift(zigzagindexes, index)
array.unshift(zigzagvalues, value)
array.unshift(zigzagdir, dir*mult)
if array.size(zigzagindexes) > max_array_size
array.pop(zigzagindexes)
array.pop(zigzagvalues)
array.pop(zigzagdir)
add_to_zigzag(dir, dirchanged, ph, pl, index)=>
value = (dir == 1? ph : pl)
if array.size(zigzagvalues) == 0 or dirchanged
add_to_array(value, index, dir)
else if(dir == 1 and value > array.get(zigzagvalues, 0)) or (dir == -1 and value < array.get(zigzagvalues, 0))
array.shift(zigzagvalues)
array.shift(zigzagindexes)
array.shift(zigzagdir)
add_to_array(value, index, dir)
zigzag(length)=>
[dir, ph, pl] = pivots(length)
dirchanged = change(dir)
if(ph or pl)
add_to_zigzag(dir, dirchanged, ph, pl, bar_index)
calculate_double_pattern()=>
doubleTop = false
doubleTopConfirmation = 0
doubleBottom = false
doubleBottomConfirmation = 0
if(array.size(zigzagvalues) >= 4)
index = array.get(zigzagindexes, 1)
value = array.get(zigzagvalues, 1)
highLow = array.get(zigzagdir, 1)
lindex = array.get(zigzagindexes, 2)
lvalue = array.get(zigzagvalues, 2)
lhighLow = array.get(zigzagdir, 2)
llindex = array.get(zigzagindexes, 3)
llvalue = array.get(zigzagvalues, 3)
llhighLow = array.get(zigzagdir, 3)
risk = abs(value-llvalue)
reward = abs(value-lvalue)
riskPerReward = risk*100/(risk+reward)
if(highLow == 1 and llhighLow == 2 and lhighLow < 0 and riskPerReward < MaxRiskPerReward)
doubleTop := true
if(highLow == -1 and llhighLow == -2 and lhighLow > 0 and riskPerReward < MaxRiskPerReward)
doubleBottom := true
if(doubleTop or doubleBottom)
array.set(doubleTopBottomValues, 0, value)
array.set(doubleTopBottomValues, 1, lvalue)
array.set(doubleTopBottomValues, 2, llvalue)
array.set(doubleTopBottomIndexes, 0, index)
array.set(doubleTopBottomIndexes, 1, lindex)
array.set(doubleTopBottomIndexes, 2, llindex)
array.set(doubleTopBottomDir, 0, highLow)
array.set(doubleTopBottomDir, 1, lhighLow)
array.set(doubleTopBottomDir, 2, llhighLow)
[doubleTop, doubleBottom]
get_crossover_info(doubleTop, doubleBottom)=>
index = array.get(doubleTopBottomIndexes, 0)
value = array.get(doubleTopBottomValues, 0)
highLow = array.get(doubleTopBottomDir, 0)
lindex = array.get(doubleTopBottomIndexes, 1)
lvalue = array.get(doubleTopBottomValues, 1)
lhighLow = array.get(doubleTopBottomDir, 1)
llindex = array.get(doubleTopBottomIndexes, 2)
llvalue = array.get(doubleTopBottomValues, 2)
llhighLow = array.get(doubleTopBottomDir, 2)
latestDoubleTop = false
latestDoubleBottom = false
latestDoubleTop := doubleTop ? true : doubleBottom? false : latestDoubleTop[1]
latestDoubleBottom := doubleBottom? true : doubleTop? false : latestDoubleBottom[1]
doubleTopConfirmation = 0
doubleBottomConfirmation = 0
doubleTopConfirmation := latestDoubleTop? (crossunder(low, lvalue) ? 1 : crossover(high, llvalue) ? -1 : 0) : 0
doubleBottomConfirmation := latestDoubleBottom? (crossover(high, lvalue) ? 1 : crossunder(low, llvalue) ? -1 : 0) : 0
[doubleTopConfirmation, doubleBottomConfirmation]
draw_double_pattern(doubleTop,doubleBottom,doubleTopConfirmation,doubleBottomConfirmation)=>
index = array.get(doubleTopBottomIndexes, 0)
value = array.get(doubleTopBottomValues, 0)
highLow = array.get(doubleTopBottomDir, 0)
lindex = array.get(doubleTopBottomIndexes, 1)
lvalue = array.get(doubleTopBottomValues, 1)
lhighLow = array.get(doubleTopBottomDir, 1)
llindex = array.get(doubleTopBottomIndexes, 2)
llvalue = array.get(doubleTopBottomValues, 2)
llhighLow = array.get(doubleTopBottomDir, 2)
isBullish = true
isBullish := (doubleTop or doubleBottom)? doubleTop : isBullish[1]
risk = abs(value-llvalue)
reward = abs(value-lvalue)
riskPerReward = risk*100/(risk+reward)
base = line.new(x1=index, y1=value,
x2 = llindex, y2=llvalue,
color=doubleTop? bearishColor : bullishColor, width=2, style=line.style_solid)
l1 = line.new(x1=index, y1=value,
x2 = lindex, y2=lvalue,
color=doubleTop? bearishColor : bullishColor, width=2, style=line.style_dotted)
l2 = line.new(x1=lindex, y1=lvalue,
x2 = llindex, y2=llvalue,
color=doubleTop? bearishColor : bullishColor, width=2, style=line.style_dotted)
labelText = (doubleTop? "Double Top" : "Double Bottom") + (DisplayRiskPerReward ? " RR - "+tostring(riskPerReward) : "")
baseLabel = label.new(x=index, y=value, text=labelText, yloc=doubleTop?yloc.abovebar:yloc.belowbar,
color=doubleTop?bearishColor:bullishColor,
style=doubleTop?label.style_label_down:label.style_label_up,
textcolor=textColor, size=size.normal)
if not (doubleTop or doubleBottom)
line.delete(base)
line.delete(l1)
line.delete(l2)
label.delete(baseLabel)
var doubleTopCount = 0
var doubleBottomCount = 0
doubleTopCount := doubleTop? nz(doubleTopCount[1],0) + 1 : nz(doubleTopCount[1],0)
doubleBottomCount := doubleBottom? nz(doubleBottomCount[1],0) + 1 : nz(doubleBottomCount[1],0)
if(line.get_x2(base) == line.get_x2(base[1]))
line.delete(base[1])
line.delete(l1[1])
line.delete(l2[1])
label.delete(baseLabel[1])
doubleTopCount := doubleTop? doubleTopCount -1 : doubleTopCount
doubleBottomCount := doubleBottom? doubleBottomCount -1 : doubleBottomCount
if(barstate.islast)
lres = line.new(x1=bar_index, y1=lvalue,
x2 = lindex, y2=lvalue,
color=isBullish? bearishColor : bullishColor, width=2, style=line.style_dashed, extend=extend.left)
lsup = line.new(x1=bar_index, y1=llvalue,
x2 = llindex, y2=llvalue,
color=isBullish? bullishColor : bearishColor , width=2, style=line.style_dashed, extend=extend.left)
doubleTopConfirmationCount = doubleTopConfirmation>0? 1 : 0
doubleBottomConfirmationCount = doubleBottomConfirmation>0? 1:0
doubleTopInvalidationCount = doubleTopConfirmation<0? 1 : 0
doubleBottomInvalidationCount = doubleBottomConfirmation<0? 1:0
if(doubleTopConfirmation != 0 or doubleBottomConfirmation !=0)
if(doubleTopConfirmation>0 or doubleBottomConfirmation > 0)
lresbreak = line.new(x1=lindex, y1=lvalue,
x2 = bar_index, y2=lvalue,
color=isBullish? bearishColor : bullishColor, width=2, style=line.style_dashed)
if(line.get_x1(lresbreak[1]) == line.get_x1(lresbreak))
doubleTopConfirmationCount := 0
doubleBottomConfirmationCount := 0
doubleTopInvalidationCount := 0
doubleBottomInvalidationCount := 0
line.delete(lresbreak)
lresbreak := lresbreak[1]
else if(doubleTopConfirmation<0 or doubleBottomConfirmation < 0)
lsupbreak = line.new(x1=llindex, y1=llvalue,
x2 = bar_index, y2=llvalue,
color=isBullish? bullishColor : bearishColor , width=2, style=line.style_dashed)
if(line.get_x1(lsupbreak[1]) == line.get_x1(lsupbreak))
doubleTopInvalidationCount := 0
doubleBottomInvalidationCount := 0
doubleTopConfirmationCount := 0
doubleBottomConfirmationCount := 0
line.delete(lsupbreak)
lsupbreak := lsupbreak[1]
doubleTopConfirmationCount := nz(doubleTopConfirmationCount[1],0)+doubleTopConfirmationCount
doubleBottomConfirmationCount := nz(doubleBottomConfirmationCount[1],0)+doubleBottomConfirmationCount
doubleTopInvalidationCount := nz(doubleTopInvalidationCount[1],0)+doubleTopInvalidationCount
doubleBottomInvalidationCount := nz(doubleBottomInvalidationCount[1],0)+doubleBottomInvalidationCount
[doubleTopCount, doubleBottomCount, doubleTopConfirmationCount, doubleBottomConfirmationCount, doubleTopInvalidationCount, doubleBottomInvalidationCount]
zigzag(length)
[doubleTop, doubleBottom] = calculate_double_pattern()
[doubleTopConfirmation, doubleBottomConfirmation] = get_crossover_info(doubleTop, doubleBottom)
[doubleTopCount, doubleBottomCount,
doubleTopConfirmationCount, doubleBottomConfirmationCount,
doubleTopInvalidationCount, doubleBottomInvalidationCount] = draw_double_pattern(doubleTop,doubleBottom,doubleTopConfirmation,doubleBottomConfirmation)
var stats = table.new(position = position.top_right, columns = 5, rows = 5, border_width = 1)
if(barstate.islast and showStats)
colorWorst = color.rgb(255, 153, 51)
colorBest = color.rgb(51, 204, 51)
colorBad = color.rgb(255, 204, 153)
colorGood = color.rgb(204, 255, 204)
colorNeutral = color.rgb(255, 255, 204)
dtConfirmationPercent = doubleTopConfirmationCount+doubleTopInvalidationCount == 0? 0.5 : doubleTopConfirmationCount/(doubleTopConfirmationCount+doubleTopInvalidationCount)
dbConfirmationPercent = (doubleBottomConfirmationCount+doubleBottomInvalidationCount) == 0? 0.5 : doubleBottomConfirmationCount/(doubleBottomConfirmationCount+doubleBottomInvalidationCount)
dtColor = dtConfirmationPercent >= 0.8? colorBest :
dtConfirmationPercent >= 0.6? colorGood :
dtConfirmationPercent >= 0.4? colorNeutral :
dtConfirmationPercent >= 0.2? colorBad : colorWorst
dbColor = dbConfirmationPercent >= 0.8? colorBest :
dbConfirmationPercent >= 0.6? colorGood :
dbConfirmationPercent >= 0.4? colorNeutral :
dbConfirmationPercent >= 0.2? colorBad : colorWorst
table.cell(table_id = stats, column = 0, row = 0 , text = "", bgcolor=color.black, text_color=color.white)
table.cell(table_id = stats, column = 0, row = 1 , text = "Double Top", bgcolor=color.black, text_color=color.white)
table.cell(table_id = stats, column = 0, row = 2 , text = "Double Bottom", bgcolor=color.black, text_color=color.white)
table.cell(table_id = stats, column = 1, row = 0 , text = "Count", bgcolor=color.black, text_color=color.white)
table.cell(table_id = stats, column = 2, row = 0 , text = "Confirmation", bgcolor=color.black, text_color=color.white)
table.cell(table_id = stats, column = 3, row = 0 , text = "Invalidation", bgcolor=color.black, text_color=color.white)
table.cell(table_id = stats, column = 1, row = 1, text = tostring(doubleTopCount), bgcolor=dtColor)
table.cell(table_id = stats, column = 1, row = 2, text = tostring(doubleBottomCount), bgcolor=dbColor)
table.cell(table_id = stats, column = 2, row = 1, text = tostring(doubleTopConfirmationCount), bgcolor=dtColor)
table.cell(table_id = stats, column = 3, row = 1, text = tostring(doubleTopInvalidationCount), bgcolor=dtColor)
table.cell(table_id = stats, column = 2, row = 2, text = tostring(doubleBottomConfirmationCount), bgcolor=dbColor)
table.cell(table_id = stats, column = 3, row = 2, text = tostring(doubleBottomInvalidationCount), bgcolor=dbColor)
if(barstate.islast and array.size(zigzagindexes) > 1)
lastHigh = 0.0
lastLow = 0.0
for x = 0 to array.size(zigzagindexes)-1
i = array.size(zigzagindexes)-1-x
index = array.get(zigzagindexes, i)
value = array.get(zigzagvalues, i)
highLow = array.get(zigzagdir, i)
index_offset = bar_index-index
labelText = highLow ==2 ? "HH" : highLow == 1? "LH" : highLow == -1? "HL" : "LL"
labelColor = highLow ==2 ? bullishColor : highLow == 1? bullTrapColor : highLow == -1? bearTrapColor : bearishColor
labelStyle = highLow > 0? label.style_label_down : label.style_label_up
// labelLocation = highLow > 0? yloc.abovebar : yloc.belowbar
labelLocation = yloc.price
if(showPivots)
l = label.new(x=index, y = value, text=labelText, xloc=xloc.bar_index, yloc=labelLocation, style=labelStyle, size=size.tiny,
color=labelColor, textcolor=textColor)
array.unshift(labelArray, l)
if(array.size(labelArray) > 100)
label.delete(array.pop(labelArray))
if(i < array.size(zigzagindexes)-1 and showZigzag)
indexLast = array.get(zigzagindexes, i+1)
valueLast = array.get(zigzagvalues, i+1)
l = line.new(x1=index, y1=value,
x2 = indexLast, y2=valueLast,
color=labelColor, width=2, style=line.style_solid)
array.unshift(lineArray, l)
if(array.size(lineArray) > 100)
line.delete(array.pop(lineArray))
alertcondition(doubleBottom, "Double Bottom", "Probable double bottom observed for {{ticker}} on {{interval}} timeframe")
alertcondition(doubleBottomConfirmation > 0, "Double Bottom Confirmation", "Double bottom confirmation observed for {{ticker}} on {{interval}} timeframe")
alertcondition(doubleBottomConfirmation < 0, "Double Bottom Invalidation", "Double bottom invalidation observed for {{ticker}} on {{interval}} timeframe")
alertcondition(doubleTop, "Double Top", "Probable double top observed for {{ticker}} on {{interval}} timeframe")
alertcondition(doubleTopConfirmation > 0, "Double Top Confirmation", "Double top confirmation observed for {{ticker}} on {{interval}} timeframe")
alertcondition(doubleTopConfirmation < 0, "Double Top Invalidation", "Double top invalidation observed for {{ticker}} on {{interval}} timeframe") |
Baekdoo ANGN | https://www.tradingview.com/script/UgmSp4PV-Baekdoo-ANGN/ | traderbaekdoosan | https://www.tradingview.com/u/traderbaekdoosan/ | 79 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © traderbaekdoosan
//@version=4
//ANGN
study(title="Baekdoo ANGN", overlay=true, scale=scale.left)
OLratio=abs((open-low)/(high-low))
HCratio=abs((high-close)/(high-low))
LCratio=abs((close-low)/(high-low))
HOratio=abs((high-open)/(high-low))
PV_ANGN=if close>open
volume*(-HCratio) + volume - volume*OLratio
else
volume*LCratio + volume - volume*HOratio
NV_ANGN=if close<open
volume*LCratio - volume + volume*HOratio
else
volume*(-HCratio) - volume + volume*OLratio
ANGN_volume=if close>=close[1]
PV_ANGN
else
NV_ANGN
Cumulative_volume=sum(ANGN_volume/10, 500)
plot(Cumulative_volume, color=color.white)
//market cap
Outstanding = financial(syminfo.tickerid, "TOTAL_SHARES_OUTSTANDING", "FQ")
MarketCap = Outstanding*close
//positive volume
//chunk=1500000000
VolumeRatio=input(1)
chunk=MarketCap/100*VolumeRatio
pAA=close>close[1]
pBB=ohlc4*volume>chunk
pv=0.0
if pAA and pBB
pv:=volume
else
pv:=0
//negative volume
nAA=close<close[1]
nBB=ohlc4*volume>chunk
nv=0.0
if nAA and nBB
nv:=volume
else
nv:=0
plot(pv, color=color.red, style=plot.style_columns)
plot(nv, color=color.blue, style=plot.style_columns) |
Pivot Tracker | https://www.tradingview.com/script/ckHZ7cEg-Pivot-Tracker/ | imbes2 | https://www.tradingview.com/u/imbes2/ | 108 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © imbes2
//@version=4
study("Pivot Tracker", overlay = true)
//lookback period
lb = input(type = input.integer, defval = 30, minval = 3, title = "Number of Pivots")
pivotlb = input(type = input.integer, defval = 6, minval = 1, title = "Pivot Lookback")
pivotlf = input(type = input.integer, defval = 4, minval = 1, title = "Pivot Lookahead")
upperoffset = input(type = input.float, defval = .005, minval = .001, maxval = .100, title = 'Upper Text Offset', tooltip = 'This is placed based on percent above the high price of pivot.')
loweroffset = input(type = input.float, defval = .005, minval = .001, maxval = .100, title = 'Lower Text Offset', tooltip = 'This is placed based on percent below the low price of the pivot.')
showprice = input(type=input.bool, defval = false, title = "Show Price At Pivot?")
//constants
hh = "HH"
lh = "LH"
hl = "HL"
ll = "LL"
//colors
chh = input(type= input.color, defval = color.new(color.green, 35), title= "Higher High", type = input.color)
chl = input(type= input.color, defval = color.new(#3179f5, 35), title = "Higher Low", type = input.color)
clh = input(type= input.color, defval = color.new(color.orange, 35), title = "Lower High", type = input.color)
cll = input(type= input.color, defval = color.new(color.red, 35), title = "Lower Lower", type = input.color)
//define new arrays
var ph_arr = array.new_float(0)
var pl_arr = array.new_float(0)
var ph_index = array.new_float(0)
var pl_index = array.new_float(0)
// pivothi and lo
pihi = pivothigh(high, pivotlb, pivotlf)
pilo = pivotlow(low, pivotlb, pivotlf)
//shift the array to the right and add the new pivot to the index 0
if (not na(pihi))
array.unshift(ph_arr, pihi)
array.unshift(ph_index, bar_index)
if (not na(pilo))
array.unshift(pl_arr, pilo)
array.unshift(pl_index, bar_index)
if array.size(ph_arr)>=lb
ph_slice = array.slice(ph_arr, 0, lb)
ph_bar_slice = array.slice(ph_index, 0, lb)
for i=0 to (lb-2) by 1
if array.get(ph_slice, i) > array.get(ph_slice, i+1)
xbar = int((array.get(ph_bar_slice, i)-(pivotlf)))
hhigh = (array.get(ph_slice, i))
ybar = (1+upperoffset)*hhigh
x = label.new(x = xbar, y = ybar, xloc= xloc.bar_index, yloc= yloc.price, text = showprice == false ? hh : 'HH\n' + tostring(hhigh), textcolor = chh, size = size.small, style= label.style_none)
else if array.get(ph_arr, i) < array.get(ph_arr, i+1)
xbar = int((array.get(ph_index, i)-(pivotlf)))
lhigh = (array.get(ph_arr, i))
ybar = (1+upperoffset)*lhigh
x = label.new(x = xbar, y = ybar, xloc= xloc.bar_index, yloc= yloc.price, text = showprice == false ? lh : 'LH\n' + tostring(lhigh), textcolor = clh, size = size.small, style= label.style_none)
if array.size(pl_arr)>=lb
pl_slice = array.slice(pl_arr, 0, lb)
pl_bar_slice = array.slice(pl_index, 0, lb)
for i=0 to (lb-2) by 1
if array.get(pl_slice, i) > array.get(pl_slice, i+1)
xbar = int((array.get(pl_bar_slice, i)-(pivotlf)))
hlow = (array.get(pl_slice, i))
ybar = (1-loweroffset)*hlow
x = label.new(x = xbar, y = ybar, xloc= xloc.bar_index, yloc= yloc.price, text = showprice == false ? hl : "HL\n" + tostring(hlow), textcolor = chl, size = size.small, style= label.style_none)
else if array.get(pl_slice, i) < array.get(pl_slice, i+1)
xbar = int((array.get(pl_bar_slice, i)-pivotlf))
llow = (array.get(pl_slice, i))
ybar = (1-loweroffset)*llow
x = label.new(x = xbar, y = ybar, xloc= xloc.bar_index, yloc= yloc.price, text = showprice == false ? ll : "LL\n" + tostring(llow), textcolor = cll, size = size.small, style= label.style_none)
|
SAR-adjusted extremes | https://www.tradingview.com/script/vIuxCbCu-SAR-adjusted-extremes/ | tech24trader-ben-au | https://www.tradingview.com/u/tech24trader-ben-au/ | 38 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tech24trader-ben-au
//@version=4
study(title="SAR-adjusted extremes",overlay=false)
mysar = sar(0.01,0.01,0.3)
highLine = abs(high - mysar)
lowLine = abs(low - mysar)
plot(highLine, 'High', color = #00ff00)
plot(lowLine, 'Low', color = #ff8800) |
Complete MA Division | https://www.tradingview.com/script/vZfD2erV-Complete-MA-Division/ | OrionAlgo | https://www.tradingview.com/u/OrionAlgo/ | 83 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OrionAlgo
//@version=4
study("Complete MA Division", max_bars_back = 4999, overlay=false)
x = input(100, 'MA1')
y = input(200, 'MA2')
curve_smoothing = input(2, 'Curve Smoothing')
slope_smoothing = input(14, 'Slope Smoothing')
f_slope(x) =>
slopePeriod = 1
(x - x[slopePeriod]) / slopePeriod
period = close
count = cum(1+1==2 ? 1 : 0)
div = x/y
// We need to calculate the moving average before the inputs
// so we have to count each bar until the period is met
ma1 = sma( period, count<y?round((count*div))==0?1:round(count*div):x)
ma2 = sma( period, count<y?round(count):y)
curve = sma(ma1/ma2,curve_smoothing)
slope_curve = sma(f_slope(curve),slope_smoothing)
slope_curve_rsi = (rsi(slope_curve,1)/100)-0.5
plot(curve, color=slope_curve>slope_curve[1]?color.green:color.red, linewidth=4)
//plot(slope_curve_rsi, color=color.white, style=plot.style_stepline)
|
Papercuts Dynamic EMA - Relative Parameter Function | https://www.tradingview.com/script/0Kp5Q6j2-Papercuts-Dynamic-EMA-Relative-Parameter-Function/ | joelly3d | https://www.tradingview.com/u/joelly3d/ | 145 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © joelly3d
//@version=4
study("Papercuts Dynamic EMA - Relative Parameter Function", overlay=true)
//The goal of this is to link two parameters of different known low and high values so one affects the other.
//In this case, I want to link Relative Volume to the length of an MA, so it responds faster in times of high volume.
//As an animator I am used to linking values in this way with Maya using a set driven key, took some work to figure it out in pine.
rvolMin = input(0.75, title="RVOL Minimum", tooltip="This value sets the Relative Volume minimum cutoff amount for trading since low volume leads to manipulation and trends become useless.")
rvolMax = input(1.5, title="RVOL Maximum", tooltip="This value sets a limit of Relative Volume maximum cutoff for the fast limit of ema lengths to be hit. This will help protect profit in rapid moves.")
rvolLen = input(50, title="RVOL: Relative Volume Length")
lengthMult = input(5, title="MA: Length High Volume Speed Multiplier", tooltip="How fast do you want the fast MA?!")
stdEMA = input(50, title="MA: Standard Target Length")
colorBull = input(defval=#2196F3, type=input.color, title="Bullish Color", inline="clr1") //Light Blue
colorBear = input(defval= #C1B82F, type=input.color, title="Bearish Color", inline="clr1") //yellow
//get relative volume
averageVolume = hma(volume, rvolLen)
relativeVolume = hma(volume / averageVolume, rvolLen)
//Relative values...
//aka linear interpolation
//aka rescale values
f_relativeVal(_source, in_bot, in_top, out_bot, out_top) =>
// float _source: input signal
// float in_bot : minimum range of input signal.
// float in_top : maximum range of input signal.
// float out_bot : minimum range of output signal.
// float out_top : maximum range of output signal.
clampSrc = _source > in_top ? in_top : _source < in_bot ? in_bot : _source //claps source to create a controlled range
//relInput = (clampSrc - in_bot) / (in_top - in_bot) * 100
inDiffIncrement = (in_top - in_bot)
outDiffIncrement = (out_top - out_bot)
out_bot + (clampSrc - in_bot) * outDiffIncrement / inDiffIncrement // rescale input range to output range
//Dynamic Ema function that allows for variable as length
Ema_f(src,p) =>
ema = 0.0
sf = 2/(p+1)
ema := nz(ema[1] + sf*(src - ema[1]),src)
theEMASlow = Ema_f(close, stdEMA)
slowplot = plot(theEMASlow, style=plot.style_circles, color=theEMASlow > theEMASlow[1] ? color.new(colorBull,60) : color.new(colorBear,60), linewidth=1)
theEMAFast = Ema_f(close, stdEMA / lengthMult)
fastplot = plot(theEMAFast, style=plot.style_circles, color=theEMAFast > theEMAFast[1] ? color.new(colorBull,60) : color.new(colorBear,60), linewidth=1)
theEMADynamic = Ema_f(close, f_relativeVal(relativeVolume, rvolMin, rvolMax, stdEMA, stdEMA / lengthMult))
theColor= theEMADynamic > theEMADynamic[1] ? colorBull : colorBear
fill(slowplot, fastplot, color.new(theColor, 90))
plot(theEMADynamic, style=plot.style_line, color=theColor, linewidth=3)
//info_panel = label.new(x=timenow, y=close, text="ema: "+tostring(theEMADynamic)+"\n rvol: "+tostring(relativeVolume), xloc=xloc.bar_time, yloc=yloc.price,
// color=color.white, style=label.style_label_left, textcolor=color.black, size=size.normal)
//label.delete(info_panel[1])
barcolor(theColor) |
AP Index - Geomagnetic disturbances | https://www.tradingview.com/script/QoEdYVqW-AP-Index-Geomagnetic-disturbances/ | firerider | https://www.tradingview.com/u/firerider/ | 21 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © firerider
//@version=5
indicator('AP Index')
// from https://www.gfz-potsdam.de/en/kp-index/
varip int[] ap_index = array.from(6, 11, 12, 18, 15, 12, 31, 13, 6, 9, 10, 7, 7, 6, 5, 7, 6, 4, 4, 2, 11, 12, 8, 6, 5, 15, 11, 7, 8, 9, 9, 20, 27, 16, 8, 12, 5, 9, 10, 7, 6, 5, 4, 2, 2, 6, 5, 22, 18, 8, 5, 7, 6, 16, 25, 8, 4, 2, 11, 26, 28, 10, 9, 5, 10, 21, 11, 5, 4, 9, 8, 6, 5, 6, 12, 108, 47, 26, 22, 12, 24, 19, 10, 13, 8, 8, 8, 11, 4, 9, 7, 12, 12, 11, 6, 5, 4, 3, 11, 33, 16, 3, 6, 13, 28, 42, 22, 10, 8, 10, 22, 10, 6, 3, 0, 2, 4, 5, 4, 4, 5, 7, 8, 7, 5, 22, 6, 5, 7, 9, 14, 15, 46, 8, 6, 5, 4, 15, 13, 6, 2, 2, 3, 4, 2, 5, 4, 6, 6, 4, 4, 6, 2, 3, 2, 2, 4, 7, 36, 14, 11, 9, 6, 8, 17, 12, 10, 14, 6, 3, 1, 7, 57, 72, 16, 32, 8, 8, 13, 4, 5, 4, 2, 2, 19, 22, 10, 4, 4, 4, 8, 23, 12, 33, 6, 6, 7, 4, 2, 2, 3, 7, 6, 21, 5, 7, 6, 9, 7, 4, 12, 13, 9, 10, 6, 6, 5, 10, 18, 10, 10, 8, 7, 10, 10, 2, 35, 32, 22, 8, 18, 11, 5, 8, 26, 6, 8, 27, 52, 40, 13, 4, 4, 4, 7, 8, 20, 12, 13, 44, 24, 59, 12, 60, 16, 11, 14, 17, 11, 10, 11, 16, 44, 8, 10, 12, 7, 6, 4, 3, 3, 5, 2, 10, 12, 10, 17, 18, 18, 74, 45, 27, 11, 12, 21, 24, 21, 8, 6, 10, 19, 4, 8, 10, 4, 6, 9, 6, 1, 3, 1, 4, 8, 6, 9, 4, 29, 30, 16, 14, 38, 14, 25, 37, 22, 4, 13, 8, 8, 12, 8, 15, 8, 4, 2, 2, 1, 0, 0, 1, 6, 6, 8, 17, 13, 8, 4, 4, 14, 22, 19, 10, 8, 24, 19, 10, 7, 20, 16, 6, 6, 5, 10, 70, 38, 12, 9, 11, 7, 14, 9, 4, 6, 2, 35, 28, 9, 6, 4, 5, 16, 13, 7, 5, 8, 13, 13, 13, 7, 4, 3, 3, 4, 10, 26, 33, 13, 11, 10, 2, 3, 4, 4, 3, 2, 9, 7, 5, 12, 5, 10, 6, 8, 17, 8, 4, 8, 12, 7, 9, 11, 37, 34, 29, 16, 5, 4, 2, 5, 6, 5, 7, 3, 3, 4, 8, 6, 6, 4, 3, 31, 24, 6, 6, 7, 19, 11, 3, 12, 24, 20, 22, 7, 14, 10, 6, 6, 10, 6, 5, 2, 11, 9, 11, 11, 6, 2, 19, 14, 6, 5, 6, 17, 8, 2, 6, 4, 18, 25, 22, 8, 11, 18, 4, 2, 3, 4, 12, 11, 11, 4, 5, 9, 4, 2, 7, 14, 30, 10, 3, 6, 15, 9, 70, 30, 13, 5, 3, 6, 9, 13, 12, 12, 7, 7, 5, 15, 6, 3, 4, 2, 2, 9, 13, 6, 11, 10, 5, 3, 2, 3, 29, 23, 8, 5, 3, 6, 9, 10, 8, 21, 11, 6, 7, 7, 4, 4, 3, 12, 10, 12, 7, 10, 8, 5, 4, 6, 6, 7, 8, 5, 3, 4, 21, 19, 12, 9, 10, 18, 7, 11, 10, 7, 5, 3, 8, 19, 5, 7, 7, 14, 18, 4, 2, 14, 13, 5, 3, 2, 17, 32, 16, 16, 12, 12, 10, 12, 15, 8, 10, 4, 3, 3, 5, 8, 6, 4, 3, 8, 4, 18, 19, 10, 6, 4, 2, 6, 17, 6, 28, 37, 36, 25, 17, 13, 12, 12, 3, 3, 3, 4, 4, 8, 6, 2, 3, 6, 8, 18, 8, 3, 3, 4, 22, 20, 35, 36, 36, 20, 17, 16, 13, 23, 11, 5, 5, 7, 5, 10, 2, 5, 46, 22, 10, 17, 20, 9, 6, 2, 1, 5, 8, 16, 57, 44, 26, 16, 27, 16, 8, 10, 14, 16, 4, 2, 4, 3, 2, 6, 14, 11, 18, 21, 10, 7, 4, 3, 2, 1, 2, 5, 11, 11, 20, 30, 11, 8, 7, 5, 3, 2, 4, 2, 1, 4, 7, 9, 21, 24, 15, 14, 5, 4, 4, 2, 1, 5, 8, 5, 5, 23, 22, 19, 12, 20, 20, 11, 5, 4, 2, 12, 12, 6, 11, 10, 17, 14, 20, 16, 11, 10, 7, 4, 4, 4, 4, 2, 3, 14, 10, 10, 10, 9, 4, 2, 5, 11, 20, 9, 6, 6, 22, 28, 21, 18, 10, 15, 12, 7, 4, 6, 7, 4, 3, 5, 1, 2, 8, 19, 16, 10, 9, 4, 9, 10, 18, 6, 2, 7, 8, 35, 32, 18, 20, 18, 23, 14, 12, 13, 10, 5, 8, 2, 4, 6, 4, 2, 2, 2, 1, 24, 24, 9, 5, 3, 3, 46, 27, 20, 19, 27, 15, 7, 4, 19, 8, 6, 9, 15, 15, 4, 10, 5, 4, 11, 6, 3, 3, 6, 14, 28, 17, 47, 36, 19, 10, 8, 6, 5, 5, 5, 4, 4, 3, 5, 4, 4, 8, 5, 5, 5, 6, 7, 4, 8, 12, 8, 6, 9, 12, 22, 8, 9, 8, 3, 2, 2, 13, 47, 9, 5, 3, 6, 4, 8, 2, 5, 4, 4, 3, 3, 3, 15, 6, 6, 5, 3, 23, 14, 10, 4, 2, 3, 4, 4, 8, 9, 6, 4, 3, 4, 3, 12, 17, 5, 4, 2, 6, 4, 2, 24, 8, 6, 4, 3, 2, 3, 44, 26, 6, 3, 6, 13, 15, 12, 10, 9, 10, 5, 7, 3, 3, 2, 4, 4, 10, 22, 15, 12, 4, 4, 4, 4, 7, 9, 6, 4, 2, 5, 24, 20, 29, 20, 9, 17, 23, 10, 4, 3, 8, 2, 8, 3, 30, 16, 20, 7, 16, 11, 8, 36, 106, 3, 4, 11, 17, 14, 22, 34, 28, 14, 20, 7, 8, 5, 5, 4, 6, 4, 3, 37, 51, 11, 14, 11, 5, 6, 5, 6, 8, 3, 3, 1, 2, 28, 26, 37, 30, 25, 8, 5, 4, 12, 7, 8, 6, 4, 18, 19, 17, 4, 5, 3, 2, 2, 2, 8, 8, 3, 1, 1, 35, 44, 18, 20, 7, 5, 6, 11, 11, 14, 4, 6, 4, 6, 27, 10, 8, 9, 6, 2, 4, 7, 4, 10, 7, 3, 1, 10, 28, 15, 10, 5, 3, 2, 10, 12, 6, 4, 3, 3, 23, 16, 4, 5, 2, 1, 5, 11, 9, 10, 7, 4, 4, 3, 3, 10, 4, 2, 3, 4, 2, 2, 9, 9, 3, 2, 3, 6, 13, 9, 4, 1, 1, 7, 7, 9, 11, 4, 9, 9, 7, 6, 3, 3, 3, 6, 4, 3, 3, 3, 8, 4, 2, 2, 4, 6, 2, 3, 2, 2, 11, 7, 11, 13, 16, 3, 2, 10, 15, 8, 3, 6, 18, 6, 6, 4, 5, 6, 4, 4, 3, 3, 10, 12, 4, 2, 2, 10, 15, 18, 14, 22, 14, 7, 4, 6, 15, 8, 16, 10, 8, 2, 3, 4, 6, 4, 4, 2, 4, 8, 3, 4, 5, 11, 17, 12, 8, 8, 5, 5, 2, 3, 5, 2, 43, 12, 5, 6, 4, 4, 4, 5, 3, 3, 5, 2, 4, 3, 4, 23, 26, 16, 14, 14, 11, 14, 8, 7, 4, 3, 3, 10, 4, 2, 2, 2, 4, 8, 3, 3, 3, 3, 4, 3, 4, 12, 23, 16, 8, 4, 5, 6, 5, 4, 3, 2, 3, 3, 4, 4, 3, 2, 4, 16, 5, 5, 3, 3, 18, 6, 12, 20, 6, 5, 3, 3, 2, 2, 2, 4, 17, 7, 5, 4, 2, 6, 7, 7, 5, 4, 3, 7, 7, 3, 3, 6, 10, 4, 3, 17, 8, 3, 3, 4, 4, 4, 4, 5, 5, 5, 4, 4, 3, 9, 4, 4, 3, 10, 5, 4, 3, 13, 10, 12, 9, 7, 14, 7, 5, 4, 4, 12, 67, 25, 8, 5, 3, 4, 4, 4, 4, 8, 10, 4, 4, 4, 6, 20, 35, 9, 17, 14, 7, 5, 11, 5, 3, 1, 7, 27, 10, 6, 10, 7, 6, 7, 9, 5, 8, 7, 4, 4, 8, 4, 24, 19, 16, 15, 9, 5, 13, 5, 10, 5, 2, 0, 2, 1, 4, 5, 3, 3, 5, 6, 3, 3, 1, 3, 3, 4, 4, 3, 16, 32, 7, 9, 11, 11, 13, 7, 9, 3, 3, 1, 1, 1, 2, 4, 6, 4, 2, 2, 3, 3, 2, 5, 2, 2, 2, 6, 11, 8, 8, 4, 5, 9, 10, 9, 10, 8, 4, 1, 2, 1, 2, 5, 6, 5, 11, 4, 2, 2, 2, 3, 2, 3, 22, 9, 9, 7, 5, 0, 1, 9, 16, 9, 6, 6, 4, 3, 6, 2, 2, 6, 5, 5, 6, 5, 4, 3, 3, 3, 12, 17, 12, 7, 4, 1, 2, 1, 14, 15, 16, 10, 5, 5, 8, 4, 8, 9, 5, 8, 4, 13, 9, 3, 3, 3, 6, 2, 3, 10, 3, 2, 1, 1, 2, 11, 23, 23, 13, 6, 6, 4, 7, 6, 4, 4, 3, 2, 6, 4, 7, 7, 12, 15, 2, 6, 5, 2, 1, 1, 1, 4, 4, 6, 9, 6, 3, 9, 6, 6, 10, 10, 12, 7, 4, 11, 9, 14, 6, 7, 7, 4, 6, 5, 3, 2, 4, 4, 3, 3, 7, 6, 4, 3, 5, 4, 4, 4, 11, 11, 7, 8, 3, 4, 4, 2, 6, 7, 24, 4, 6, 32, 5, 7, 4, 4, 2, 5, 3, 4, 4, 4, 3, 4, 8, 7, 13, 7, 4, 3, 3, 3, 6, 4, 2, 4, 20, 6, 2, 2, 3, 9, 6, 3, 4, 2, 3, 3, 6, 5, 3, 2, 4, 3, 5, 3, 4, 3, 4, 8, 4, 3, 4, 4, 3, 4, 8, 15, 15, 6, 4, 5, 5, 6, 4, 5, 3, 3, 2, 8, 7, 5, 4, 2, 2, 4, 4, 4, 8, 7, 7, 3, 2, 3, 34, 10, 5, 6, 6, 6, 5, 4, 6, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 4, 3, 5, 10, 4, 3, 9, 38, 44, 22, 8, 10, 12, 7, 6, 8, 13, 4, 4, 5, 7, 5, 8, 10, 8, 8, 3, 3, 6, 3, 2, 12, 4, 3, 22, 24, 12, 12, 10, 6, 4, 6, 7, 4, 6, 4, 8, 13, 7, 4, 0, 5, 3, 5, 5, 5, 4, 4, 4, 2, 1, 18, 25, 24, 15, 10, 7, 7, 6, 3, 1, 1, 4, 5, 6, 4, 3, 4, 2, 8, 3, 1, 2, 2, 6, 4, 0, 2, 1, 10, 13, 10, 11, 4, 2, 4, 3, 4, 3, 3, 1, 1, 3, 1, 2, 2, 2, 4, 4, 5, 3, 3, 2, 4, 2, 1, 12, 11, 5, 4, 3, 3, 1, 3, 4, 2, 1, 1, 2, 3, 2, 2, 5, 5, 8, 8, 4, 6, 11, 6, 5, 2, 2, 2, 3, 4, 2, 2, 1, 0, 5, 6, 4, 2, 2, 3, 2, 4, 8, 12, 7, 5, 5, 4, 6, 4, 15, 13, 6, 6, 4, 5, 4, 2, 2, 4, 2, 7, 13, 12, 7, 13, 8, 4, 4, 2, 3, 3, 6, 10, 6, 4, 5, 6, 3, 4, 4, 5, 5, 3, 2, 6, 7, 2, 4, 4, 5, 6, 10, 6, 8, 6, 11, 4, 3, 5, 5, 4, 7, 11, 14, 5, 6, 8, 4, 4, 2, 2, 13, 4, 4, 7, 6, 4, 7, 7, 4, 3, 3, 1, 16, 8, 7, 3, 6, 4, 6, 6, 5, 2, 1, 4, 4, 4, 5, 5, 5, 3, 3, 1, 3, 4, 3, 3, 2, 2, 3, 2, 3, 4, 2, 5, 5, 3, 4, 5, 3, 3, 2, 3, 15, 3, 5, 6, 3, 4, 3, 2, 7, 4, 4, 6, 3, 3, 2, 2, 3, 5, 3, 4, 4, 5, 3, 2, 3, 3, 3, 5, 6, 3, 2, 4, 4, 3, 3, 7, 10, 4, 3, 2, 3, 2, 2, 2, 6, 10, 4, 3, 4, 3, 3, 3, 4, 3, 2, 12, 12, 3, 3, 4, 4, 3, 4, 3, 10, 15, 7, 5, 4, 3, 4, 2, 2, 2, 3, 3, 3, 2, 3, 3, 6, 5, 2, 3, 6, 7, 2, 3, 6, 7, 10, 12, 8, 24, 18, 9, 3, 7, 5, 4, 3, 3, 1, 2, 2, 4, 6, 11, 5, 2, 2, 3, 2, 3, 2, 5, 10, 20, 17, 24, 20, 32, 16, 16, 10, 8, 4, 4, 10, 6, 4, 2, 0, 1, 2, 2, 2, 0, 1, 4, 4, 2, 6, 4, 8, 5, 14, 17, 14, 14, 8, 10, 12, 4, 5, 8, 2, 2, 2, 3, 7, 7, 4, 0, 0, 3, 3, 3, 2, 2, 0, 1, 3, 2, 7, 10, 24, 7, 3, 6, 6, 6, 9, 3, 7, 1, 3, 2, 0, 4, 6, 1, 4, 7, 7, 6, 4, 4, 3, 2, 2, 1, 2, 5, 4, 12, 13, 11, 8, 4, 4, 5, 6, 6, 8, 3, 2, 0, 1, 2, 10, 10, 4, 2, 2, 3, 12, 9, 3, 1, 2, 3, 1, 3, 5, 5, 1, 2, 3, 5, 15, 11, 10, 3, 2, 1, 1, 4, 16, 12, 7, 5, 7, 18, 6, 3, 2, 2, 5, 12, 4, 4, 12, 7, 4, 15, 21, 20, 17, 12, 19, 14, 9, 4, 5, 25, 20, 19, 9, 5, 15, 8, 5, 3, 1, 3, 11, 16, 23, 7, 2, 4, 4, 5, 27, 22, 7, 10, 9, 17, 10, 7, 5, 3, 3, 9, 7, 5, 4, 3, 4, 2, 15, 4, 2, 4, 6, 4, 5, 6, 12, 19, 28, 17, 17, 12, 6, 4, 13, 8, 18, 12, 6, 2, 4, 5, 4, 8, 5, 3, 1, 3, 2, 3, 3, 6, 2, 42, 6, 3, 7, 4, 5, 9, 5, 24, 5, 4, 3, 2, 2, 12, 14, 2, 5, 5, 2, 1, 4, 5, 4, 4, 3, 11, 4, 3, 4, 8, 9, 5, 4, 17, 13, 5, 6, 3, 4, 3, 5, 3, 4, 6, 3, 3, 3, 4, 13, 5, 4, 3, 3, 7, 6, 5, 4, 4, 6, 3, 6, 4, 14, 8, 4, 3, 4, 7, 10, 5, 8, 3, 3, 2, 3, 4, 13, 8, 6, 6, 3, 15, 8, 4, 1, 6, 10, 4, 4, 6, 5, 3, 5, 3, 8, 7, 4, 6, 4, 6, 3, 2, 2, 4, 8, 5, 21, 14, 8, 7, 6, 4, 3, 7, 4, 5, 6, 8, 14, 4, 7, 7, 5, 9, 6, 4, 3, 22, 9, 2, 2, 7, 12, 10, 6)
calculateCandleTimeDiff() =>
// 2015-01-01 00:00 signal day time serie start.
referenceUnixTime = 1420066800
candleUnixTime = time / 1000 + 1
timeDiff = candleUnixTime - referenceUnixTime
timeDiff < 0 ? na : timeDiff
getSignalCandleIndex() =>
timeDiff = calculateCandleTimeDiff()
// Day index, days count elapsed from reference date.
candleIndex = math.floor(timeDiff / 86400)
candleIndex < 0 ? na : candleIndex
getSignal() =>
// Map array data items indexes to candles.
int candleIndex = getSignalCandleIndex()
int itemsCount = array.size(ap_index)
// Return na for candles where indicator data is not available.
int index = candleIndex >= itemsCount ? na : candleIndex
signal = if index >= 0 and itemsCount > 1
array.get(ap_index, index)
else
na
signal
// Compose signal time serie from array data.
int SignalSerie = getSignal()
// Calculate plot offset estimating market week open days
plot(series=SignalSerie, style=plot.style_histogram, linewidth=4, color=color.new(color.blue, 0))
|
Daily Sunspots EISN | https://www.tradingview.com/script/FNpULm3u-Daily-Sunspots-EISN/ | firerider | https://www.tradingview.com/u/firerider/ | 35 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © firerider
//@version=5
indicator('Sunspots')
// from https://wwwbis.sidc.be/silso/eisnplot
varip int[] sunspots = array.from(18, 21, 16, 15, 10, 0, 0, 15, 15, 22, 37, 35, 31, 26, 26, 23, 18, 13, 0, 13, 18, 31, 38, 38, 34, 25, 13, 12, 12, 12, 16, 17, 14, 14, 12, 12, 36, 38, 59, 56, 50, 44, 41, 43, 33, 30, 30, 43, 23, 20, 20, 17, 17, 15, 30, 29, 27, 14, 14, 23, 37, 36, 39, 28, 0, 12, 17, 0, 0, 34, 36, 31, 33, 27, 23, 28, 30, 22, 14, 22, 17, 14, 17, 23, 22, 34, 31, 33, 33, 27, 22, 22, 24, 33, 34, 25, 21, 29, 9, 10, 10, 10, 9, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 16, 0, 0, 10, 0, 9, 13, 21, 40, 51, 47, 19, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 21, 22, 19, 24, 16, 13, 13, 19, 29, 18, 15, 18, 21, 28, 26, 12, 18, 14, 29, 39, 46, 46, 25, 14, 0, 0, 12, 12, 26, 18, 14, 15, 14, 12, 17, 18, 11, 11, 22, 11, 13, 13, 13, 14, 27, 25, 13, 13, 17, 22, 36, 34, 30, 17, 25, 16, 14, 14, 14, 30, 31, 36, 44, 47, 39, 33, 19, 34, 38, 31, 30, 24, 24, 14, 32, 51, 51, 48, 38, 55, 58, 67, 50, 41, 33, 38, 51, 26, 23, 15, 12, 0, 0, 0, 12, 23, 23, 12, 12, 27, 29, 30, 30, 58, 49, 58, 43, 29, 14, 0, 0, 16, 12, 13, 26, 27, 27, 43, 53, 51, 49, 39, 38, 36, 39, 39, 39, 49, 56, 55, 55, 48, 36, 27, 29, 21, 13, 0, 0, 0, 13, 13, 13, 13, 23, 37, 41, 49, 57, 60, 63, 51, 36, 36, 44, 60, 67, 63, 41, 31, 39, 33, 34, 21, 18, 18, 14, 27, 35, 37, 37, 30, 48, 51, 48, 69, 61, 61, 59, 56, 46, 42, 32, 27, 24, 26, 13, 24, 14, 13, 27, 29, 24, 32, 36, 41, 53, 44, 29, 31, 31, 29, 36, 27, 27, 47, 27, 14, 24, 12, 0, 0, 0, 0, 17, 17, 14, 25, 34, 17, 22, 19, 14, 42, 48, 48, 47, 48, 36, 28, 35, 25, 32, 26, 25, 22, 13, 0, 12, 20, 28, 32, 26, 29, 33, 32, 33, 29, 28, 25, 20, 13, 15, 19, 20, 24, 21, 29, 36, 26, 18, 15, 64, 51, 34, 57, 60, 78, 87, 83, 78, 65, 85, 82, 69, 47, 38, 31, 24, 13, 42, 44, 51, 62, 56, 73, 99, 116, 130, 138, 141, 113, 83, 83, 83, 93, 61, 48, 38, 38, 28, 32, 30, 24, 45, 42, 55, 97, 101, 118, 124, 104, 96, 87, 67, 63, 60, 67, 56, 57, 81, 84, 78, 56, 67, 92, 111, 123, 127, 92, 71, 71, 71, 73, 80, 87, 78, 64, 56, 74, 73, 62, 62, 80, 70, 55, 71, 76, 76, 45, 43, 63, 84, 90, 66, 46, 36, 52, 57, 57, 50, 41, 36, 35, 36, 56, 31, 11, 24, 42, 63, 73, 98, 115, 106, 126, 135, 130, 115, 80, 70, 58, 45, 39, 33, 23, 17, 15, 36, 52, 59, 59, 61, 47, 39, 50, 50, 58, 65, 50, 27, 15, 38, 41, 49, 56, 44, 41, 46, 32, 34, 38, 63, 49, 59, 75, 72, 68, 68, 82, 74, 93, 115, 109, 71, 60, 54, 43, 43, 29, 43, 63, 96, 90, 91, 99, 107, 95, 81, 92, 88, 79, 79, 70, 61, 36, 38, 29, 18, 0, 12, 31, 51, 59, 60, 59, 73, 92, 98, 70, 65, 86, 77, 64, 56, 90, 125, 131, 136, 140, 105, 114, 89, 72, 54, 72, 80, 94, 139, 145, 169, 191, 191, 160, 143, 142, 123, 108, 109, 91, 116, 122, 112, 103, 109, 128, 116, 118, 118, 113, 128, 100, 100, 89, 69, 79, 90, 124, 146, 161, 170, 148, 154, 176, 156, 141, 183, 194, 174, 134, 130, 110, 104, 93, 101, 94, 103, 96, 125, 128, 125, 99, 114, 145, 173, 171, 177, 170, 162, 157, 162, 164, 141, 125, 121, 132, 128, 137, 127, 138, 142, 131, 158, 131, 124, 98, 135, 132, 129, 127, 154, 162, 151, 151, 132, 159, 114, 102, 93, 76, 81, 78, 57, 75, 90, 100, 115, 108, 109, 103, 103, 84, 97, 117, 114, 109, 112, 93, 93, 71, 92, 120, 126, 109, 113, 113, 104, 79, 70, 63, 52, 71, 118, 149, 154, 141, 126, 105, 102, 112, 109, 113, 86, 76, 49, 65, 45, 57, 62, 75, 89, 59, 35, 38, 29, 42, 32, 13, 29, 46, 46, 49, 65, 58, 54, 48, 49, 55, 70, 64, 59, 44, 55, 58, 48, 48, 44, 39, 20, 24, 27, 63, 86, 108, 115, 106, 97, 110, 104, 116, 116, 96, 85, 88, 85, 88, 62, 74, 86, 77, 70, 71, 94, 89, 88, 84, 88, 106, 94, 89, 65, 79, 72, 64, 53, 53, 30, 25, 14, 16, 30, 58, 54, 51, 90, 61, 79, 112, 148, 168, 162, 146, 138, 134, 126, 117, 106, 112, 110, 104, 96, 95, 96, 87, 88, 87, 80, 85, 91, 96, 110, 101, 105, 119, 122, 137, 110, 102, 109, 116, 110, 80, 77, 87, 94, 80, 82, 109, 78, 73, 89, 121, 151, 165, 148, 151, 153, 127, 107, 106, 121, 128, 111, 113, 123, 117, 106, 88, 57, 51, 30, 16, 16, 16, 20, 17, 36, 70, 87, 103, 104, 126, 128, 125, 131, 129, 132, 146, 117, 122, 107, 110, 125, 129, 125, 117, 102, 86, 57, 38, 36, 29, 29, 63, 71, 68, 86, 110, 107, 111, 120, 122, 132, 143, 174, 152, 123, 98, 122, 123, 158, 131, 108, 98, 74, 33, 30, 32, 50, 54, 72, 80, 71, 69, 71, 71, 77, 78, 75, 80, 83, 126, 150, 145, 142, 171, 159, 122, 116, 95, 82, 89, 70, 76, 73, 58, 52, 61, 64, 55, 64, 67, 81, 84, 58, 75, 95, 136, 145, 113, 85, 79, 99, 78, 73, 63, 62, 60, 43, 40, 49, 70, 76, 73, 83, 80, 95, 119, 115, 102, 109, 95, 73, 82, 85, 92, 95, 79, 78, 67, 53, 69, 65, 50, 47, 45, 44, 45, 51, 47, 61, 65, 65, 79, 108, 122, 121, 133, 138, 142, 139, 132, 121, 105, 106, 95, 78, 82, 84, 72, 77, 77, 78, 70, 53, 47, 44, 54, 60, 28, 31, 50, 42, 43, 47, 67, 72, 60, 62, 65, 74, 60, 54, 56, 60, 78, 79, 57, 53, 57, 54, 53, 56, 56, 89, 99, 95, 130, 150, 162, 160, 145, 154, 156, 148, 163, 160, 128, 119, 110, 90, 63, 43, 47, 47, 37, 55, 60, 55, 49, 66, 72, 61, 52, 53, 49, 64, 72, 80, 38, 42, 43, 62, 59, 61, 48, 56, 64, 38, 35, 45, 40, 72, 109, 114, 107, 78, 67, 50, 30, 51, 53, 58, 70, 77, 96, 92, 88, 83, 77, 66, 73, 81, 100, 101, 115, 110, 123, 111, 110, 119, 107, 66, 51, 49, 49, 49, 41, 42, 30, 35, 47, 72, 73, 95, 79, 98, 101, 93, 114, 113, 126, 122, 136, 139, 126, 125, 117, 110, 93, 93, 95, 85, 87, 90, 93, 89, 82, 98, 111, 105, 107, 102, 141, 150, 142, 104, 98, 122, 110, 108, 116, 122, 116, 125, 134, 142, 153, 160, 173, 206, 183, 133, 127, 112, 113, 131, 108, 108, 118, 96, 92, 78, 72, 73, 50, 60, 77, 64, 51, 79, 76, 48, 26, 35, 26, 16, 29, 51, 64, 95, 104, 111, 113, 123, 129, 139, 137, 118, 108, 77, 60, 61, 75, 69, 80, 77, 112, 109, 121, 109, 124, 141, 122, 110, 80, 79, 73, 36, 60, 77, 77, 73, 95, 85, 59, 53, 57, 80, 70, 85, 71, 68, 73, 103, 89, 103, 96, 114, 107, 86, 82, 71, 86, 89, 64, 72, 81, 90, 108, 108, 124, 96, 100, 110, 134, 129, 146, 139, 138, 78, 50, 43, 56, 50, 53, 71, 74, 74, 90, 72, 78, 65, 49, 37, 25, 13, 18, 60, 52, 37, 25, 13, 25, 52, 63, 63, 90, 77, 79, 72, 65, 71, 54, 63, 56, 43, 53, 48, 60, 68, 79, 57, 47, 73, 96, 106, 120, 122, 112, 132, 128, 128, 119, 146, 155, 130, 114, 128, 118, 124, 144, 138, 132, 148, 147, 150, 146, 130, 106, 101, 123, 128, 122, 145, 166, 142, 104, 101, 113, 135, 152, 173, 166, 183, 192, 145, 113, 84, 72, 67, 62, 72, 40, 37, 73, 106, 98, 95, 124, 139, 110, 117, 110, 98, 89, 95, 142, 187, 176, 151, 144, 135, 135, 114, 121, 140, 140, 143, 140, 114, 111, 109, 96, 103, 106, 100, 124, 100, 136, 124, 133, 153, 136, 134, 167, 140, 107, 120, 137, 142, 133, 117, 96, 93, 80, 74, 116, 110, 133, 129, 154, 146, 116, 100, 97, 76, 77, 94, 99, 93, 94, 118, 127, 144, 167, 171, 147, 147, 147, 137, 158, 161, 147, 130, 113, 103, 106, 127, 126, 133, 136, 146, 158, 153, 171, 207, 220, 196, 155, 158, 161, 141, 154, 127, 134, 116, 111, 113, 111, 132, 112, 109, 111, 122, 126, 136, 141, 139, 126, 146, 151, 137, 136, 112, 115, 122, 118, 101, 118, 96, 114, 133, 158, 135, 121, 114, 117, 94, 65, 61, 73, 80, 105, 145, 187, 199, 178, 178, 173, 150, 123, 85, 72, 57, 45, 77, 80, 77, 82, 88, 115, 123, 127, 142, 148, 120, 132, 139, 123, 150, 154, 133, 166, 156, 133, 151, 138, 102, 87, 85, 66, 91, 109, 109, 91, 78, 70, 48, 55, 57, 64, 62, 74, 64, 87, 119, 133, 142, 156, 162, 174, 197, 182, 137, 74, 84, 95, 120, 95, 80, 93, 90, 77, 40, 55, 67, 67, 71, 93, 132, 134, 145, 167, 172, 194, 185, 197, 183, 162, 161, 144, 119, 86, 62, 18, 10, 0, 15, 35, 35, 17, 39, 65, 62, 64, 58, 78, 109, 137, 122, 131, 165, 165, 153, 146, 128, 113, 123, 89, 83, 62, 69, 75, 79, 86, 107, 109, 116, 105, 93, 102, 120, 125, 150, 149, 116, 86, 95, 82, 66, 76, 82, 96, 110, 102, 120, 116, 142, 165, 154, 175, 169, 160, 126, 125, 104, 94, 114, 123, 82, 79, 80, 95, 101, 119, 108, 144, 165, 181, 193, 180, 178, 135, 126, 117, 105, 89, 68, 68, 74, 59, 36, 30, 30, 42, 74, 89, 70, 64, 61, 92, 110, 107, 123, 132, 138, 136, 132, 107, 101, 92, 102, 80, 90, 98, 112, 109, 137, 101, 106, 86, 75, 69, 89, 92, 112, 102, 111, 103, 99, 77, 65, 74, 75, 84, 78, 103, 117, 139, 152, 143, 157, 154, 141, 125, 115, 93, 65, 57, 57, 71, 69, 90, 104, 115, 140, 162, 166, 175, 178, 154, 175, 138, 137, 118, 115, 93, 97, 88, 91, 100, 94, 88, 88, 104, 122, 102, 105, 88, 89, 103, 99, 111, 106, 122, 124, 101, 80, 59, 52, 40, 68, 66, 56, 43, 50, 60, 59, 62, 109, 126, 141, 146, 153, 138, 113, 93, 89, 96, 93, 89, 76, 84, 88, 84, 60, 51, 62, 53, 65, 41, 39, 87, 89, 64, 58, 43, 46, 44, 21, 22, 58, 60, 65, 52, 42, 37, 26, 35, 17, 28, 23, 27, 44, 56, 76, 55, 53, 46, 38, 41, 49, 20, 26, 81, 99, 108, 99, 105, 101, 81, 72, 51, 38, 43, 35, 35, 54, 55, 53, 51, 43, 47, 41, 59, 86, 103, 105, 96, 100, 117, 140, 137, 128, 127, 138, 117, 83, 69, 65, 47, 41, 30, 15, 19, 34, 44, 103, 104, 124, 145, 150, 139, 163, 163, 165, 172, 164, 124, 103, 89, 101, 77, 59, 50, 73, 72, 78, 67, 53, 14, 12, 33, 31, 29, 27, 44, 49, 80, 90, 109, 124, 112, 92, 93, 95, 98, 97, 90, 54, 70, 80, 77, 68, 64, 61, 56, 45, 36, 27, 23, 21, 32, 39, 41, 54, 75, 88, 99, 109, 97, 112, 123, 110, 103, 92, 71, 53, 43, 43, 50, 50, 58, 44, 36, 36, 36, 29, 31, 34, 40, 51, 62, 67, 76, 69, 64, 53, 61, 90, 94, 108, 112, 93, 76, 69, 78, 66, 55, 46, 39, 38, 33, 39, 50, 65, 73, 71, 81, 81, 69, 47, 55, 44, 56, 56, 35, 43, 36, 29, 37, 27, 43, 44, 42, 57, 46, 81, 89, 83, 56, 68, 86, 75, 71, 64, 65, 78, 86, 96, 101, 152, 162, 169, 156, 120, 95, 93, 62, 51, 22, 20, 26, 33, 37, 26, 13, 30, 53, 65, 57, 55, 59, 79, 75, 94, 95, 89, 107, 94, 78, 67, 78, 67, 81, 93, 88, 86, 85, 101, 82, 100, 82, 78, 82, 75, 66, 71, 61, 60, 49, 39, 56, 38, 34, 30, 41, 55, 58, 71, 56, 59, 61, 65, 61, 51, 51, 47, 32, 49, 36, 33, 50, 54, 61, 60, 78, 82, 83, 83, 81, 86, 65, 63, 56, 54, 49, 22, 18, 72, 68, 69, 76, 65, 67, 71, 57, 37, 22, 37, 40, 51, 70, 35, 31, 61, 86, 97, 90, 47, 40, 38, 41, 45, 44, 58, 54, 66, 62, 64, 67, 63, 48, 67, 69, 83, 77, 64, 36, 35, 44, 52, 83, 108, 103, 79, 89, 89, 84, 75, 85, 63, 38, 46, 50, 42, 38, 36, 46, 52, 47, 34, 37, 34, 26, 48, 26, 36, 45, 68, 78, 77, 111, 83, 78, 79, 63, 91, 80, 51, 70, 57, 70, 59, 79, 72, 47, 37, 36, 33, 20, 21, 35, 34, 32, 32, 30, 20, 17, 16, 12, 12, 12, 40, 33, 20, 18, 26, 25, 34, 43, 37, 48, 46, 33, 42, 36, 31, 28, 25, 26, 21, 13, 37, 45, 57, 76, 90, 82, 89, 87, 83, 73, 71, 60, 57, 34, 44, 52, 76, 79, 83, 78, 88, 87, 55, 38, 30, 43, 46, 18, 28, 16, 25, 35, 34, 34, 33, 33, 41, 36, 41, 14, 0, 10, 0, 0, 12, 14, 19, 33, 44, 42, 38, 38, 40, 28, 39, 47, 50, 36, 24, 23, 12, 12, 0, 0, 0, 0, 0, 0, 0, 11, 19, 0, 13, 13, 25, 41, 56, 50, 62, 59, 53, 58, 69, 60, 39, 64, 59, 56, 52, 39, 27, 13, 0, 0, 0, 13, 15, 21, 16, 12, 12, 0, 16, 38, 39, 51, 81, 72, 77, 79, 71, 58, 59, 63, 80, 58, 49, 47, 16, 14, 28, 48, 49, 48, 49, 58, 64, 68, 74, 77, 78, 67, 65, 49, 31, 43, 57, 53, 79, 78, 67, 59, 39, 28, 15, 13, 14, 38, 63, 53, 55, 36, 60, 55, 30, 29, 26, 30, 17, 12, 0, 15, 35, 40, 41, 56, 60, 63, 68, 66, 63, 41, 42, 41, 38, 29, 27, 29, 28, 16, 28, 27, 15, 15, 17, 25, 25, 37, 23, 13, 13, 12, 0, 27, 25, 25, 22, 11, 0, 14, 24, 26, 12, 36, 31, 27, 27, 29, 28, 24, 13, 0, 0, 11, 12, 13, 25, 30, 41, 46, 51, 55, 61, 56, 38, 34, 31, 19, 14, 20, 0, 0, 12, 14, 23, 12, 0, 13, 27, 15, 22, 30, 16, 0, 0, 0, 0, 16, 12, 11, 11, 11, 12, 12, 11, 0, 0, 0, 0, 0, 0, 0, 0, 11, 26, 31, 30, 25, 30, 36, 33, 56, 75, 68, 57, 43, 47, 40, 30, 30, 34, 35, 36, 47, 47, 39, 20, 14, 13, 13, 11, 19, 24, 23, 21, 19, 16, 24, 19, 14, 13, 27, 32, 27, 29, 24, 27, 32, 38, 50, 58, 59, 56, 39, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 14, 14, 18, 31, 52, 57, 52, 49, 66, 71, 83, 100, 76, 50, 36, 23, 0, 12, 14, 14, 22, 25, 19, 0, 0, 0, 23, 15, 28, 40, 30, 43, 46, 41, 38, 26, 36, 34, 24, 12, 29, 18, 17, 31, 27, 23, 11, 0, 0, 11, 15, 0, 0, 0, 25, 12, 24, 25, 30, 37, 50, 55, 20, 31, 25, 24, 21, 14, 0, 0, 15, 23, 24, 25, 34, 24, 14, 14, 0, 0, 0, 0, 11, 11, 31, 30, 30, 29, 27, 31, 35, 24, 23, 25, 18, 21, 19, 16, 12, 11, 23, 13, 0, 0, 7, 16, 26, 31, 43, 45, 38, 61, 59, 52, 33, 21, 22, 0, 0, 0, 0, 0, 0, 0, 12, 12, 0, 11, 12, 15, 0, 13, 13, 13, 14, 13, 13, 12, 13, 12, 14, 12, 13, 12, 13, 22, 33, 45, 45, 50, 60, 63, 63, 69, 54, 53, 48, 38, 23, 40, 51, 73, 59, 56, 105, 112, 119, 100, 97, 88, 62, 40, 29, 11, 23, 12, 12, 13, 14, 13, 11, 21, 22, 21, 12, 23, 36, 39, 37, 42, 42, 40, 35, 25, 24, 27, 26, 23, 11, 11, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 11, 11, 23, 23, 23, 23, 23, 24, 23, 21, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 15, 16, 25, 15, 0, 0, 0, 0, 0, 0, 15, 17, 16, 15, 13, 11, 0, 0, 0, 0, 0, 13, 11, 0, 0, 11, 13, 13, 0, 0, 0, 0, 0, 0, 11, 16, 19, 25, 26, 29, 24, 16, 13, 0, 0, 0, 13, 0, 0, 0, 13, 11, 11, 12, 13, 16, 20, 12, 0, 0, 12, 13, 15, 16, 12, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 12, 0, 0, 0, 11, 13, 16, 20, 22, 25, 25, 28, 25, 23, 20, 16, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 15, 12, 12, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 11, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 13, 16, 11, 13, 12, 11, 0, 13, 16, 27, 22, 23, 21, 18, 15, 14, 0, 0, 0, 0, 0, 0, 13, 14, 15, 14, 20, 23, 11, 11, 13, 12, 0, 0, 0, 0, 0, 0, 0, 12, 13, 27, 33, 30, 27, 33, 20, 23, 21, 22, 22, 21, 13, 0, 0, 11, 10, 0, 0, 0, 0, 11, 15, 15, 14, 14, 14, 29, 33, 56, 48, 41, 37, 19, 16, 14, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 12, 12, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 13, 12, 11, 14, 16, 16, 12, 15, 29, 32, 28, 13, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 14, 12, 16, 14, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 17, 14, 12, 11, 0, 0, 0, 0, 0, 0, 5, 13, 26, 23, 17, 0, 11, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 11, 3, 0, 15, 11, 11, 13, 15, 15, 14, 12, 0, 0, 0, 0, 9, 11, 3, 0, 0, 0, 0, 0, 0, 0, 0, 17, 21, 18, 5, 0, 0, 13, 0, 0, 11, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 15, 15, 13, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 16, 19, 21, 22, 26, 19, 16, 13, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 18, 16, 11, 11, 11, 11, 11, 0, 12, 0, 0, 0, 13, 15, 32, 38, 30, 22, 14, 0, 0, 0, 0, 0, 0, 13, 14, 17, 19, 11, 5, 0, 11, 12, 12, 13, 12, 13, 16, 14, 12, 11, 16, 24, 24, 11, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 16, 26, 25, 26, 26, 27, 26, 24, 24, 18, 13, 13, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 12, 7, 0, 0, 5, 0, 5, 0, 0, 0, 0, 0, 9, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 14, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 23, 8, 0, 0, 0, 0, 0, 6, 12, 13, 12, 14, 7, 4, 4, 15, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 12, 19, 14, 12, 12, 12, 12, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 11, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 11, 13, 13, 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 13, 26, 15, 24, 20, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 6, 0, 9, 11, 13, 16, 16, 16, 14, 12, 11, 11, 11, 11, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 4, 0, 0, 0, 4, 2, 0, 7, 5, 5, 8, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 6, 11, 11, 11, 11, 11, 11, 20, 21, 21, 21, 26, 15, 11, 11, 12, 14, 17, 12, 13, 13, 12, 17, 10, 5, 0, 0, 0, 13, 16, 12, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 7, 5, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 20, 18, 20, 14, 0, 4, 13, 13, 14, 21, 17, 14, 14, 12, 17, 18, 19, 22, 41, 35, 42, 34, 26, 5, 9, 16, 26, 31, 41, 38, 44, 29, 29, 29, 32, 26, 20, 5, 0, 10, 13, 13, 13, 26, 34, 48, 44, 53, 58, 75, 86, 96, 87, 56, 48, 45, 41, 37, 25, 21, 14, 14, 12, 12, 11, 11, 13, 20, 14, 13, 7, 0, 0, 12, 12, 24, 28, 31, 35, 33, 30, 32, 32, 34, 24, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 14, 12, 14, 12, 20, 21, 25, 35, 32, 23, 27, 17, 20, 7, 0, 0, 0, 0, 9, 7, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 10, 9, 9, 10, 16, 36, 38, 34, 18, 17, 13, 10, 16, 35, 30, 13, 7, 21, 14, 15, 17, 22, 14, 11, 23, 24, 19, 13, 13, 13, 11, 8, 22, 27, 30, 27, 25, 19, 12, 12, 9, 0, 0, 0, 4, 13, 10, 6, 0, 0, 0, 0, 10, 14, 19, 21, 25, 35, 15, 19, 36, 57, 46, 44, 36, 54, 55, 50, 55, 46, 37, 29, 10, 0, 0, 0, 0, 0, 10, 16, 20, 33, 32, 33, 30, 26, 28, 13, 14, 28, 27, 20, 14, 19, 27, 31, 41, 41, 42, 30, 14, 28, 29, 22, 30, 31, 35, 39, 38, 50, 36, 26, 27, 19, 8, 15, 12, 11, 12, 12, 22, 15, 15, 13, 16, 11, 11, 23, 19, 34, 46, 57, 56, 57, 61, 61, 51, 44, 50, 20, 17, 12, 16, 22, 23, 19, 29, 22, 35, 50, 48, 49, 46, 72, 75, 55, 31, 36, 31, 21, 7, 4, 0, 2, 8, 13, 17, 17, 24, 9, 0, 0, 7, 0, 19, 8, 10, 20, 23, 20, 15, 13, 22, 13, 17, 19, 17, 21, 35, 48, 70, 75, 51, 43, 40, 33, 33, 22, 67, 73, 83, 81, 96, 96, 93, 75, 47, 32, 22, 11, 0, 0, 0, 13, 43, 64, 81, 68, 56, 44)
i = input.int(title='Offset', defval=3)
calculateCandleTimeDiff() =>
referenceUnixTime = 1262300400
candleUnixTime = time / 1000 + 1
timeDiff = candleUnixTime - referenceUnixTime
timeDiff < 0 ? na : timeDiff
getSignalCandleIndex() =>
timeDiff = calculateCandleTimeDiff()
// Day index, days count elapsed from reference date.
candleIndex = math.floor(timeDiff / 86400)
candleIndex < 0 ? na : candleIndex
getSignal() =>
// Map array data items indexes to candles.
int candleIndex = getSignalCandleIndex()
int itemsCount = array.size(sunspots)
// Return na for candles where indicator data is not available.
int index = candleIndex >= itemsCount ? na : candleIndex
signal = if index >= 0 and itemsCount > 1
array.get(sunspots, index)
else
na
signal
// Compose signal time serie from array data.
int SignalSerie = getSignal()
// Calculate plot offset estimating market week open days
plot(series=SignalSerie, style=plot.style_histogram, linewidth=4, color=color.new(color.orange, 0), offset=i)
|
Pivot Target (5m Futures) | https://www.tradingview.com/script/2EN4YLp1-Pivot-Target-5m-Futures/ | kb0iaa | https://www.tradingview.com/u/kb0iaa/ | 120 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kb0iaa
//@version=4
study("Pivot Target (5m Futures)", overlay=true)
SR = input(title="Show Support & Resistance Levels", type=input.bool, defval=true)
TFP=timeframe.period=='5'
HI=security(syminfo.tickerid, '120', high[1], lookahead=barmerge.lookahead_on)
LO=security(syminfo.tickerid, '120', low[1], lookahead=barmerge.lookahead_on)
CL=security(syminfo.tickerid, '120', close[1], lookahead=barmerge.lookahead_on)
P=(HI+LO+CL)/3
S1=2*P-HI
R1=2*P-LO
S2=P-(R1-S1)
R2=P+(R1-S1)
S3=LO-2*(HI-P)
R3=HI+2*(P-LO)
plot(TFP and SR and R3 ? R3 : na, "R3", style=plot.style_circles, linewidth=1, color=#ff0000)
plot(TFP and SR and R2 ? R2 : na, "R2", style=plot.style_circles, linewidth=1, color=#ff0000)
plot(TFP and SR and R1 ? R1 : na, "R1", style=plot.style_circles, linewidth=1, color=#ff0000)
plot(TFP and P ? P : na, "Pivot", style=plot.style_circles, linewidth=3, color=#ac59ac)
plot(TFP and SR and S1 ? S1 : na, "S1", style=plot.style_circles, linewidth=1, color=#7cfc00)
plot(TFP and SR and S2 ? S2 : na, "S2", style=plot.style_circles, linewidth=1, color=#7cfc00)
plot(TFP and SR and S3 ? S3 : na, "S3", style=plot.style_circles, linewidth=1, color=#7cfc00) |
Early Relative Volume | https://www.tradingview.com/script/29EAlHKP-Early-Relative-Volume/ | EasyTradingSignals | https://www.tradingview.com/u/EasyTradingSignals/ | 122 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EasyTradingSignals
//@version=4
//This indicator attempts to show what the relative volume is per current e.g. minute to the relative volume of the previous candle's average minute
//This means that instead of having to wait to see if the volume of the current bar is greater than the previous one, you can get an early indication if it is greater
study(title="Early Relative Volume", shorttitle="ETS ERV", format=format.volume, resolution="")
showMA = input(false)
barColorsOnPrevClose = input(title="Blue bars if candle body and volume bigger", type=input.bool, defval=true)
secondsLeft = barstate.isrealtime ?
(time_close - timenow) / 1000 :
na
timeDiff = time[1] - time[2]
barSeconds = timeDiff / 1000
//Calc relative volume
vcurr = volume/(barSeconds-secondsLeft)
vprev = volume[1]/barSeconds
//Calc relative candle body size
pcurr = abs(open-close)/(barSeconds-secondsLeft)
pprev = abs(open[1]-close[1])/barSeconds
palette = vcurr < vprev ? color.silver : barColorsOnPrevClose ? pcurr > pprev ? color.blue : #66FFFF : #66FFFF
plot(volume, color = palette, style=plot.style_columns, title="Volume")
palettep = volume[1] < volume[2] ? color.silver : barColorsOnPrevClose ? abs(open[1]-close[1]) > abs(open[2]-close[2]) ? color.blue : #66FFFF : #66FFFF
plot(volume[1], color = palettep, style=plot.style_columns, title="Volume", offset=-1)
plot(showMA ? sma(volume,20) : na, style=plot.style_line, color=color.blue, title="Volume MA")
|
7 Moving Averages [Plus] | https://www.tradingview.com/script/yfWkuwZI/ | OskarGallard | https://www.tradingview.com/u/OskarGallard/ | 165 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OskarGallard
//@version=5
indicator(title="7 Moving Averages [Plus]", shorttitle="7MA[+]", overlay=true, precision = 4, linktoseries = true, max_bars_back = 500, max_lines_count = 500)
// Function to select the type of source
get_src(Type) =>
switch Type
"VWAP" => ta.vwap
"Close" => close
"Open" => open
"HL2" => hl2
"HLC3" => hlc3
"OHLC4" => ohlc4
"HLCC4" => hlcc4
"High" => high
"Low" => low
"vwap(Close)" => ta.vwap(close)
"vwap(Open)" => ta.vwap(open)
"vwap(High)" => ta.vwap(high)
"vwap(Low)" => ta.vwap(low)
"AVG(vwap(H,L))" => math.avg(ta.vwap(high), ta.vwap(low))
"AVG(vwap(O,C))" => math.avg(ta.vwap(open), ta.vwap(close))
"OBV" => ta.obv // On Balance Volume
"AccDist" => ta.accdist // Accumulation Distribution
"PVT" => ta.pvt // Price Volume Trend
//_________________________________________________________________________________________
// Based on "Fancy Triple Moving Averages [BigBitsIO]" - Author: @BigBitsIO
// https://www.tradingview.com/script/7emR6ckb-Fancy-Triple-Moving-Averages-BigBitsIO/
// https://www.tradingview.com/script/UQAv1U0c-MA-Study-Different-Types-and-More-NeoButane/
//_________________________________________________________________________________________
MA_0Visible = input.bool(false, "⮩ Average (WMA21 + EMA20)")
MA_1Visible = input.bool(true, "⮩ MA1", inline ="MA1")
MA_1Period = input.int(21, "Period", minval=1, step=1, inline ="MA1")
MA_1Type = input.string("WMA", "Type", options=["SMA", "EMA", "WMA", "DWMA", "NWMA", "VAMA", "VWMA", "DVWMA", "HMA", "ALMA", "LSMA", "Wilder", "RSS_WMA", "JMA", "COVWMA", "FRAMA", "ADX MA", "RSI EMA", "Zero Lag", "Tillson T3", "VIDYA", "KAMA", "CTI", "DEMA", "TEMA", "SWMA"], inline ="MA1")
MA_2Visible = input.bool(true, "⮩ MA2", inline ="MA2")
MA_2Period = input.int(55, "Period", minval=1, step=1, inline ="MA2")
MA_2Type = input.string("EMA", "Type", options=["SMA", "EMA", "WMA", "DWMA", "NWMA", "VAMA", "VWMA", "DVWMA", "HMA", "ALMA", "LSMA", "Wilder", "RSS_WMA", "JMA", "COVWMA", "FRAMA", "ADX MA", "RSI EMA", "Zero Lag", "Tillson T3", "VIDYA", "KAMA", "CTI", "DEMA", "TEMA", "SWMA"], inline ="MA2")
MA_3Visible = input.bool(true, "⮩ MA3", inline ="MA3")
MA_3Period = input.int(200, "Period", minval=1, step=1, inline ="MA3")
MA_3Type = input.string("SMA", "Type", options=["SMA", "EMA", "WMA", "DWMA", "NWMA", "VAMA", "VWMA", "DVWMA", "HMA", "ALMA", "LSMA", "Wilder", "RSS_WMA", "JMA", "COVWMA", "FRAMA", "ADX MA", "RSI EMA", "Zero Lag", "Tillson T3", "VIDYA", "KAMA", "CTI", "DEMA", "TEMA", "SWMA"], inline ="MA3")
Source1 = input.string("Close", "MA1 SRC", options=["VWAP", "Close", "Open", "HL2", "HLC3", "HLCC4", "OHLC4", "High", "Low", "vwap(Close)", "vwap(Open)", "vwap(High)", "vwap(Low)", "AVG(vwap(H,L))", "AVG(vwap(O,C))", "OBV", "AccDist", "PVT"], inline = "g1")
Source2 = input.string("Close", "MA2 SRC", options=["VWAP", "Close", "Open", "HL2", "HLC3", "HLCC4", "OHLC4", "High", "Low", "vwap(Close)", "vwap(Open)", "vwap(High)", "vwap(Low)", "AVG(vwap(H,L))", "AVG(vwap(O,C))", "OBV", "AccDist", "PVT"], inline = "g1")
Source3 = input.string("Close", "MA3 SRC", options=["VWAP", "Close", "Open", "HL2", "HLC3", "HLCC4", "OHLC4", "High", "Low", "vwap(Close)", "vwap(Open)", "vwap(High)", "vwap(Low)", "AVG(vwap(H,L))", "AVG(vwap(O,C))", "OBV", "AccDist", "PVT"], inline = "g1")
MA_1Strategy = input.string("3-MA", "▷ MA1 ⮩ Strategy Color", options=["None", "3-MA", "SuperTrend", "IchimokuTrend"], inline ="strag")
MA_abc_Type = input.string("EMA", "Type", options=["SMA", "EMA", "WMA", "DWMA", "NWMA", "VAMA", "VWMA", "DVWMA", "HMA", "ALMA", "LSMA", "Wilder", "RSS_WMA", "JMA", "COVWMA", "FRAMA", "Zero Lag", "Tillson T3", "VIDYA", "KAMA", "CTI", "DEMA", "TEMA", "SWMA"], inline ="strag")
MA_a_Period = input.int(4, "Fast", minval=1, step=1, inline ="MA")
MA_b_Period = input.int(9, "Middle", minval=1, step=1, inline ="MA")
MA_c_Period = input.int(18, "Slow", minval=1, step=1, inline ="MA")
MA_2Strategy = input.string("SuperTrend", "▷ MA2 ⮩ Strategy Color", options=["None", "3-MA", "SuperTrend"], inline ="strag2")
MA_abc2_Type = input.string("EMA", "Type", options=["SMA", "EMA", "WMA", "DWMA", "NWMA", "VAMA", "VWMA", "DVWMA", "HMA", "ALMA", "LSMA", "Wilder", "RSS_WMA", "JMA", "COVWMA", "FRAMA", "Zero Lag", "Tillson T3", "VIDYA", "KAMA", "CTI", "DEMA", "TEMA", "SWMA"], inline ="strag2")
MA_a2_Period = input.int(3, "Fast", minval=1, step=1, inline ="M2")
MA_b2_Period = input.int(13, "Middle", minval=1, step=1, inline ="M2")
MA_c2_Period = input.int(144, "Slow", minval=1, step=1, inline ="M2")
MA_4Visible = input.bool(false, "⮩ MA4", inline ="MA4")
MA_4Period = input.int(20, "Period", minval=1, step=1, inline ="MA4")
MA_4Type = input.string("EMA", "Type", options=["SMA", "EMA", "WMA", "DWMA", "NWMA", "VAMA", "VWMA", "DVWMA", "HMA", "ALMA", "LSMA", "Wilder", "RSS_WMA", "JMA", "COVWMA", "FRAMA", "ADX MA", "RSI EMA", "Zero Lag", "Tillson T3", "VIDYA", "KAMA", "CTI", "DEMA", "TEMA", "SWMA"], inline ="MA4")
MA_5Visible = input.bool(false, "⮩ MA5", inline ="MA5")
MA_5Period = input.int(50, "Period", minval=1, step=1, inline ="MA5")
MA_5Type = input.string("SMA", "Type", options=["SMA", "EMA", "WMA", "DWMA", "NWMA", "VAMA", "VWMA", "DVWMA", "HMA", "ALMA", "LSMA", "Wilder", "RSS_WMA", "JMA", "COVWMA", "FRAMA", "ADX MA", "RSI EMA", "Zero Lag", "Tillson T3", "VIDYA", "KAMA", "CTI", "DEMA", "TEMA", "SWMA"], inline ="MA5")
MA_6Visible = input.bool(false, "⮩ MA6", inline ="MA6")
MA_6Period = input.int(30, "Period", minval=1, step=1, inline ="MA6")
MA_6Type = input.string("WMA", "Type", options=["SMA", "EMA", "WMA", "DWMA", "NWMA", "VAMA", "VWMA", "DVWMA", "HMA", "ALMA", "LSMA", "Wilder", "RSS_WMA", "JMA", "COVWMA", "FRAMA", "ADX MA", "RSI EMA", "Zero Lag", "Tillson T3", "VIDYA", "KAMA", "CTI", "DEMA", "TEMA", "SWMA"], inline ="MA6")
Source4 = input.string("Close", "MA4 SRC", options=["VWAP", "Close", "Open", "HL2", "HLC3", "HLCC4", "OHLC4", "High", "Low", "vwap(Close)", "vwap(Open)", "vwap(High)", "vwap(Low)", "AVG(vwap(H,L))", "AVG(vwap(O,C))", "OBV", "AccDist", "PVT"], inline = "g2")
Source5 = input.string("Close", "MA5 SRC", options=["VWAP", "Close", "Open", "HL2", "HLC3", "HLCC4", "OHLC4", "High", "Low", "vwap(Close)", "vwap(Open)", "vwap(High)", "vwap(Low)", "AVG(vwap(H,L))", "AVG(vwap(O,C))", "OBV", "AccDist", "PVT"], inline = "g2")
Source6 = input.string("Close", "MA6 SRC", options=["VWAP", "Close", "Open", "HL2", "HLC3", "HLCC4", "OHLC4", "High", "Low", "vwap(Close)", "vwap(Open)", "vwap(High)", "vwap(Low)", "AVG(vwap(H,L))", "AVG(vwap(O,C))", "OBV", "AccDist", "PVT"], inline = "g2")
MA_1Source = get_src(Source1)
MA_2Source = get_src(Source2)
MA_3Source = get_src(Source3)
MA_4Source = get_src(Source4)
MA_5Source = get_src(Source5)
MA_6Source = get_src(Source6)
MA_4Resolution = input.string("11 1D", "MA4 Res", options=["00 Current", "01 1m", "02 3m", "03 5m", "04 15m", "05 30m", "06 45m", "07 1h", "08 2h", "09 3h", "10 4h", "11 1D", "12 1W", "13 1M"], inline = "g2r")
MA_5Resolution = input.string("11 1D", "MA5 Res", options=["00 Current", "01 1m", "02 3m", "03 5m", "04 15m", "05 30m", "06 45m", "07 1h", "08 2h", "09 3h", "10 4h", "11 1D", "12 1W", "13 1M"], inline = "g2r")
MA_6Resolution = input.string("12 1W", "MA6 Res", options=["00 Current", "01 1m", "02 3m", "03 5m", "04 15m", "05 30m", "06 45m", "07 1h", "08 2h", "09 3h", "10 4h", "11 1D", "12 1W", "13 1M"], inline = "g2r")
MA_4off = input.int(0, "4 Offset", minval=-200, maxval=200, inline = "g2off")
MA_5off = input.int(0, "5 Offset", minval=-200, maxval=200, inline = "g2off")
MA_6off = input.int(0, "6 Offset", minval=-200, maxval=200, inline = "g2off")
// Input - Bollinger Bands
BB_Visible = input.bool(false, "⮩ Visible", group ="Bollinger Bands")
length_BB = input.int(20, "Length", minval=1, inline ="bb", group ="Bollinger Bands")
BB_Type = input.string("SMA", "Type", inline ="bb", group ="Bollinger Bands", options=["SMA", "EMA", "WMA", "DWMA", "NWMA", "VAMA", "VWMA", "DVWMA", "HMA", "ALMA", "LSMA", "Wilder", "RSS_WMA", "JMA", "COVWMA", "FRAMA", "ADX MA", "RSI EMA", "Zero Lag", "Tillson T3", "VIDYA", "KAMA", "CTI", "DEMA", "TEMA", "SWMA"])
Source_BB = input.string("Close", "Source", inline ="bb", group ="Bollinger Bands", options=["VWAP", "Close", "Open", "HL2", "HLC3", "HLCC4", "OHLC4", "High", "Low", "vwap(Close)", "vwap(Open)", "vwap(High)", "vwap(Low)", "AVG(vwap(H,L))", "AVG(vwap(O,C))", "OBV", "AccDist", "PVT"])
src_BB = get_src(Source_BB)
mult_BB = input.float(2.0, "Multiplier", minval=0.001, maxval=50, inline ="mx", group ="Bollinger Bands")
show_bands = input.bool(false, "▷ Show Extra Bands", inline ="mx", group ="Bollinger Bands")
mult_KC = input.float(1.25, "Keltner\'s Channel MultFactor", step=0.25, inline ="kc", group ="Bollinger Bands")
True_Range = input.bool(true, "Use TrueRange", inline ="kc", group ="Bollinger Bands")
show_disp = input.bool(false, "Show dispersion", inline="disp", group ="Bollinger Bands")
dispersion = input.float(0.1, "", minval=0.01, maxval=1, step=0.01, inline="disp", group ="Bollinger Bands")
// Input - Parabolic SAR
PSAR_Visible = input.bool(false, "⮩ Visible", group ="Parabolic SAR")
start = input.float(0.02, "Start", step=0.001, inline ="sar", group ="Parabolic SAR")
increment = input.float(0.02, "Increment", step=0.001, inline ="sar", group ="Parabolic SAR")
maximum = input.float(0.2, "Maximum", step=0.01, inline ="sar", group ="Parabolic SAR")
showsignals = input.bool(true, "Show Signals", inline ="Opc SAR", group ="Parabolic SAR")
highlighting = input.bool(true, "Highlighter", inline ="Opc SAR", group ="Parabolic SAR")
// Volume Weighted Colored Bars
VBCB_Visible = input.bool(false, "⮩ Visible", group ="Volume Weighted Colored Bars")
vbcbLength = input.int(21, "Volume MA Length", minval=1, inline ="v1", group ="Volume Weighted Colored Bars")
v_show_last = input.int(233, "Plotting Length", inline ="v1", group ="Volume Weighted Colored Bars")
vwcbUpper = input.float(1.5, "Upper Theshold", minval = 0.1, step = .1, inline ="v2", group ="Volume Weighted Colored Bars")
vwcbLower = input.float(.5, "Lower Theshold", minval = 0.1, step = .1, inline ="v2", group ="Volume Weighted Colored Bars")
// Input - Linear Regression (Logarithmic)
LR_Visible = input.bool(false, "⮩ Visible", group ="Linear Regression (log)")
lenLR = input.int(100, "Count", minval=10, maxval=300, inline ="lr", group ="Linear Regression (log)")
sourceLR = input.source(close, "Source", inline ="lr", group ="Linear Regression (log)")
upperMult = input.float(2.0, "Upper Deviation", inline ="devi", group ="Linear Regression (log)")
lowerMult = input.float(-2.0, "Lower Deviation", inline ="devi", group ="Linear Regression (log)")
useUpperDev = input.bool(true, "Use Upper Deviation", group ="Linear Regression (log)")
useLowerDev = input.bool(true, "Use Lower Deviation", group ="Linear Regression (log)")
showPearson = input.bool(false, "Show Pearson`s R", group ="Linear Regression (log)")
extendLines = input.bool(false, "Extend Lines", group ="Linear Regression (log)")
// Input - Laguerre Average
LMA_Visible = input.bool(false, "⮩ Visible", group ="Laguerre Average")
src_LMA = input.string("HL2", "Source", options=["VWAP", "Close", "Open", "HL2", "HLC3", "HLCC4", "OHLC4", "High", "Low", "vwap(Close)", "vwap(Open)", "vwap(High)", "vwap(Low)", "AVG(vwap(H,L))", "AVG(vwap(O,C))"], inline ="L1", group ="Laguerre Average")
src_L = get_src(src_LMA)
Gamma = input.float(0.77, inline ="L1", group ="Laguerre Average")
useCurrentRes = input.bool(true, "▷ Use Current Chart Resolution?", inline ="L2", group ="Laguerre Average")
resCustom = input.timeframe("", "Time Frame", inline ="L2", group ="Laguerre Average")
res_LMA = useCurrentRes ? timeframe.period : resCustom
sd = input.bool(true, "Show dots?", inline ="L3", group ="Laguerre Average")
ccol = input.bool(true, "Change Color?", inline ="L3", group ="Laguerre Average")
//______________________________________________________________________________
//______________________________________________________________________________
// ALMA - Arnaud Legoux Moving Average of @kurtsmock
enhanced_alma(_series, _length, _offset, _sigma) =>
length = int(_length) // Floating point protection
numerator = 0.0
denominator = 0.0
m = _offset * (length - 1)
s = length / _sigma
for i=0 to length-1
weight = math.exp(-((i-m)*(i-m)) / (2 * s * s))
numerator := numerator + weight * _series[length - 1 - i]
denominator := denominator + weight
numerator / denominator
// Kaufman's Adaptive Moving Average
kama(x, t)=>
fast = 0.666 // KAMA Fast End
slow = 0.0645 // KAMA Slow End
dist = math.abs(x[0] - x[1])
signal = math.abs(x - x[t])
noise = math.sum(dist, t)
effr = noise!=0 ? signal/noise : 1
sc = math.pow(effr*(fast - slow) + slow,2)
KAma = x
KAma := nz(KAma[1]) + sc*(x - nz(KAma[1]))
// Jurik Moving Average of @everget
jma(src, length, power, phase) =>
phaseRatio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : phase / 100 + 1.5
beta = 0.45 * (length - 1) / (0.45 * (length - 1) + 2)
alpha = math.pow(beta, power)
Jma = 0.0
e0 = 0.0
e0 := (1 - alpha) * src + alpha * nz(e0[1])
e1 = 0.0
e1 := (src - e0) * (1 - beta) + beta * nz(e1[1])
e2 = 0.0
e2 := (e0 + phaseRatio * e1 - nz(Jma[1])) * math.pow(1 - alpha, 2) + math.pow(alpha, 2) * nz(e2[1])
Jma := e2 + nz(Jma[1])
Jma
cti(sm, src, cd) =>
di = (sm - 1.0) / 2.0 + 1.0
c1 = 2 / (di + 1.0)
c2 = 1 - c1
c3 = 3.0 * (cd * cd + cd * cd * cd)
c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
i1 = 0.0
i2 = 0.0
i3 = 0.0
i4 = 0.0
i5 = 0.0
i6 = 0.0
i1 := c1*src + c2*nz(i1[1])
i2 := c1*i1 + c2*nz(i2[1])
i3 := c1*i2 + c2*nz(i3[1])
i4 := c1*i3 + c2*nz(i4[1])
i5 := c1*i4 + c2*nz(i5[1])
i6 := c1*i5 + c2*nz(i6[1])
bfr = -cd*cd*cd*i6 + c3*(i5) + c4*(i4) + c5*(i3)
bfr
T3ma(src,Len) =>
a = 0.618
e1 = ta.ema(src, Len)
e2 = ta.ema(e1, Len)
e3 = ta.ema(e2, Len)
e4 = ta.ema(e3, Len)
e5 = ta.ema(e4, Len)
e6 = ta.ema(e5, Len)
C1 = -a*a*a
C2 = 3*a*a+3*a*a*a
C3 = -6*a*a-3*a-3*a*a*a
C4 = 1+3*a+a*a*a+3*a*a
C1*e6+C2*e5+C3*e4+C4*e3
VIDYA(src,Len) =>
mom = ta.change(src)
upSum = math.sum(math.max(mom, 0), Len)
downSum = math.sum(-math.min(mom, 0), Len)
out = (upSum - downSum) / (upSum + downSum)
cmo = math.abs(out)
alpha = 2 / (Len + 1)
vidya = 0.0
vidya := src * alpha * cmo + nz(vidya[1]) * (1 - alpha * cmo)
vidya
// ZLEMA: Zero Lag
zema(_src, _len) =>
_alpha = (_len - 1) / 2
_zlema0 = (_src + (_src - _src[_alpha]))
_zlemaF = ta.ema(_zlema0, _len)
// EMA RSI Adaptive of @glaz
rsi_ema(src, period) =>
RsiPeriod = 14
ema = 0.0
RSvoltl = math.abs(ta.rsi(close, RsiPeriod)-50)+1.0
multi = (5.0+100.0/RsiPeriod) / (0.06+0.92*RSvoltl+0.02*math.pow(RSvoltl,2))
pdsx = multi*period
alpha = 2.0 /(1.0+pdsx)
ema := nz(ema[1])+alpha*(ta.sma(close, period)-nz(ema[1]))
ema
// ADX Weighted Moving Average of @Duyck
adx_weighted_ma(_src, _period) =>
[_diplus, _diminus, _adx] = ta.dmi(17, 14)
_vol_sum = 0.0
_adx_sum = 0.0
for i = 0 to _period
_vol_sum := _src[i] * _adx[i] + _vol_sum
_adx_sum := _adx[i] + _adx_sum
_volwma = _vol_sum / _adx_sum
// COVWMA - Coefficient of Variation Weighted Moving Average of @DonovanWall
covwma(a, b) =>
cov = ta.stdev(a, b) / ta.sma(a, b)
cw = a*cov
covwma = math.sum(cw, b) / math.sum(cov, b)
// FRAMA - Fractal Adaptive Moving Average of @DonovanWall
frama(a, b) =>
w = -4.6 // Coefficient
frama = 0.0
n3 = (ta.highest(high, b) - ta.lowest(low, b))/b
hd2 = ta.highest(high, b/2)
ld2 = ta.lowest(low, b/2)
n2 = (hd2 - ld2)/(b/2)
n1 = (hd2[b/2] - ld2[b/2])/(b/2)
dim = (n1 > 0) and (n2 > 0) and (n3 > 0) ? (math.log(n1 + n2) - math.log(n3))/math.log(2) : 0
alpha = math.exp(w*(dim - 1))
sc = (alpha < 0.01 ? 0.01 : (alpha > 1 ? 1 : alpha))
frama := ta.cum(1)<=2*b ? a : (a*sc) + nz(frama[1])*(1 - sc)
frama
// VAMA - Volume Adjusted Moving Average of @allanster
vama(_src,_len,_fct,_rul,_nvb) => // vama(source,length,factor,rule,sample)
tvb = 0, tvb := _nvb == 0 ? nz(tvb[1]) + 1 : _nvb // total volume bars used in sample
tvs = _nvb == 0 ? ta.cum(volume) : math.sum(volume, _nvb) // total volume in sample
v2i = volume / ((tvs / tvb) * _fct) // ratio of volume to increments of volume
wtd = _src*v2i // weighted prices
nmb = 1 // initialize number of bars summed back
wtdSumB = 0.0 // initialize weighted prices summed back
v2iSumB = 0.0 // initialize ratio of volume to increments of volume summed back
for i = 1 to _len * 10 // set artificial cap for strict to VAMA length * 10 to help reduce edge case timeout errors
strict = _rul ? false : i == _len // strict rule N bars' v2i ratios >= vama length, else <= vama length
wtdSumB := wtdSumB + nz(wtd[i-1]) // increment number of bars' weighted prices summed back
v2iSumB := v2iSumB + nz(v2i[i-1]) // increment number of bars' v2i's summed back
if v2iSumB >= _len or strict // if chosen rule met
break // break (exit loop)
nmb := nmb + 1 // increment number of bars summed back counter
nmb // number of bars summed back to fulfill volume requirements or vama length
wtdSumB // number of bars' weighted prices summed back
v2iSumB // number of bars' v2i's summed back
vama = (wtdSumB - (v2iSumB - _len) * _src[nmb]) / _len // volume adjusted moving average
// New WMA
NWMA(_src, _n1) =>
fast = int(_n1 / 2)
lambda = _n1 / fast
alpha = lambda * (_n1 - 1) / (_n1 - lambda)
ma1 = ta.wma(_src, _n1)
ma2 = ta.wma(ma1, fast)
nwma = (1 + alpha) * ma1 - alpha * ma2
// VWMA with Tick Volume
enhanced_vwma(_series, _length) =>
tick = syminfo.mintick
rng = close - open
tickrng = tick
tickrng := math.abs(rng) < tick ? nz(tickrng[1]) : rng
tickvol = math.abs(tickrng)/tick
vol = nz(volume) == 0 ? tickvol : volume
vmp = _series * vol
VWMA = math.sum(vmp, _length) / math.sum(vol, _length)
VWMA
// RSS_WMA of @RedKTrader
f_LazyLine(_data, _length) =>
w1 = 0, w2 = 0, w3 = 0
L1 = 0.0, L2 = 0.0, L3 = 0.0
w = _length / 3
if _length > 2
w2 := math.round(w)
w1 := math.round((_length - w2) / 2)
w3 := int((_length - w2) / 2)
L1 := ta.wma(_data, w1)
L2 := ta.wma(L1, w2)
L3 := ta.wma(L2, w3)
else
L3 := _data
L3
ma(MAType, MASource, MAPeriod) =>
switch MAType
"SMA" => ta.sma(MASource, MAPeriod)
"EMA" => ta.ema(MASource, MAPeriod)
"WMA" => ta.wma(MASource, MAPeriod)
"HMA" => ta.hma(MASource, MAPeriod)
"DEMA" => e = ta.ema(MASource, MAPeriod), 2 * e - ta.ema(e, MAPeriod)
"TEMA" => e = ta.ema(MASource, MAPeriod), 3 * (e - ta.ema(e, MAPeriod)) + ta.ema(ta.ema(e, MAPeriod), MAPeriod)
"VWMA" => enhanced_vwma(MASource, MAPeriod) //ta.vwma(MASource, MAPeriod)
"ALMA" => enhanced_alma(MASource, MAPeriod, .85, 6) //ta.alma(MASource, MAPeriod, .85, 6)
"CTI" => cti(MAPeriod, MASource, 0)
"KAMA" => kama(MASource, MAPeriod)
"SWMA" => ta.swma(MASource)
"JMA" => jma(MASource, MAPeriod, 2, 50)
"LSMA" => ta.linreg(MASource, MAPeriod, 0) // Least Squares
"Wilder" => wild = MASource, wild := nz(wild[1]) + (MASource - nz(wild[1])) / MAPeriod
"Tillson T3" => T3ma(MASource, MAPeriod)
"VIDYA" => VIDYA(MASource, MAPeriod)
"DWMA" => ta.wma(ta.wma(MASource, MAPeriod), MAPeriod) // Double Weighted Moving Average
"DVWMA" => ta.vwma(ta.vwma(MASource, MAPeriod), MAPeriod) // Double Volume-Weighted Moving Average
"Zero Lag" => zema(MASource, MAPeriod)
"RSI EMA" => rsi_ema(MASource, MAPeriod)
"ADX MA" => adx_weighted_ma(MASource, MAPeriod)
"COVWMA" => covwma(MASource, MAPeriod)
"FRAMA" => frama(MASource, MAPeriod)
"VAMA" => vama(MASource, MAPeriod, 0.67, true, 0)
"NWMA" => NWMA(MASource, MAPeriod)
"RSS_WMA" => f_LazyLine(MASource, MAPeriod)
res(MAResolution) =>
switch MAResolution
"00 Current" => timeframe.period
"01 1m" => "1"
"02 3m" => "3"
"03 5m" => "5"
"04 15m" => "15"
"05 30m" => "30"
"06 45m" => "45"
"07 1h" => "60"
"08 2h" => "120"
"09 3h" => "180"
"10 4h" => "240"
"11 1D" => "1D"
"12 1W" => "1W"
"13 1M" => "1M"
color_lavender = #8080FF
color_coral = #FF8080
color_black = color.new(color.black, 10)
color_fuchsia = #FF00FF // Color MA 4
color_hanpurple = #6600FF // Color MA 5
color_chartreuse = #80FF00 // Color MA 6
color_redorange = #FF4000
// Strategy 3-MA
// When the color is green, this is a bullish zone.
// When the color is red, this is a bearish zone.
// When the color is red, this is a bearish zone.
f_color_3ma(Type, Period1, Period2, Period3) =>
ma_v = ma(Type, close, Period1)
ma_a = ma(Type, close, Period2)
ma_r = ma(Type, close, Period3)
bulls = ma_v >= ma_a and ma_a > ma_r
bears = ma_v < ma_a and ma_a < ma_r
color_3 = bulls ? color.lime : bears ? color.red : color.yellow
color_3ma_m1 = f_color_3ma(MA_abc_Type, MA_a_Period, MA_b_Period, MA_c_Period)
color_3ma_m2 = f_color_3ma(MA_abc2_Type, MA_a2_Period, MA_b2_Period, MA_c2_Period)
//______________________________________________________________________________
// Based on "Pivot Point Supertrend" - Author: @LonesomeTheBlue
// https://www.tradingview.com/script/L0AIiLvH-Pivot-Point-Supertrend/
//______________________________________________________________________________
prd = 2 // Pivot Point Period
Factor = 3 // ATR Factor
Pd = 10 // ATR Period
// Get Pivot High/Low
float ph = ta.pivothigh(prd, prd)
float pl = ta.pivotlow(prd, prd)
// Calculate the Center line using pivot points
var float center = na
float lastpp = ph ? ph : pl ? pl : na
if lastpp
if na(center)
center := lastpp
else
center := (center * 2 + lastpp) / 3 // Weighted calculation
// Upper/Lower bands calculation
Up = center - (Factor * ta.atr(Pd))
Dn = center + (Factor * ta.atr(Pd))
// Get the trend
float TUp = na
float TDown = na
Trend = 0
TUp := close[1] > TUp[1] ? math.max(Up, TUp[1]) : Up
TDown := close[1] < TDown[1] ? math.min(Dn, TDown[1]) : Dn
Trend := close > TDown[1] ? 1 : close < TUp[1] ? -1 : nz(Trend[1], 1)
Trailingsl = Trend == 1 ? TUp : TDown
color_SuperTrend = Trend == 1 and nz(Trend[1]) == 1 ? #00C0FF : Trend == -1 and nz(Trend[1]) == -1 ? #FF4000 : color.yellow
// Ichimoku Trend and MFI
conversionLine = math.avg(ta.lowest(9), ta.highest(9))
baseLine = math.avg(ta.lowest(26), ta.highest(26))
ssa = math.avg(conversionLine, baseLine)
ssb = math.avg(ta.lowest(52), ta.highest(52))
valor_mfi = math.avg(ta.mfi(hlc3, 14), ta.rsi(close, 14))
bull_Ichi = close > ssa[26] and close > ssb[26] and valor_mfi >= 50
bear_Ichi = close < ssa[26] and close < ssb[26] and valor_mfi < 50
color_Ichi = bull_Ichi ? color.lime : bear_Ichi ? color.red : color.yellow
// Color MA 1
color_MA1 = color_redorange
if MA_1Strategy == "None"
na
else if MA_1Strategy == "3-MA"
color_MA1 := color_3ma_m1
else if MA_1Strategy == "SuperTrend"
color_MA1 := color_SuperTrend
else if MA_1Strategy == "IchimokuTrend"
color_MA1 := color_Ichi
// Color MA 2
color_MA2 = color_coral
if MA_2Strategy == "None"
na
else if MA_2Strategy == "3-MA"
color_MA2 := color_3ma_m2
else if MA_2Strategy == "SuperTrend"
color_MA2 := color_SuperTrend
// Color MA 3
color_MA3 = color_lavender
// PLOT - MA
// Average (WMA21 + EMA20)
MA_0 = (ta.wma(close, 21) + ta.ema(close, 20))/2
color_MA0 = MA_0 > MA_0[1] ? #15FF00 : #2C6C2F
plot(MA_0Visible ? MA_0 : na, "Average(WMA+EMA)", color_MA0, 2)
MA_1 = ma(MA_1Type, MA_1Source, MA_1Period)
plot(MA_1Visible ? MA_1 : na, color=color_MA1, linewidth=2, title="MA1")
plot(MA_1Visible ? MA_1[MA_1Period-1] : na, color=color_black, linewidth=2, title="MA1 Trail", offset=((MA_1Period-1)*-1))
MA_2 = ma(MA_2Type, MA_2Source, MA_2Period)
plot(MA_2Visible ? MA_2 : na, color=color_MA2, linewidth=1, title="MA2")
plot(MA_2Visible ? MA_2[MA_2Period-1] : na, color=color_black, linewidth=2, title="MA2 Trail", offset=((MA_2Period-1)*-1))
MA_3 = ma(MA_3Type, MA_3Source, MA_3Period)
plot(MA_3Visible ? MA_3 : na, color=color_MA3, linewidth=1, title="MA3")
plot(MA_3Visible ? MA_3[MA_3Period-1] : na, color=color_black, linewidth=2, title="MA3 Trail", offset=((MA_3Period-1)*-1))
// https://www.tradingview.com/pine-script-reference/#fun_security
MA_4 = request.security(syminfo.tickerid, res(MA_4Resolution), ma(MA_4Type, MA_4Source, MA_4Period))
plot(MA_4Visible ? MA_4 : na, color=color_fuchsia, linewidth=2, title="MA4", offset=MA_4off)
MA_5 = request.security(syminfo.tickerid, res(MA_5Resolution), ma(MA_5Type, MA_5Source, MA_5Period))
plot(MA_5Visible ? MA_5 : na, color=color_hanpurple, linewidth=2, title="MA5", offset=MA_5off)
MA_6 = request.security(syminfo.tickerid, res(MA_6Resolution), ma(MA_6Type, MA_6Source, MA_6Period))
plot(MA_6Visible ? MA_6 : na, color=color_chartreuse, linewidth=2, title="MA6", offset=MA_6off)
// Forecasting - forcasted prices are calculated using our MAType and MASource for the MAPeriod - the last X candles.
// it essentially replaces the oldest X candles, with the selected source * X candles
MAForecast1 = MA_1Period > 1 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_1Type, MA_1Source, MA_1Period - 1)) * (MA_1Period - 1) + ((MA_1Source * 1) )) / MA_1Period : na
MAForecast2 = MA_1Period > 2 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_1Type, MA_1Source, MA_1Period - 2)) * (MA_1Period - 2) + ((MA_1Source * 2) )) / MA_1Period : na
MAForecast3 = MA_1Period > 3 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_1Type, MA_1Source, MA_1Period - 3)) * (MA_1Period - 3) + ((MA_1Source * 3) )) / MA_1Period : na
MAForecast4 = MA_1Period > 4 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_1Type, MA_1Source, MA_1Period - 4)) * (MA_1Period - 4) + ((MA_1Source * 4) )) / MA_1Period : na
MAForecast5 = MA_1Period > 5 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_1Type, MA_1Source, MA_1Period - 5)) * (MA_1Period - 5) + ((MA_1Source * 5) )) / MA_1Period : na
plot( MA_1Visible ? MAForecast1 : na, color=color_MA1, linewidth=1, style=plot.style_circles, title="MA1 F1", offset=1, show_last=1)
plot( MA_1Visible ? MAForecast2 : na, color=color_MA1, linewidth=1, style=plot.style_circles, title="MA1 F2", offset=2, show_last=1)
plot( MA_1Visible ? MAForecast3 : na, color=color_MA1, linewidth=1, style=plot.style_circles, title="MA1 F3", offset=3, show_last=1)
plot( MA_1Visible ? MAForecast4 : na, color=color_MA1, linewidth=1, style=plot.style_circles, title="MA1 F4", offset=4, show_last=1)
plot( MA_1Visible ? MAForecast5 : na, color=color_MA1, linewidth=1, style=plot.style_circles, title="MA1 F5", offset=5, show_last=1)
MA2Forecast1 = MA_2Period > 1 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_2Type, MA_2Source, MA_2Period - 1)) * (MA_2Period - 1) + ((MA_2Source * 1) )) / MA_2Period : na
MA2Forecast2 = MA_2Period > 2 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_2Type, MA_2Source, MA_2Period - 2)) * (MA_2Period - 2) + ((MA_2Source * 2) )) / MA_2Period : na
MA2Forecast3 = MA_2Period > 3 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_2Type, MA_2Source, MA_2Period - 3)) * (MA_2Period - 3) + ((MA_2Source * 3) )) / MA_2Period : na
MA2Forecast4 = MA_2Period > 4 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_2Type, MA_2Source, MA_2Period - 4)) * (MA_2Period - 4) + ((MA_2Source * 4) )) / MA_2Period : na
MA2Forecast5 = MA_2Period > 5 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_2Type, MA_2Source, MA_2Period - 5)) * (MA_2Period - 5) + ((MA_2Source * 5) )) / MA_2Period : na
plot( MA_2Visible ? MA2Forecast1 : na, color=color.gray, linewidth=1, style=plot.style_circles, title="MA2 F1", offset=1, show_last=1)
plot( MA_2Visible ? MA2Forecast2 : na, color=color.gray, linewidth=1, style=plot.style_circles, title="MA2 F2", offset=2, show_last=1)
plot( MA_2Visible ? MA2Forecast3 : na, color=color.gray, linewidth=1, style=plot.style_circles, title="MA2 F3", offset=3, show_last=1)
plot( MA_2Visible ? MA2Forecast4 : na, color=color.gray, linewidth=1, style=plot.style_circles, title="MA2 F4", offset=4, show_last=1)
plot( MA_2Visible ? MA2Forecast5 : na, color=color.gray, linewidth=1, style=plot.style_circles, title="MA2 F5", offset=5, show_last=1)
MA3Forecast1 = MA_3Period > 1 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_3Type, MA_3Source, MA_3Period - 1)) * (MA_3Period - 1) + ((MA_3Source * 1) )) / MA_3Period : na
MA3Forecast2 = MA_3Period > 2 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_3Type, MA_3Source, MA_3Period - 2)) * (MA_3Period - 2) + ((MA_3Source * 2) )) / MA_3Period : na
MA3Forecast3 = MA_3Period > 3 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_3Type, MA_3Source, MA_3Period - 3)) * (MA_3Period - 3) + ((MA_3Source * 3) )) / MA_3Period : na
MA3Forecast4 = MA_3Period > 4 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_3Type, MA_3Source, MA_3Period - 4)) * (MA_3Period - 4) + ((MA_3Source * 4) )) / MA_3Period : na
MA3Forecast5 = MA_3Period > 5 ? (request.security(syminfo.tickerid, timeframe.period, ma(MA_3Type, MA_3Source, MA_3Period - 5)) * (MA_3Period - 5) + ((MA_3Source * 5) )) / MA_3Period : na
plot( MA_3Visible ? MA3Forecast1 : na, color=color.gray, linewidth=1, style=plot.style_circles, title="MA3 F1", offset=1, show_last=1)
plot( MA_3Visible ? MA3Forecast2 : na, color=color.gray, linewidth=1, style=plot.style_circles, title="MA3 F2", offset=2, show_last=1)
plot( MA_3Visible ? MA3Forecast3 : na, color=color.gray, linewidth=1, style=plot.style_circles, title="MA3 F3", offset=3, show_last=1)
plot( MA_3Visible ? MA3Forecast4 : na, color=color.gray, linewidth=1, style=plot.style_circles, title="MA3 F4", offset=4, show_last=1)
plot( MA_3Visible ? MA3Forecast5 : na, color=color.gray, linewidth=1, style=plot.style_circles, title="MA3 F5", offset=5, show_last=1)
//_____________________________________________________________________________________________
// Parabolic SAR
//_____________________________________________________________________________________________
htclose = request.security(syminfo.tickerid, timeframe.period, close)
psar = ta.sar(start, increment, maximum)
Trend_SAR = psar < htclose ? 1 : -1
//Plot line and fill
upPlot = plot(PSAR_Visible and Trend_SAR == 1 ? psar : na, title='Uptrend', style=plot.style_circles, color=#12DA00, linewidth=1)
dnPlot = plot(PSAR_Visible and Trend_SAR == -1 ? psar : na, title='Downtrend', style=plot.style_circles, color=#FF0000, linewidth=1)
mPlot = plot(PSAR_Visible ? ohlc4 : na, title="", style=plot.style_circles, linewidth=0, editable = false)
fillColor = PSAR_Visible and highlighting ? (Trend_SAR == 1 ? color.new(#12DA00, 90) : color.new(#CC0000, 90)) : na
fill(mPlot, upPlot, title="UpTrend Highligter", color=fillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=fillColor)
//Plot Long Signal
buySignal = Trend_SAR == 1 and Trend_SAR[1] == -1
plotshape(PSAR_Visible and buySignal and showsignals ? psar : na, title="PSAR Buy", text="B", location=location.absolute, style=shape.labelup, size=size.tiny, color=#0EAE00, textcolor=color.white)
//Plot Short Signal
sellSignal = Trend_SAR == -1 and Trend_SAR[1] == 1
plotshape(PSAR_Visible and sellSignal and showsignals ? psar : na, title="PSAR Sell", text="S", location=location.absolute, style=shape.labeldown, size=size.tiny, color=#CC0000, textcolor=color.white)
//_____________________________________________________________________________________________
// Bollinger Bands
//_____________________________________________________________________________________________
basis = ma(BB_Type, src_BB, length_BB)
stdDevBB = ta.stdev(src_BB, length_BB)
devBase = mult_BB * stdDevBB
upperBB = basis + devBase
lowerBB = basis - devBase
disp_up = basis + ((upperBB - lowerBB) * dispersion)
disp_down = basis - ((upperBB - lowerBB) * dispersion)
devInc1 = (mult_BB + 0.5) * stdDevBB
devInc2 = (mult_BB + (0.5 * 2)) * stdDevBB
[_, upperKC, lowerKC] = ta.kc(src_BB, length_BB, mult_KC, True_Range)
sqzOn = lowerBB > lowerKC and upperBB < upperKC
sqzOff = lowerBB < lowerKC and upperBB > upperKC
noSqz = sqzOn == false and sqzOff == false
rojo = color.new(#FF5500, 0)
rojo85 = color.new(#FF5500, 85)
rojo80 = color.new(#FF5500, 80)
azul = color.new(#004EF7, 0)
azul85 = color.new(#004EF7, 85)
azul80 = color.new(#004EF7, 80)
color_Squeeze = sqzOn or noSqz ? #00FFBB : #88A7FE
color_Squeeze2 = sqzOn or noSqz ? color.new(#00FFBB, 90) : color.new(#88A7FE, 95)
plot(BB_Visible ? basis : na, "Basis", color_Squeeze, 2)
plot(BB_Visible ? basis[length_BB-1] : na, "Basis Trail", color_black, 2, offset=((length_BB-1)*-1))
p1 = plot(BB_Visible ? upperBB : na, "Upper", rojo)
p2 = plot(BB_Visible ? lowerBB : na, "Lower", azul)
fill(p1, p2, title = "BB Background", color = color_Squeeze2)
plot(BB_Visible ? upperBB[length_BB-1] : na, "Upper Trail", color_black, offset=((length_BB-1)*-1))
plot(BB_Visible ? lowerBB[length_BB-1] : na, "Lower Trail", color_black, offset=((length_BB-1)*-1))
plot(show_bands ? (basis + devInc1) : na, "Upper - Middle Band", rojo85, 2)
plot(show_bands ? (basis + devInc2) : na, "Upper - Top Band", rojo80, 2)
plot(show_bands ? (basis - devInc1) : na, "Lower - Middle Band", azul85, 2)
plot(show_bands ? (basis - devInc2) : na, "Lower - Low Band", azul80, 2)
p3 = plot(show_disp ? disp_up : na, color=color_black)
p4 = plot(show_disp ? disp_down : na, color=color_black)
fill(p3, p4, title = "Dispersion Background", color = color.new(#FEDF88, 97))
BBForecast1 = length_BB > 1 ? (request.security(syminfo.tickerid, timeframe.period, ma(BB_Type, src_BB, length_BB - 1)) * (length_BB - 1) + ((src_BB * 1) )) / length_BB : na
BBForecast2 = length_BB > 2 ? (request.security(syminfo.tickerid, timeframe.period, ma(BB_Type, src_BB, length_BB - 2)) * (length_BB - 2) + ((src_BB * 2) )) / length_BB : na
BBForecast3 = length_BB > 3 ? (request.security(syminfo.tickerid, timeframe.period, ma(BB_Type, src_BB, length_BB - 3)) * (length_BB - 3) + ((src_BB * 3) )) / length_BB : na
plot(BB_Visible ? BBForecast1 : na, "BB F1", #9A9EEC, 1, plot.style_circles, offset=1, show_last=1)
plot(BB_Visible ? BBForecast2 : na, "BB F2", #9A9EEC, 1, plot.style_circles, offset=2, show_last=1)
plot(BB_Visible ? BBForecast3 : na, "BB F3", #9A9EEC, 1, plot.style_circles, offset=3, show_last=1)
//______________________________________________________________________________
// Volume Weighted Colored Bars by KIVANÇ ÖZBİLGİÇ
// https://www.tradingview.com/script/8RPiMMmn-Volume-Based-Coloured-Bars/
//______________________________________________________________________________
volMA = ta.sma(volume, vbcbLength)
vwcbColor = if close < open
if volume > volMA * vwcbUpper
#FF0000 // Red
else if volume < volMA * vwcbLower
#820000 // Dark Red
else
if volume > volMA * vwcbUpper
#3FFF5E // Screamin' Green
else if volume < volMA * vwcbLower
#208230 // Forest Green
barcolor(VBCB_Visible and nz(volume) ? vwcbColor : na, title = "Volume Weighted Colored Bars", show_last = v_show_last)
//______________________________________________________________________________________
// LMA (Laguerre) v2 - multi timeframe by TheLark
// https://www.tradingview.com/script/u3irwHjc-TheLark-LMA-Laguerre-v2-multi-timeframe/
//______________________________________________________________________________________
lag(g) =>
L0 = 0.0
L1 = 0.0
L2 = 0.0
L3 = 0.0
L0 := (1 - g) * src_L + g * nz(L0[1])
L1 := -g * L0 + nz(L0[1]) + g * nz(L1[1])
L2 := -g * L1 + nz(L1[1]) + g * nz(L2[1])
L3 := -g * L2 + nz(L2[1]) + g * nz(L3[1])
f = (L0 + 2 * L1 + 2 * L2 + L3) / 6
f
lma = request.security(syminfo.tickerid, res_LMA, lag(Gamma))
col = 0.0
col := ccol ? lma == lma[1] and col[1] == 1 ? 1 :
lma == lma[1] and col[1] == 2 ? 2 : lma > lma[1] ? 1 : 2 : 2
color_lag = col < 2 ? #00CC96 : #FF3571
color_dots = col < 2 ? color.new(#00CC96, 60) : color.new(#FF3571, 60)
up = col < col[1] ? 1 : 0
down = col > col[1] ? 1 : 0
plot(LMA_Visible ? lma : na, title = "MT Laguerre", color = color_lag, linewidth = 2)
plot(LMA_Visible and sd and ta.cross(up, down) ? lma : na, style=plot.style_circles, linewidth = 7, color = color_dots)
//_____________________________________________________________________________________________
// Based on "Linear Regression (Log Scale)" - Author: @Forza
// https://www.tradingview.com/script/cxcEYTkE-Linear-Regression-Log-Scale/
//_____________________________________________________________________________________________
srcLR = request.security(syminfo.tickerid, timeframe.period, math.log(sourceLR))
extend = extendLines ? extend.right : extend.none
calcSlope(src, len) =>
if not barstate.islast or len <= 1
[float(na), float(na), float(na)]
else
sumX = 0.0
sumY = 0.0
sumXSqr = 0.0
sumXY = 0.0
for i = 0 to len - 1
val = src[i]
per = i + 1.0
sumX := sumX + per
sumY := sumY + val
sumXSqr := sumXSqr + per * per
sumXY := sumXY + val * per
slope = (len * sumXY - sumX * sumY) / (len * sumXSqr - sumX * sumX)
average = sumY / len
intercept = average - slope * sumX / len + slope
[slope, average, intercept]
[s, aa, i] = calcSlope(srcLR, lenLR)
startPrice = i + s * (lenLR - 1)
endPrice = i
var line baseLineR = na
if LR_Visible and na(baseLineR) and not na(startPrice)
baseLineR := line.new(bar_index - lenLR + 1, math.exp(startPrice), bar_index, math.exp(endPrice), width=2, extend=extend, color = rojo)
else
line.set_xy1(baseLineR, bar_index - lenLR + 1, startPrice)
line.set_xy2(baseLineR, bar_index, endPrice)
na
calcDev(src, len, slope, average, intercept) =>
upDev = 0.0
dnDev = 0.0
stdDevAcc = 0.0
dsxx = 0.0
dsyy = 0.0
dsxy = 0.0
periods = len - 1
daY = intercept + (slope * periods) / 2
val = intercept
for i = 0 to periods
price = high[i] - val
if (price > upDev)
upDev := price
price := val - low[i]
if (price > dnDev)
dnDev := price
price := src[i]
dxt = price - average
dyt = val - daY
price := price - val
stdDevAcc := stdDevAcc + price * price
dsxx := dsxx + dxt * dxt
dsyy := dsyy + dyt * dyt
dsxy := dsxy + dxt * dyt
val := val + slope
stdDev = math.sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / math.sqrt(dsxx * dsyy)
[stdDev, pearsonR, upDev, dnDev]
[stdDev, pearsonR, upDev, dnDev] = calcDev(srcLR, lenLR, s, aa, i)
upperStartPrice = startPrice + (useUpperDev ? upperMult * stdDev : upDev)
upperEndPrice = endPrice + (useUpperDev ? upperMult * stdDev : upDev)
var line upper = na
lowerStartPrice = startPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
lowerEndPrice = endPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
var line lower = na
if LR_Visible and na(upper) and not na(upperStartPrice)
upper := line.new(bar_index - lenLR + 1, math.exp(upperStartPrice), bar_index, math.exp(upperEndPrice), width=1, extend=extend, color = azul)
else
line.set_xy1(upper, bar_index - lenLR + 1, upperStartPrice)
line.set_xy2(upper, bar_index, upperEndPrice)
na
if LR_Visible and na(lower) and not na(lowerStartPrice)
lower := line.new(bar_index - lenLR + 1, math.exp(lowerStartPrice), bar_index, math.exp(lowerEndPrice), width=1, extend=extend, color = azul)
else
line.set_xy1(lower, bar_index - lenLR + 1, lowerStartPrice)
line.set_xy2(lower, bar_index, lowerEndPrice)
na
// Pearson`s R
var label r = na
transparent = color.new(color.white, 100)
label.delete(r[1])
if LR_Visible and showPearson and not na(pearsonR)
r := label.new(bar_index - lenLR + 1, math.exp(lowerStartPrice), str.tostring(pearsonR, "#.#####"), color=transparent, textcolor = azul, size=size.normal, style=label.style_label_up)
//______________________________________________________________________________
// Based on "Volume Profile" - Author: @kv4coins
// https://www.tradingview.com/script/r3VrWAO4-Volume-Profile/
//______________________________________________________________________________
//// INPUTS
VP_Visible = input.bool(false, "⮩ Visible", group ="Volume Profile")
vp_lookback = input.int(defval = 220,
title = "Volume Lookback Depth [10-500]",
minval = 10,
maxval = 500, group="Volume Profile")
vp_max_bars = input.int(defval = 500,
title = "Number of Bars [10-500]",
minval = 10,
maxval = 500, group="Volume Profile")
vp_bar_mult = input.int(defval = 50,
title = "Bar Length Multiplier [10-100]",
minval = 10,
maxval = 100, group="Volume Profile")
vp_bar_offset = input.int(defval = 55,
title = "Bar Horizontal Offset [0-100]",
minval = 0,
maxval = 100, group="Volume Profile")
vp_bar_width = input.int(defval = 2,
title = "Bar Width [1-20]",
minval = 1,
maxval = 20, group="Volume Profile")
vp_delta_type = input.string(defval = "Both",
title = "Delta Type",
options = ['Both', 'Bullish', 'Bearish'], group="Volume Profile")
vp_poc_show = input.bool(defval = true,
title = "Show POC Line",
group="Volume Profile")
vp_bar_color = input.color(defval = color.new(#EFEFBF, 80) ,
title = "Area Color",
inline ="colVP", group="Volume Profile")
vp_poc_color = input.color(defval = color.new(#B71C1C, 0),
title = "POC Color",
inline ="colVP", group="Volume Profile")
//// VARIABLES
float vp_Vmax = 0.0
int vp_VmaxId = 0
int vp_N_BARS = vp_max_bars
var int vp_first = time
vp_a_P = array.new_float((vp_N_BARS + 1), 0.0)
vp_a_V = array.new_float(vp_N_BARS, 0.0)
vp_a_D = array.new_float(vp_N_BARS, 0.0)
vp_a_W = array.new_int(vp_N_BARS, 0)
//// CALCULATIONS
float vp_HH = ta.highest(high, vp_lookback)
float vp_LL = ta.lowest(low, vp_lookback)
if barstate.islast and VP_Visible
float vp_HL = (vp_HH - vp_LL) / vp_N_BARS
for j = 1 to (vp_N_BARS + 1)
array.set(vp_a_P, (j-1), (vp_LL + vp_HL * j))
for i = 0 to (vp_lookback - 1)
int Dc = 0
array.fill(vp_a_D, 0.0)
for j = 0 to (vp_N_BARS - 1)
float Pj = array.get(vp_a_P, j)
if low[i] < Pj and high[i] > Pj and (vp_delta_type == "Bullish" ?
close[i] >= open[i] : (vp_delta_type == "Bearish" ? close[i] <= open[i] : true))
float Dj = array.get(vp_a_D, j)
float dDj = Dj + nz(volume[i])
array.set(vp_a_D, j, dDj)
Dc := Dc + 1
for j = 0 to (vp_N_BARS - 1)
float Vj = array.get(vp_a_V, j)
float Dj = array.get(vp_a_D, j)
float dVj = Vj + ((Dc > 0) ? (Dj / Dc) : 0.0)
array.set(vp_a_V, j, dVj)
vp_Vmax := array.max(vp_a_V)
vp_VmaxId := array.indexof(vp_a_V, vp_Vmax)
for j = 0 to (vp_N_BARS - 1)
float Vj = array.get(vp_a_V, j)
int Aj = math.round(vp_bar_mult * Vj / vp_Vmax)
array.set(vp_a_W, j, Aj)
//// PLOTING
if barstate.isfirst and VP_Visible
vp_first := time
vp_change = ta.change(time)
vp_x_loc = timenow + math.round(vp_change * vp_bar_offset)
if barstate.islast and VP_Visible
for ind = 0 to (vp_N_BARS - 1) by 1
x1 = ((vp_VmaxId == ind) and vp_poc_show) ? math.max(time[vp_lookback], vp_first) :
(timenow + math.round(vp_change * (vp_bar_offset - array.get(vp_a_W, ind))))
ys = array.get(vp_a_P, ind)
line.new(x1 = x1,
y1 = ys,
x2 = vp_x_loc,
y2 = ys,
xloc = xloc.bar_time,
extend = extend.none,
color = (vp_VmaxId == ind ? vp_poc_color : vp_bar_color),
style = line.style_solid,
width = vp_bar_width) |
Bank Levels - Psychological Levels - Bitcoin, Indices, Forex | https://www.tradingview.com/script/bnCtnxwC-Bank-Levels-Psychological-Levels-Bitcoin-Indices-Forex/ | ShitCoinInc | https://www.tradingview.com/u/ShitCoinInc/ | 397 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © cryptomachine2
//@version=4
study("Bank Levels", overlay=true)
var levels = input(5, title="Number of levels", type=input.integer)
var lineColor = input(color.white, "Line color", type=input.color)
var lineWidth = input(1, title="Line width", type=input.integer)
var spacing = if syminfo.ticker == 'XAUUSD'
25000
else if syminfo.ticker == 'SPX500USD'
500
else if syminfo.ticker == 'NAS100USD'
2500
else if syminfo.ticker == 'US30USD'
2500
else if syminfo.ticker == 'BTCUSDT'
500000
else if syminfo.type == 'crypto'
500
else if syminfo.type == 'forex'
500
else
2500
var step = syminfo.mintick * spacing
if barstate.islast
//label.new(bar_index, low, text=syminfo.type, yloc=yloc.abovebar)
for counter = 0 to levels - 1
price = if syminfo.type == 'index'
ceil(close / 4) * 4
else
close
stepUp = ceil(price / step) * step + (counter * step)
stepDown = floor(price / step) * step - (counter * step)
line.new(bar_index, stepUp, bar_index - 1, stepUp, xloc=xloc.bar_index, extend=extend.both, color=lineColor, width=lineWidth, style=line.style_dashed)
line.new(bar_index, stepDown, bar_index - 1, stepDown, xloc=xloc.bar_index, extend=extend.both, color=lineColor, width=lineWidth, style=line.style_dashed)
|
User Selectable Moving Average Guppy | https://www.tradingview.com/script/fWqRmZCA-User-Selectable-Moving-Average-Guppy/ | animecummer | https://www.tradingview.com/u/animecummer/ | 321 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Credit: LucF from PineCoders for the Gradient Coloring function, see Color Gradient Framework tutorial
//@version=5
indicator(title='User Selectable Moving Average Guppy', shorttitle='User Selectable MA Guppy', overlay=true, timeframe="", timeframe_gaps=true)
lsmaoffset = input.int(title='LEAST SQUARES (LSMA) ONLY - LS Offset', defval=0, inline='3')
almaoffset = input.float(title='ALMA Offset', defval=0.85, step=0.01, inline='4')
almasigma = input.float(title='ALMA Sigma', defval=6, inline='4')
a1 = input.float(title='Tillson T3 Volume Factor', defval=0.7, inline='5', step=0.001)
f_ehma(_source, _length) =>
_return = ta.ema(2 * ta.ema(_source, _length / 2) - ta.ema(_source, _length), math.round(math.sqrt(_length)))
_return
f_tema(_source, _length) =>
_out = 3 * (ta.ema(_source, _length) - ta.ema(ta.ema(_source, _length), _length)) + ta.ema(ta.ema(ta.ema(_source, _length), _length), _length)
_out
f_t3(_source, _length, _a1) =>
_output = (-_a1 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(ta.ema(ta.ema(ta.ema(_source, _length), _length), _length), _length), _length), _length)) + (3 * _a1 * _a1 + 3 * _a1 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(ta.ema(ta.ema(_source, _length), _length), _length), _length), _length)) + (-6 * _a1 * _a1 - 3 * _a1 - 3 * _a1 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(ta.ema(_source, _length), _length), _length), _length)) + (1 + 3 * _a1 + _a1 * _a1 * _a1 + 3 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(_source, _length), _length), _length))
_output
MA(source, length, type) =>
type == 'SMA' ? ta.sma(source, length) :
type == 'EMA' ? ta.ema(source, length) :
type == 'SMMA (RMA)' ? ta.rma(source, length) :
type == 'WMA' ? ta.wma(source, length) :
type == 'VWMA' ? ta.vwma(source, length) :
type == 'HMA' ? ta.hma(source, length) :
type == 'EHMA' ? f_ehma(source, length) :
type == 'TEMA' ? f_tema(source, length) :
type == 'ALMA' ? ta.alma(source, length, almaoffset, almasigma) :
type == 'Tillson T3' ? f_t3(source, length, a1) :
type == 'LSMA' ? ta.linreg(source, length, lsmaoffset) : na
//COLOR INPUTS
color ltfbullma = input.color(color.new(color.aqua, 50), 'Lower TF', inline='6')
color ltfbearma = input.color(color.new(color.orange, 50), 'Lower TF', inline='6')
color bullma = input.color(color.new(color.aqua, 75), 'HTF', inline='6')
color bearma = input.color(color.new(color.orange, 75), 'HTF', inline='6')
//GRADIENT
showlabels = input.bool(title='Label HTF Crosses?', defval=false, inline='49')
colorgrad = input.bool(defval=true, title='Fill HTF Gradient?', inline='49')
color bullfill = input.color(color.aqua, '', inline='49')
color bearfill = input.color(color.orange, '', inline='49')
gradmult = input.float(0.25, title='Gradient \'Intensity\' (Higher = more intense)', step=0.01, inline='52')
gradconst = input.int(1, title='Gradient Constant (Higher = less intense)', minval=-100, maxval=100, inline='53')
gradlimit = input.int(99, title='Gradient Transparency Limit', minval=0, maxval=100, inline='54')
// —————————————————————————————————————————
// ————— Advance/Decline Gradient (Credit: LucF from PineCoders)
// —————————————————————————————————————————
// ————— Function returning one of the bull/bear colors in a transparency proportional to the current qty of advances/declines
// relative to the historical max qty of adv/dec for this `_source`.
f_c_gradientAdvDec(_source, _center, _c_bear, _c_bull) =>
// float _source: input signal.
// float _center: centerline used to determine if signal is bull/bear.
// color _c_bear: most bearish color.
// color _c_bull: most bullish color.
// Dependency: `f_colorNew()`
var float _maxAdvDec = 0.
var float _qtyAdvDec = 0.
bool _xUp = ta.crossover(_source, _center)
bool _xDn = ta.crossunder(_source, _center)
float _chg = ta.change(_source)
bool _up = _chg > 0
bool _dn = _chg < 0
bool _srcBull = _source > _center
bool _srcBear = _source < _center
_qtyAdvDec := _srcBull ? _xUp ? 1 : _up ? _qtyAdvDec + 1 : _dn ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec : _srcBear ? _xDn ? 1 : _dn ? _qtyAdvDec + 1 : _up ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec : _qtyAdvDec
// Keep track of max qty of advances/declines.
_maxAdvDec := math.max(_maxAdvDec, _qtyAdvDec)
// Calculate transparency from the current qty of advances/declines relative to the historical max qty of adv/dec for this `_source`.
float _transp = 100 - _qtyAdvDec * 100 / _maxAdvDec * gradmult + gradconst
_transp2 = _transp > gradlimit ? gradlimit : _transp
var color _return = na
_return := _srcBull ? color.new(_c_bull, _transp2) : _srcBear ? color.new(_c_bear, _transp2) : _return
_return
//KEY MA
show_MA22 = input.bool(true, 'MA №22', inline='MA #22', group='Higher Timeframe Key MAs (Alerts/Signals)')
MA22_type = input.string('HMA', '', inline='MA #22', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Higher Timeframe Key MAs (Alerts/Signals)')
MA22_source = input.source(close, '', inline='MA #22', group='Higher Timeframe Key MAs (Alerts/Signals)')
MA22_length = input.int(55, '', inline='MA #22', minval=1, group='Higher Timeframe Key MAs (Alerts/Signals)')
MA22 = MA(MA22_source, MA22_length, MA22_type)
show_MA23 = input.bool(true, 'MA №23', inline='MA #23', group='Higher Timeframe Key MAs (Alerts/Signals)')
MA23_type = input.string('HMA', '', inline='MA #23', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Higher Timeframe Key MAs (Alerts/Signals)')
MA23_source = input.source(close, '', inline='MA #23', group='Higher Timeframe Key MAs (Alerts/Signals)')
MA23_length = input.int(200, '', inline='MA #23', minval=1, group='Higher Timeframe Key MAs (Alerts/Signals)')
MA23 = MA(MA23_source, MA23_length, MA23_type)
//FAST
show_MA1 = input.bool(true, 'MA №1', inline='MA #1', group='Multiple Moving Average Guppy Ribbon')
MA1_type = input.string('HMA', '', inline='MA #1', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA1_source = input.source(close, '', inline='MA #1', group='Multiple Moving Average Guppy Ribbon')
MA1_length = input.int(3, '', inline='MA #1', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA1 = MA(MA1_source, MA1_length, MA1_type)
show_MA2 = input.bool(true, 'MA №2', inline='MA #2', group='Multiple Moving Average Guppy Ribbon')
MA2_type = input.string('HMA', '', inline='MA #2', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA2_source = input.source(close, '', inline='MA #2', group='Multiple Moving Average Guppy Ribbon')
MA2_length = input.int(5, '', inline='MA #2', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA2 = MA(MA2_source, MA2_length, MA2_type)
show_MA3 = input.bool(true, 'MA №3', inline='MA #3', group='Multiple Moving Average Guppy Ribbon')
MA3_type = input.string('HMA', '', inline='MA #3', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA3_source = input.source(close, '', inline='MA #3', group='Multiple Moving Average Guppy Ribbon')
MA3_length = input.int(9, '', inline='MA #3', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA3 = MA(MA3_source, MA3_length, MA3_type)
show_MA4 = input.bool(true, 'MA №4', inline='MA #4', group='Multiple Moving Average Guppy Ribbon')
MA4_type = input.string('HMA', '', inline='MA #4', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA4_source = input.source(close, '', inline='MA #4', group='Multiple Moving Average Guppy Ribbon')
MA4_length = input.int(12, '', inline='MA #4', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA4 = MA(MA4_source, MA4_length, MA4_type)
show_MA5 = input.bool(true, 'MA №5', inline='MA #5', group='Multiple Moving Average Guppy Ribbon')
MA5_type = input.string('HMA', '', inline='MA #5', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA5_source = input.source(close, '', inline='MA #5', group='Multiple Moving Average Guppy Ribbon')
MA5_length = input.int(15, '', inline='MA #5', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA5 = MA(MA5_source, MA5_length, MA5_type)
show_MA6 = input.bool(true, 'MA №6', inline='MA #6', group='Multiple Moving Average Guppy Ribbon')
MA6_type = input.string('HMA', '', inline='MA #6', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA6_source = input.source(close, '', inline='MA #6', group='Multiple Moving Average Guppy Ribbon')
MA6_length = input.int(18, '', inline='MA #6', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA6 = MA(MA6_source, MA6_length, MA6_type)
show_MA7 = input.bool(true, 'MA №7', inline='MA #7', group='Multiple Moving Average Guppy Ribbon')
MA7_type = input.string('HMA', '', inline='MA #7', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA7_source = input.source(close, '', inline='MA #7', group='Multiple Moving Average Guppy Ribbon')
MA7_length = input.int(21, '', inline='MA #7', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA7 = MA(MA7_source, MA7_length, MA7_type)
//SLOW
show_MA8 = input.bool(true, 'MA №8', inline='MA #8', group='Multiple Moving Average Guppy Ribbon')
MA8_type = input.string('HMA', '', inline='MA #8', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA8_source = input.source(close, '', inline='MA #8', group='Multiple Moving Average Guppy Ribbon')
MA8_length = input.int(24, '', inline='MA #8', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA8 = MA(MA8_source, MA8_length, MA8_type)
show_MA9 = input.bool(true, 'MA №9', inline='MA #9', group='Multiple Moving Average Guppy Ribbon')
MA9_type = input.string('HMA', '', inline='MA #9', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA9_source = input.source(close, '', inline='MA #9', group='Multiple Moving Average Guppy Ribbon')
MA9_length = input.int(26, '', inline='MA #9', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA9 = MA(MA9_source, MA9_length, MA9_type)
show_MA10 = input.bool(true, 'MA №10', inline='MA #10', group='Multiple Moving Average Guppy Ribbon')
MA10_type = input.string('HMA', '', inline='MA #10', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA10_source = input.source(close, '', inline='MA #10', group='Multiple Moving Average Guppy Ribbon')
MA10_length = input.int(28, '', inline='MA #10', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA10 = MA(MA10_source, MA10_length, MA10_type)
show_MA11 = input.bool(true, 'MA №11', inline='MA #11', group='Multiple Moving Average Guppy Ribbon')
MA11_type = input.string('HMA', '', inline='MA #11', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA11_source = input.source(close, '', inline='MA #11', group='Multiple Moving Average Guppy Ribbon')
MA11_length = input.int(30, '', inline='MA #11', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA11 = MA(MA11_source, MA11_length, MA11_type)
show_MA12 = input.bool(true, 'MA №12', inline='MA #12', group='Multiple Moving Average Guppy Ribbon')
MA12_type = input.string('HMA', '', inline='MA #12', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA12_source = input.source(close, '', inline='MA #12', group='Multiple Moving Average Guppy Ribbon')
MA12_length = input.int(32, '', inline='MA #12', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA12 = MA(MA12_source, MA12_length, MA12_type)
show_MA13 = input.bool(true, 'MA №13', inline='MA #13', group='Multiple Moving Average Guppy Ribbon')
MA13_type = input.string('HMA', '', inline='MA #13', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA13_source = input.source(close, '', inline='MA #13', group='Multiple Moving Average Guppy Ribbon')
MA13_length = input.int(34, '', inline='MA #13', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA13 = MA(MA13_source, MA13_length, MA13_type)
show_MA14 = input.bool(true, 'MA №14', inline='MA #14', group='Multiple Moving Average Guppy Ribbon')
MA14_type = input.string('HMA', '', inline='MA #14', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA14_source = input.source(close, '', inline='MA #14', group='Multiple Moving Average Guppy Ribbon')
MA14_length = input.int(36, '', inline='MA #14', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA14 = MA(MA14_source, MA14_length, MA14_type)
show_MA15 = input.bool(true, 'MA №15', inline='MA #15', group='Multiple Moving Average Guppy Ribbon')
MA15_type = input.string('HMA', '', inline='MA #15', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA15_source = input.source(close, '', inline='MA #15', group='Multiple Moving Average Guppy Ribbon')
MA15_length = input.int(38, '', inline='MA #15', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA15 = MA(MA15_source, MA15_length, MA15_type)
show_MA16 = input.bool(true, 'MA №16', inline='MA #16', group='Multiple Moving Average Guppy Ribbon')
MA16_type = input.string('HMA', '', inline='MA #16', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA16_source = input.source(close, '', inline='MA #16', group='Multiple Moving Average Guppy Ribbon')
MA16_length = input.int(40, '', inline='MA #16', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA16 = MA(MA16_source, MA16_length, MA16_type)
show_MA17 = input.bool(true, 'MA №17', inline='MA #17', group='Multiple Moving Average Guppy Ribbon')
MA17_type = input.string('HMA', '', inline='MA #17', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA17_source = input.source(close, '', inline='MA #17', group='Multiple Moving Average Guppy Ribbon')
MA17_length = input.int(42, '', inline='MA #17', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA17 = MA(MA17_source, MA17_length, MA17_type)
show_MA18 = input.bool(true, 'MA №18', inline='MA #18', group='Multiple Moving Average Guppy Ribbon')
MA18_type = input.string('HMA', '', inline='MA #18', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA18_source = input.source(close, '', inline='MA #18', group='Multiple Moving Average Guppy Ribbon')
MA18_length = input.int(44, '', inline='MA #18', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA18 = MA(MA18_source, MA18_length, MA18_type)
show_MA19 = input.bool(true, 'MA №19', inline='MA #19', group='Multiple Moving Average Guppy Ribbon')
MA19_type = input.string('HMA', '', inline='MA #19', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA19_source = input.source(close, '', inline='MA #19', group='Multiple Moving Average Guppy Ribbon')
MA19_length = input.int(46, '', inline='MA #19', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA19 = MA(MA19_source, MA19_length, MA19_type)
show_MA20 = input.bool(true, 'MA №20', inline='MA #20', group='Multiple Moving Average Guppy Ribbon')
MA20_type = input.string('HMA', '', inline='MA #20', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA20_source = input.source(close, '', inline='MA #20', group='Multiple Moving Average Guppy Ribbon')
MA20_length = input.int(48, '', inline='MA #20', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA20 = MA(MA20_source, MA20_length, MA20_type)
show_MA21 = input.bool(true, 'MA №21', inline='MA #21', group='Multiple Moving Average Guppy Ribbon')
MA21_type = input.string('HMA', '', inline='MA #21', options=['SMA', 'EMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA', 'EHMA', 'TEMA', 'ALMA', 'Tillson T3', 'LSMA'], group='Multiple Moving Average Guppy Ribbon')
MA21_source = input.source(close, '', inline='MA #21', group='Multiple Moving Average Guppy Ribbon')
MA21_length = input.int(50, '', inline='MA #21', minval=1, group='Multiple Moving Average Guppy Ribbon')
MA21 = MA(MA21_source, MA21_length, MA21_type)
//PLOTS
basecolorfast = MA23 > MA22 ? bearma : bullma
basecolorslow = MA23 > MA22 ? bearma : bullma
color c_1 = f_c_gradientAdvDec(MA22, MA23, bearfill, bullfill)
//Fast MA Plots
p1 = plot(show_MA1 ? MA1 : na, title='Fast MA 1', linewidth=1, color=MA1 > MA1[1] ? ltfbullma : ltfbearma)
p2 = plot(show_MA2 ? MA2 : na, title='Fast MA 2', linewidth=1, color=MA2 > MA2[1] ? ltfbullma : ltfbearma)
p3 = plot(show_MA3 ? MA3 : na, title='Fast MA 3', linewidth=1, color=MA3 > MA3[1] ? ltfbullma : ltfbearma)
p4 = plot(show_MA4 ? MA4 : na, title='Fast MA 4', linewidth=1, color=MA4 > MA4[1] ? ltfbullma : ltfbearma)
p5 = plot(show_MA5 ? MA5 : na, title='Fast MA 5', linewidth=1, color=MA5 > MA5[1] ? ltfbullma : ltfbearma)
p6 = plot(show_MA6 ? MA6 : na, title='Fast MA 6', linewidth=1, color=MA6 > MA6[1] ? ltfbullma : ltfbearma)
p7 = plot(show_MA7 ? MA7 : na, title='Fast MA 7', linewidth=1, color=MA7 > MA7[1] ? ltfbullma : ltfbearma)
//Slow MA Plots
p8 = plot(show_MA8 ? MA8 : na, title='Slow MA 8', linewidth=1, color=MA8 > MA8[1] ? ltfbullma : ltfbearma)
p9 = plot(show_MA9 ? MA9 : na, title='Slow MA 9', linewidth=1, color=MA9 > MA9[1] ? ltfbullma : ltfbearma)
p10 = plot(show_MA10 ? MA10 : na, title='Slow MA 10', linewidth=1, color=MA10 > MA10[1] ? ltfbullma : ltfbearma)
p11 = plot(show_MA11 ? MA11 : na, title='Slow MA 11', linewidth=1, color=MA11 > MA11[1] ? ltfbullma : ltfbearma)
p12 = plot(show_MA12 ? MA12 : na, title='Slow MA 12', linewidth=1, color=MA12 > MA12[1] ? ltfbullma : ltfbearma)
p13 = plot(show_MA13 ? MA13 : na, title='Slow MA 13', linewidth=1, color=MA13 > MA13[1] ? ltfbullma : ltfbearma)
p14 = plot(show_MA14 ? MA14 : na, title='Slow MA 14', linewidth=1, color=MA14 > MA14[1] ? ltfbullma : ltfbearma)
p15 = plot(show_MA15 ? MA15 : na, title='Slow MA 15', linewidth=1, color=MA15 > MA15[1] ? ltfbullma : ltfbearma)
p16 = plot(show_MA16 ? MA16 : na, title='Slow MA 16', linewidth=1, color=MA16 > MA16[1] ? ltfbullma : ltfbearma)
p17 = plot(show_MA17 ? MA17 : na, title='Slow MA 17', linewidth=1, color=MA17 > MA17[1] ? ltfbullma : ltfbearma)
p18 = plot(show_MA18 ? MA18 : na, title='Slow MA 18', linewidth=1, color=MA18 > MA18[1] ? ltfbullma : ltfbearma)
p19 = plot(show_MA19 ? MA19 : na, title='Slow MA 19', linewidth=1, color=MA19 > MA19[1] ? ltfbullma : ltfbearma)
p20 = plot(show_MA20 ? MA20 : na, title='Slow MA 20', linewidth=1, color=MA20 > MA20[1] ? ltfbullma : ltfbearma)
p21 = plot(show_MA21 ? MA21 : na, title='Slow MA 21', linewidth=1, color=MA21 > MA21[1] ? ltfbullma : ltfbearma)
//HTF KEY MA Plots
p22 = plot(show_MA22 ? MA22 : na, title='Slow MA 22', linewidth=2, color=basecolorfast)
p23 = plot(show_MA23 ? MA23 : na, title='Slow MA 23', linewidth=2, color=basecolorslow)
fill(p22, p23, colorgrad == true ? c_1 : color.new(color.white, 100), title='Adv/Dec MA fill')
//ALERTS
plotshape(showlabels and ta.crossover(MA22, MA23), title='Cross Long', style=shape.labelup, location=location.belowbar, text='LONG', textcolor=color.new(color.white, 0), color=color.new(color.teal, 0), size=size.small)
plotshape(showlabels and ta.crossunder(MA22, MA23), title='Cross Short', style=shape.labeldown, location=location.abovebar, text='SHORT', textcolor=color.new(color.white, 0), color=color.new(color.maroon, 0), size=size.small)
alertcondition(ta.crossover(MA22, MA23), 'HTF Bullish Cross', 'HTF Bullish Cross')
alertcondition(ta.crossunder(MA22, MA23), 'HTF Bearish Cross', 'HTF Bearish Cross') |
15m Candle Tool | https://www.tradingview.com/script/6ch71c2U-15m-Candle-Tool/ | SamRecio | https://www.tradingview.com/u/SamRecio/ | 303 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SamRecio
//@version=5
indicator('15m Candle Tool', shorttitle='15mCandleTool', overlay=true, precision=2, max_lines_count = 500, max_boxes_count = 500)
fteenbars = input.int(defval=10, title='# of 15m Bars on Display', minval=0, maxval=240, group = "15 Minute Candles")
green = input(defval=color.rgb(139, 255, 50, 55), title=' Up Color', group = "15 Minute Candles", inline = "2")
red = input(defval=color.rgb(255, 84, 50, 55), title=' Down Color', group = "15 Minute Candles", inline = "2")
lvl1_tog = input.bool(true, title = "Lvl 1", group = "measurments", inline = "1", tooltip = "How levels are drawn:\nGreen Candle = High(0.00) to Low(1.00)\nRed Candle = Low(0.00) to High(1.00)")
lvl1 = input.float(0.382, step = 0.01, title = "", group = "measurments", inline = "1")
lvl1_style = input.string(". . .", title = "", options = ["___","- - -",". . ."], group = "measurments", inline = "1")
lvl2_tog = input.bool(true, title = "Lvl 2", group = "measurments", inline = "2")
lvl2 = input.float(0.5, title = "", step = 0.01, group = "measurments", inline = "2")
lvl2_style = input.string("- - -", title = "", options = ["___","- - -",". . ."], group = "measurments", inline = "2")
lvl3_tog = input.bool(true, title = "Lvl 3", group = "measurments", inline = "3")
lvl3 = input.float(0.618, title = "", step = 0.01, group = "measurments", inline = "3")
lvl3_style = input.string(". . .", title = "", options = ["___","- - -",". . ."], group = "measurments", inline = "3")
display_5 = input.bool(true, title = "5 Minute ", group = "Display Countdowns", inline = "1")
color_5 = input.color(color.rgb(255, 84, 50), title = "", group = "Display Countdowns", inline = "1")
style_5 = input.string(". . .", title = "", options = ["___","- - -",". . ."], group = "Display Countdowns", inline = "1")
disp_5 = input.bool(false, title = "Display Line?", group = "Display Countdowns", inline = "1")
display_15 = input.bool(true, title = "15 Minute ", group = "Display Countdowns", inline = "2")
color_15 = input.color(color.rgb(50, 204, 255), title = "", group = "Display Countdowns", inline = "2")
style_15 = input.string("- - -", title = "", options = ["___","- - -",". . ."], group = "Display Countdowns", inline = "2")
disp_15 = input.bool(false, title = "Display Line?", group = "Display Countdowns", inline = "2")
display_hour = input.bool(true, title = "1 Hour ", group = "Display Countdowns", inline = "3")
color_60 = input.color(color.rgb(139, 255, 50), title = "", group = "Display Countdowns", inline = "3")
style_60 = input.string("___", title = "", options = ["___","- - -",". . ."], group = "Display Countdowns", inline = "3")
disp_60 = input.bool(false, title = "Display Line?", group = "Display Countdowns", inline = "3")
linestyle(_input) =>
_input == "___"?line.style_solid:
_input == "- - -"?line.style_dashed:
_input == ". . ."?line.style_dotted:
na
tf_check = timeframe.isminutes and (timeframe.multiplier == 1 or timeframe.multiplier == 3 or timeframe.multiplier == 5)
if tf_check == false
runtime.error("Please Use 1, 3, or 5 Minute chart.")
tf = timeframe.multiplier
tf60 = 60 / tf
tf15 = 15 / tf
tf5 = 5 / tf
o15 = tf == 1 ? open[15] : tf == 3 ? open[5] : tf == 5 ? open[3] : na
c15 = tf == 1 ? close[1] : tf == 3 ? close[1] : tf == 5 ? close[1] : na
hourcheck = timeframe.change("60")
fivecheck = timeframe.change("5")
fteencheck = timeframe.change("15")
barsback = fteenbars * (15 / tf)
var ftlow = close
var fthigh = close
if high > fthigh
fthigh := high
if low < ftlow
ftlow := low
if fteencheck
ftlow := low
fthigh := high
var line l = display_hour and disp_60?line.new(x1=bar_index + tf60, y1=close + 1, x2=bar_index + tf60, y2=close + 2, color=color_60, style=linestyle(style_60), extend=extend.both):na
if hourcheck and disp_60
line.set_x1(l,bar_index + tf60)
line.set_x2(l,bar_index + tf60)
line.set_y1(l,close + 1)
line.set_y2(l,close + 2)
var line z = display_5 and disp_5?line.new(x1=bar_index + tf5, y1=close + 1, x2=bar_index + tf5, y2=close + 2, color=color_5, style=linestyle(style_5), extend=extend.both):na
if fivecheck and disp_5
line.set_x1(z,bar_index + tf5)
line.set_x2(z,bar_index + tf5)
line.set_y1(z,close + 1)
line.set_y2(z,close + 2)
anchor = o15 < c15 ? fthigh[1] : ftlow[1]
seg = fthigh[1] - ftlow[1]
s5line = anchor + seg * (o15 < c15 ? -lvl1 : lvl1)
f0line = anchor + seg * (o15 < c15 ? -lvl2 : lvl2)
t5line = anchor + seg * (o15 < c15 ? -lvl3 : lvl3)
rg = o15 < c15 ? green : red
var line x = display_15 and disp_15?line.new(x1=bar_index + tf15, y1=close + 1, x2=bar_index + tf15, y2=close + 2, color=color_15, style=linestyle(style_15), extend=extend.both):na
var b = box.new(left=bar_index - 15 / tf, top=o15, right=bar_index - 1, bottom=c15, bgcolor=rg, border_color=rg)
var line fw1 = na
var line fw2 = na
var line fh = line.new(x1=bar_index - 15 / tf, y1=fthigh[1], x2=bar_index + tf15, y2=fthigh[1], color=color.new(rg,0), width=2)
var line fl = line.new(x1=bar_index - 15 / tf, y1=ftlow[1], x2=bar_index + tf15, y2=ftlow[1], color=color.new(rg,0), width=2)
var line fha = na
var line fla = na
var line fma = na
var line s5 = lvl1_tog?line.new(x1=bar_index - 15 / tf, y1=s5line, x2=bar_index + tf15 + 1, y2=s5line, color=color.rgb(255, 255, 255),style=linestyle(lvl1_style)):na
var line f0 = lvl2_tog?line.new(x1=bar_index - 15 / tf, y1=f0line, x2=bar_index + tf15 + 1, y2=f0line, color=color.rgb(255, 255, 255),style=linestyle(lvl2_style)):na
var line t5 = lvl3_tog?line.new(x1=bar_index - 15 / tf, y1=t5line, x2=bar_index + tf15 + 1, y2=t5line, color=color.rgb(255, 255, 255),style=linestyle(lvl3_style)):na
if fteencheck
if disp_15
line.set_x1(x,bar_index + tf15)
line.set_x2(x,bar_index + tf15)
line.set_y1(x,close + 1)
line.set_y2(x,close + 2)
if lvl1_tog
line.set_x1(s5,bar_index - 15 / tf)
line.set_x2(s5,bar_index + tf15)
line.set_y1(s5,s5line)
line.set_y2(s5,s5line)
if lvl2_tog
line.set_x1(f0,bar_index - 15 / tf)
line.set_x2(f0,bar_index + tf15)
line.set_y1(f0,f0line)
line.set_y2(f0,f0line)
if lvl3_tog
line.set_x1(t5,bar_index - 15 / tf)
line.set_x2(t5,bar_index + tf15)
line.set_y1(t5,t5line)
line.set_y2(t5,t5line)
line.set_x1(fh,bar_index - 15 / tf)
line.set_x2(fh,bar_index + tf15)
line.set_y1(fh,fthigh[1])
line.set_y2(fh,fthigh[1])
line.set_color(fh,rg)
line.set_x1(fl,bar_index - 15 / tf)
line.set_x2(fl,bar_index + tf15)
line.set_y1(fl,ftlow[1])
line.set_y2(fl,ftlow[1])
line.set_color(fl,rg)
fw1 := line.new(x1=bar_index - 15 / tf / 2, y1=math.max(o15,c15), x2=bar_index - 15 / tf / 2, y2=fthigh[1], color=color.new(rg,0))
fw2 := line.new(x1=bar_index - 15 / tf / 2, y1=math.min(o15,c15), x2=bar_index - 15 / tf / 2, y2=ftlow[1], color=color.new(rg,0))
b := box.new(left=bar_index - 15 / tf, top=o15, right=bar_index - 1, bottom=c15, bgcolor=rg, border_color=rg)
box.delete(b[barsback])
line.delete(fw1[barsback])
line.delete(fw2[barsback])
bar_secs = (tf * 60) // How many seconds in a bar
hourcount = (60 / tf) - ta.barssince(hourcheck) // How many bars in an hour - Number of bars lapsed = How many bars left in hour
sec = math.floor((timenow - time) / 1000) // (Current time - Bar start time) / 1000 = Number of Seconds since Bar start
seccount = bar_secs - sec // How many seconds in a bar - seconds since bar start = seconds left in bar
mins = math.floor(seccount / 60) // Seconds left in bar / 60 = Minutes left in bar
secs = seccount - (mins * 60) // Seconds left in bar - (minutes left in bar*60) = Seconds left until next minute
untilhour = (mins + (secs * .01)) + ((hourcount * tf) - tf) // (Minutes left in bar + Seconds left until next minute*0.01) + bars left in hour* timeframe)
untilfteen = untilhour - math.floor(untilhour / 15) * 15 //
untilfive = untilhour - math.floor(untilhour / 5) * 5 //
tablesize = input.string('normal', ' Table Size', inline='1', options=['small', 'normal', 'large','huge'], group = "Countdown Table")
horz = input.bool(false, title = "Use Flat Display?", group = "Countdown Table", inline = "1")
tableYpos = input.string('middle', 'Position ', inline='2', options=['top', 'middle', 'bottom'], group = "Countdown Table")
tableXpos = input.string('right', '', inline='2', options=['left', 'center', 'right'], group = "Countdown Table")
var table table1 = table.new(tableYpos + '_' + tableXpos, 3, 6)
add_zero(_input) =>
_input == 0? "00":
_input == 1? "01":
_input == 2? "02":
_input == 3? "03":
_input == 4? "04":
_input == 5? "05":
_input == 6? "06":
_input == 7? "07":
_input == 8? "08":
_input == 9? "09":
str.tostring(_input)
timeform(_input) =>
place1 = math.floor(_input)
place2 = (_input - math.floor(_input))*100
add_zero(place1) + ":" + add_zero(place2)
titlesize(_input) =>
tablesize == "huge"?"large":
tablesize == "large"?"normal":
tablesize == "normal"?"small":
tablesize == "small"?"tiny":na
if barstate.islast and display_5
if horz
table.cell(table1,0,0, text = "5 Min", text_color = color_5, text_size = titlesize(tablesize))
table.cell(table1,0,1, text = session.islastbar?"Market\nClosed":timeform(untilfive), text_color = color_5, text_size = tablesize)
if horz == false
table.cell(table1,0,0, text = "5 Min", text_color = color_5, text_size = titlesize(tablesize))
table.cell(table1,0,1, text = session.islastbar?"Market\nClosed":timeform(untilfive), text_color = color_5, text_size = tablesize)
if barstate.islast and display_15
if horz
table.cell(table1,1,0, text = "15 Min", text_color = color_15, text_size = titlesize(tablesize))
table.cell(table1,1,1, text = session.islastbar?"Market\nClosed":timeform(untilfteen), text_color = color_15, text_size = tablesize)
if horz == false
table.cell(table1,0,2, text = "15 Min", text_color = color_15, text_size = titlesize(tablesize))
table.cell(table1,0,3, text = session.islastbar?"Market\nClosed":timeform(untilfteen), text_color = color_15, text_size = tablesize)
if barstate.islast and display_hour
if horz
table.cell(table1,2,0, text = "1 Hour", text_color = color_60, text_size = titlesize(tablesize))
table.cell(table1,2,1, text = session.islastbar?"Market\nClosed":timeform(untilhour), text_color = color_60, text_size = tablesize)
if horz == false
table.cell(table1,0,4, text = "1 Hour", text_color = color_60, text_size = titlesize(tablesize))
table.cell(table1,0,5, text = session.islastbar?"Market\nClosed":timeform(untilhour), text_color = color_60, text_size = tablesize)
|
Yield Curve Inversion Indicator | https://www.tradingview.com/script/IESfANaJ-Yield-Curve-Inversion-Indicator/ | TradeAutomation | https://www.tradingview.com/u/TradeAutomation/ | 95 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @version=5
// Author = TradeAutomation
indicator("Bond Yield Curve Inversion", shorttitle="Yield Curve Inversion", overlay=false, timeframe="", timeframe_gaps=false)
//Indicator can be used as a quick/easy check to see if there is a US bond interest rate yield curve inversion.
//Indicator can be applied to any chart, as it pulls in a comparison of 2 bond interest rate tickers regardless of the chart it is on.
//If the red line is over the green line, it indicates that there is a yield curve inversion.
//More information about the significance of an inverted yield curve can be found here: https://www.investopedia.com/terms/i/invertedyieldcurve.asp
// Pulls in and compares the value of 13 week and 10 year bonds
Treasury13Wk = request.security("US03M", timeframe.period, close)
Treasury5Yr = request.security("US05Y", timeframe.period, close)
Treasury10Yr = request.security("US10Y", timeframe.period, close)
CBOE13Wk = request.security("CBOE:IRX.P", timeframe.period, close)
CBOE5yr = request.security("CBOE:FVX.P", timeframe.period, close)
CBOE10Yr = request.security("CBOE:TNX.P", timeframe.period, close)
//FRB10YR13WDifference = request.security("T10Y3M", timeframe.period, close)
// Allows the user to select the data source for the data pull
YieldSource = input.bool(false, "Use CBOE Index Rate Instead of Actual Yield?", tooltip="The default will pull in actual yields. If CBOE is selected it will pull in the equivalent CBOE index rate. The index rate is not the actual rate, but will give you an approximation of the relative yield curves with more historical data")
Bond13Wk = YieldSource==true ? CBOE13Wk : Treasury13Wk
Bond5Yr = YieldSource==true ? CBOE5yr : Treasury5Yr
Bond10Yr = YieldSource==true ? CBOE10Yr : Treasury10Yr
Inverted = Bond13Wk>Bond10Yr
//or FRB10YR13WDifference<0
// Plots
plot(input.bool(true, "Plot 13wk?") ==true ? Bond13Wk : na, color = color.red)
plot(input.bool(false, "Plot 5yr?") ==true ? Bond5Yr : na, color=color.yellow)
plot(input.bool(true, "Plot 10yr?") ==true ? Bond10Yr : na, color = color.green)
//plot(input.bool(false, "Plot Fed Published 10yr-13wk?") ==true ? FRB10YR13WDifference : na, color = color.orange)
hline(input.float(2, "H Line", step=.1, tooltip = "This is a custom dashed line. You can define the value with this input make the indicator easier to check if it is over/under a value"))
plotshape(Inverted, style=shape.cross, location=location.bottom) |
Auto AVWAP (Anchored-VWAP) | https://www.tradingview.com/script/ZmNNKbwE-Auto-AVWAP-Anchored-VWAP/ | Electrified | https://www.tradingview.com/u/Electrified/ | 830 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Electrified (electrifiedtrading)
// @version=4
study(title="Auto AVWAP (Anchored-VWAP)", shorttitle="Auto AVWAP", overlay=true, format=format.price, precision=2, resolution="") // image v3
kcolor = #0094FF
dcolor = #FF6A00
WMA = "WMA", EMA = "EMA", SMA = "SMA", VWMA = "VWMA", VAWMA = "VAWMA"
///////////////////////////////////////////////////
// Input
useHiLow = input(true, "Use High/Low instead of HLC3", group="Anchored VWAP", tooltip="When true, high and low values are used to caclulate the value of each AVWAP instead of HLC3.")
useOpen = input(true, "Use open instead of close for alerts.", group="Anchored VWAP", tooltip="Using the open instead of the close is more confirmative of a breakout as live values are based upon the close value and could be transient.")
k_mode = input(WMA, "K Mode", group="Stochastic RSI", inline="Source", options=[SMA, EMA, WMA, VWMA, VAWMA])
src = input(hlc3, "Source", group="Stochastic RSI", inline="Source")
smoothK = input(4, "K", group="Stochastic RSI", inline="Values", minval=1)
smoothD = input(4, "D", group="Stochastic RSI", inline="Values", minval=1)
lengthRSI = input(64, "RSI", group="Lengths", inline="Lengths", minval=1)
lengthStoch = input(48, "Stochastic", group="Lengths", inline="Lengths", minval=1)
lowerBand = input(20, "Lower", group="Band", inline="Band", maxval=50, minval=0)
upperBand = input(80, "Upper", group="Band", inline="Band", minval=50, maxval=100)
lowerReversal = input(20, "Lower", group="Reversal", inline="Reversal", maxval=100, minval=0, tooltip="The level that if broken (down) signfies a reversal has begun/occured.\nDefault represents the lower band.")
upperReversal = input(80, "Upper", group="Reversal", inline="Reversal", minval=0, maxval=100, tooltip="The level that if broken (up) signfies a reversal has begun/occured.\nDefault represents the upper band.")
///////////////////////////////////////////////////
// Functions
vawma(src, len) =>
sum = 0.0
vol = 0.0
for m = 1 to len // m = triangular multiple
i = len - m
v = volume[i] * m
vol := vol + v
sum := sum + src[i] * v
sum/vol
////
getMA(series, mode, len) =>
mode==WMA ? wma(series, len) :
mode==EMA ? ema(series, len) :
mode==VWMA ? vwma(series, len) :
mode==VAWMA ? vawma(series, len) :
sma(series, len)
////
///////////////////////////////////////////////////
// Calculation
rsi1 = rsi(src, lengthRSI)
stoch = stoch(rsi1, rsi1, rsi1, lengthStoch)
k = getMA(stoch, k_mode, smoothK)
d = sma(k, smoothD)
k_c = change(k)
d_c = change(d)
kd = k - d
var hi = high
var lo = low
var phi = high
var plo = low
var state = 0
var float hiAVWAP_s = 0
var float loAVWAP_s = 0
var float hiAVWAP_v = 0
var float loAVWAP_v = 0
var float hiAVWAP_s_next = 0
var float loAVWAP_s_next = 0
var float hiAVWAP_v_next = 0
var float loAVWAP_v_next = 0
if(d<lowerBand or high>phi)
phi := high
hiAVWAP_s_next := 0
hiAVWAP_v_next := 0
if(d>upperBand or low<plo)
plo := low
loAVWAP_s_next := 0
loAVWAP_v_next := 0
if(high>hi)
hi := high
hiAVWAP_s := 0
hiAVWAP_v := 0
if(low<lo)
lo := low
loAVWAP_s := 0
loAVWAP_v := 0
vwapHi = useHiLow ? high : hlc3
vwapLo = useHiLow ? low : hlc3
hiAVWAP_s += vwapHi * volume
loAVWAP_s += vwapLo * volume
hiAVWAP_v += volume
loAVWAP_v += volume
hiAVWAP_s_next += vwapHi * volume
loAVWAP_s_next += vwapLo * volume
hiAVWAP_v_next += volume
loAVWAP_v_next += volume
if(state!=-1 and d<lowerBand)
state := -1
else if(state!=+1 and d>upperBand)
state := +1
if(hi>phi and state==+1 and k<d and k<lowerReversal)
hi := phi
hiAVWAP_s := hiAVWAP_s_next
hiAVWAP_v := hiAVWAP_v_next
if(lo<plo and state==-1 and k>d and k>upperReversal)
lo := plo
loAVWAP_s := loAVWAP_s_next
loAVWAP_v := loAVWAP_v_next
hiAVWAP = hiAVWAP_s / hiAVWAP_v
loAVWAP = loAVWAP_s / loAVWAP_v
hiAVWAP_next = hiAVWAP_s_next / hiAVWAP_v_next
loAVWAP_next = loAVWAP_s_next / loAVWAP_v_next
plot(hiAVWAP_next, "High Next",color.new(color.red, 75), 1, style=plot.style_circles)
plot(loAVWAP_next, "Low Next", color.new(color.green, 75), 1, style=plot.style_circles)
plot(hiAVWAP, "High",color.new(color.red, 50), 2, style=plot.style_circles)
plot(loAVWAP, "Low", color.new(color.green, 50), 2, style=plot.style_circles)
alertValue = useOpen ? open : close
resistance = alertValue - hiAVWAP
support = alertValue - loAVWAP
alertcondition(resistance>0 or support<0, title="Breakout (▲▼)", message="Breakout ({{ticker}} {{interval}})")
alertcondition(resistance>0 , title="Resistance Broken ▲", message="Resistance Broken ▲ ({{ticker}} {{interval}})")
alertcondition(support<0 , title="Support Broken ▼", message="Support Broken ▼ ({{ticker}} {{interval}})")
|
Stochastic RSI+ Support/Resistance (beta) | https://www.tradingview.com/script/9H2W19TJ-Stochastic-RSI-Support-Resistance-beta/ | Electrified | https://www.tradingview.com/u/Electrified/ | 398 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Electrified (electrifiedtrading)
// @version=4
study(title="Stochastic RSI+ Support/Resistance (beta)", shorttitle="SRSI+ S/R", overlay=true, format=format.price, precision=2, resolution="")
kcolor = #0094FF
dcolor = #FF6A00
WMA = "WMA", EMA = "EMA", SMA = "SMA", VWMA = "VWMA", VAWMA = "VAWMA"
///////////////////////////////////////////////////
// Input
k_mode = input(SMA, "K Mode", inline="Source", options=[SMA, EMA, WMA, VWMA, VAWMA])
src = input(close, "Source", inline="Source")
smoothK = input(3, "K", inline="Values", minval=1)
smoothD = input(3, "D", inline="Values", minval=1)
lengthRSI = input(64, "RSI", group="Lengths", inline="Lengths", minval=1)
lengthStoch = input(64, "Stochastic", group="Lengths", inline="Lengths", minval=1)
lowerBand = input(20, "Lower", group="Band", inline="Band", maxval=50, minval=0)
upperBand = input(80, "Upper", group="Band", inline="Band", minval=50, maxval=100)
lowerReversal = input(20, "Lower", group="Reversal", inline="Reversal", maxval=100, minval=0, tooltip="The level that if broken (down) signfies a reversal has begun/occured.\nDefault represents the lower band.")
upperReversal = input(80, "Upper", group="Reversal", inline="Reversal", minval=0, maxval=100, tooltip="The level that if broken (up) signfies a reversal has begun/occured.\nDefault represents the upper band.")
///////////////////////////////////////////////////
// Functions
vawma(src, len) =>
sum = 0.0
vol = 0.0
for m = 1 to len // m = triangular multiple
i = len - m
v = volume[i] * m
vol := vol + v
sum := sum + src[i] * v
sum/vol
////
getMA(series, mode, len) =>
mode==WMA ? wma(series, len) :
mode==EMA ? ema(series, len) :
mode==VWMA ? vwma(series, len) :
mode==VAWMA ? vawma(series, len) :
sma(series, len)
////
///////////////////////////////////////////////////
// Calculation
rsi1 = rsi(src, lengthRSI)
stoch = stoch(rsi1, rsi1, rsi1, lengthStoch)
k = getMA(stoch, k_mode, smoothK)
d = sma(k, smoothD)
k_c = change(k)
d_c = change(d)
kd = k - d
var hi = high
var lo = low
var phi = high
var plo = low
var state = 0
if(d<lowerBand)
phi := high
if(d>upperBand)
plo := low
if(high>phi)
phi := high
if(low<plo)
plo := low
if(state!=-1 and d<lowerBand)
state := -1
else if(state!=+1 and d>upperBand)
state := +1
if(hi>phi and state==+1 and k<d and k<lowerReversal)
hi := phi
if(lo<plo and state==-1 and k>d and k>upperReversal)
lo := plo
if(high>hi)
hi := high
if(low<lo)
lo := low
ptop = plot(hi, "Resistance",color.new(color.red, 25), 3, style=plot.style_linebr)
pbot = plot(lo, "Support", color.new(color.green, 30), 3, style=plot.style_linebr)
fill(ptop, pbot, color.new(color.gray, 90), title="Range")
resistance = change(hi)
support = change(lo)
alertcondition(resistance>0 or support<0 , title="Breakout (▲▼)", message="Breakout ({{ticker}} {{interval}})")
alertcondition(resistance>0 , title="Resistance Broken ▲", message="Resistance Broken ▲ ({{ticker}} {{interval}})")
alertcondition(resistance<0 , title="Resistence Lowered (-)", message="Resistence Lowered (-) ({{ticker}} {{interval}})")
alertcondition(support<0 , title="Support Broken ▼", message="Support Broken ▼ ({{ticker}} {{interval}})")
alertcondition(support>0 , title="Support Raised (+)", message="Support Raised (+) ({{ticker}} {{interval}})")
|
SMADIF4 Indicator | https://www.tradingview.com/script/QX7d7T3k/ | ihsuka942 | https://www.tradingview.com/u/ihsuka942/ | 14 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ihsuka942
//@version=4
study("SMADIF4 Indicator", overlay=true)
len = input(defval=100,minval = 0, title="Bars in work", type=input.integer)
ema_1 = input(defval=20,minval = 0, title="Period SMA 1", type=input.integer)
ema_2 = input(defval=50,minval = 0, title="Period SMA 2", type=input.integer)
ema_3 = input(defval=100,minval = 0, title="Period SMA 3", type=input.integer)
ema_4 = input(defval=200,minval = 0, title="Period SMA 4", type=input.integer)
src = input(title="Source", type=input.source, defval=close)
Nstd = input(defval=1.3,minval = 0, title="Confidence Level in Standard deviations", type=input.float)
EMA1 = sma(src, ema_1)
EMA2 = sma(src, ema_2)
EMA3 = sma(src, ema_3)
EMA4 = sma(src, ema_4)
emaclose1 = 100*(src - EMA1)/EMA1
emaclose2 = 100*(src - EMA2)/EMA2
emaclose3 = 100*(src - EMA3)/EMA3
emaclose4 = 100*(src - EMA4)/EMA4
emap1 = sma(emaclose1,len)+Nstd*stdev(emaclose1,len)
emap2 = sma(emaclose2,len)+Nstd*stdev(emaclose2,len)
emap3 = sma(emaclose3,len)+Nstd*stdev(emaclose3,len)
emap4 = sma(emaclose4,len)+Nstd*stdev(emaclose4,len)
emam1 = sma(emaclose1,len)-Nstd*stdev(emaclose1,len)
emam2 = sma(emaclose2,len)-Nstd*stdev(emaclose2,len)
emam3 = sma(emaclose3,len)-Nstd*stdev(emaclose3,len)
emam4 = sma(emaclose4,len)-Nstd*stdev(emaclose4,len)
backgroundemas1 = emaclose1 > emap1 and close > sma(close,200) ? color.green:
emaclose1 < emam1 and close < sma(close,200) ? color.red :
na
backgroundemas2 = emaclose2 > emap2 and close > sma(close,200) ? color.green:
emaclose2 < emam2 and close < sma(close,200) ? color.red :
na
backgroundemas3 = emaclose3 > emap3 and close > sma(close,200) ? color.green:
emaclose3 < emam3 and close < sma(close,200) ? color.red :
na
backgroundemas4 = emaclose4 > emap4 and close > sma(close,200) ? color.green:
emaclose4 < emam4 and close < sma(close,200) ? color.red :
na
bgcolor(color=backgroundemas1,title ='SMA 20', transp=75)
bgcolor(color=backgroundemas2,title ='SMA 50', transp=75)
bgcolor(color=backgroundemas3,title ='SMA 100', transp=75)
bgcolor(color=backgroundemas4,title ='SMA 200', transp=75)
|
Inverse Fisher Transform on Williams %R | https://www.tradingview.com/script/cf7gmIkm/ | only_fibonacci | https://www.tradingview.com/u/only_fibonacci/ | 369 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// inspire KIVANC @fr3762
// creator John EHLERS
// only_fibonacci
//@version=4
study("Inverse Fisher Transform Williams %R", overlay=false, shorttitle="IFTWR")
wprlength=input(14,"Williams%R Length")
wmalength=input(9,"Smoothing Length")
wprs=0.1*(wpr(wprlength)+50)
wprsw=wma(wprs,wmalength)
INVWR=(exp(2*wprsw)-1)/(exp(2*wprsw)+1)
plot(INVWR,color=color.black, linewidth=1, title="%R")
obPlot=hline(0.5, color=color.black,title="Upper Band")
osPlot=hline(-0.5, color=color.black,title="Lower Band")
fill(obPlot,osPlot,color.black)
|
Mean reverting strategy based on time and SMAs | https://www.tradingview.com/script/x5LWCHai/ | LorenzoT95 | https://www.tradingview.com/u/LorenzoT95/ | 39 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LorenzoT95, thanks to ZenandTheArtofTrading for script tips
//@version=4
study(title="Prima.Strat.Lollo", shorttitle="Strategia 1 L", overlay = true)
//MAs definition
src = input(hl2, title="Source")
offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)
len1 = input(50, minval=1, title="Length1")
out1 = sma(src, len1)
plot(out1, color=color.yellow, transp=50)
len2 = input(100, minval=1, title="Length2")
out2 = sma(src, len2)
plot(out2, color=color.orange, transp=50)
len3 = input(200, minval=1, title="Length3")
out3 = sma(src, len3)
plot(out3, color=color.red, transp=50)
//Tiempo50 var def
var tiempo1 = 0
if low > out1
tiempo1 := tiempo1 + 1
else
tiempo1 :=0
var tiempo2 = 0
if high < out1
tiempo2 := tiempo2 - 1
else
tiempo2 := 0
//Tiempo100 var def
var tiempo3 = 0
if low > out2
tiempo3 := tiempo3 + 1
else
tiempo3 :=0
var tiempo4 = 0
if high < out2
tiempo4 := tiempo4 - 1
else
tiempo4 := 0
//Tiempo 200 var def
var tiempo5 = 0
if low > out3
tiempo5 := tiempo5 + 1
else
tiempo5 :=0
var tiempo6 = 0
if high < out3
tiempo6 := tiempo6 - 1
else
tiempo6 := 0
//Tiempo conditions
TiempoBear50 = tiempo1 >= len1 or tiempo1[1] >= len1
TiempoBull50 = tiempo2 <= -len1 or tiempo2[1] <= -len1
TiempoBear100 = tiempo3 >= len2 or tiempo3[1] >= len2
TiempoBull100 = tiempo4 <= -len2 or tiempo4[1] <= -len2
TiempoBear200 = tiempo5 >= len3 or tiempo5[1] >= len3
TiempoBull200 = tiempo6 <= -len3 or tiempo6[1] <= -len3
// Detect candlestick patterns
bearishEngulfing = close <= open[1] and close[1] >= open[1]
bullishEngulfing = close >= open[1] and close[1] <= open[1]
//Detect trading setups
bearishSetup50 = TiempoBear50 and bearishEngulfing
bullishSetup50 = TiempoBull50 and bullishEngulfing
bearishSetup100 = TiempoBear100 and bearishEngulfing
bullishSetup100 = TiempoBull100 and bullishEngulfing
bearishSetup200 = TiempoBear200 and bearishEngulfing
bullishSetup200 = TiempoBull200 and bullishEngulfing
//Draw data on chart
plotshape(bearishSetup50 ? 1 : na, style=shape.arrowdown, color=color.yellow, location=location.abovebar, title="Bear Signal", text="Sell")
plotshape(bullishSetup50 ? 1 : na, style=shape.arrowup, color=color.yellow, location=location.belowbar, title="Bull Signal", text="Buy")
plotshape(bearishSetup100 ? 1 : na, style=shape.arrowdown, color=color.orange, location=location.abovebar, title="Bear Signal", text="Sell")
plotshape(bullishSetup100 ? 1 : na, style=shape.arrowup, color=color.orange, location=location.belowbar, title="Bull Signal", text="Buy")
plotshape(bearishSetup200 ? 1 : na, style=shape.arrowdown, color=color.red, location=location.abovebar, title="Bear Signal", text="Sell")
plotshape(bullishSetup200 ? 1 : na, style=shape.arrowup, color=color.red, location=location.belowbar, title="Bull Signal", text="Buy")
alertcondition(condition= bearishSetup50 or bullishSetup50, title="Tiempo Alert!", message="Tiempo Setup detected for: {{ticker}}")
|
Crypto Market Caps (BTC, ETH, TOTAL3) | https://www.tradingview.com/script/abSGioj7-Crypto-Market-Caps-BTC-ETH-TOTAL3/ | BigPhilBxl | https://www.tradingview.com/u/BigPhilBxl/ | 46 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BigPhilBxl
//@version=5
indicator('Crypto Market Caps (BTC, ETH, TOTAL3)')
// inputs
int length = input.int(21, 'RSI length', group='Settings')
btc = input.symbol(title='Market Cap BTC', defval='CRYPTOCAP:BTC', group='Market Cap')
eth = input.symbol(title='Market Cap ETH', defval='CRYPTOCAP:ETH', group='Market Cap')
total3 = input.symbol(title='Market Cap Total3', defval='CRYPTOCAP:TOTAL3', group='Market Cap')
// hlines
hline(30, 'Low')
hline(50, 'Medium', linewidth=2)
hline(70, 'High')
// Get BTC & alt market caps
b = request.security(btc, timeframe=timeframe.period, expression=close)
e = request.security(eth, timeframe=timeframe.period, expression=close)
t3 = request.security(total3, timeframe=timeframe.period, expression=close)
// RSI
rsi_b = ta.rsi(b, length)
rsi_e = ta.rsi(e, length)
rsi_t3 = ta.rsi(t3, length)
// Plot
plot(rsi_b, 'BTC', color=color.new(color.orange, 0))
plot(rsi_e, 'ETH', color=color.new(color.gray, 0))
plot(rsi_t3, 'TOTAL3', color=color.new(color.blue, 0))
|
MACD Advanced | https://www.tradingview.com/script/zmOed3Fk-MACD-Advanced/ | Skyrex | https://www.tradingview.com/u/Skyrex/ | 228 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SkyRockSignals
//@version=4
study("MACD Advanced",shorttitle="MACD Adv", resolution="",overlay=false,format=format.price)
// Getting inputs
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
src = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Oscillator MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"])
sma_signal = input(title="Signal Line MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"])
// Plot colors
col_macd = input(#2962FF, "MACD Line ", input.color, group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line ", input.color, group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above Grow", input.color, group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", input.color, group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", input.color, group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", input.color, group="Histogram", inline="Below")
//divergence
len = input(title="Divergence Checker Period", minval=1, defval=14)
lbR = input(title="Pivot Lookback Right", defval=5)
lbL = input(title="Pivot Lookback Left", defval=5)
rangeUpper = input(title="Max of Lookback Range", defval=60)
rangeLower = input(title="Min of Lookback Range", defval=5)
// Calculating
fast_ma = sma_source == "SMA" ? sma(src, fast_length) : ema(src, fast_length)
slow_ma = sma_source == "SMA" ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? sma(macd, signal_length) : ema(macd, signal_length)
//divergence
osc = macd
plFound = na(pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
bars = barssince(cond == true)
rangeLower <= bars and bars <= rangeUpper
//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
oscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
// Price: Lower Low
priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1)
bullCond = priceLL and oscHL and plFound
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
oscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
// Price: Higher Low
priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1)
hiddenBullCond = priceHL and oscLL and plFound
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
oscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
// Price: Higher High
priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1)
bearCond = priceHH and oscLH and phFound
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
oscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
// Price: Lower High
priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1)
hiddenBearCond = priceLH and oscHH and phFound
crosover= crossover(macd,signal)
crosunder=crossunder(macd,signal)
var bool strong_bull=false
var bool bull=false
var bool bear=false
var bool strong_bear=false
strong_bull:=crosover and bullCond
strong_bear:=crosunder and bearCond
bull:=crosover and not hiddenBearCond and macd<0 and signal<0
bear:=crosunder and not hiddenBullCond and macd>0 and signal>0
hist = macd - signal
plot(0)
plot(macd, title="MACD", color=col_macd)
plot(signal, title="Signal", color=col_signal)
plotshape(bull?true: na,text="Bullish Signal",size=size.tiny,offset=0,color=color.green,textcolor=color.green,style=shape.flag,location=location.absolute)
plotshape(bear?true: na,text="Bearish Signal",location=location.absolute,size=size.tiny,offset=0,color=color.red,textcolor=color.red)
plotshape(strong_bull?true: na,text="Strong Bullish Signal",style=shape.flag,size=size.tiny,offset=2,color=color.green,textcolor=color.green,location=location.absolute)
plotshape(strong_bear?true: na,text="Strong Bearish Signal",style=shape.flag,size=size.tiny,offset=2,color=color.red,textcolor=color.red,location=location.absolute)
|
Elephant - Shooting Star Candles | https://www.tradingview.com/script/IavGTWFw/ | ihsuka942 | https://www.tradingview.com/u/ihsuka942/ | 42 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ihsuka942
//@version=4
study("Elephant - Shooting Star Candles", overlay=true)
len = input(defval=100,minval = 0, title="Period", type=input.integer)
CS = input(defval=70,minval = 0,maxval = 100, title="Elephant Body size (0-100)%", type=input.float)
ss = input(defval=50,minval = 0,maxval = 50, title="ShootingStar Body size (0-100)%", type=input.float)
Nstd = input(defval=1.3,minval = 0, title="Confidence Level in Standard deviations for Elephant bars", type=input.float)
Nstd2 = input(defval=1.3,minval = 0, title="Confidence Level in Standard deviations for Shooting Star", type=input.float)
cs = (close - open)/low
ws = (high - low)/low
p = sma(cs,len)+Nstd*stdev(cs,len)
m = sma(cs,len)-Nstd*stdev(cs,len)
p2 = sma(ws,len)+Nstd2*stdev(ws,len)
center = (high+low)/2
backgroundele = cs < m and abs(cs) > CS*(ws)/100 and close < sma(close,200) ? color.red:
cs > p and abs(cs) > CS*(ws)/100 and close > sma(close,200) ? color.green :
na
backgroundrockets = ws > p2 and abs(cs) > 0.0 and abs(cs) < ss*(ws)/100 and open > center and close > center? color.green:
ws > p2 and abs(cs) > 0.0 and abs(cs) < ss*(ws)/100 and open < center and close < center ? color.red:
na
bgcolor(color=backgroundele,title ='Elephant Bars', transp=50)
bgcolor(color=backgroundrockets,title ='ShootingStart Bars', transp=30)
|
MTF StochRSI indicator by noop42 | https://www.tradingview.com/script/OwRzXzIb/ | noop-noop | https://www.tradingview.com/u/noop-noop/ | 102 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © noop42
//@version=4
study("MTF StochRSI indicator by noop42", overlay=false)
// Input parameters
src = input(close, title="Source")
average_value = input(title="Use average value mode (K+D/2)", type=input.bool, defval=true)
repainting = input(title="Allow repaint ? (disable to get live values)", type=input.bool, defval=true)
tf1 = input(title="Timeframe 1", type=input.resolution, defval="1")
tf2 = input(title="Timeframe 2", type=input.resolution, defval="5")
tf3 = input(title="Timeframe 3", type=input.resolution, defval="15")
smoothKD = input(3, "K", minval=1, group="Stoch RSI")
lengthRSI = input(14, "RSI Length", minval=1, group="Stoch RSI")
lengthStoch = input(14, "Stochastic Length", minval=1, group="Stoch RSI")
stoch_low = input(20, title="Stoch Oversold Level", group="Stoch RSI")
stoch_high = input(80, title="Stoch Overbought Level", group="Stoch RSI")
// On/Off repainting function
rp_security(_symbol, _res, _src) => security(_symbol, _res, _src[barstate.isrealtime ? (repainting ? 0 : 1) : 0], gaps=false)
// MTF Stochastic RSI
rsi_tf1 = rp_security(syminfo.tickerid, tf1, rsi(src,lengthRSI))
stoch_k_tf1 = rp_security(syminfo.tickerid, tf1, sma(stoch(rsi_tf1, rsi_tf1, rsi_tf1, lengthStoch), smoothKD))
stoch_d_tf1 = rp_security(syminfo.tickerid, tf1, sma(stoch_k_tf1, smoothKD))
rsi_tf2 = rp_security(syminfo.tickerid, tf2, rsi(src,lengthRSI))
stoch_k_tf2 = rp_security(syminfo.tickerid, tf2, sma(stoch(rsi_tf2, rsi_tf2, rsi_tf2, lengthStoch), smoothKD))
stoch_d_tf2 = rp_security(syminfo.tickerid, tf2, sma(stoch_k_tf2, smoothKD))
rsi_tf3 = rp_security(syminfo.tickerid, tf3, rsi(src,lengthRSI))
stoch_k_tf3 = rp_security(syminfo.tickerid, tf3, sma(stoch(rsi_tf3, rsi_tf3, rsi_tf3, lengthStoch), smoothKD))
stoch_d_tf3 = rp_security(syminfo.tickerid, tf3, sma(stoch_k_tf3, smoothKD))
// Zones lines
h0 = hline(stoch_high, "Upper Band", color=#eb500e45)
hmid = hline(50, "Middle Band", color=#ffffff45)
h1 = hline(stoch_low, "Lower Band", color=#10a3de45)
fill(h0, h1, color=#1984d110)
// Average mode
avgtf1 = (stoch_k_tf1 + stoch_d_tf1) / 2
avgtf2 = (stoch_k_tf2 + stoch_d_tf2) / 2
avgtf3 = (stoch_k_tf3 + stoch_d_tf3) / 2
bColor1 = #00bfff
bColor2 = #0048ff
bColor3 = #1e1e8f
plot(average_value ? avgtf1: na, "SRSI tf1 (avg mode)", color = bColor1, linewidth=1, transp=25)
plot(average_value ? avgtf2: na, "SRSI tf2 (avg mode)", color = bColor2, linewidth=2, transp=25)
plot(average_value ? avgtf3: na, "SRSI tf3 (avg mode)", color = bColor3, linewidth=4, transp=25)
// Classic mode
plot(average_value ? na: stoch_k_tf1, "K #1", color=color.aqua, linewidth=1)
plot(average_value ? na: stoch_d_tf1, "D #1", color=color.blue, linewidth=1)
plot(average_value ? na: stoch_k_tf2, "K #2", color=color.lime, linewidth=2)
plot(average_value ? na: stoch_d_tf2, "D #2", color=color.green, linewidth=2)
plot(average_value ? na: stoch_k_tf3, "K #3", color=color.yellow, linewidth=3)
plot(average_value ? na: stoch_d_tf3, "D #3", color=color.orange, linewidth=3)
|
Multi timeframe Stochastic RSI Screener by noop42 | https://www.tradingview.com/script/i05S7XJb/ | noop-noop | https://www.tradingview.com/u/noop-noop/ | 420 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © noop42
//@version=5
indicator('MTF StochRSI Screener & indicator by noop42', overlay=false)
// Input parameters
src = input(close, title='Source')
average_value = input.bool(title='Use average value mode (K+D/2)', defval=true, group='Options')
repainting = input.bool(title='Allow repaint ? (enable to get live values)', defval=true, group='Options')
show_screener = input.bool(title='Show Screener', defval=true, group='Options')
show_lines = input.bool(title='Show StochasticRSI lines ?', defval=true, group='Options')
color_mode = input.string(title='Color mode', options=["Binary", "Progressive"], defval="Progressive", group='Options')
tf1 = input.timeframe(title='Timeframe 1', defval='1', group='Options')
tf2 = input.timeframe(title='Timeframe 2', defval='5', group='Options')
tf3 = input.timeframe(title='Timeframe 3', defval='15', group='Options')
tf4 = input.timeframe(title='Timeframe 4', defval='60', group='Options')
tf1_cvg_opt = input.bool(true, 'Include Timeframe #1 in convergence signals', group='Options')
tf2_cvg_opt = input.bool(true, 'Include Timeframe #2 in convergence signals', group='Options')
tf3_cvg_opt = input.bool(true, 'Include Timeframe #3 in convergence signals', group='Options')
tf4_cvg_opt = input.bool(false, 'Include Timeframe #4 in convergence signals', group='Options')
smoothKD = input.int(3, 'K & D smoothing', minval=1, group='Stoch RSI')
lengthRSI = input.int(14, 'RSI Length', minval=1, group='Stoch RSI')
lengthStoch = input.int(14, 'Stochastic Length', minval=1, group='Stoch RSI')
stoch_low = input.int(20, title='Stoch Oversold Level', group='Stoch RSI')
stoch_high = input.int(80, title='Stoch Overbought Level', group='Stoch RSI')
rsi_low = input.int(30, title='RSI Oversold Level', group='Stoch RSI')
rsi_high = input.int(70, title='RSI Overbought Level', group='Stoch RSI')
// Custom functions
rp_security(_symbol, _res, _src) =>
request.security(_symbol, _res, _src[barstate.isrealtime ? repainting ? 0 : 1 : 0], gaps=barmerge.gaps_off)
get_movement(k, d) =>
k > d ? 'Bull' : 'Bear'
show_drawings(data) =>
show_lines ? data : na
color_value(value) =>
step = (200/100.0)
d = value * step
g = value < 50 ? d : 127
r = value < 50 ? 127: 200 - d
color.rgb(math.round(r), math.round(g), 0, 0)
// MTF Stochastic RSI
rsi_tf1 = rp_security(syminfo.tickerid, tf1, ta.rsi(src, lengthRSI))
stoch_k_tf1 = rp_security(syminfo.tickerid, tf1, ta.sma(ta.stoch(rsi_tf1, rsi_tf1, rsi_tf1, lengthStoch), smoothKD))
stoch_d_tf1 = rp_security(syminfo.tickerid, tf1, ta.sma(stoch_k_tf1, smoothKD))
rsi_tf2 = rp_security(syminfo.tickerid, tf2, ta.rsi(src, lengthRSI))
stoch_k_tf2 = rp_security(syminfo.tickerid, tf2, ta.sma(ta.stoch(rsi_tf2, rsi_tf2, rsi_tf2, lengthStoch), smoothKD))
stoch_d_tf2 = rp_security(syminfo.tickerid, tf2, ta.sma(stoch_k_tf2, smoothKD))
rsi_tf3 = rp_security(syminfo.tickerid, tf3, ta.rsi(src, lengthRSI))
stoch_k_tf3 = rp_security(syminfo.tickerid, tf3, ta.sma(ta.stoch(rsi_tf3, rsi_tf3, rsi_tf3, lengthStoch), smoothKD))
stoch_d_tf3 = rp_security(syminfo.tickerid, tf3, ta.sma(stoch_k_tf3, smoothKD))
rsi_tf4 = rp_security(syminfo.tickerid, tf4, ta.rsi(src, lengthRSI))
stoch_k_tf4 = rp_security(syminfo.tickerid, tf4, ta.sma(ta.stoch(rsi_tf4, rsi_tf4, rsi_tf4, lengthStoch), smoothKD))
stoch_d_tf4 = rp_security(syminfo.tickerid, tf4, ta.sma(stoch_k_tf4, smoothKD))
avgtf1 = (stoch_k_tf1 + stoch_d_tf1) / 2
avgtf2 = (stoch_k_tf2 + stoch_d_tf2) / 2
avgtf3 = (stoch_k_tf3 + stoch_d_tf3) / 2
avgtf4 = (stoch_k_tf4 + stoch_d_tf4) / 2
tf1ob = avgtf1 > stoch_high
tf1os = avgtf1 < stoch_low
tf2ob = avgtf2 > stoch_high
tf2os = avgtf2 < stoch_low
tf3ob = avgtf3 > stoch_high
tf3os = avgtf3 < stoch_low
tf4ob = avgtf4 > stoch_high
tf4os = avgtf4 < stoch_low
rsi1ob = rsi_tf1 > rsi_high
rsi1os = rsi_tf1 < rsi_low
rsi2ob = rsi_tf2 > rsi_high
rsi2os = rsi_tf2 < rsi_low
rsi3ob = rsi_tf3 > rsi_high
rsi3os = rsi_tf3 < rsi_low
rsi4ob = rsi_tf4 > rsi_high
rsi4os = rsi_tf4 < rsi_low
// Screener
obColor = #1c701e
osColor = #a11806
tf1mov = get_movement(stoch_k_tf1, stoch_d_tf1)
tf2mov = get_movement(stoch_k_tf2, stoch_d_tf2)
tf3mov = get_movement(stoch_k_tf3, stoch_d_tf3)
tf4mov = get_movement(stoch_k_tf4, stoch_d_tf4)
tf1movColor = tf1mov == 'Bull' ? color.lime : color.red
tf2movColor = tf2mov == 'Bull' ? color.lime : color.red
tf3movColor = tf3mov == 'Bull' ? color.lime : color.red
tf4movColor = tf4mov == 'Bull' ? color.lime : color.red
tf1Color = color_mode == "Binary" ? (tf1ob ? obColor : tf1os ? osColor : tf1movColor) : color_value(avgtf1)
tf2Color = color_mode == "Binary" ? (tf2ob ? obColor : tf2os ? osColor : tf2movColor) : color_value(avgtf2)
tf3Color = color_mode == "Binary" ? (tf3ob ? obColor : tf3os ? osColor : tf3movColor) : color_value(avgtf3)
tf4Color = color_mode == "Binary" ? (tf4ob ? obColor : tf4os ? osColor : tf3movColor) : color_value(avgtf4)
tf1status = tf1ob ? 'Overbought' : tf1os ? 'Oversold' : 'OK'
tf2status = tf2ob ? 'Overbought' : tf2os ? 'Oversold' : 'OK'
tf3status = tf3ob ? 'Overbought' : tf3os ? 'Oversold' : 'OK'
tf4status = tf4ob ? 'Overbought' : tf4os ? 'Oversold' : 'OK'
tf1RSIColor = color_mode == "Binary" ? (rsi1ob ? obColor : rsi1os ? osColor : tf1movColor) : color_value(rsi_tf1)
tf2RSIColor = color_mode == "Binary" ? (rsi2ob ? obColor : rsi2os ? osColor : tf2movColor) : color_value(rsi_tf2)
tf3RSIColor = color_mode == "Binary" ? (rsi3ob ? obColor : rsi3os ? osColor : tf3movColor) : color_value(rsi_tf3)
tf4RSIColor = color_mode == "Binary" ? (rsi4ob ? obColor : rsi4os ? osColor : tf4movColor) : color_value(rsi_tf4)
os_convergence = (tf1_cvg_opt ? tf1os : true) and (tf2_cvg_opt ? tf2os : true) and (tf3_cvg_opt ? tf3os : true) and (tf4_cvg_opt ? tf4os : true)
ob_convergence = (tf1_cvg_opt ? tf1ob : true) and (tf2_cvg_opt ? tf2ob : true) and (tf3_cvg_opt ? tf3ob : true) and (tf4_cvg_opt ? tf4ob : true)
rsi_ob_convergence = (tf1_cvg_opt ? rsi1ob : true) and (tf2_cvg_opt ? rsi2ob : true) and (tf3_cvg_opt ? rsi3ob : true) and (tf4_cvg_opt ? rsi4ob : true)
rsi_os_convergence = (tf1_cvg_opt ? rsi1os : true) and (tf2_cvg_opt ? rsi2os : true) and (tf3_cvg_opt ? rsi3os : true) and (tf4_cvg_opt ? rsi4os : true)
default_bg = #cccccc
var tbl = table.new(position.bottom_right, 6, 6)
if show_screener
if barstate.islast
table.cell(tbl, 0, 0, 'TimeFrame', bgcolor=default_bg)
table.cell(tbl, 1, 0, 'K', bgcolor=default_bg)
table.cell(tbl, 2, 0, 'D', bgcolor=default_bg)
table.cell(tbl, 3, 0, 'RSI', bgcolor=default_bg)
table.cell(tbl, 4, 0, 'Movement', bgcolor=default_bg)
table.cell(tbl, 5, 0, 'StochRSI Status', bgcolor=default_bg)
table.cell(tbl, 0, 1, tf1 + (tf1_cvg_opt ? '*' : ''), bgcolor=default_bg)
table.cell(tbl, 1, 1, str.tostring(stoch_k_tf1, '#.##'), bgcolor=tf1Color)
table.cell(tbl, 2, 1, str.tostring(stoch_d_tf1, '#.##'), bgcolor=tf1Color)
table.cell(tbl, 3, 1, str.tostring(rsi_tf1, '#.##'), bgcolor=tf1RSIColor)
table.cell(tbl, 4, 1, tf1mov, bgcolor=tf1movColor)
table.cell(tbl, 5, 1, tf1status, bgcolor=tf1Color)
table.cell(tbl, 0, 2, tf2 + (tf2_cvg_opt ? '*' : ''), bgcolor=default_bg)
table.cell(tbl, 1, 2, str.tostring(stoch_k_tf2, '#.##'), bgcolor=tf2Color)
table.cell(tbl, 2, 2, str.tostring(stoch_d_tf2, '#.##'), bgcolor=tf2Color)
table.cell(tbl, 3, 2, str.tostring(rsi_tf2, '#.##'), bgcolor=tf2RSIColor)
table.cell(tbl, 4, 2, tf2mov, bgcolor=tf2movColor)
table.cell(tbl, 5, 2, tf2status, bgcolor=tf2Color)
table.cell(tbl, 0, 3, tf3 + (tf3_cvg_opt ? '*' : ''), bgcolor=default_bg)
table.cell(tbl, 1, 3, str.tostring(stoch_k_tf3, '#.##'), bgcolor=tf3Color)
table.cell(tbl, 2, 3, str.tostring(stoch_d_tf3, '#.##'), bgcolor=tf3Color)
table.cell(tbl, 3, 3, str.tostring(rsi_tf3, '#.##'), bgcolor=tf3RSIColor)
table.cell(tbl, 4, 3, tf3mov, bgcolor=tf3movColor)
table.cell(tbl, 5, 3, tf3status, bgcolor=tf3Color)
table.cell(tbl, 0, 4, tf4 + (tf4_cvg_opt ? '*' : ''), bgcolor=default_bg)
table.cell(tbl, 1, 4, str.tostring(stoch_k_tf4, '#.##'), bgcolor=tf4Color)
table.cell(tbl, 2, 4, str.tostring(stoch_d_tf4, '#.##'), bgcolor=tf4Color)
table.cell(tbl, 3, 4, str.tostring(rsi_tf4, '#.##'), bgcolor=tf4RSIColor)
table.cell(tbl, 4, 4, tf4mov, bgcolor=tf4movColor)
table.cell(tbl, 5, 4, tf4status, bgcolor=tf4Color)
// Warning convergence alerts
srsi_warning_message = os_convergence ? 'SRSI OS convergence' : ob_convergence ? 'SRSI OB convergence' : 'No SRSI warning'
srsi_warning_color = os_convergence ? color.lime : ob_convergence ? color.red : default_bg
rsi_warning_message = rsi_os_convergence ? 'RSI OS convergence' : rsi_ob_convergence ? 'RSI OB convergence' : 'No RSI warning'
rsi_warning_color = rsi_os_convergence ? color.lime : rsi_ob_convergence ? color.red : default_bg
table.cell(tbl, 0, 5, 'Warnings', bgcolor=color.orange)
table.cell(tbl, 1, 5, srsi_warning_message, bgcolor=srsi_warning_color)
table.cell(tbl, 2, 5, rsi_warning_message, bgcolor=rsi_warning_color)
// Oscillators
// Zones lines
ob_zone_color = #eb500e10
os_zone_color = #24fc0310
invisible = #00000000
h0 = hline(show_drawings(stoch_high), 'Upper Band', color=ob_zone_color)
hmid = hline(show_drawings(50), 'Middle Band', color=#ffffff45)
h1 = hline(show_drawings(stoch_low), 'Lower Band', color=os_zone_color)
hmax_display = hline(show_drawings(110), color=invisible)
hmin_display = hline(show_drawings(-10), color=invisible)
obZone = hline(show_drawings(stoch_high), color=invisible)
osZone = hline(show_drawings(stoch_low), color=invisible)
hmax = hline(show_drawings(100), color=ob_zone_color)
hmin = hline(show_drawings(0), color=os_zone_color)
fill(hmax, obZone, color=ob_zone_color, transp=90)
fill(hmin, osZone, color=os_zone_color, transp=90)
// Average mode
plot(show_drawings(average_value) ? avgtf1 : na, 'SRSI tf1 (avg mode)', color=color_mode == "Binary" ? tf1movColor: tf1Color, linewidth=1, transp=25)
plot(show_drawings(average_value) ? avgtf2 : na, 'SRSI tf2 (avg mode)', color=color_mode == "Binary" ? tf2movColor : tf2Color, linewidth=2, transp=25)
plot(show_drawings(average_value) ? avgtf3 : na, 'SRSI tf3 (avg mode)', color=color_mode == "Binary" ? tf3movColor : tf3Color, linewidth=4, transp=25)
plot(show_drawings(average_value) ? avgtf4 : na, 'SRSI tf4 (avg mode)', color=color_mode == "Binary" ? tf4movColor : tf4Color, linewidth=6, transp=25)
// Classic mode
plot(average_value ? na : stoch_k_tf1, 'K #1 (classic mode)', color=color.new(color.aqua, 0), linewidth=1)
plot(average_value ? na : stoch_d_tf1, 'D #1 (classic mode)', color=color.new(color.navy, 0), linewidth=1)
plot(average_value ? na : stoch_k_tf2, 'K #2 (classic mode)', color=color.new(color.lime, 0), linewidth=2)
plot(average_value ? na : stoch_d_tf2, 'D #2 (classic mode)', color=color.new(color.green, 0), linewidth=2)
plot(average_value ? na : stoch_k_tf3, 'K #3 (classic mode)', color=color.new(color.yellow, 0), linewidth=3)
plot(average_value ? na : stoch_d_tf3, 'D #3 (classic mode)', color=color.new(color.orange, 0), linewidth=3)
plot(average_value ? na : stoch_k_tf4, 'K #4 (classic mode)', color=color.new(color.fuchsia, 0), linewidth=4)
plot(average_value ? na : stoch_d_tf4, 'D #4 (classic mode)', color=color.new(color.purple, 0), linewidth=4)
// Shapes
plotshape(show_drawings(os_convergence) ? 1 : 0, color=color.new(color.lime, 0), location=location.bottom, size=size.tiny, style=shape.triangleup, title='Bullish movement')
plotshape(show_drawings(ob_convergence) ? 1 : 0, color=color.new(color.red, 0), location=location.top, size=size.tiny, style=shape.triangledown, title='Bearish movement')
|
[RedK] Stepped Moving Average Channel (SMAC) | https://www.tradingview.com/script/p8oxiQhq-RedK-Stepped-Moving-Average-Channel-SMAC/ | RedKTrader | https://www.tradingview.com/u/RedKTrader/ | 265 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RedKTrader
//@version=4
study(title="Stepped Moving Average Channel", shorttitle="SMAC v2.0", overlay = true) //, resolution = "", resolution_gaps = false)
// ===================================================================================================================
// Functions Section
// ===================================================================================================================
// step function
// this function picks a step size based on the price range
// it wil then scale the step up/down based on TF changes
// change and personalize these ranges as needed
f_step(x) =>
initstep =
x < 1 ? 0.05 : x < 5 ? 0.20 :
x < 20 ? 0.50 : x < 100 ? 1.00 :
x < 300 ? 2.00 : x < 500 ? 5.00 :
x < 1000 ? 10.0 : x < 5000 ? 20.0 :
x < 10000 ? 50.0 : x < 20000 ? 100. :
200.0
//Adjust step value up or down for different timeframes
adjstep =
timeframe.isweekly ? initstep * 2 :
timeframe.ismonthly ? initstep * 5 :
timeframe.isintraday and timeframe.multiplier > 60 ? initstep / 2 :
timeframe.isintraday and timeframe.multiplier <= 60 ? initstep / 5 :
initstep
// need to replace the 4's in weekly and minutes with 5's
// cause we want to track the mental increments of traders - round values are more effective
_incstr = tostring(adjstep)
_newstr = str.replace_all(_incstr,"4","5")
tonumber(_newstr)
// =============================================================================
// the rounding function chooses the type of step rounding to apply
// we can use either a regular rounding up/down to nearest step (ex: for step size = 10, a value of 17 becomes 20 and a value of 13 becomes 10)
// or an integer type, which considers only the "fully completed" step level (ex: for step size = 10, both values of 13 and 17 become 10)
f_rounding(_value, _step, _option) =>
_option == 'Round up/down' ?
round(_value / _step) * _step :
int(_value / _step) * _step
//==============================================================================
// Compund Ratio Moving Average function
f_CoraWave(_source, _length, _s) =>
numerator = 0.0, denom = 0.0, c_weight = 0.0
r_multi = 2.0
Start_Wt = 0.01 // Start Weight & r_multi are set to basic values here.
End_Wt = _length // use length as initial End Weight to calculate base "r"
r = pow((End_Wt / Start_Wt),(1 / (_length - 1))) - 1
base = 1 + r * r_multi
for i = 0 to _length - 1
c_weight := Start_Wt * pow(base, (_length - i))
numerator := numerator + _source[i] * c_weight
denom := denom + c_weight
cora_raw = numerator / denom
cora_wave = wma(cora_raw, _s)
//===================================================================================================================
// inputs
// ===================================================================================================================
length = input(title = "Length", defval = 10, minval = 1, inline = 'MA Line')
smooth = input(title = "Extra Smoothing", defval = 3, minval = 1, inline = 'MA Line')
s_use = input(title = "", defval = true, inline = "Step")
s_size = input(title = "Step Size [0 = Auto]", defval = 0.0, minval = 0, inline = "Step")
r_option = input(title = "Step Calculation", defval = 'Round up/down', options=['Round up/down', 'Whole Step'])
e_show = input(title = "", defval = true, inline = "Pct Envelope")
e_pct = input(title = "Pct Envelope %", defval = 2.0, minval = 0, step = 0.25, inline = "Pct Envelope")
tr_show = input(title = "", defval = false, inline = "ATR Envelope")
tr_multi = input(title = "ATR Envelope ATR Multi", defval = 2.0, minval = 0, step = 0.25, inline = "ATR Envelope")
// ===================================================================================================================
// Calculation
// ===================================================================================================================
SMAC_u = f_CoraWave(high, length, smooth)
SMAC_l = f_CoraWave(low, length, smooth)
//Apply Stepping to Channel Lines
s = s_use ? s_size == 0.0 ? f_step(close) : s_size : 0
SMAC_us = s_use ? f_rounding(SMAC_u, s, r_option) : SMAC_u
SMAC_ls = s_use ? f_rounding(SMAC_l, s, r_option) : SMAC_l
// Calculate Envelopes
e_upper = SMAC_us * (1 + e_pct/100)
e_lower = SMAC_ls * (1 - e_pct/100)
// while the pct envelope is a static absolute value, the ATR will change with each bar
// below we use a new ATR value only when the channel step changes - non-stepping/unrestricted ATR is still avaialble by disabling the stepping option
// maybe in future versions we make this a user option by itself ?
ATR = atr(length) * tr_multi
ATR_us = ATR, ATR_ls = ATR
ATR_us := change(SMAC_us) != 0 ? ATR : ATR_us[1]
ATR_ls := change(SMAC_ls) != 0 ? ATR : ATR_ls[1]
ATR_upper = SMAC_us + ATR_us
ATR_lower = SMAC_ls - ATR_ls
// ===================================================================================================================
// Plot
// ===================================================================================================================
c_upper = color.new(#55ff00,0)
c_lower = color.new(#d5180b,0)
c_env = color.new(color.silver, 50)
c_ATR = color.new(color.yellow, 50)
PStyle = plot.style_line
Channel_Up = plot(SMAC_us, title="Upper Border", style = PStyle, color=c_upper, linewidth=2)
Channel_Lo = plot(SMAC_ls, title="Lower Border", style = PStyle, color=c_lower, linewidth=2)
fill(Channel_Up, Channel_Lo, color.new(#115500,70), title="Channel Fill")
//PStyle1 = plot.style_stepline
PStyle1 = plot.style_line //change default plot style to regular line for consistency
plot(e_show ? e_upper : na, "Upper Pct Envelope", style = PStyle1, color = c_env)
plot(e_show ? e_lower : na, "Lower Pct Envelope", style = PStyle1, color = c_env)
plot(tr_show ? ATR_upper : na, "Upper ATR Envelope", style = PStyle1, color = c_ATR)
plot(tr_show ? ATR_lower : na, "Lower ATR Envelope", style = PStyle1, color = c_ATR)
// ===================================================================================================================
// table
// ===================================================================================================================
txt_sz = size.small
tbl_pos = position.top_right
ctable = #1111ff
cframe = #ffeb3b
ctext = #ffffff
c_vbg = #2962ff
var QuickTable = table.new(position = tbl_pos, columns = 2, rows = 9,
bgcolor = ctable , frame_color = cframe, frame_width = 2)
// fill table
// =====================================================================================================================
f_FillRow(_table, _row, _label, _value) =>
table.cell(_table, 0, _row, _label, bgcolor = ctable, text_color = ctext,
text_size = txt_sz, text_halign = text.align_left)
table.cell(_table, 1, _row, tostring(_value), bgcolor = c_vbg, text_color = ctext,
text_size = txt_sz)
// =====================================================================================================================
step_state = s_use ? s_size == 0.0 ? "Auto" : "Manual" : "Not Used"
TF = timeframe.multiplier
NoVal = "-"
val_pctenv = e_show ? tostring(e_pct) : NoVal
val_pct = e_show ? tostring(close * e_pct/100, "##0.00") : NoVal // note that we simplified the value of % here. in reality the %env of high and low will be slightly different
val_ATRMulti= tr_show ? tostring(tr_multi) : NoVal
val_ATR = tr_show ? tostring(ATR,"##0.00") : NoVal
i = -1
if barstate.islast
i += 1, f_FillRow(QuickTable, i, "Step Mode", step_state)
i += 1, f_FillRow(QuickTable, i, "Step Size", s)
i += 1, f_FillRow(QuickTable, i, "TF Multi", TF)
i += 1, f_FillRow(QuickTable, i, "Pct Env", e_show ? "On" : "Off")
i += 1, f_FillRow(QuickTable, i, "Pct Env %", val_pctenv)
i += 1, f_FillRow(QuickTable, i, "Pct Env Value", val_pct)
i += 1, f_FillRow(QuickTable, i, "ATR Env", tr_show ? "On" : "Off")
i += 1, f_FillRow(QuickTable, i, "ATR Multi", val_ATRMulti)
i += 1, f_FillRow(QuickTable, i, "ATR Value", val_ATR) |
Buffett Indicator | https://www.tradingview.com/script/HWpTctAX-Buffett-Indicator/ | IcedMilo | https://www.tradingview.com/u/IcedMilo/ | 159 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © IcedMilo
//@version=5
indicator(title='Buffett Indicator')
//data
marketval = request.security("FRED:WILL5000PR", '1D', close)
gdp = request.security("FRED:GDP", '1D', close) / 1000000000
//calculations
indicator_1 = float(marketval/gdp) * 100
//indicator plot
plot(indicator_1, color=color.new(#2196F3, 0), linewidth=2)
//line plots
plot(50, title='50% of GDP', color=color.new(#4CAF50, 0), linewidth=2)
plot(100, title='100% of GDP', color=color.new(#FF9800, 0), linewidth=2)
plot(150, title='150% of GDP', color=color.new(#FF5252, 0), linewidth=2)
plot(200, title='200% of GDP', color=color.new(#880E4F, 0), linewidth=2)
// SMA plot
smaLength = input.int(200, title = "SMA Length")
sma200 = ta.sma(indicator_1, smaLength)
plot(sma200, title='SMA', color=color.new(#A020F0, 0))
|
Davood Kumo | https://www.tradingview.com/script/HgXTNyMV-Davood-Kumo/ | AlphaNodal | https://www.tradingview.com/u/AlphaNodal/ | 80 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Mr_Amiiin_n
//@version=5
indicator('Davood Kumo', overlay=true)
//draw ichimoku cloud
conversionPeriods = input.int(9, minval=1, title='Conversion Line Length', group="Ichimoku")
basePeriods = input.int(26, minval=1, title='Base Line Length', group="Ichimoku")
laggingSpan2Periods = input.int(52, minval=1, title='Leading Span B Length', group="Ichimoku")
displacement = input.int(26, minval=1, title='Displacement', group="Ichimoku")
donchian(len) =>
math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
p1 = plot(leadLine1, offset=displacement - 1, color=color.new(#A5D6A7, 0), title='Leading Span A')
p2 = plot(leadLine2, offset=displacement - 1, color=color.new(#EF9A9A, 0), title='Leading Span B')
fill(p1, p2, color=leadLine1 > leadLine2 ? color.rgb(67, 160, 71, 90) : color.rgb(244, 67, 54, 90))
//get date period
startDate = input.time(title='Start Time : ', defval=timestamp('1 aug 2022 00:00'), tooltip='first time', group="Date & Time")
endDate = input.time(title='End Time : ', defval=timestamp('1 Sep 2022 00:00'), tooltip='last time', group="Date & Time")
res = input.timeframe(title='Time Frame : ', defval='D', group="Date & Time")
//counting the period range
timeDispute = endDate - startDate
int t = 0
int divide = 0
float highst = 0.00
float lowst = 0.00
float hCloud = 0.00
float lCloud = 0.00
htp1 = line.new(t, t, t, t, xloc=xloc.bar_time, color=color.green, style=line.style_dashed)
htp2 = line.new(t, t, t, t, xloc=xloc.bar_time, color=color.green, style=line.style_dashed)
ltp1 = line.new(t, t, t, t, xloc=xloc.bar_time, color=color.red, style=line.style_dashed)
ltp2 = line.new(t, t, t, t, xloc=xloc.bar_time, color=color.red, style=line.style_dashed)
if res == '15'
divide := timeDispute / 900000
t := math.floor((timenow - startDate) / 900000)
highst := high[t]
lowst := low[t]
hCloud := leadLine1[t + displacement - 1]
lCloud := leadLine2[t + displacement - 1]
for i = 0 to divide by 1
if highst < high[t]
highst := high[t]
highst
if lowst > low[t]
lowst := low[t]
lowst
if leadLine1[t + displacement - 1] >= leadLine2[t + displacement - 1]
if hCloud < leadLine1[t + displacement - 1]
hCloud := leadLine1[t + displacement - 1]
hCloud
if lCloud > leadLine2[t + displacement - 1]
lCloud := leadLine2[t + displacement - 1]
lCloud
if leadLine1[t + displacement - 1] < leadLine2[t + displacement - 1]
if hCloud < leadLine2[t + displacement - 1]
hCloud := leadLine2[t + displacement - 1]
hCloud
if lCloud > leadLine1[t + displacement - 1]
lCloud := leadLine1[t + displacement - 1]
lCloud
t -= 1
t
if res == '60'
divide := timeDispute / 3600000
t := math.floor((timenow - startDate) / 3600000)
highst := high[t]
lowst := low[t]
hCloud := leadLine1[t + displacement - 1]
lCloud := leadLine2[t + displacement - 1]
for i = 0 to divide by 1
if highst < high[t]
highst := high[t]
highst
if lowst > low[t]
lowst := low[t]
lowst
if leadLine1[t + displacement - 1] >= leadLine2[t + displacement - 1]
if hCloud < leadLine1[t + displacement - 1]
hCloud := leadLine1[t + displacement - 1]
hCloud
if lCloud > leadLine2[t + displacement - 1]
lCloud := leadLine2[t + displacement - 1]
lCloud
if leadLine1[t + displacement - 1] < leadLine2[t + displacement - 1]
if hCloud < leadLine2[t + displacement - 1]
hCloud := leadLine2[t + displacement - 1]
hCloud
if lCloud > leadLine1[t + displacement - 1]
lCloud := leadLine1[t + displacement - 1]
lCloud
t -= 1
t
if res == '240'
divide := timeDispute / 14400000
t := math.floor((timenow - startDate) / 14400000)
highst := high[t]
lowst := low[t]
hCloud := leadLine1[t + displacement - 1]
lCloud := leadLine2[t + displacement - 1]
for i = 0 to divide by 1
if highst < high[t]
highst := high[t]
highst
if lowst > low[t]
lowst := low[t]
lowst
if leadLine1[t + displacement - 1] >= leadLine2[t + displacement - 1]
if hCloud < leadLine1[t + displacement - 1]
hCloud := leadLine1[t + displacement - 1]
hCloud
if lCloud > leadLine2[t + displacement - 1]
lCloud := leadLine2[t + displacement - 1]
lCloud
if leadLine1[t + displacement - 1] < leadLine2[t + displacement - 1]
if hCloud < leadLine2[t + displacement - 1]
hCloud := leadLine2[t + displacement - 1]
hCloud
if lCloud > leadLine1[t + displacement - 1]
lCloud := leadLine1[t + displacement - 1]
lCloud
t -= 1
t
if res == '1D'
divide := timeDispute / 86400000
t := math.floor((timenow - startDate) / 86400000)
highst := high[t]
lowst := low[t]
hCloud := leadLine1[t + displacement - 1]
lCloud := leadLine2[t + displacement - 1]
for i = 0 to divide by 1
if highst < high[t]
highst := high[t]
highst
if lowst > low[t]
lowst := low[t]
lowst
if leadLine1[t + displacement - 1] >= leadLine2[t + displacement - 1]
if hCloud < leadLine1[t + displacement - 1]
hCloud := leadLine1[t + displacement - 1]
hCloud
if lCloud > leadLine2[t + displacement - 1]
lCloud := leadLine2[t + displacement - 1]
lCloud
if leadLine1[t + displacement - 1] < leadLine2[t + displacement - 1]
if hCloud < leadLine2[t + displacement - 1]
hCloud := leadLine2[t + displacement - 1]
hCloud
if lCloud > leadLine1[t + displacement - 1]
lCloud := leadLine1[t + displacement - 1]
lCloud
t -= 1
t
if res == '1W'
divide := timeDispute / 604800000
t := math.floor((timenow - startDate) / 604800000)
highst := high[t]
lowst := low[t]
hCloud := leadLine1[t + displacement - 1]
lCloud := leadLine2[t + displacement - 1]
for i = 0 to divide by 1
if highst < high[t]
highst := high[t]
highst
if lowst > low[t]
lowst := low[t]
lowst
if leadLine1[t + displacement - 1] >= leadLine2[t + displacement - 1]
if hCloud < leadLine1[t + displacement - 1]
hCloud := leadLine1[t + displacement - 1]
hCloud
if lCloud > leadLine2[t + displacement - 1]
lCloud := leadLine2[t + displacement - 1]
lCloud
if leadLine1[t + displacement - 1] < leadLine2[t + displacement - 1]
if hCloud < leadLine2[t + displacement - 1]
hCloud := leadLine2[t + displacement - 1]
hCloud
if lCloud > leadLine1[t + displacement - 1]
lCloud := leadLine1[t + displacement - 1]
lCloud
t -= 1
t
cloudArea = (hCloud - lCloud) / 2
highTP1 = highst + cloudArea
highTP2 = highst + cloudArea * 2
lowTP1 = lowst - cloudArea
lowTP2 = lowst - cloudArea * 2
plot(cloudArea, title='cloud area', color=color.new(color.red, 0))
line.set_x1(htp1, startDate)
line.set_y1(htp1, highTP1)
line.set_x2(htp1, endDate)
line.set_y2(htp1, highTP1)
line.set_extend(htp1, extend.right)
line.delete(htp1[1])
t1=label.new(bar_index, highTP1, "First Long Target", textcolor=color.green, style=label.style_none)
label.delete(t1[1])
line.set_x1(htp2, startDate)
line.set_y1(htp2, highTP2)
line.set_x2(htp2, endDate)
line.set_y2(htp2, highTP2)
line.set_extend(htp2, extend.right)
line.delete(htp2[1])
t2=label.new(bar_index, highTP2, "Second Long Target", textcolor=color.green, style=label.style_none)
label.delete(t2[1])
line.set_x1(ltp1, startDate)
line.set_y1(ltp1, lowTP1)
line.set_x2(ltp1, endDate)
line.set_y2(ltp1, lowTP1)
line.set_extend(ltp1, extend.right)
line.delete(ltp1[1])
t3=label.new(bar_index, lowTP1, "First Short Target", textcolor=color.red, style=label.style_none)
label.delete(t3[1])
line.set_x1(ltp2, startDate)
line.set_y1(ltp2, lowTP2)
line.set_x2(ltp2, endDate)
line.set_y2(ltp2, lowTP2)
line.set_extend(ltp2, extend.right)
line.delete(ltp2[1])
t4=label.new(bar_index, lowTP2, "Second Short Target", textcolor=color.red, style=label.style_none)
label.delete(t4[1])
|
MarketProfile | https://www.tradingview.com/script/UQAKYGfY-MarketProfile/ | alphatrader09 | https://www.tradingview.com/u/alphatrader09/ | 141 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © shahanimesh
//@version=5
indicator("Market Profile", overlay = true, max_lines_count = 500)
_1 = input(title='---------Settings for Generating Market Profile---------', defval=true)
tpoSize = input(title='Declaring TPOsize', defval=20)
timeFrame = input(title='Specifying the Timeframe for MarketProfile', defval='D')
_targetArea = input(title='Defing Value Area', defval=70)
_showSession = input.int(title='Sessions to display', defval=5, minval=1, maxval=20, tooltip='Session number to display.')
sizing = input.int(title='Adjust Size of Plot', defval=100, tooltip='Reduces/Increase the box size')
uppercol = input(title='Colors for Value Area High', defval=#f50000)
downcol = input(title='Colors for Value Area Low', defval=#00c700)
poccol = input(title='Color of PoC', defval=#00bfff)
pvacol = input.color(title = "PreviousValue Area", defval = color.silver)
cvacol = input.color(title = "Current Value Area Color", defval = color.orange)
showMp = input.bool(defval = true, title = "Show MarketProfile")
// Declaring Global Variables
bool newSession = ta.change(time(timeFrame)) != 0
bool inSession = ta.change(time(timeFrame)) == 0
// support functions for calculation of Market Profile
inrange(_tpo, _high, _low) =>
cond = _high >= _tpo and _low <= _tpo
cond
get_index(_array, up, dn) =>
upval = array.get(_array, up)
dnval = array.get(_array, dn)
index = upval > dnval ? up : dn
val = math.max(upval, dnval)
[index, val]
//Define Function
MarketProfile(res) =>
float tfHigh = na
float tfLow = na
int barNum = na
var tpoIndex = array.new_float(tpoSize + 2, 0)
var tpoValue = array.new_float(tpoSize + 2, 0)
// setting Values
tfHigh := newSession ? high : math.max(tfHigh[1], high)
tfLow := newSession ? low : math.min(tfLow[1], low)
barNum := newSession ? 0 : barNum[1] + 1
ranGe = tfHigh - tfLow
tpoDiff = ranGe / tpoSize
// assigning values to arrays and generating tpos and Length
float tpoSum = 0
for x = 0 to tpoSize by 1
_tpovalue = tfLow + x * tpoDiff
array.set(tpoValue, x, _tpovalue)
float tpoind = 0.0
for i = 0 to barNum by 1
if inrange(_tpovalue, high[i], low[i])
tpoind += 1.0
tpoind
_tpoIndex = tpoind
array.set(tpoIndex, x, _tpoIndex)
tpoSum += _tpoIndex
tpoSum
//getting Point of Control, Value Area High and Value Area Low
pocLen = array.max(tpoIndex)
pocIndex = array.indexof(tpoIndex, pocLen)
pocValue = tfLow + pocIndex * tpoDiff
int vaHighIndex = pocIndex
int vaLowIndex = pocIndex
float valueArea = pocLen
float targetArea = tpoSum * _targetArea / 100
for x = 0 to tpoSize by 1
if valueArea <= targetArea
tup = math.min(tpoSize, vaHighIndex + 1)
tdn = math.max(0, vaLowIndex - 1)
[index, val] = get_index(tpoIndex, tup, tdn)
if index == tdn
vaLowIndex := tdn
valueArea += val
valueArea
else
vaHighIndex := tup
valueArea += val
valueArea
vaHigh = tfLow + vaHighIndex * tpoDiff
vaLow = tfLow + vaLowIndex * tpoDiff
[pocValue, vaHigh, vaLow, tpoIndex, tpoValue, tpoDiff]
[pocValue, vaHigh, vaLow, tpoIndex, tpoValue, tpoDiff] = MarketProfile(timeFrame)
var int bartime = na
bartime := na(bartime) ? time - time[1] : math.min(bartime, time - time[1])
start = time_close(timeFrame)
drawLine(val,index) =>
_x1 = start
_x2 = _x1 - bartime* int(index) * sizing/100
is_va = val <= vaHigh and val >= vaLow
is_poc = val == array.max(tpoIndex)
_col = is_poc ? poccol : is_va ? cvacol : color.silver
line.new(_x1,val,_x2,val,xloc = xloc.bar_time,color = color.new(_col,70),style = line.style_solid, width = 8)
setvalues(Line,val,index) =>
_x1 = start
_x2 = _x1 - bartime* int(index) * sizing/100
is_va = val <= vaHigh and val >= vaLow
is_poc = val == pocValue
_col = is_poc ? poccol : is_va ? cvacol : color.silver
line.set_xy1(Line,_x1,val)
line.set_xy2(Line,_x2,val)
line.set_color(Line,color.new(_col,70))
var line [] mpro = array.new_line(tpoSize + 2)
if newSession and showMp
for x = 0 to tpoSize
array.set(mpro,x,drawLine(array.get(tpoValue,x), array.get(tpoIndex,x)))
else
for x = 0 to tpoSize
setvalues(array.get(mpro,x),array.get(tpoValue,x), array.get(tpoIndex,x))
previousDayPOC = ta.valuewhen(newSession, pocValue[1], 0)
previousDayVaH = ta.valuewhen(newSession, vaHigh[1], 0)
previousDayVaL = ta.valuewhen(newSession, vaLow[1], 0)
drawLines(x1,x2,value,col,_style,_width)=>
line.new(x1,value,x2,value, xloc = xloc.bar_time, color = col, style = _style, width = _width)
drawBox(x1,y1,x2,y2, col, _style, _width, _bgcol, txt, size)=>
box.new(x1,y1,x2,y2, border_color = col, border_width = _width, border_style = _style, extend = extend.none, xloc = xloc.bar_time, bgcolor = _bgcol, text = txt, text_size = size)
setvalue(Line,val)=>
line.set_y1(Line,val)
line.set_y2(Line, val)
var line Poc = na
var line cPOC = na
var line cVaH = na
var line cVaL = na
var box valuebox = na
if newSession
starts = time
end = time_close(timeFrame)
// Poc := drawLines(starts, end, previousDayPOC, color.aqua, line.style_solid,2)
cPOC := drawLines(starts, end, pocValue, poccol, line.style_solid,2)
cVaH := drawLines(starts, end, vaHigh, uppercol, line.style_solid,2)
cVaL := drawLines(starts, end, vaLow, downcol, line.style_solid,2)
valuebox := drawBox(starts,previousDayVaH, end, previousDayVaL, pvacol, line.style_dotted, 1, color.new(pvacol,90), "Previous Value Area", size.normal)
else
setvalue(cPOC, pocValue)
setvalue(cVaH, vaHigh)
setvalue(cVaL, vaLow)
|
Crypto Relative Performance | https://www.tradingview.com/script/thurYejZ-Crypto-Relative-Performance/ | mcamps-nl | https://www.tradingview.com/u/mcamps-nl/ | 12 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mcamps-nl
//@version=4
study("Crypto Relative Performance")
var symTotalCryptoCap = "CRYPTOCAP:TOTAL"
var dailyTimeFramePeriod = "D"
totalOpen = security(symTotalCryptoCap, dailyTimeFramePeriod, open)
totalClose = security(symTotalCryptoCap, timeframe.period, close)
totalChangeFraction = (totalClose - totalOpen) / totalOpen
currentOpen = security(syminfo.tickerid, dailyTimeFramePeriod, open)
currentClose = close
currentChangeFraction = (currentClose - currentOpen) / currentOpen
diff = currentChangeFraction - totalChangeFraction
performance = (diff[0] * diff[1]) > 0 or (diff[1] * diff[2]) > 0 ? diff * 100 : 0
plotColor = performance >= 0 ? color.green : color.red
plot0 = plot(0, color=plotColor)
plotPerformance = plot(performance, color=plotColor)
fill(plot0, plotPerformance, color= color.new(plotColor, 70)) |
RSI Enhanced Candles | https://www.tradingview.com/script/RUSxJQIa-RSI-Enhanced-Candles/ | Javafuel | https://www.tradingview.com/u/Javafuel/ | 47 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//
// IMPOTANT:
// In order to use this script, the default candles must be hidden via
// Chart Settings->Symbol Body, Borders and Wick.
//
// © Javafuel
//@version=4
study("RSI Enhanced Candles", overlay=true)
// RSI Settings
src = input(close, title="RSI Source")
len = input(14, minval=1, title="RSI Length")
len1 = input(70, minval=1, title="RSI Upper Level")
len2 = input(30, minval=1, title="RSI Lower Level")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
// RSI candles cretiera
upRsiCandleBull = rsi >= len1 and close >= open
upRsiCandleBear = rsi >= len1 and close <= open
lowRsiCandleBull = rsi <= len2 and close >= open
lowRsiCandleBear = rsi <= len2 and close <= open
// Stanard Candles Coloring
bullCandle = close >= open
bullCandleP = input(40, minval=0, maxval=100, step=10, title="Candles Transparency")
bullCandleC = input(title="Bull Candles Color", type=input.color, defval=#26a69a)
bearCandleC = input(title="Bear Candles Color", type=input.color, defval=#ef5350)
// Plot Stanard Candles
// Plot Stanard Bull Candles
plotcandle(bullCandle ? open : na, bullCandle ? high : na, bullCandle ? low : na, bullCandle ? close : na,
color=color.new(bullCandleC, bullCandleP), wickcolor=color.new(bullCandleC, bullCandleP), bordercolor=color.new(bullCandleC, bullCandleP), title="Bull Candles")
// plot Stanard Bear Candles
plotcandle(bullCandle ? na : open, bullCandle ? na : high, bullCandle ? na : low, bullCandle ? na : close,
color=color.new(bearCandleC, bullCandleP), wickcolor=color.new(bearCandleC, bullCandleP), bordercolor=color.new(bearCandleC, bullCandleP), title="Bear Candles")
// RSI Candles Coloring
rsiCandleP = input(0, minval=0, maxval=100, step=10, title="RSI Candles Transparency")
rsiBullCandleC = input(title="RSI Bull Candles Color", type=input.color, defval=#50ffee)
rsiBearCandleC = input(title="RSI Bear Candles Color", type=input.color, defval=#ff0065)
// Plot RSI Candles
// Plot upRsiCandleBull
plotcandle(upRsiCandleBull ? open : na, upRsiCandleBull ? high : na, upRsiCandleBull ? low : na, upRsiCandleBull ? close : na,
color=color.new(rsiBullCandleC, rsiCandleP), wickcolor=color.new(rsiBullCandleC, rsiCandleP), bordercolor=color.new(rsiBullCandleC, rsiCandleP), title="RSI Upper Bulls")
// Plot pRsiCandleBear
plotcandle(upRsiCandleBear ? open : na, upRsiCandleBear ? high : na, upRsiCandleBear ? low : na, upRsiCandleBear ? close : na,
color=color.new(rsiBearCandleC, rsiCandleP), wickcolor=color.new(rsiBearCandleC, rsiCandleP), bordercolor=color.new(rsiBearCandleC, rsiCandleP), title="RSI Upper Bears")
// Plot lowRsiCandleBull
plotcandle(lowRsiCandleBull ? open : na, lowRsiCandleBull ? high : na, lowRsiCandleBull ? low : na, lowRsiCandleBull ? close : na,
color=color.new(rsiBullCandleC, rsiCandleP), wickcolor=color.new(rsiBullCandleC, rsiCandleP), bordercolor=color.new(rsiBullCandleC, rsiCandleP), title="RSI Lower Bulls")
// Plot lowRsiCandleBear
plotcandle(lowRsiCandleBear ? open : na, lowRsiCandleBear ? high : na, lowRsiCandleBear ? low : na, lowRsiCandleBear ? close : na,
color=color.new(rsiBearCandleC, rsiCandleP), wickcolor=color.new(rsiBearCandleC, rsiCandleP), bordercolor=color.new(rsiBearCandleC, rsiCandleP), title="RSI Lower Bears") |
Seasonality | https://www.tradingview.com/script/i1TZiqVf-Seasonality/ | ChartingCycles | https://www.tradingview.com/u/ChartingCycles/ | 343 | study | 4 | MPL-2.0 | //This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//©ChartingCycles
//@version=4
study("Seasonality",scale=scale.none,overlay=true,precision=0,format=format.percent)
//-----------------------------------------------------------------------------------------
//Inputs
var string GP1 = "Seasonality Line"
Smoothing = input(title="Smoothing", type=input.integer, defval=1, minval=1, maxval=20,group=GP1)
Manual = input(title="Offset Adjust", type=input.integer, defval=0, minval=-500, maxval=500,group=GP1)
//-----------------------------------------------------------------------------------------
//This is used to exclude incomplete years
var firstBarTime = time
var firstBar = bar_index
fyear= (month(firstBarTime)>1 and dayofmonth(firstBarTime)>1) ? year(firstBarTime)+1 : year(firstBarTime)
afterStartDate = (time >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after252 = (time[252] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after504 = (time[504] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after756 = (time[756] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after1008 = (time[1008] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after1260 = (time[1260] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after1512 = (time[1512] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after1764 = (time[1764] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after2016 = (time[2016] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after2268 = (time[2268] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after2520 = (time[2520] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after2772 = (time[2772] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after3024 = (time[3024] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after3276 = (time[3276] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after3528 = (time[3528] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after3780 = (time[3780] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after4032 = (time[4032] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after4284 = (time[4284] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after4536 = (time[4536] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after4788 = (time[4788] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after5040 = (time[5040] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after5292 = (time[5292] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after5544= (time[5544] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after5796= (time[5796] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after6048= (time[6048] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after6300= (time[6300] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after6552= (time[6552] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after6804= (time[6804] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after7056= (time[7056] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after7308= (time[7308] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after7560= (time[7560] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after7812= (time[7812] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after8064= (time[8064] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after8316= (time[8316] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after8568= (time[8568] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after8820= (time[8820] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after9072= (time[9072] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after9324= (time[9324] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after9576= (time[9576] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after9828= (time[9828] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
after10080= (time[10080] >= timestamp(syminfo.timezone,fyear, 1, 1, 0, 0))
//-----------------------------------------------------------------------------------------
//Calculation for the Seasonality Line
percentage = timeframe.isdaily ? ema(
(bar_index >= 5040 and after5040) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269]),cum((close[2520]-close[2521])/close[2521]),cum((close[2772]-close[2773])/close[2773]),
cum((close[3024]-close[3025])/close[3025]),cum((close[3276]-close[3277])/close[3277]),cum((close[3528]-close[3529])/close[3529]),cum((close[3780]-close[3781])/close[3781]),cum((close[4032]-close[4033])/close[4033]),cum((close[4284]-close[4285])/close[4285]),
cum((close[4536]-close[4537])/close[4537]),cum((close[4788]-close[4789])/close[4789]),cum((close[5040]-close[5041])/close[5041])) :
(bar_index >= 4788 and after4788) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269]),cum((close[2520]-close[2521])/close[2521]),cum((close[2772]-close[2773])/close[2773]),
cum((close[3024]-close[3025])/close[3025]),cum((close[3276]-close[3277])/close[3277]),cum((close[3528]-close[3529])/close[3529]),cum((close[3780]-close[3781])/close[3781]),cum((close[4032]-close[4033])/close[4033]),cum((close[4284]-close[4285])/close[4285]),
cum((close[4536]-close[4537])/close[4537]),cum((close[4788]-close[4789])/close[4789])) :
(bar_index >= 4536 and after4536) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269]),cum((close[2520]-close[2521])/close[2521]),cum((close[2772]-close[2773])/close[2773]),
cum((close[3024]-close[3025])/close[3025]),cum((close[3276]-close[3277])/close[3277]),cum((close[3528]-close[3529])/close[3529]),cum((close[3780]-close[3781])/close[3781]),cum((close[4032]-close[4033])/close[4033]),cum((close[4284]-close[4285])/close[4285]),
cum((close[4536]-close[4537])/close[4537])) :
(bar_index >= 4284 and after4284) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269]),cum((close[2520]-close[2521])/close[2521]),cum((close[2772]-close[2773])/close[2773]),
cum((close[3024]-close[3025])/close[3025]),cum((close[3276]-close[3277])/close[3277]),cum((close[3528]-close[3529])/close[3529]),cum((close[3780]-close[3781])/close[3781]),cum((close[4032]-close[4033])/close[4033]),cum((close[4284]-close[4285])/close[4285])) :
(bar_index >= 4032 and after4032) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269]),cum((close[2520]-close[2521])/close[2521]),cum((close[2772]-close[2773])/close[2773]),
cum((close[3024]-close[3025])/close[3025]),cum((close[3276]-close[3277])/close[3277]),cum((close[3528]-close[3529])/close[3529]),cum((close[3780]-close[3781])/close[3781]),cum((close[4032]-close[4033])/close[4033])) :
(bar_index >= 3780 and after3780) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269]),cum((close[2520]-close[2521])/close[2521]),cum((close[2772]-close[2773])/close[2773]),
cum((close[3024]-close[3025])/close[3025]),cum((close[3276]-close[3277])/close[3277]),cum((close[3528]-close[3529])/close[3529]),cum((close[3780]-close[3781])/close[3781])) :
(bar_index >= 3528 and after3528) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269]),cum((close[2520]-close[2521])/close[2521]),cum((close[2772]-close[2773])/close[2773]),
cum((close[3024]-close[3025])/close[3025]),cum((close[3276]-close[3277])/close[3277]),cum((close[3528]-close[3529])/close[3529])) :
(bar_index >= 3276 and after3276) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269]),cum((close[2520]-close[2521])/close[2521]),cum((close[2772]-close[2773])/close[2773]),
cum((close[3024]-close[3025])/close[3025]),cum((close[3276]-close[3277])/close[3277])) :
(bar_index >= 3024 and after3024) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269]),cum((close[2520]-close[2521])/close[2521]),cum((close[2772]-close[2773])/close[2773]),
cum((close[3024]-close[3025])/close[3025])) :
(bar_index >= 2772 and after2772) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269]),cum((close[2520]-close[2521])/close[2521]),cum((close[2772]-close[2773])/close[2773])) :
(bar_index >= 2520 and after2520) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269]),cum((close[2520]-close[2521])/close[2521])) :
(bar_index >= 2268 and after2268) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017]),cum((close[2268]-close[2269])/close[2269])) :
(bar_index >= 2016 and after2016) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765]),cum((close[2016]-close[2017])/close[2017])) :
(bar_index >= 1764 and after1764) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513]),cum((close[1764]-close[1765])/close[1765])) :
(bar_index >= 1512 and after1512) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261]),
cum((close[1512]-close[1513])/close[1513])) :
(bar_index >= 1260 and after1260) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009]),cum((close[1260]-close[1261])/close[1261])) :
(bar_index >= 1008 and after1008) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757]),cum((close[1008]-close[1009])/close[1009])) :
(bar_index >= 756 and after756) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505]),cum((close[756]-close[757])/close[757])) :
(bar_index >= 504 and after504) ? avg(cum((close[0]-close[1])/close[1]),cum((close[252]-close[253])/close[253]),cum((close[504]-close[505])/close[505])) :
(bar_index >= 252 and after252) ? avg(cum((close[252]-close[253])/close[253]),cum((close[0]-close[1])/close[1])) :
(bar_index >= 0 and afterStartDate) ? cum((close[0]-close[1])/close[1]): na,Smoothing): na
//-----------------------------------------------------------------------------------------
//Rolling 5-Day Seasonality
y2= timeframe.isdaily ? (bar_index >= 5040 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268], (close[2515]-close[2520])/close[2520], (close[2767]-close[2772])/close[2772], (close[3019]-close[3024])/close[3024], (close[3271]-close[3276])/close[3276], (close[3523]-close[3528])/close[3528],
(close[3775]-close[3780])/close[3780], (close[4027]-close[4032])/close[4032], (close[4279]-close[4284])/close[4284], (close[4531]-close[4536])/close[4536], (close[4783]-close[4788])/close[4788], (close[5035]-close[5040])/close[5040]) :
bar_index >= 4788 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268], (close[2515]-close[2520])/close[2520], (close[2767]-close[2772])/close[2772], (close[3019]-close[3024])/close[3024], (close[3271]-close[3276])/close[3276], (close[3523]-close[3528])/close[3528],
(close[3775]-close[3780])/close[3780], (close[4027]-close[4032])/close[4032], (close[4279]-close[4284])/close[4284], (close[4531]-close[4536])/close[4536], (close[4783]-close[4788])/close[4788]) :
bar_index >= 4536 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268], (close[2515]-close[2520])/close[2520], (close[2767]-close[2772])/close[2772], (close[3019]-close[3024])/close[3024], (close[3271]-close[3276])/close[3276], (close[3523]-close[3528])/close[3528],
(close[3775]-close[3780])/close[3780], (close[4027]-close[4032])/close[4032], (close[4279]-close[4284])/close[4284], (close[4531]-close[4536])/close[4536]) :
bar_index >= 4284 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268], (close[2515]-close[2520])/close[2520], (close[2767]-close[2772])/close[2772], (close[3019]-close[3024])/close[3024], (close[3271]-close[3276])/close[3276], (close[3523]-close[3528])/close[3528],
(close[3775]-close[3780])/close[3780], (close[4027]-close[4032])/close[4032], (close[4279]-close[4284])/close[4284]) :
bar_index >= 4032 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268], (close[2515]-close[2520])/close[2520], (close[2767]-close[2772])/close[2772], (close[3019]-close[3024])/close[3024], (close[3271]-close[3276])/close[3276], (close[3523]-close[3528])/close[3528],
(close[3775]-close[3780])/close[3780], (close[4027]-close[4032])/close[4032]) :
bar_index >= 3780 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268], (close[2515]-close[2520])/close[2520], (close[2767]-close[2772])/close[2772], (close[3019]-close[3024])/close[3024], (close[3271]-close[3276])/close[3276], (close[3523]-close[3528])/close[3528],
(close[3775]-close[3780])/close[3780]) :
bar_index >= 3528 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268], (close[2515]-close[2520])/close[2520], (close[2767]-close[2772])/close[2772], (close[3019]-close[3024])/close[3024], (close[3271]-close[3276])/close[3276], (close[3523]-close[3528])/close[3528]) :
bar_index >= 3276 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268], (close[2515]-close[2520])/close[2520], (close[2767]-close[2772])/close[2772], (close[3019]-close[3024])/close[3024], (close[3271]-close[3276])/close[3276]) :
bar_index >= 3024 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268], (close[2515]-close[2520])/close[2520], (close[2767]-close[2772])/close[2772], (close[3019]-close[3024])/close[3024]) :
bar_index >= 2772 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268], (close[2515]-close[2520])/close[2520], (close[2767]-close[2772])/close[2772]) :
bar_index >= 2520 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268], (close[2515]-close[2520])/close[2520]) :
bar_index >= 2268 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016], (close[2263]-close[2268])/close[2268]) :
bar_index >= 2016 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764],
(close[2011]-close[2016])/close[2016]) :
bar_index >= 1764 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512], (close[1759]-close[1764])/close[1764]) :
bar_index >= 1512 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260], (close[1507]-close[1512])/close[1512]) :
bar_index >= 1260 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008], (close[1255]-close[1260])/close[1260]) :
bar_index >= 1008 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756], (close[1003]-close[1008])/close[1008]) :
bar_index >= 756 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504], (close[751]-close[756])/close[756]) :
bar_index >= 504 ? avg((close[247]-close[252])/close[252], (close[499]-close[504])/close[504]) :
bar_index >= 252 ? (close[247]-close[252])/close[252] : na): na
//-----------------------------------------------------------------------------------------
//Rolling 20-Day Seasonality
y3= timeframe.isdaily ? (bar_index >= 5040 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268], (close[2450]-close[2520])/close[2520], (close[2752]-close[2772])/close[2772], (close[3004]-close[3024])/close[3024], (close[3256]-close[3276])/close[3276], (close[3508]-close[3528])/close[3528],
(close[3760]-close[3780])/close[3780], (close[4012]-close[4032])/close[4032], (close[4264]-close[4284])/close[4284], (close[4516]-close[4536])/close[4536], (close[4768]-close[4788])/close[4788], (close[5020]-close[5040])/close[5040]):
bar_index >= 4788 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268], (close[2450]-close[2520])/close[2520], (close[2752]-close[2772])/close[2772], (close[3004]-close[3024])/close[3024], (close[3256]-close[3276])/close[3276], (close[3508]-close[3528])/close[3528],
(close[3760]-close[3780])/close[3780], (close[4012]-close[4032])/close[4032], (close[4264]-close[4284])/close[4284], (close[4516]-close[4536])/close[4536], (close[4768]-close[4788])/close[4788]) :
bar_index >= 4536 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268], (close[2450]-close[2520])/close[2520], (close[2752]-close[2772])/close[2772], (close[3004]-close[3024])/close[3024], (close[3256]-close[3276])/close[3276], (close[3508]-close[3528])/close[3528],
(close[3760]-close[3780])/close[3780], (close[4012]-close[4032])/close[4032], (close[4264]-close[4284])/close[4284], (close[4516]-close[4536])/close[4536]) :
bar_index >= 4284 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268], (close[2450]-close[2520])/close[2520], (close[2752]-close[2772])/close[2772], (close[3004]-close[3024])/close[3024], (close[3256]-close[3276])/close[3276], (close[3508]-close[3528])/close[3528],
(close[3760]-close[3780])/close[3780], (close[4012]-close[4032])/close[4032], (close[4264]-close[4284])/close[4284]) :
bar_index >= 4032 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268], (close[2450]-close[2520])/close[2520], (close[2752]-close[2772])/close[2772], (close[3004]-close[3024])/close[3024], (close[3256]-close[3276])/close[3276], (close[3508]-close[3528])/close[3528],
(close[3760]-close[3780])/close[3780], (close[4012]-close[4032])/close[4032]) :
bar_index >= 3780 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268], (close[2450]-close[2520])/close[2520], (close[2752]-close[2772])/close[2772], (close[3004]-close[3024])/close[3024], (close[3256]-close[3276])/close[3276], (close[3508]-close[3528])/close[3528],
(close[3760]-close[3780])/close[3780]) :
bar_index >= 3528 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268], (close[2450]-close[2520])/close[2520], (close[2752]-close[2772])/close[2772], (close[3004]-close[3024])/close[3024], (close[3256]-close[3276])/close[3276], (close[3508]-close[3528])/close[3528]) :
bar_index >= 3276 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268], (close[2450]-close[2520])/close[2520], (close[2752]-close[2772])/close[2772], (close[3004]-close[3024])/close[3024], (close[3256]-close[3276])/close[3276]) :
bar_index >= 3024 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268], (close[2450]-close[2520])/close[2520], (close[2752]-close[2772])/close[2772], (close[3004]-close[3024])/close[3024]) :
bar_index >= 2772 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268], (close[2450]-close[2520])/close[2520], (close[2752]-close[2772])/close[2772]) :
bar_index >= 2520 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268], (close[2450]-close[2520])/close[2520]) :
bar_index >= 2268 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016], (close[2248]-close[2268])/close[2268]) :
bar_index >= 2016 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764],
(close[1996]-close[2016])/close[2016]) :
bar_index >= 1764 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512], (close[1744]-close[1764])/close[1764]) :
bar_index >= 1512 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260], (close[1492]-close[1512])/close[1512]) :
bar_index >= 1260 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008], (close[1240]-close[1260])/close[1260]) :
bar_index >= 1008 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756], (close[988]-close[1008])/close[1008]) :
bar_index >= 756 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504], (close[736]-close[756])/close[756]) :
bar_index >= 504 ? avg((close[232]-close[252])/close[252], (close[484]-close[504])/close[504]) :
bar_index >= 252 ? (close[232]-close[252])/close[252] : na): na
//-----------------------------------------------------------------------------------------
//This is used to align the offset according to how many bars of data there are. Not every year has a perfect 252 trading days.
autoset =
(bar_index >= 9828 and after9828) ? 4788 :
(bar_index >= 9576 and after9576) ? 4536 :
(bar_index >= 9324 and after9324) ? 4284 :
(bar_index >= 9072 and after9072) ? 4032 :
(bar_index >= 8820 and after8820) ? 3780 :
(bar_index >= 8568 and after8568) ? 3530 :
(bar_index >= 8316 and after8316) ? 3276 :
(bar_index >= 8064 and after8064) ? 3025 :
(bar_index >= 7812 and after7812) ? 2772 :
(bar_index >= 7560 and after7560) ? 2520 :
(bar_index >= 7308 and after7308) ? 2268 :
(bar_index >= 7056 and after7056) ? 2012 :
(bar_index >= 6804 and after6804) ? 1764 :
(bar_index >= 6552 and after6552) ? 1512 :
(bar_index >= 6300 and after6300) ? 1250 :
(bar_index >= 6048 and after6048) ? 999 :
(bar_index >= 5796 and after5796) ? 748 :
(bar_index >= 5544 and after5544) ? 496 :
(bar_index >= 5292 and after5292) ? 244 :
(bar_index >= 5040 and after5040) ? 244 :
(bar_index >= 4788 and after4788) ? 248 :
(bar_index >= 4536 and after4536) ? 248 :
(bar_index >= 4284 and after4284) ? 248 :
(bar_index >= 4032 and after4032) ? 248 :
(bar_index >= 3780 and after3780) ? 248 :
(bar_index >= 3528 and after3528) ? 248 :
(bar_index >= 3276 and after3276) ? 248 :
(bar_index >= 3024 and after3024) ? 249 :
(bar_index >= 2772 and after2772) ? 249 :
(bar_index >= 2520 and after2520) ? 249 :
(bar_index >= 2268 and after2268) ? 249 :
(bar_index >= 2016 and after2016) ? 251 :
(bar_index >= 1764 and after1764) ? 251 :
(bar_index >= 1512 and after1512) ? 251 :
(bar_index >= 1260 and after1260) ? 251 :
(bar_index >= 1008 and after1008) ? 251 :
(bar_index >= 756 and after756) ? 252 :
(bar_index >= 504 and after504) ? 252 :
(bar_index >= 252 and after252) ? 253 : 252
//-----------------------------------------------------------------------------------------
//Seasonality Plot
sline = plot( percentage*100, color = percentage>0 ? color.new(#26a69a, 50) : color.new(#ef5350,50),offset = autoset+Manual,linewidth=3)
hline(0,linestyle=hline.style_dotted,color = color.new(color.gray,75))
//-----------------------------------------------------------------------------------------
//YTD % Gain Calculation
specificDate = time >= timestamp(2021, 1, 4, 00, 00)
var float closeOnDate= na
if specificDate and not specificDate[1]
closeOnDate := close
YTD = (close - closeOnDate)/closeOnDate
//-----------------------------------------------------------------------------------------
//Panel
var string GP2 = "Display"
show_header = timeframe.isdaily ? input(true, title="Show Table Header", type=input.bool, inline = "10", group = GP2): false
string i_tableYpos = input("top", "Panel Position", inline = "11", options = ["top", "middle", "bottom"], group = GP2)
string i_tableXpos = input("right", "", inline = "11", options = ["left", "center", "right"], group = GP2)
string textsize = input("normal", "Text Size", inline = "12", options = ["small", "normal", "large"], group = GP2)
var table dtrDisplay = table.new(i_tableYpos + "_" + i_tableXpos, 3, 2,frame_width=1, frame_color=color.black, border_width = 1, border_color=color.black)
first_time = 0
first_time := bar_index==0 ? time : first_time[1]
if barstate.islast
// We only populate the table on the last bar.
if (show_header == true)
table.cell(dtrDisplay, 1, 0, "5-Day Seasonality", bgcolor = color.black,text_size=textsize,text_color=color.white)
table.cell(dtrDisplay, 1, 1, tostring(round(y2*100,1))+"%", bgcolor = y2<=0 ? color.red : color.teal,text_size=textsize,text_color=color.white)
table.cell(dtrDisplay, 2, 0, "20-Day Seasonality", bgcolor = color.black,text_size=textsize,text_color=color.white)
table.cell(dtrDisplay, 2, 1, tostring(round(y3*100,1))+"%", bgcolor = y3<=0 ? color.red : color.teal,text_size=textsize,text_color=color.white)
table.cell(dtrDisplay, 0, 0, "YTD Return", bgcolor= color.black,text_size=textsize,text_color=color.white)
table.cell(dtrDisplay, 0, 1, tostring(round(YTD*100,1))+"%", bgcolor= YTD<=0 ? color.red : color.teal,text_size=textsize,text_color=color.white) |
Volume Weighted Super Guppy | https://www.tradingview.com/script/3AJVyXqk-Volume-Weighted-Super-Guppy/ | pmk07 | https://www.tradingview.com/u/pmk07/ | 248 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pmk07
// based on Daryl Guppy Super EMA's https://www.tradingview.com/script/ViEwbRCA-CM-Super-Guppy/
//@version=4
study(title="Volume Weighted CM Super Guppy", shorttitle="VW CM SuperGuppy", overlay=true)
vol = na(volume) ? 1 : volume
src = close * vol
vema(x, length) =>
ema(x, length)/ema(vol, length)
len1 = input(3, minval=1, title="Fast EMA 1")
len2 = input(6, minval=1, title="Fast EMA 2")
len3 = input(9, minval=1, title="Fast EMA 3")
len4 = input(12, minval=1, title="Fast EMA 4")
len5 = input(15, minval=1, title="Fast EMA 5")
len6 = input(18, minval=1, title="Fast EMA 6")
len7 = input(21, minval=1, title="Fast EMA 7")
len8 = input(24, minval=1, title="Slow EMA 8")
len9 = input(27, minval=1, title="Slow EMA 9")
len10 = input(30, minval=1, title="Slow EMA 10")
len11 = input(33, minval=1, title="Slow EMA 11")
len12 = input(36, minval=1, title="Slow EMA 12")
len13 = input(39, minval=1, title="Slow EMA 13")
len14 = input(42, minval=1, title="Slow EMA 14")
len15 = input(45, minval=1, title="Slow EMA 15")
len16 = input(48, minval=1, title="Slow EMA 16")
len17 = input(51, minval=1, title="Slow EMA 17")
len18 = input(54, minval=1, title="Slow EMA 18")
len19 = input(57, minval=1, title="Slow EMA 19")
len20 = input(60, minval=1, title="Slow EMA 20")
len21 = input(63, minval=1, title="Slow EMA 21")
len22 = input(66, minval=1, title="Slow EMA 22")
len23 = input(200, minval=1, title="EMA 200")
ema1 = vema(src, len1)
ema2 = vema(src, len2)
ema3 = vema(src, len3)
ema4 = vema(src, len4)
ema5 = vema(src, len5)
ema6 = vema(src, len6)
ema7 = vema(src, len7)
ema8 = vema(src, len8)
ema9 = vema(src, len9)
ema10 = vema(src, len10)
ema11 = vema(src, len11)
ema12 = vema(src, len12)
ema13 = vema(src, len13)
ema14 = vema(src, len14)
ema15 = vema(src, len15)
ema16 = vema(src, len16)
ema17 = vema(src, len17)
ema18 = vema(src, len18)
ema19 = vema(src, len19)
ema20 = vema(src, len20)
ema21 = vema(src, len21)
ema22 = vema(src, len22)
ema23 = vema(src, len23)
colfastL = (ema1 > ema2 and ema2 > ema3 and ema3 > ema4 and ema4 > ema5 and ema5 > ema6 and ema6 > ema7)
colfastS = (ema1 < ema2 and ema2 < ema3 and ema3 < ema4 and ema4 < ema5 and ema5 < ema6 and ema6 < ema7)
colslowL = ema8 > ema9 and ema9 > ema10 and ema10 > ema11 and ema11 > ema12 and ema12 > ema13 and ema13 > ema14 and ema14 > ema15 and ema15 > ema16 and ema16 > ema17 and ema17 > ema18 and ema18 > ema19 and ema19 > ema20 and ema20 > ema21 and ema21 > ema22
colslowS = ema8 < ema9 and ema9 < ema10 and ema10 < ema11 and ema11 < ema12 and ema12 < ema13 and ema13 < ema14 and ema14 < ema15 and ema15 < ema16 and ema16 < ema17 and ema17 < ema18 and ema18 < ema19 and ema19 < ema20 and ema20 < ema21 and ema21 < ema22
colFinal = colfastL and colslowL? color.aqua : colfastS and colslowS? color.orange : color.gray
colFinal2 = colslowL ? color.lime : colslowS ? color.red : color.gray
plot(ema1, title="Fast EMA 1", linewidth=2, color=colFinal)
plot(ema2, title="Fast EMA 2", linewidth=1, color=colFinal)
plot(ema3, title="Fast EMA 3", linewidth=1, color=colFinal)
plot(ema4, title="Fast EMA 4", linewidth=1, color=colFinal)
plot(ema5, title="Fast EMA 5", linewidth=1, color=colFinal)
plot(ema6, title="Fast EMA 6", linewidth=1, color=colFinal)
plot(ema7, title="Fast EMA 7", linewidth=2, color=colFinal)
plot(ema8, title="Slow EMA 8", linewidth=1, color=colFinal2)
plot(ema9, title="Slow EMA 9", linewidth=1, color=colFinal2)
plot(ema10, title="Slow EMA 10", linewidth=1, color=colFinal2)
plot(ema11, title="Slow EMA 11", linewidth=1, color=colFinal2)
plot(ema12, title="Slow EMA 12", linewidth=1, color=colFinal2)
plot(ema13, title="Slow EMA 13", linewidth=1, color=colFinal2)
plot(ema14, title="Slow EMA 14", linewidth=1, color=colFinal2)
plot(ema15, title="Slow EMA 15", linewidth=1, color=colFinal2)
plot(ema16, title="Slow EMA 16", linewidth=1, color=colFinal2)
plot(ema17, title="Slow EMA 17", linewidth=1, color=colFinal2)
plot(ema18, title="Slow EMA 18", linewidth=1, color=colFinal2)
plot(ema19, title="Slow EMA 19", linewidth=1, color=colFinal2)
plot(ema20, title="Slow EMA 20", linewidth=1, color=colFinal2)
plot(ema21, title="Slow EMA 21", linewidth=1, color=colFinal2)
plot(ema22, title="Slow EMA 22", linewidth=2, color=colFinal2)
plot(ema23, title="EMA 200", linewidth=2) |
Multi-Length Stochastic Average [LuxAlgo] | https://www.tradingview.com/script/XagQA3d6-Multi-Length-Stochastic-Average-LuxAlgo/ | LuxAlgo | https://www.tradingview.com/u/LuxAlgo/ | 2,127 | study | 4 | CC-BY-NC-SA-4.0 | // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=4
study("Multi-Length Stochastic Average [LuxAlgo]")
length = input(14)
source = input(close)
presmooth = input(10,'Pre-Smoothing'
,inline='presmooth')
premethod = input('SMA','',options=['None','SMA','TMA','LSMA']
,inline='presmooth')
postsmooth = input(10,'Post-Smoothing'
,inline='postsmooth')
postmethod = input('SMA','',options=['None','SMA','TMA','LSMA']
,inline='postsmooth')
//----
ma(x,k,order) =>
if order == 'SMA'
sma(x,k)
else if order == 'TMA'
sma(sma(x,k),k)
else if order == 'LSMA'
linreg(x,k,0)
else
x
//----
src = ma(source,presmooth,premethod)
var weight = array.new_float(0)
prices = array.new_float(0)
//----
avg = 0.
for i = 0 to length-1
array.push(prices,src[i])
for i = 4 to length
slice = array.slice(prices,0,i)
avg += (src-array.min(slice))/(array.max(slice)-array.min(slice))
norm = avg/(length-3)*100
sta = ma(norm,postsmooth,postmethod)
//----
css = sta > sta[1] ? #39FF11 : sta < sta[1] ? #FF3131 : na
plot = plot(sta,"Plot",fixnan(css),2)
up = plot(80,"Plot",color.gray)
dn = plot(20,"Plot",color.gray)
//----
fill(plot,up,sta > 80 ? #FF3131 : na,50)
fill(plot,dn,sta < 20 ? #39FF11 : na,50)
//----
plot(crossunder(sta,80) ? 80 : crossover(sta,20) ? 20 : na,'Circles',css,3,plot.style_circles) |
CCFp (Complex Common Frames percent) ,Currency Strength | https://www.tradingview.com/script/MYg9mC0K/ | kita3bb | https://www.tradingview.com/u/kita3bb/ | 203 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kita3bb
//@version=4
study("CCFp (Complex Common Frames percent)","CCFp",false,format.price,4)
// —————————————————————Inputs———————————————————————————————————————
show_only_pair = input(false,'Show Only Pair On Chart')
mode = input('3:LWMA','MA_Method', options = ['0:SMA','1:EMA','2:SMMA','3:LWMA'] )
src = input(ohlc4,"Price",input.source)
fastlen = input( 3,"Fast",minval = 1, maxval = 50)
slowlen = input( 5,"Slow",minval = 2, maxval = 100)
prefix = syminfo.prefix
sym1 = syminfo.basecurrency
sym2 = syminfo.currency
tf = timeframe.period
int time_frame = tf=='1' ? 1 :tf=='5' ? 5: tf=='15' ? 15 :tf=='30' ? 30 :tf == '60'? 60 :tf=='240'?240:tf == 'D'? 1440: tf == 'W' ? 10080:tf == 'M' ? 43200:na
usd = input(true,'USD')
eur = input(true,'EUR')
gbp = input(true,'GBP')
aud = input(true,'AUD')
nzd = input(true,'NZD')
cad = input(true,'CAD')
chf = input(true,'CHF')
jpy = input(true,'JPY')
color_usd = input(color.green,'Color_USD',input.color)
color_eur = input(color.blue,'Color_EUR',input.color)
color_gbp = input(color.red,'Color_GBP',input.color)
color_chf = input(color.gray,'Color_CHF',input.color)
color_jpy = input(color.maroon,'Color_JPY',input.color)
color_aud = input(color.orange,'Color_AUD',input.color)
color_cad = input(color.purple,'Color_CAD',input.color)
color_nzd = input(color.teal,'Color_NZD',input.color)
// —————————————————— data —————————————————————————————
eurusd = security(prefix + ":EURUSD",tf,src,lookahead=barmerge.lookahead_off)
gbpusd = security(prefix + ":GBPUSD",tf,src,lookahead=barmerge.lookahead_off)
audusd = security(prefix + ":AUDUSD",tf,src,lookahead=barmerge.lookahead_off)
nzdusd = security(prefix + ":NZDUSD",tf,src,lookahead=barmerge.lookahead_off)
usdcad = security(prefix + ":USDCAD",tf,src,lookahead=barmerge.lookahead_off)
usdchf = security(prefix + ":USDCHF",tf,src,lookahead=barmerge.lookahead_off)
usdjpy = security(prefix + ":USDJPY",tf,src,lookahead=barmerge.lookahead_off)
// ———————————— Calculations ———————————————————————————
/// LWMA Method
lwma(src,period) =>
float p = na
float sum = 0
float divider = period * (period + 1) / 2
for i = 0 to period-1
p := src[i] * (period - i)
sum := sum + p
sum / divider
//SMMA Method
smma(src,period) =>
ret_val = 0.0
sma_1 = sma(src, period)
ret_val := na(ret_val[1]) ? sma_1 : (ret_val[1] * (period - 1) + src) / period
ret_val
//calc ma
ma(source,method,period,time_frame) =>
float ret_val = 0
k = 1
if method == '0:SMA'
if time_frame <= 1
ret_val := ret_val + sma(source,period*k)
k += 5
if time_frame <= 5
ret_val := ret_val + sma(source,period*k)
k += 3
if time_frame <= 15
ret_val := ret_val + sma(source,period*k)
k += 2
if time_frame <= 30
ret_val := ret_val + sma(source,period*k)
k += 2
if time_frame <= 60
ret_val := ret_val + sma(source,period*k)
k += 4
if time_frame <= 240
ret_val := ret_val + sma(source,period*k)
k += 6
if time_frame <= 1440
ret_val := ret_val + sma(source,period*k)
k += 4
if time_frame <= 10080
ret_val := ret_val + sma(source,period*k)
k += 4
if time_frame <= 43200
ret_val := ret_val + sma(source,period*k)
if method == '1:EMA'
if time_frame <= 1
ret_val := ret_val + ema(source,period*k)
k += 5
if time_frame <= 5
ret_val := ret_val + ema(source,period*k)
k += 3
if time_frame <= 15
ret_val := ret_val + ema(source,period*k)
k += 2
if time_frame <= 30
ret_val := ret_val + ema(source,period*k)
k += 2
if time_frame <= 60
ret_val := ret_val + ema(source,period*k)
k += 4
if time_frame <= 240
ret_val := ret_val + ema(source,period*k)
k += 6
if time_frame <= 1440
ret_val := ret_val + ema(source,period*k)
k += 4
if time_frame <= 10080
ret_val := ret_val + ema(source,period*k)
k += 4
if time_frame <= 43200
ret_val := ret_val + ema(source,period*k)
if method == '2:SMMA'
if time_frame <= 1
ret_val := ret_val + smma(source,period*k)
k += 5
if time_frame <= 5
ret_val := ret_val + smma(source,period*k)
k += 3
if time_frame <= 15
ret_val := ret_val + smma(source,period*k)
k += 2
if time_frame <= 30
ret_val := ret_val + smma(source,period*k)
k += 2
if time_frame <= 60
ret_val := ret_val + smma(source,period*k)
k += 4
if time_frame <= 240
ret_val := ret_val + smma(source,period*k)
k += 6
if time_frame <= 1440
ret_val := ret_val + smma(source,period*k)
k += 4
if time_frame <= 10080
ret_val := ret_val + smma(source,period*k)
k += 4
if time_frame <= 43200
ret_val := ret_val + smma(source,period*k)
if method == '3:LWMA'
if time_frame <= 1
ret_val := ret_val + lwma(source,period*k)
k += 5
if time_frame <= 5
ret_val := ret_val + lwma(source,period*k)
k += 3
if time_frame <= 15
ret_val := ret_val + lwma(source,period*k)
k += 2
if time_frame <= 30
ret_val := ret_val + lwma(source,period*k)
k += 2
if time_frame <= 60
ret_val := ret_val + lwma(source,period*k)
k += 4
if time_frame <= 240
ret_val := ret_val + lwma(source,period*k)
k += 6
if time_frame <= 1440
ret_val := ret_val + lwma(source,period*k)
k += 4
if time_frame <= 10080
ret_val := ret_val + lwma(source,period*k)
k += 4
if time_frame <= 43200
ret_val := ret_val + lwma(source,period*k)
ret_val
// CCFP index
CalcCCFP(ticker,eurusd,gbpusd,audusd,nzdusd,usdchf,usdcad,usdjpy,usd,eur,gbp,aud,nzd,chf,cad,jpy,eurusd_slow,eurusd_fast,gbpusd_slow,gbpusd_fast,audusd_slow,audusd_fast,nzdusd_slow,nzdusd_fast,usdchf_slow,usdchf_fast,usdcad_slow,usdcad_fast,usdjpy_slow,usdjpy_fast) =>
float ccfp_idx = 0.0
if ticker == 'USD'
if eur
ccfp_idx += eurusd_slow / eurusd_fast - 1
if gbp
ccfp_idx += gbpusd_slow / gbpusd_fast - 1
if aud
ccfp_idx += audusd_slow / audusd_fast - 1
if nzd
ccfp_idx += nzdusd_slow / nzdusd_fast - 1
if chf
ccfp_idx += usdchf_fast / usdchf_slow - 1
if cad
ccfp_idx += usdcad_fast / usdcad_slow - 1
if jpy
ccfp_idx += usdjpy_fast / usdjpy_slow - 1
else if ticker == 'EUR'
if usd
ccfp_idx += eurusd_fast / eurusd_slow - 1
if gbp
ccfp_idx += (eurusd_fast / gbpusd_fast) / (eurusd_slow/gbpusd_slow) - 1
if aud
ccfp_idx += (eurusd_fast / audusd_fast) / (eurusd_slow/audusd_slow) - 1
if nzd
ccfp_idx += (eurusd_fast / nzdusd_fast) / (eurusd_slow/nzdusd_slow) - 1
if chf
ccfp_idx += (eurusd_fast * usdchf_fast) / (eurusd_slow * usdchf_slow) - 1
if cad
ccfp_idx += (eurusd_fast * usdcad_fast) / (eurusd_slow * usdcad_slow) - 1
if jpy
ccfp_idx += (eurusd_fast * usdjpy_fast) / (eurusd_slow * usdjpy_slow) - 1
else if ticker == 'GBP'
if usd
ccfp_idx += gbpusd_fast / gbpusd_slow - 1
if eur
ccfp_idx += (eurusd_slow / gbpusd_slow) / (eurusd_fast / gbpusd_fast) - 1
if aud
ccfp_idx += (gbpusd_fast / audusd_fast) / (gbpusd_slow / audusd_slow) - 1
if nzd
ccfp_idx += (gbpusd_fast / nzdusd_fast) / (gbpusd_slow / nzdusd_slow) - 1
if chf
ccfp_idx += (gbpusd_fast * usdchf_fast) / (gbpusd_slow * usdchf_slow) - 1
if cad
ccfp_idx += (gbpusd_fast * usdcad_fast) / (gbpusd_slow * usdcad_slow) - 1
if jpy
ccfp_idx += (gbpusd_fast * usdjpy_fast) / (gbpusd_slow * usdjpy_slow) - 1
else if ticker == 'AUD'
if usd
ccfp_idx += audusd_fast / audusd_slow - 1
if eur
ccfp_idx += (eurusd_slow / audusd_slow) / (eurusd_fast / audusd_fast) - 1
if gbp
ccfp_idx += (gbpusd_slow / audusd_slow) / (gbpusd_fast / audusd_fast) - 1
if nzd
ccfp_idx += (audusd_fast / nzdusd_fast) / (audusd_slow / nzdusd_slow) - 1
if chf
ccfp_idx += (audusd_fast * usdchf_fast) / (audusd_slow * usdchf_slow) - 1
if cad
ccfp_idx += (audusd_fast * usdcad_fast) / (audusd_slow * usdcad_slow) - 1
if jpy
ccfp_idx += (audusd_fast * usdjpy_fast) / (audusd_slow * usdjpy_slow) - 1
else if ticker == 'NZD'
if usd
ccfp_idx += nzdusd_fast / nzdusd_slow - 1
if eur
ccfp_idx += (eurusd_slow / nzdusd_slow) / (eurusd_fast / nzdusd_fast) - 1
if gbp
ccfp_idx += (gbpusd_slow / nzdusd_slow) / (gbpusd_fast / nzdusd_fast) - 1
if aud
ccfp_idx += (audusd_slow / nzdusd_slow) / (audusd_fast / nzdusd_fast) - 1
if chf
ccfp_idx += (nzdusd_fast * usdchf_fast) / (nzdusd_slow * usdchf_slow) - 1
if cad
ccfp_idx += (nzdusd_fast * usdcad_fast) / (nzdusd_slow * usdcad_slow) - 1
if jpy
ccfp_idx += (nzdusd_fast * usdjpy_fast) / (nzdusd_slow * usdjpy_slow) - 1
else if ticker == 'CAD'
if usd
ccfp_idx += usdcad_slow / usdcad_fast - 1
if eur
ccfp_idx += (eurusd_slow * usdcad_slow) / (eurusd_fast * usdcad_fast) - 1
if gbp
ccfp_idx += (gbpusd_slow * usdcad_slow) / (gbpusd_fast * usdcad_fast) - 1
if aud
ccfp_idx += (audusd_slow * usdcad_slow) / (audusd_fast * usdcad_fast) - 1
if nzd
ccfp_idx += (nzdusd_slow * usdcad_slow) / (nzdusd_fast * usdcad_fast) - 1
if chf
ccfp_idx += (usdchf_fast / usdcad_fast) / (usdchf_slow / usdcad_slow) - 1
if jpy
ccfp_idx += (usdjpy_fast / usdcad_fast) / (usdjpy_slow / usdcad_slow) - 1
else if ticker == 'CHF'
if usd
ccfp_idx += usdchf_slow / usdchf_fast - 1
if eur
ccfp_idx += (eurusd_slow * usdchf_slow) / (eurusd_fast * usdchf_fast) - 1
if gbp
ccfp_idx += (gbpusd_slow * usdchf_slow) / (gbpusd_fast * usdchf_fast) - 1
if aud
ccfp_idx += (audusd_slow * usdchf_slow) / (audusd_fast * usdchf_fast) - 1
if nzd
ccfp_idx += (nzdusd_slow * usdchf_slow) / (nzdusd_fast * usdchf_fast) - 1
if cad
ccfp_idx += (usdchf_slow / usdcad_slow) / (usdchf_fast / usdcad_fast) - 1
if jpy
ccfp_idx += (usdjpy_fast / usdchf_fast) / (usdjpy_slow / usdchf_slow) - 1
else if ticker == 'JPY'
if usd
ccfp_idx += usdjpy_slow / usdjpy_fast - 1
if eur
ccfp_idx += (eurusd_slow * usdjpy_slow) / (eurusd_fast * usdjpy_fast) - 1
if gbp
ccfp_idx += (gbpusd_slow * usdjpy_slow) / (gbpusd_fast * usdjpy_fast) - 1
if aud
ccfp_idx += (audusd_slow * usdjpy_slow) / (audusd_fast * usdjpy_fast) - 1
if nzd
ccfp_idx += (nzdusd_slow * usdjpy_slow) / (nzdusd_fast * usdjpy_fast) - 1
if cad
ccfp_idx += (usdjpy_slow / usdcad_slow) / (usdjpy_fast / usdcad_fast) - 1
if chf
ccfp_idx += (usdjpy_slow / usdchf_slow) / (usdjpy_fast / usdchf_fast) - 1
ccfp_idx
show_usd = show_only_pair ? (sym1 == 'USD' or sym2 == 'USD') and usd :usd
show_eur = show_only_pair ? (sym1 == 'EUR' or sym2 == 'EUR') and eur :eur
show_gbp = show_only_pair ? (sym1 == 'GBP' or sym2 == 'GBP') and gbp :gbp
show_aud = show_only_pair ? (sym1 == 'AUD' or sym2 == 'AUD') and aud :aud
show_nzd = show_only_pair ? (sym1 == 'NZD' or sym2 == 'NZD') and nzd :nzd
show_cad = show_only_pair ? (sym1 == 'CAD' or sym2 == 'CAD') and cad :cad
show_chf = show_only_pair ? (sym1 == 'CHF' or sym2 == 'CHF') and chf :chf
show_jpy = show_only_pair ? (sym1 == 'JPY' or sym2 == 'JPY') and jpy :jpy
eurusd_slow = eur ? ma(eurusd,mode,slowlen,time_frame) : na
eurusd_fast = eur ? ma(eurusd,mode,fastlen,time_frame) : na
gbpusd_slow = gbp ? ma(gbpusd,mode,slowlen,time_frame) : na
gbpusd_fast = gbp ? ma(gbpusd,mode,fastlen,time_frame) : na
audusd_slow = aud ? ma(audusd,mode,slowlen,time_frame) : na
audusd_fast = aud ? ma(audusd,mode,fastlen,time_frame) : na
nzdusd_slow = nzd ? ma(nzdusd,mode,slowlen,time_frame) : na
nzdusd_fast = nzd ? ma(nzdusd,mode,fastlen,time_frame) : na
usdchf_slow = chf ? ma(usdchf,mode,slowlen,time_frame) : na
usdchf_fast = chf ? ma(usdchf,mode,fastlen,time_frame) : na
usdcad_slow = cad ? ma(usdcad,mode,slowlen,time_frame) : na
usdcad_fast = cad ? ma(usdcad,mode,fastlen,time_frame) : na
usdjpy_slow = jpy ? ma(usdjpy,mode,slowlen,time_frame) : na
usdjpy_fast = jpy ? ma(usdjpy,mode,fastlen,time_frame) : na
USD = show_usd ? CalcCCFP('USD',eurusd,gbpusd,audusd,nzdusd,usdchf,usdcad,usdjpy,usd,eur,gbp,aud,nzd,chf,cad,jpy,eurusd_slow,eurusd_fast,gbpusd_slow,gbpusd_fast,audusd_slow,audusd_fast,nzdusd_slow,nzdusd_fast,usdchf_slow,usdchf_fast,usdcad_slow,usdcad_fast,usdjpy_slow,usdjpy_fast) : na
EUR = show_eur ? CalcCCFP('EUR',eurusd,gbpusd,audusd,nzdusd,usdchf,usdcad,usdjpy,usd,eur,gbp,aud,nzd,chf,cad,jpy,eurusd_slow,eurusd_fast,gbpusd_slow,gbpusd_fast,audusd_slow,audusd_fast,nzdusd_slow,nzdusd_fast,usdchf_slow,usdchf_fast,usdcad_slow,usdcad_fast,usdjpy_slow,usdjpy_fast) : na
GBP = show_gbp ? CalcCCFP('GBP',eurusd,gbpusd,audusd,nzdusd,usdchf,usdcad,usdjpy,usd,eur,gbp,aud,nzd,chf,cad,jpy,eurusd_slow,eurusd_fast,gbpusd_slow,gbpusd_fast,audusd_slow,audusd_fast,nzdusd_slow,nzdusd_fast,usdchf_slow,usdchf_fast,usdcad_slow,usdcad_fast,usdjpy_slow,usdjpy_fast) : na
AUD = show_aud ? CalcCCFP('AUD',eurusd,gbpusd,audusd,nzdusd,usdchf,usdcad,usdjpy,usd,eur,gbp,aud,nzd,chf,cad,jpy,eurusd_slow,eurusd_fast,gbpusd_slow,gbpusd_fast,audusd_slow,audusd_fast,nzdusd_slow,nzdusd_fast,usdchf_slow,usdchf_fast,usdcad_slow,usdcad_fast,usdjpy_slow,usdjpy_fast) : na
NZD = show_nzd ? CalcCCFP('NZD',eurusd,gbpusd,audusd,nzdusd,usdchf,usdcad,usdjpy,usd,eur,gbp,aud,nzd,chf,cad,jpy,eurusd_slow,eurusd_fast,gbpusd_slow,gbpusd_fast,audusd_slow,audusd_fast,nzdusd_slow,nzdusd_fast,usdchf_slow,usdchf_fast,usdcad_slow,usdcad_fast,usdjpy_slow,usdjpy_fast) : na
CAD = show_cad ? CalcCCFP('CAD',eurusd,gbpusd,audusd,nzdusd,usdchf,usdcad,usdjpy,usd,eur,gbp,aud,nzd,chf,cad,jpy,eurusd_slow,eurusd_fast,gbpusd_slow,gbpusd_fast,audusd_slow,audusd_fast,nzdusd_slow,nzdusd_fast,usdchf_slow,usdchf_fast,usdcad_slow,usdcad_fast,usdjpy_slow,usdjpy_fast) : na
CHF = show_chf ? CalcCCFP('CHF',eurusd,gbpusd,audusd,nzdusd,usdchf,usdcad,usdjpy,usd,eur,gbp,aud,nzd,chf,cad,jpy,eurusd_slow,eurusd_fast,gbpusd_slow,gbpusd_fast,audusd_slow,audusd_fast,nzdusd_slow,nzdusd_fast,usdchf_slow,usdchf_fast,usdcad_slow,usdcad_fast,usdjpy_slow,usdjpy_fast) : na
JPY = show_jpy ? CalcCCFP('JPY',eurusd,gbpusd,audusd,nzdusd,usdchf,usdcad,usdjpy,usd,eur,gbp,aud,nzd,chf,cad,jpy,eurusd_slow,eurusd_fast,gbpusd_slow,gbpusd_fast,audusd_slow,audusd_fast,nzdusd_slow,nzdusd_fast,usdchf_slow,usdchf_fast,usdcad_slow,usdcad_fast,usdjpy_slow,usdjpy_fast) : na
// ————— Plots --------//
plot(USD,title = 'USD',color = color_usd,linewidth= 2, style = plot.style_line,transp = 20)
plot(EUR,title = 'EUR',color = color_eur,linewidth= 2, style = plot.style_line,transp = 20)
plot(GBP,title = 'GBP',color = color_gbp,linewidth= 2, style = plot.style_line,transp = 20)
plot(AUD,title = 'AUD',color = color_aud,linewidth= 2, style = plot.style_line,transp = 20)
plot(NZD,title = 'NZD',color = color_nzd,linewidth= 2, style = plot.style_line,transp = 20)
plot(CAD,title = 'CAD',color = color_cad,linewidth= 2, style = plot.style_line,transp = 20)
plot(CHF,title = 'CHF',color = color_chf,linewidth= 2, style = plot.style_line,transp = 20)
plot(JPY,title = 'JPY',color = color_jpy,linewidth= 2, style = plot.style_line,transp = 20)
// --------Label------------//
style = label.style_label_left
size = size.small
var usd_label = label.new(bar_index, na, 'USD', color=color_usd, style=style, textcolor=color.white, size=size)
var eur_label = label.new(bar_index, na, 'EUR', color=color_eur, style=style, textcolor=color.white, size=size)
var gbp_label = label.new(bar_index, na, 'GBP', color=color_gbp, style=style, textcolor=color.white, size=size)
var aud_label = label.new(bar_index, na, 'AUD', color=color_aud, style=style, textcolor=color.white, size=size)
var nzd_label = label.new(bar_index, na, 'NZD', color=color_nzd, style=style, textcolor=color.white, size=size)
var cad_label = label.new(bar_index, na, 'CAD', color=color_cad, style=style, textcolor=color.white, size=size)
var chf_label = label.new(bar_index, na, 'CHF', color=color_chf, style=style, textcolor=color.white, size=size)
var jpy_label = label.new(bar_index, na, 'JPY', color=color_jpy, style=style, textcolor=color.white, size=size)
if barstate.islast
if show_usd
label.set_xy(usd_label,bar_index + 3, USD)
if show_eur
label.set_xy(eur_label,bar_index + 3, EUR)
if show_gbp
label.set_xy(gbp_label,bar_index + 3, GBP)
if show_aud
label.set_xy(aud_label,bar_index + 3, AUD)
if show_nzd
label.set_xy(nzd_label,bar_index + 3, NZD)
if show_cad
label.set_xy(cad_label,bar_index + 3, CAD)
if show_chf
label.set_xy(chf_label,bar_index + 3, CHF)
if show_jpy
label.set_xy(jpy_label,bar_index + 3, JPY)
|
Gann Angle Table Calculator Plotter | https://www.tradingview.com/script/MS2Lkn1K-Gann-Angle-Table-Calculator-Plotter/ | RozaniGhani-RG | https://www.tradingview.com/u/RozaniGhani-RG/ | 283 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RozaniGhani-RG
//@version=4
study("Gann Angle Table Calculator Plotter", shorttitle = "GA", overlay = true, precision = 2)
// 1. Input
// 2. Variables
// 3. Ternary Conditional Operator
// 4. Array
// 5. Custom functions
// 6. Construct
// 7. Plot
// 1. Input
// Tooltip
string T0 = "Enter Price High or Low or any Price value."
string T1 = "Direction depends Price.\nUntick to reverse color."
string T2 = "Change table position."
string T3 = "Enable price to use decimal (0 to 3) and currency."
string T4 = "Hide table."
string T5 = "Track Plot."
// Group
var string G1 = "Table Font Position"
var string G2 = "Gann Angle Track Plot"
// Inline
var string I1 = "Cardinal 1"
var string I2 = "Cross"
var string I3 = "Cardinal 2"
// Price
i_price = input(0, "Price ", inline = "0", type = input.float, minval= 0)
col_price = input(color.yellow, " ", inline = "0", tooltip = T0)
i_dir = input("Positive", "Direction ", inline = "1", options = ["Positive", "Negative"])
i_reverse = input(true, "", inline = "1")
i_pos = input(color.lime, "", inline = "1")
i_neg = input(color.red, "", inline = "1", tooltip = T1)
// Table
// Table 0
i_show_0 = input(true, "Gann ", inline = "2", group = G1)
string i_font_0 = input("normal", "", inline = "2", group = G1, options = ["tiny", "small", "normal", "large", "huge"])
string i_Y_0 = input("bottom", "", inline = "2", group = G1, options = ["top", "middle", "bottom"])
string i_X_0 = input("right", "", inline = "2", group = G1, options = ["left", "center", "right"])
// Table 1
i_show_1 = input(true, "Formula", inline = "3", group = G1)
string i_font_1 = input("normal", "", inline = "3", group = G1, options = ["tiny", "small", "normal", "large", "huge"])
string i_Y_1 = input("bottom", "", inline = "3", group = G1, options = ["top", "middle", "bottom"])
string i_X_1 = input("left", "", inline = "3", group = G1, options = ["left", "center", "right"])
// Other table setting
i_value = input(false, "Price ", inline = "4", group = G1)
i_currency = input(false, "Currency ", inline = "4", group = G1)
i_decimal = input(0, "", inline = "4", group = G1, tooltip = T3, options = [0, 1, 2, 3])
// Gann Angle
g_025 = input(true, "45 ", inline = I1, group = G2)
g_050 = input(true, "90 ", inline = I1, group = G2)
g_075 = input(true, "135 ", inline = I1, group = G2)
track_price = input(false, "Price", inline = I1, group = G2)
//
g_200 = input(true, "360", inline = I2, group = G2)
g_price = input(true, "Price", inline = I2, group = G2)
g_100 = input(true, "180 ", inline = I2, group = G2)
track_gann = input(false, "Gann", inline = I2, group = G2)
//
g_175 = input(true, "315", inline = I3, group = G2)
g_150 = input(true, "270 ", inline = I3, group = G2)
g_125 = input(true, "225", inline = I3, group = G2)
// 2. Variables
var gann_table = table.new(position = i_Y_0 + "_" + i_X_0, columns = 7, rows = 5, bgcolor = color.new(color.blue,100))
var calc_table = table.new(position = i_Y_1 + "_" + i_X_1, columns = 7, rows = 10, bgcolor = color.new(color.blue,100), border_color = color.new(color.blue, 100), border_width = 1)
// 3. Ternary Conditional Operator
col_pos = i_reverse ? i_pos : i_neg
col_neg = i_reverse ? i_neg : i_pos
ter_currency = i_currency ? syminfo.currency + "\n" : ""
price_text = i_dir == "Positive" ? "+++" : "---"
decimal = i_decimal == 1 ? "#.#" : i_decimal == 2 ? "#.##" : i_decimal == 3 ? "#.###" : "#"
// 4. Array
// Array for both table
arr_deg = array.new_int(), array.push(arr_deg, 0)
arr_mult = array.new_float(), array.push(arr_mult, 0)
arr_pos = array.new_float()
arr_neg = array.new_float()
sqrt_price = sqrt(i_price)
// Gann Degree
for d = 0 to 7
array.push(arr_deg, array.get(arr_deg, d) + 45)
array.push(arr_mult, array.get(arr_mult, d) + 0.25)
array.remove(arr_deg, 0)
array.remove(arr_mult, 0)
// Gann Formula
for n = 0 to 7
array.push(arr_pos, pow(sqrt_price + ((n + 1) * 0.25), 2))
array.push(arr_neg, pow(sqrt_price - ((n + 1) * 0.25), 2))
// 5. Custom functions
td(_id) => tostring(array.get(arr_deg, _id))
tm(_id) => tostring(array.get(arr_mult, _id))
tp(_id) => tostring(array.get(arr_pos, _id), decimal)
tn(_id) => tostring(array.get(arr_neg, _id), decimal)
ip = tostring(i_price, decimal)
sym = i_dir == "Positive" ? ") + " : ") - "
// Table custom functions for Gann Table
fun_cell_0(_column, _row, _text, _color) => table.cell(gann_table, _column, _row, _text, bgcolor = _color, text_color = color.black, text_size = i_font_0)
fun_pos(_column, _row, _text) => fun_cell_0(_column, _row, _text, col_pos)
fun_neg(_column, _row, _text) => fun_cell_0(_column, _row, _text, col_neg)
fun_trans_0(_column, _row) => fun_cell_0(_column, _row, " ", color.new(color.blue,100))
fun_blank_0() => fun_trans_0(5, 2), fun_trans_0(6, 2)
fun_price() => g_price ? i_price : na
fun_cond_0(_expr, _index) => i_dir == "Positive" and _expr ? array.get(arr_pos, _index) : na
fun_cond_1(_expr, _index) => i_dir == "Negative" and _expr ? array.get(arr_neg, _index) : na
fun_val(_column, _row, _index) =>
if i_value
if i_dir == "Positive"
table.cell_set_text(gann_table, _column, _row, ter_currency + tostring(array.get(arr_pos, _index), decimal))
else
table.cell_set_text(gann_table, _column, _row, ter_currency + tostring(array.get(arr_neg, _index), decimal))
fun_ref() =>
if i_value
table.cell_set_text(gann_table, 2, 2, ter_currency + tostring(i_price, decimal))
// Table custom functions for Formula
fun_cell_1(_column, _row, _text, _color) =>
table.cell(calc_table, _column, _row, _text, bgcolor = _color, text_color = color.black, text_size = i_font_1)
fun_trans_1(_column, _row) => fun_cell_1(_column, _row, " ", color.new(color.blue,100))
fun_blank_1() => fun_trans_1(4, 0), fun_trans_1(5, 0), fun_trans_1(6, 0)
dir(_id) =>
if i_dir == "Positive"
tp(_id)
else
tn(_id)
cal_pos(_row) =>
table.cell_set_bgcolor(calc_table, 0, _row, col_pos), table.cell_set_bgcolor(calc_table, 1, _row, col_pos)
table.cell_set_bgcolor(calc_table, 2, _row, col_pos), table.cell_set_bgcolor(calc_table, 3, _row, col_pos)
cal_neg(_row) =>
table.cell_set_bgcolor(calc_table, 0, _row, col_neg), table.cell_set_bgcolor(calc_table, 1, _row, col_neg)
table.cell_set_bgcolor(calc_table, 2, _row, col_neg), table.cell_set_bgcolor(calc_table, 3, _row, col_neg)
fun_clear_1(_input, _pos) =>
if _input == false
table.clear(calc_table, 0, _pos, 4, _pos)
// Custom functions for Formula
fun_cond(_expr, _index) => i_dir == "Positive" and _expr ? array.get(arr_pos, _index) : i_dir == "Negative" and _expr ? array.get(arr_neg, _index) : na
// 6. Construct
if barstate.islast
// Gann Table
if i_show_0
fun_blank_0()
fun_cell_0(2, 2, price_text, col_price)
fun_pos(1, 1, " "), fun_pos(3, 1, " "), fun_pos(3, 3, " "), fun_pos(1, 3, " ")
fun_neg(1, 2, " "), fun_neg(2, 1, " "), fun_neg(3, 2, " "), fun_neg(2, 3, " ")
fun_pos(0, 0, td(0)), fun_val(0, 0, 0)
fun_neg(2, 0, td(1)), fun_val(2, 0, 1)
fun_pos(4, 0, td(2)), fun_val(4, 0, 2)
fun_neg(4, 2, td(3)), fun_val(4, 2, 3)
fun_pos(4, 4, td(4)), fun_val(4, 4, 4)
fun_neg(2, 4, td(5)), fun_val(2, 4, 5)
fun_pos(0, 4, td(6)), fun_val(0, 4, 6)
fun_neg(0, 2, td(7)), fun_val(0, 2, 7)
// Default Price
fun_ref()
if g_025 == false
table.clear(gann_table, 0, 0, 1, 1)
if g_050 == false
table.clear(gann_table, 2, 0, 2, 1)
if g_075 == false
table.clear(gann_table, 3, 0, 4, 1)
if g_100 == false
table.clear(gann_table, 3, 2, 4, 2)
if g_125 == false
table.clear(gann_table, 3, 3, 4, 4)
if g_150 == false
table.clear(gann_table, 2, 3, 2, 4)
if g_175 == false
table.clear(gann_table, 0, 3, 1, 4)
if g_200 == false
table.clear(gann_table, 0, 2, 1, 2)
// Calculation Table
if i_show_1
fun_cell_1(0, 0, "Direction", color.yellow)
fun_cell_1(1, 0, i_dir, color.yellow)
fun_cell_1(2, 0, "Reference Price", color.yellow)
fun_cell_1(3, 0, ip, color.yellow)
fun_cell_1(0, 1, "Degree", color.blue)
fun_cell_1(1, 1, "Multiplier", color.blue)
fun_cell_1(2, 1, "Calculation", color.blue)
fun_cell_1(3, 1, "Gann\nPrice", color.blue)
// Cell Formula
for id = 0 to 7
fun_cell_1(0, abs(id - 9), td(id), color.white)
fun_cell_1(1, abs(id - 9), tm(id), color.white)
fun_cell_1(2, abs(id - 9), "(sqrt(" + tm(id) + sym + ip + ")^2", color.white)
fun_cell_1(3, abs(id - 9), dir(id), color.white)
// Cell blank
fun_blank_1()
// Cell color
cal_neg(2) // 360
cal_pos(3) // 315
cal_neg(4) // 270
cal_pos(5) // 225
cal_neg(6) // 180
cal_pos(7) // 135
cal_neg(8) // 90
cal_pos(9) // 45
// Clear cell if input is selected
fun_clear_1(g_200, 2) // 360
fun_clear_1(g_175, 3) // 315
fun_clear_1(g_150, 4) // 270
fun_clear_1(g_125, 5) // 225
fun_clear_1(g_100, 6) // 180
fun_clear_1(g_075, 7) // 135
fun_clear_1(g_050, 8) // 90
fun_clear_1(g_025, 9) // 45
// 7. Plot
// Plot Price
plot(fun_price(), "Price", col_price, 1, trackprice = track_price, editable = false)
// Plot Cardinal
plot(fun_cond_0(g_025, 0), "45", col_pos, 1, trackprice = track_gann, editable = false)
plot(fun_cond_0(g_075, 2), "135", col_pos, 2, trackprice = track_gann, editable = false)
plot(fun_cond_0(g_125, 4), "225", col_pos, 3, trackprice = track_gann, editable = false)
plot(fun_cond_0(g_175, 6), "315", col_pos, 4, trackprice = track_gann, editable = false)
// Plot Cross
plot(fun_cond_0(g_050,1 ), "90", col_neg, 1, trackprice = track_gann, editable = false)
plot(fun_cond_0(g_100,3 ), "180", col_neg, 2, trackprice = track_gann, editable = false)
plot(fun_cond_0(g_150,5 ), "270", col_neg, 3, trackprice = track_gann, editable = false)
plot(fun_cond_0(g_200,7 ), "360", col_neg, 4, trackprice = track_gann, editable = false)
// Plot Cardinal
plot(fun_cond_1(g_025, 0), "45", col_pos, 1, trackprice = track_gann, editable = false)
plot(fun_cond_1(g_075, 2), "135", col_pos, 2, trackprice = track_gann, editable = false)
plot(fun_cond_1(g_125, 4), "225", col_pos, 3, trackprice = track_gann, editable = false)
plot(fun_cond_1(g_175, 6), "315", col_pos, 4, trackprice = track_gann, editable = false)
// Plot Cross
plot(fun_cond_1(g_050,1 ), "90", col_neg, 1, trackprice = track_gann, editable = false)
plot(fun_cond_1(g_100,3 ), "180", col_neg, 2, trackprice = track_gann, editable = false)
plot(fun_cond_1(g_150,5 ), "270", col_neg, 3, trackprice = track_gann, editable = false)
plot(fun_cond_1(g_200,7 ), "360", col_neg, 4, trackprice = track_gann, editable = false) |
TMA crossover | https://www.tradingview.com/script/4vg5UGy0-TMA-crossover/ | Lirshah | https://www.tradingview.com/u/Lirshah/ | 501 | study | 3 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Lirshah
//@version=3
study(" TMA crossover", shorttitle="TMA crossover(Lirshah)", overlay=true)
length = input(title="Length1", type=integer, minval=1, defval=30)
shift= -15
tma = sma(sma(close, ceil(length / 2)), floor(length / 2) + 1)
cl = green
plot(tma, title="TMA", linewidth=2, color=cl, transp=0, offset=shift)
//////////////////extrapolate
func (i) =>
x = sma(sma(close, ceil((length-i) / 2)), floor((length-i) / 2) + 1)[0]
out = (x * (length-i) + close[0]*i)/length
ld=2
trs=0
plot(func(1),color=cl,linewidth=ld, style=circles ,transp=trs, offset=1+shift, show_last=1)
plot(func(2),color=cl,linewidth=ld, style=circles ,transp=trs, offset=2+shift, show_last=1)
plot(func(3),color=cl,linewidth=ld, style=circles,transp=trs, offset=3+shift, show_last=1)
plot(func(4),color=cl,linewidth=ld, style=circles,transp=trs, offset=4+shift, show_last=1)
plot(func(5),color=cl,linewidth=ld, style=circles,transp=trs, offset=5+shift, show_last=1)
plot(func(6),color=cl,linewidth=ld, style=circles,transp=trs, offset=6+shift, show_last=1)
plot(func(7),color=cl,linewidth=ld, style=circles,transp=trs, offset=7+shift, show_last=1)
plot(func(8),color=cl,linewidth=ld, style=circles,transp=trs, offset=8+shift, show_last=1)
plot(func(9),color=cl,linewidth=ld, style=circles,transp=trs, offset=9+shift, show_last=1)
plot(func(10),color=cl,linewidth=ld, style=circles,transp=trs, offset=10+shift, show_last=1)
plot(func(11),color=cl,linewidth=ld, style=circles,transp=trs, offset=11+shift, show_last=1)
plot(func(12),color=cl,linewidth=ld, style=circles,transp=trs, offset=12+shift, show_last=1)
plot(func(13),color=cl,linewidth=ld, style=circles,transp=trs, offset=13+shift, show_last=1)
plot(func(14),color=cl,linewidth=ld, style=circles,transp=trs, offset=14+shift, show_last=1)
plot(func(15),color=cl,linewidth=ld, style=circles,transp=trs, offset=15+shift, show_last=1)
plot(func(16),color=cl,linewidth=ld, style=circles,transp=trs, offset=16+shift, show_last=1)
plot(func(17),color=cl,linewidth=ld, style=circles,transp=trs, offset=17+shift, show_last=1)
length2 = input(title="Length1", type=integer, minval=1, defval=30)
shift2= -10
tma2 = sma(sma(close, ceil(length2 / 2)), floor(length2 / 2) + 1)
cl2 = red
plot(tma2, title="TMA", linewidth=2, color=cl2, transp=0, offset=shift2)
//////////////////extrapolate
func2 (i2) =>
x2 = sma(sma(close, ceil((length2-i2) / 2)), floor((length2-i2) / 2) + 1)[0]
out2 = (x2 * (length2-i2) + close[0]*i2)/length2
plot(func2(1),color=cl2,linewidth=ld, style=circles ,transp=trs, offset=1+shift2, show_last=1)
plot(func2(2),color=cl2,linewidth=ld, style=circles ,transp=trs, offset=2+shift2, show_last=1)
plot(func2(3),color=cl2,linewidth=ld, style=circles,transp=trs, offset=3+shift2, show_last=1)
plot(func2(4),color=cl2,linewidth=ld, style=circles,transp=trs, offset=4+shift2, show_last=1)
plot(func2(5),color=cl2,linewidth=ld, style=circles,transp=trs, offset=5+shift2, show_last=1)
plot(func2(6),color=cl2,linewidth=ld, style=circles,transp=trs, offset=6+shift2, show_last=1)
plot(func2(7),color=cl2,linewidth=ld, style=circles,transp=trs, offset=7+shift2, show_last=1)
plot(func2(8),color=cl2,linewidth=ld, style=circles,transp=trs, offset=8+shift2, show_last=1)
plot(func2(9),color=cl2,linewidth=ld, style=circles,transp=trs, offset=9+shift2, show_last=1)
plot(func2(10),color=cl2,linewidth=ld, style=circles,transp=trs, offset=10+shift2, show_last=1)
plot(func2(11),color=cl2,linewidth=ld, style=circles,transp=trs, offset=11+shift2, show_last=1)
plot(func2(12),color=cl2,linewidth=ld, style=circles,transp=trs, offset=12+shift2, show_last=1)
plot(func2(13),color=cl2,linewidth=ld, style=circles,transp=trs, offset=13+shift2, show_last=1)
plot(func2(14),color=cl2,linewidth=ld, style=circles,transp=trs, offset=14+shift2, show_last=1)
plot(func2(15),color=cl2,linewidth=ld, style=circles,transp=trs, offset=15+shift2, show_last=1)
|
Crypto Market Cap Oscillator | https://www.tradingview.com/script/rH3Ljgwa-Crypto-Market-Cap-Oscillator/ | BigPhilBxl | https://www.tradingview.com/u/BigPhilBxl/ | 80 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BigPhilBxl
//@version=5
indicator('Crypto Market Cap Oscillator')
// inputs
int length = input.int(21, 'Length', group='Settings')
int hhigh = input.int(20, 'High Bar', group='Settings')
int hlow = input.int(-20, 'Low Bar', group='Settings')
leader_market_cap = input.symbol(title='BTC Market Cap', defval='CRYPTOCAP:BTC', group='Market Cap')
alt_market_cap = input.symbol(title='Alt Market Cap', defval='CRYPTOCAP:TOTAL3', group='Market Cap')
custom_market_cap = input.symbol(title='Custom Crypto Cap', defval='', group='Market Cap')
// Get BTC & alt market caps
leader_cap = request.security(leader_market_cap, timeframe=timeframe.period, expression=close)
alt_cap = request.security(alt_market_cap, timeframe=timeframe.period, expression=close)
// base 100
leader = 100 - leader_cap[length] / leader_cap * 100
alt = 100 - alt_cap[length] / alt_cap * 100
// plot BTC and Alt market cap 100 base
l = plot(leader, color=color.new(color.orange, 0), linewidth=1, title='BTC Plot')
a = plot(alt, color=color.new(color.blue, 0), title='Alt Plot')
// Custom cap
custom_cap = request.security(custom_market_cap == '' ? ticker.new('CRYPTOCAP', syminfo.basecurrency) : custom_market_cap, timeframe.period, close)
custom = 100 - custom_cap[length] / custom_cap * 100
grad = color.from_gradient(custom, hlow, hhigh, color.lime, color.red)
customplot = plot(custom, linewidth=3, color=color.new(grad, 0), title='Custom Crypto Plot')
baseline = plot(series=0, color=custom > 0 ? color.red : color.lime, style=plot.style_circles, title='Baseline')
// Add horizontal lines
hline(hhigh, title='High')
hline(hlow, title='Low')
|
Flow of Range | https://www.tradingview.com/script/v93s7ndt-Flow-of-Range/ | trading_mentalist | https://www.tradingview.com/u/trading_mentalist/ | 32 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradingMentalist
//@version=4
study("Flow of Range", overlay=false)
sidein2 = input(500, step=100, title='Range')
side1 = (close[1] + close[sidein2]) / 2
side2 = close[1] - close[sidein2]
side3 = side2 / side1
truncate(number, decimals) =>
factor = pow(10000, decimals)
int(number * factor) / factor
side3pc= truncate(side3, 2)
side3in=10000
flowofrange=side3pc*side3in
flowbuy=flowofrange < -150
flowsell= flowofrange > 150
flowbuy2=flowofrange < -100
flowofrangeavg= sma(flowofrange,100)
flowofrangeavg2= sma(flowofrange*2,1000)
plot(flowofrangeavg2,
style=plot.style_area,
color=flowofrangeavg2 > 0 ? color.new(#9DFAF8,60) : color.new(#707CFA,60),
linewidth=1)
plot(flowofrangeavg,
style=plot.style_area,
color=flowofrangeavg > 0 ? color.new(#4EC5C7,60) : color.new(#707CFA,60))
|
Multi-ZigZag Multi-Oscillator Trend Detector | https://www.tradingview.com/script/7Cx62e19-Multi-ZigZag-Multi-Oscillator-Trend-Detector/ | Trendoscope | https://www.tradingview.com/u/Trendoscope/ | 475 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed
// __ __ __ __ __ __ __ __ __ __ __ _______ __ __ __
// / | / | / | _ / |/ | / \ / | / | / \ / | / | / \ / \ / | / |
// $$ | $$ | ______ $$ | / \ $$ |$$ |____ ______ $$ \ /$$ | __ __ _______ _$$ |_ $$ \ $$ | ______ _$$ |_ $$$$$$$ | ______ $$ \ $$ | ______ _____ ____ ______ ____$$ |
// $$ |__$$ | / \ $$ |/$ \$$ |$$ \ / \ $$$ \ /$$$ |/ | / | / |/ $$ | $$$ \$$ | / \ / $$ | $$ |__$$ | / \ $$$ \$$ | / \ / \/ \ / \ / $$ |
// $$ $$ |/$$$$$$ |$$ /$$$ $$ |$$$$$$$ |/$$$$$$ |$$$$ /$$$$ |$$ | $$ |/$$$$$$$/ $$$$$$/ $$$$ $$ |/$$$$$$ |$$$$$$/ $$ $$< /$$$$$$ |$$$$ $$ | $$$$$$ |$$$$$$ $$$$ |/$$$$$$ |/$$$$$$$ |
// $$$$$$$$ |$$ $$ |$$ $$/$$ $$ |$$ | $$ |$$ | $$ |$$ $$ $$/$$ |$$ | $$ |$$ \ $$ | __ $$ $$ $$ |$$ | $$ | $$ | __ $$$$$$$ |$$ $$ |$$ $$ $$ | / $$ |$$ | $$ | $$ |$$ $$ |$$ | $$ |
// $$ | $$ |$$$$$$$$/ $$$$/ $$$$ |$$ | $$ |$$ \__$$ |$$ |$$$/ $$ |$$ \__$$ | $$$$$$ | $$ |/ |$$ |$$$$ |$$ \__$$ | $$ |/ |$$ |__$$ |$$$$$$$$/ $$ |$$$$ |/$$$$$$$ |$$ | $$ | $$ |$$$$$$$$/ $$ \__$$ |
// $$ | $$ |$$ |$$$/ $$$ |$$ | $$ |$$ $$/ $$ | $/ $$ |$$ $$/ / $$/ $$ $$/ $$ | $$$ |$$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$$ |$$ $$ |$$ | $$ | $$ |$$ |$$ $$ |
// $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ $$$$$$$/ $$$$/ $$/ $$/ $$$$$$/ $$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$$$$/
//
//
//
//@version=5
indicator('Multi-ZigZag Multi-Oscillator Trend Detector', shorttitle='MZigZag-MOscillator-Trend-Detector', overlay=true, max_bars_back=1000, max_lines_count=500, max_labels_count=500)
useAlternativeSource = input.bool(true, title='', group='Source', inline='src')
source = input.source(close, title='Alternative Source', group='Source', inline='src')
max_array_size = input.int(10, step=20, title='History', group='Source', inline='src')
table_position = input.string(position.middle_center, title='Position', group='Table', options=[position.top_left, position.top_right, position.top_center, position.middle_left, position.middle_right, position.middle_center, position.bottom_left, position.bottom_right, position.bottom_center])
text_size = input.string(size.tiny, title='Size', group='Table', options=[size.tiny, size.small, size.normal, size.large, size.huge, size.auto])
supertrendHistory = input.int(4, step=1, title='Pivot History', group='Zigzag Supertrend')
atrPeriods = input.int(22, title='ATR Length', step=5, group='Zigzag Supertrend')
atrMult = input.float(1, step=0.5, title='ATR Multiplier', group='Zigzag Supertrend')
oscMultiplier = input.int(4, title='Length Multiplier', group='Oscillator', inline='osc')
zigzag1Length = input.int(5, step=1, minval=3, title='Zigzag', group='Zigzag', inline='z')
zigzag2Length = input.int(8, step=1, minval=2, title='', group='Zigzag', inline='z')
zigzag3Length = input.int(13, step=1, minval=2, title='', group='Zigzag', inline='z')
zigzag4Length = input.int(21, step=1, minval=2, title='', group='Zigzag', inline='z')
var numberOfZigzags = 4
var numberOfOscillators = 8
var oscillatorValues = array.new_float(numberOfOscillators * numberOfZigzags, 0)
f_get_oscillator_index(oscillatorSource, zigzagLength) =>
zigzagIndex = zigzagLength == zigzag1Length ? 0 : zigzagLength == zigzag2Length ? 1 : zigzagLength == zigzag3Length ? 2 : 3
numberOfItems = numberOfOscillators
startIndex = zigzagIndex * numberOfItems
oscillatorIndex = oscillatorSource == 'CCI' ? 0 : oscillatorSource == 'CMO' ? 1 : oscillatorSource == 'COG' ? 2 : oscillatorSource == 'MFI' ? 3 : oscillatorSource == 'ROC' ? 4 : oscillatorSource == 'RSI' ? 5 : oscillatorSource == 'WPR' ? 6 : oscillatorSource == 'BB' ? 7 : 6
startIndex + oscillatorIndex
f_initialize_oscillators(zigzagLength) =>
oscillatorLength = zigzagLength * oscMultiplier
[bbmiddle, bbupper, bblower] = ta.bb(close, oscillatorLength, 5)
cci = ta.cci(close, oscillatorLength)
cmo = ta.cmo(close, oscillatorLength)
cog = ta.cog(close, oscillatorLength)
mfi = ta.mfi(close, oscillatorLength)
roc = ta.roc(close, oscillatorLength)
rsi = ta.rsi(close, oscillatorLength)
wpr = ta.wpr(oscillatorLength)
bbr = (close - bblower) * 100 / (bbupper - bblower)
array.set(oscillatorValues, f_get_oscillator_index('CCI', zigzagLength), cci)
array.set(oscillatorValues, f_get_oscillator_index('CMO', zigzagLength), cmo)
array.set(oscillatorValues, f_get_oscillator_index('COG', zigzagLength), cog)
array.set(oscillatorValues, f_get_oscillator_index('MFI', zigzagLength), mfi)
array.set(oscillatorValues, f_get_oscillator_index('ROC', zigzagLength), roc)
array.set(oscillatorValues, f_get_oscillator_index('RSI', zigzagLength), rsi)
array.set(oscillatorValues, f_get_oscillator_index('WPR', zigzagLength), wpr)
array.set(oscillatorValues, f_get_oscillator_index('BB', zigzagLength), bbr)
f_initialize_oscillators(zigzag1Length)
f_initialize_oscillators(zigzag2Length)
f_initialize_oscillators(zigzag3Length)
f_initialize_oscillators(zigzag4Length)
f_get_oscillators_by_length_and_type(oscillatorSource, zigzagLength) =>
array.get(oscillatorValues, f_get_oscillator_index(oscillatorSource, zigzagLength))
f_get_oscullators_by_length(zigzagLength) =>
zigzagIndex = zigzagLength == zigzag1Length ? 0 : zigzagLength == zigzag2Length ? 1 : zigzagLength == zigzag3Length ? 2 : 3
startIndex = zigzagIndex * numberOfOscillators
array.slice(oscillatorValues, startIndex, startIndex + numberOfOscillators)
var zigzagpivots1 = array.new_float(0)
var zigzagpivotbars1 = array.new_int(0)
var zigzagpivotdirs1 = array.new_int(0)
var zigzagoscdirs1 = array.new_int(0)
var zigzagosc1 = array.new_float(0)
var zigzagtrend1 = array.new_int(0)
var zigzagpivots2 = array.new_float(0)
var zigzagpivotbars2 = array.new_int(0)
var zigzagpivotdirs2 = array.new_int(0)
var zigzagoscdirs2 = array.new_int(0)
var zigzagosc2 = array.new_float(0)
var zigzagtrend2 = array.new_int(0)
var zigzagpivots3 = array.new_float(0)
var zigzagpivotbars3 = array.new_int(0)
var zigzagpivotdirs3 = array.new_int(0)
var zigzagoscdirs3 = array.new_int(0)
var zigzagosc3 = array.new_float(0)
var zigzagtrend3 = array.new_int(0)
var zigzagpivots4 = array.new_float(0)
var zigzagpivotbars4 = array.new_int(0)
var zigzagpivotdirs4 = array.new_int(0)
var zigzagoscdirs4 = array.new_int(0)
var zigzagosc4 = array.new_float(0)
var zigzagtrend4 = array.new_int(0)
var zigzag1lines = array.new_line(0)
var zigzag2lines = array.new_line(0)
var zigzag3lines = array.new_line(0)
var zigzag4lines = array.new_line(0)
var zigzag1labels = array.new_label(0)
var zigzag2labels = array.new_label(0)
var zigzag3labels = array.new_label(0)
var zigzag4labels = array.new_label(0)
var zigzagsupertrenddirs = array.new_int(numberOfZigzags, 1)
var zigzagsupertrend = array.new_float(numberOfOscillators, na)
f_get_zigzag_arrays(zigzagLength) =>
zigzagPivots = zigzagLength == zigzag1Length ? zigzagpivots1 : zigzagLength == zigzag2Length ? zigzagpivots2 : zigzagLength == zigzag3Length ? zigzagpivots3 : zigzagpivots4
zigzagPivotBars = zigzagLength == zigzag1Length ? zigzagpivotbars1 : zigzagLength == zigzag2Length ? zigzagpivotbars2 : zigzagLength == zigzag3Length ? zigzagpivotbars3 : zigzagpivotbars4
zigzagPivotDirs = zigzagLength == zigzag1Length ? zigzagpivotdirs1 : zigzagLength == zigzag2Length ? zigzagpivotdirs2 : zigzagLength == zigzag3Length ? zigzagpivotdirs3 : zigzagpivotdirs4
zigzagOscillators = zigzagLength == zigzag1Length ? zigzagosc1 : zigzagLength == zigzag2Length ? zigzagosc2 : zigzagLength == zigzag3Length ? zigzagosc3 : zigzagosc4
zigzagOscDirs = zigzagLength == zigzag1Length ? zigzagoscdirs1 : zigzagLength == zigzag2Length ? zigzagoscdirs2 : zigzagLength == zigzag3Length ? zigzagoscdirs3 : zigzagoscdirs4
zigzagTrend = zigzagLength == zigzag1Length ? zigzagtrend1 : zigzagLength == zigzag2Length ? zigzagtrend2 : zigzagLength == zigzag3Length ? zigzagtrend3 : zigzagtrend4
[zigzagPivots, zigzagPivotBars, zigzagPivotDirs, zigzagOscillators, zigzagOscDirs, zigzagTrend]
f_get_zigzag_drawings(zigzagLength) =>
zigzagLines = zigzagLength == zigzag1Length ? zigzag1lines : zigzagLength == zigzag2Length ? zigzag2lines : zigzagLength == zigzag3Length ? zigzag3lines : zigzag4lines
zigzagLabels = zigzagLength == zigzag1Length ? zigzag1labels : zigzagLength == zigzag2Length ? zigzag2labels : zigzagLength == zigzag3Length ? zigzag3labels : zigzag4labels
[zigzagLines, zigzagLabels]
add_to_array(arr, val, maxItems) =>
array.unshift(arr, val)
if array.size(arr) > maxItems
array.pop(arr)
pivots(length) =>
highsource = useAlternativeSource ? source : high
lowsource = useAlternativeSource ? source : low
float phigh = ta.highestbars(highsource, length) == 0 ? highsource : na
float plow = ta.lowestbars(lowsource, length) == 0 ? lowsource : na
[phigh, plow, bar_index, bar_index]
add_oscillators(zigzagLength, currentBarOffset, lastBarOffset, dir) =>
[zigzagPivots, zigzagPivotBars, zigzagPivotDirs, zigzagOscillators, zigzagOscDirs, zigzagTrend] = f_get_zigzag_arrays(zigzagLength)
oscillators = f_get_oscullators_by_length(zigzagLength)
for i = 0 to array.size(oscillators) > 0 ? array.size(oscillators) - 1 : na by 1
index = array.size(oscillators) - 1 - i
osc = array.get(oscillators, index)
currentValue = osc[currentBarOffset]
lastValue = osc[lastBarOffset]
newDir = dir * currentValue > dir * lastValue ? dir * 2 : dir
add_to_array(zigzagOscillators, currentValue, max_array_size * numberOfOscillators)
add_to_array(zigzagOscDirs, newDir, max_array_size * numberOfOscillators)
delete_oscillators(zigzagLength) =>
[zigzagPivots, zigzagPivotBars, zigzagPivotDirs, zigzagOscillators, zigzagOscDirs, zigzagTrend] = f_get_zigzag_arrays(zigzagLength)
for i = 1 to numberOfOscillators by 1
array.shift(zigzagOscillators)
array.shift(zigzagOscDirs)
addnewpivot(zigzagLength, value, bar, dir) =>
newDir = dir
[zigzagPivots, zigzagPivotBars, zigzagPivotDirs, zigzagOscillators, zigzagOscDirs, zigzagTrend] = f_get_zigzag_arrays(zigzagLength)
currentBarOffset = bar_index - bar
lastBarOffset = bar_index - bar
if array.size(zigzagPivots) >= 2
lastPoint = array.get(zigzagPivots, 1)
lastBar = array.get(zigzagPivotBars, 1)
newDir := dir * value > dir * lastPoint ? dir * 2 : dir
lastBarOffset := bar_index - lastBar
lastBarOffset
zigzagIndex = zigzagLength == zigzag1Length ? 0 : zigzagLength == zigzag2Length ? 1 : zigzagLength == zigzag3Length ? 2 : 3
supetrendDir = array.get(zigzagsupertrenddirs, zigzagIndex)
add_to_array(zigzagPivots, value, max_array_size)
add_to_array(zigzagPivotBars, bar, max_array_size)
add_to_array(zigzagPivotDirs, newDir, max_array_size)
add_to_array(zigzagTrend, supetrendDir[currentBarOffset], max_array_size)
add_oscillators(zigzagLength, currentBarOffset, lastBarOffset, dir)
zigzagcore(zigzagLength, phigh, plow, phighbar, plowbar) =>
pDir = 1
newZG = false
doubleZG = phigh and plow
[zigzagPivots, zigzagPivotBars, zigzagPivotDirs, zigzagOscillators, zigzagOscDirs, zigzagTrend] = f_get_zigzag_arrays(zigzagLength)
if array.size(zigzagPivots) >= 1
pDir := array.get(zigzagPivotDirs, 0)
pDir := pDir % 2 == 0 ? pDir / 2 : pDir
pDir
if (pDir == 1 and phigh or pDir == -1 and plow) and array.size(zigzagPivots) >= 1
pivot = array.shift(zigzagPivots)
pivotbar = array.shift(zigzagPivotBars)
pivotdir = array.shift(zigzagPivotDirs)
supertrendDir = array.shift(zigzagTrend)
delete_oscillators(zigzagLength)
value = pDir == 1 ? phigh : plow
bar = pDir == 1 ? phighbar : plowbar
useNewValues = value * pivotdir > pivot * pivotdir
value := useNewValues ? value : pivot
bar := useNewValues ? bar : pivotbar
newZG := newZG or useNewValues
addnewpivot(zigzagLength, value, bar, pDir)
if pDir == 1 and plow or pDir == -1 and phigh
value = pDir == 1 ? plow : phigh
bar = pDir == 1 ? plowbar : phighbar
dir = pDir == 1 ? -1 : 1
newZG := true
addnewpivot(zigzagLength, value, bar, dir)
[newZG, doubleZG]
zigzag(zigzagLength) =>
[phigh, plow, phighbar, plowbar] = pivots(zigzagLength)
zigzagcore(zigzagLength, phigh, plow, phighbar, plowbar)
f_initialize_supertrend(zigzagLength) =>
[zigzagPivots, zigzagPivotBars, zigzagPivotDirs, zigzagOscillators, zigzagOscDirs, zigzagTrend] = f_get_zigzag_arrays(zigzagLength)
zigzagIndex = zigzagLength == zigzag1Length ? 0 : zigzagLength == zigzag2Length ? 1 : zigzagLength == zigzag3Length ? 2 : 3
dir = array.get(zigzagsupertrenddirs, zigzagIndex)
buyStop = array.get(zigzagsupertrend, zigzagIndex * 2)
sellStop = array.get(zigzagsupertrend, zigzagIndex * 2 + 1)
tail = array.size(zigzagPivots) > 1 + supertrendHistory ? array.slice(zigzagPivots, 1, 1 + supertrendHistory) : array.new_float()
highest = array.max(tail)
lowest = array.min(tail)
atrDiff = ta.atr(atrPeriods) * atrMult
newBuyStop = lowest - atrDiff
newSellStop = highest + atrDiff
newDir = dir > 0 and close[1] < buyStop ? -1 : dir < 0 and close[1] > sellStop ? 1 : dir
newBuyStop := newDir > 0 ? math.max(nz(buyStop, newBuyStop), newBuyStop) : newBuyStop
newSellStop := newDir < 0 ? math.min(nz(sellStop, newSellStop), newSellStop) : newSellStop
array.set(zigzagsupertrenddirs, zigzagIndex, newDir)
array.set(zigzagsupertrend, zigzagIndex * 2, newBuyStop)
array.set(zigzagsupertrend, zigzagIndex * 2 + 1, newSellStop)
[newDir, newBuyStop, newSellStop]
getSentiment(pDir, oDir, sDir) =>
sentiment = pDir == oDir ? sDir == pDir or sDir * 2 == -pDir ? -sDir : sDir * 4 : sDir == pDir or sDir == -oDir ? 0 : (math.abs(oDir) > math.abs(pDir) ? sDir : -sDir) * (sDir == oDir ? 2 : 3)
sentiment
getSentimentDetails(sentiment) =>
sentimentSymbol = sentiment == 4 ? '⬆' : sentiment == -4 ? '⬇' : sentiment == 3 ? '↗' : sentiment == -3 ? '↘' : sentiment == 2 ? '⤴' : sentiment == -2 ? '⤵' : sentiment == 1 ? '⤒' : sentiment == -1 ? '⤓' : '▣'
sentimentColor = sentiment == 4 ? color.green : sentiment == -4 ? color.red : sentiment == 3 ? color.lime : sentiment == -3 ? color.orange : sentiment == 2 ? color.rgb(202, 224, 13, 0) : sentiment == -2 ? color.rgb(250, 128, 114, 0) : color.silver
sentimentLabel = math.abs(sentiment) == 4 ? 'C' : math.abs(sentiment) == 3 ? 'H' : math.abs(sentiment) == 2 ? 'D' : 'I'
[sentimentSymbol, sentimentLabel, sentimentColor]
getCellColorByDirection(dir) =>
dir == 2 ? color.green : dir == 1 ? color.orange : dir == -1 ? color.lime : dir == -2 ? color.red : color.silver
getLabelByDirection(dir) =>
dir == 2 ? '⇈' : dir == 1 ? '↑' : dir == -1 ? '↓' : dir == -2 ? '⇊' : 'NA'
f_add_header(tableId, header, columnStart, valueText, trendText) =>
table.cell(table_id=tableId, column=columnStart, row=0, text=header, bgcolor=color.black, text_color=color.white, text_size=text_size)
table.cell(table_id=tableId, column=columnStart, row=1, text=valueText, bgcolor=color.black, text_color=color.white, text_size=text_size)
table.cell(table_id=tableId, column=columnStart + 1, row=1, text='Direction', bgcolor=color.black, text_color=color.white, text_size=text_size)
table.cell(table_id=tableId, column=columnStart + 2, row=1, text=trendText, bgcolor=color.black, text_color=color.white, text_size=text_size)
columnStart + 3
f_add_oscillator_columns(tableId, columnStart, zigzagRow, rowIndex, zigzagLength, oscillatorIndex, pDir, sDir) =>
[zigzagPivots, zigzagPivotBars, zigzagPivotDirs, zigzagOscillators, zigzagOscDirs, zigzagTrend] = f_get_zigzag_arrays(zigzagLength)
index = numberOfOscillators * zigzagRow + oscillatorIndex
oValue = array.get(zigzagOscillators, index)
oDir = array.get(zigzagOscDirs, index)
sentiment = getSentiment(pDir, oDir, sDir)
[sentimentSymbol, sentimentLabel, sentimentColor] = getSentimentDetails(sentiment)
table.cell(table_id=tableId, column=columnStart, row=rowIndex, text=str.tostring(math.round(oValue, 2)), bgcolor=getCellColorByDirection(oDir), text_size=text_size)
table.cell(table_id=tableId, column=columnStart + 1, row=rowIndex, text=getLabelByDirection(oDir), bgcolor=getCellColorByDirection(oDir), text_size=text_size)
table.cell(table_id=tableId, column=columnStart + 2, row=rowIndex, text=sentimentSymbol, bgcolor=sentimentColor, text_size=text_size)
columnStart + 3
f_add_zigzag_oscillator_data(tableId, zigzagLength, currentRow, zgIndex) =>
[zigzagPivots, zigzagPivotBars, zigzagPivotDirs, zigzagOscillators, zigzagOscDirs, zigzagTrend] = f_get_zigzag_arrays(zigzagLength)
pDir = array.get(zigzagPivotDirs, zgIndex)
sDir = array.get(zigzagTrend, zgIndex)
trendDirection = sDir > 0 ? '⇑' : '⇓'
trendColor = sDir > 0 ? color.green : color.red
table.cell(table_id=tableId, column=2, row=currentRow, text=str.tostring(zigzagLength), bgcolor=getCellColorByDirection(pDir), text_size=text_size)
table.cell(table_id=tableId, column=3, row=currentRow, text=getLabelByDirection(pDir), bgcolor=getCellColorByDirection(pDir), text_size=text_size)
table.cell(table_id=tableId, column=4, row=currentRow, text=trendDirection, bgcolor=trendColor, text_size=text_size)
columnStart = 5
columnStart := f_add_oscillator_columns(tableId, columnStart, zgIndex, currentRow, zigzagLength, 0, pDir, sDir)
columnStart := f_add_oscillator_columns(tableId, columnStart, zgIndex, currentRow, zigzagLength, 1, pDir, sDir)
columnStart := f_add_oscillator_columns(tableId, columnStart, zgIndex, currentRow, zigzagLength, 2, pDir, sDir)
if not na(volume)
columnStart := f_add_oscillator_columns(tableId, columnStart, zgIndex, currentRow, zigzagLength, 3, pDir, sDir)
columnStart
columnStart := f_add_oscillator_columns(tableId, columnStart, zgIndex, currentRow, zigzagLength, 4, pDir, sDir)
columnStart := f_add_oscillator_columns(tableId, columnStart, zgIndex, currentRow, zigzagLength, 5, pDir, sDir)
columnStart := f_add_oscillator_columns(tableId, columnStart, zgIndex, currentRow, zigzagLength, 6, pDir, sDir)
columnStart := f_add_oscillator_columns(tableId, columnStart, zgIndex, currentRow, zigzagLength, 7, pDir, sDir)
currentRow + 1
f_add_zigzag_oscillator_sub_data(tableId, zigzagLength, pBar, price, currentRow, zgIndex) =>
[zigzagPivots, zigzagPivotBars, zigzagPivotDirs, zigzagOscillators, zigzagOscDirs, zigzagTrend] = f_get_zigzag_arrays(zigzagLength)
zBar = array.get(zigzagPivotBars, zgIndex)
zPrice = array.get(zigzagPivots, zgIndex)
zgIndexNew = zgIndex
currentRowNew = currentRow
if zBar == pBar and zPrice == price
zgIndexNew := zgIndex + 1
currentRowNew := f_add_zigzag_oscillator_data(tableId, zigzagLength, currentRow, zgIndex)
currentRowNew
[zgIndexNew, currentRowNew]
[level1ZG, doublel1ZG] = zigzag(zigzag1Length)
[level2ZG, doublel2ZG] = zigzag(zigzag2Length)
[level3ZG, doublel3ZG] = zigzag(zigzag3Length)
[level4ZG, doublel4ZG] = zigzag(zigzag4Length)
[z1Dir, z1BuyStop, z1SellStop] = f_initialize_supertrend(zigzag1Length)
[z2Dir, z2BuyStop, z2SellStop] = f_initialize_supertrend(zigzag2Length)
[z3Dir, z3BuyStop, z3SellStop] = f_initialize_supertrend(zigzag3Length)
[z4Dir, z4BuyStop, z4SellStop] = f_initialize_supertrend(zigzag4Length)
startIndex = 0
zg2Index = 0
zg3Index = 0
zg4Index = 0
if barstate.islast
stats = table.new(position=table_position, columns=numberOfOscillators * 3 + 5, rows=max_array_size * numberOfZigzags + startIndex + 3, border_width=1)
var altTextSize = text_size == size.tiny ? size.small : text_size == size.small ? size.normal : text_size == size.normal ? size.large : text_size == size.large ? size.huge : size.large
table.cell(table_id=stats, column=0, row=0, text=syminfo.ticker, bgcolor=color.teal, text_color=color.white, text_size=altTextSize)
table.cell(table_id=stats, column=1, row=0, text=timeframe.period, bgcolor=color.teal, text_color=color.white, text_size=altTextSize)
table.cell(table_id=stats, column=0, row=1, text='Bar Time', bgcolor=color.black, text_color=color.white, text_size=text_size)
table.cell(table_id=stats, column=1, row=1, text='Price', bgcolor=color.black, text_color=color.white, text_size=text_size)
headerIndex = 2
headerIndex := f_add_header(stats, 'Zigzag', headerIndex, 'Length', 'Trend')
headerIndex := f_add_header(stats, 'CCI', headerIndex, 'Value', 'Sentiment')
headerIndex := f_add_header(stats, 'CMO', headerIndex, 'Value', 'Sentiment')
headerIndex := f_add_header(stats, 'COG', headerIndex, 'Value', 'Sentiment')
if not na(volume)
headerIndex := f_add_header(stats, 'MFI', headerIndex, 'Value', 'Sentiment')
headerIndex
headerIndex := f_add_header(stats, 'ROC', headerIndex, 'Value', 'Sentiment')
headerIndex := f_add_header(stats, 'RSI', headerIndex, 'Value', 'Sentiment')
headerIndex := f_add_header(stats, 'WPR', headerIndex, 'Value', 'Sentiment')
headerIndex := f_add_header(stats, 'BB', headerIndex, 'Value', 'Sentiment')
currentRow = 2
for i = startIndex to array.size(zigzagpivotdirs1) > 0 ? array.size(zigzagpivotdirs1) - 1 : na by 1
pBar = array.get(zigzagpivotbars1, i)
price = array.get(zigzagpivots1, i)
barTime = time[bar_index - pBar]
barTimeString = str.tostring(year(barTime), '0000') + '/' + str.tostring(month(barTime), '00') + '/' + str.tostring(dayofmonth(barTime), '00') + (timeframe.isintraday ? '-' + str.tostring(hour(barTime), '00') + ':' + str.tostring(minute(barTime), '00') + ':' + str.tostring(second(barTime), '00') : '')
table.cell(table_id=stats, column=0, row=currentRow, text=barTimeString, bgcolor=color.maroon, text_color=color.white, text_size=text_size)
table.cell(table_id=stats, column=1, row=currentRow, text=str.tostring(math.round(price, 2)), bgcolor=color.maroon, text_color=color.white, text_size=text_size)
currentRow := f_add_zigzag_oscillator_data(stats, zigzag1Length, currentRow, i)
[zgIndex2New, currentRow2New] = f_add_zigzag_oscillator_sub_data(stats, zigzag2Length, pBar, price, currentRow, zg2Index)
zg2Index := zgIndex2New
currentRow := currentRow2New
[zgIndex3New, currentRow3New] = f_add_zigzag_oscillator_sub_data(stats, zigzag3Length, pBar, price, currentRow, zg3Index)
zg3Index := zgIndex3New
currentRow := currentRow3New
[zgIndex4New, currentRow4New] = f_add_zigzag_oscillator_sub_data(stats, zigzag4Length, pBar, price, currentRow, zg4Index)
zg4Index := zgIndex4New
currentRow := currentRow4New
currentRow
|
Zendog Bar Percentage | https://www.tradingview.com/script/uShNEqOX-Zendog-Bar-Percentage/ | zendog123 | https://www.tradingview.com/u/zendog123/ | 88 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © zendog123
//@version=4
study("Zendog Bar Percentage", overlay=true, max_labels_count=500)
is_green = false
is_red = false
cfg_decimals = input(type=input.integer, title="Decimals", defval=1, step=1)
get_month_string(month_number)=>
if month_number == 1
_string = "Jan"
else if month_number == 2
_string = "Feb"
else if month_number == 3
_string = "Mar"
else if month_number == 4
_string = "Apr"
else if month_number == 5
_string = "May"
else if month_number == 6
_string = "Jun"
else if month_number == 7
_string = "Jul"
else if month_number == 8
_string = "Aug"
else if month_number == 9
_string = "Sep"
else if month_number == 10
_string = "Oct"
else if month_number == 11
_string = "Nov"
else if month_number == 12
_string = "Dec"
time_to_date_string(timeinms)=>
if timeinms > 0
_string = tostring(dayofmonth(timeinms), "00/") + get_month_string(month(timeinms)) +"/"+ tostring(year(timeinms), "0000") +
" " + tostring(hour(timeinms), "00:") + tostring(minute(timeinms), "00:") + tostring(second(timeinms), "00")
else
_string = ""
//strategy timeframe limitation (run just between specific dates)
bool limit_date_range = input(title="Limit Date Range", type=input.bool, defval=false, group="Date range")
//Input options that configure backtest date range
start_time = input(defval = timestamp("01 Aug 2021 00:00 +0000"), title = "Start Time",
type = input.time, group="Backtest date range")
end_time = input(defval = timestamp("31 Dec 2021 00:00 +0000"), title = "End Time",
type = input.time, group="Backtest date range")
bool in_date_range = false
if limit_date_range
in_date_range := time >= start_time and time <= end_time
else
in_date_range := true
var float max_percentage_open_close_green = 0
var float max_percentage_high_low_green = 0
var string max_percentage_open_close_green_date = ""
var string max_percentage_high_low_green_date = ""
var float max_absolute_open_close_green = 0
var float max_absolute_high_low_green = 0
var string max_absolute_open_close_green_date = ""
var string max_absolute_high_low_green_date = ""
var float max_percentage_open_close_red = 0
var float max_percentage_high_low_red = 0
var string max_percentage_open_close_red_date = ""
var string max_percentage_high_low_red_date = ""
var float max_absolute_open_close_red = 0
var float max_absolute_high_low_red = 0
var string max_absolute_open_close_red_date = ""
var string max_absolute_high_low_red_date = ""
if in_date_range
//green
if close >= open
percentage_high_low = round(((high*100/low)-100), cfg_decimals)
percentage_open_close = round(((close*100/open)-100), cfg_decimals)
absolute_high_low = high - low
absolute_open_close = close - open
if max_percentage_open_close_green < percentage_open_close
max_percentage_open_close_green := percentage_open_close
max_percentage_open_close_green_date := time_to_date_string(time)
if max_percentage_high_low_green < percentage_high_low
max_percentage_high_low_green := percentage_high_low
max_percentage_high_low_green_date := time_to_date_string(time)
if max_absolute_open_close_green < absolute_open_close
max_absolute_open_close_green := absolute_open_close
max_absolute_open_close_green_date := time_to_date_string(time)
if max_absolute_high_low_green < absolute_high_low
max_absolute_high_low_green := absolute_high_low
max_absolute_high_low_green_date := time_to_date_string(time)
label.new(bar_index, high, text=tostring(percentage_high_low)+"\n"+tostring(percentage_open_close),
yloc=yloc.abovebar, size=size.small, style=label.style_none, textcolor=color.green)
//red
else
percentage_high_low = round(((low*100/high)-100), cfg_decimals)
percentage_open_close = round(((close*100/open)-100), cfg_decimals)
absolute_high_low = low - high
absolute_open_close = close - open
if max_percentage_open_close_red > percentage_open_close
max_percentage_open_close_red := percentage_open_close
max_percentage_open_close_red_date := time_to_date_string(time)
if max_percentage_high_low_red > percentage_high_low
max_percentage_high_low_red := percentage_high_low
max_percentage_high_low_red_date := time_to_date_string(time)
if max_absolute_open_close_red > absolute_open_close
max_absolute_open_close_red := absolute_open_close
max_absolute_open_close_red_date := time_to_date_string(time)
if max_absolute_high_low_red > absolute_high_low
max_absolute_high_low_red := absolute_high_low
max_absolute_high_low_red_date := time_to_date_string(time)
label.new(bar_index, low, text=""+tostring(percentage_high_low)+"\n"+tostring(percentage_open_close),
yloc=yloc.belowbar, size=size.small, style=label.style_none, textcolor=color.red)
if barstate.islastconfirmedhistory
table stats_table = table.new(position.top_right, columns=2, rows=10,
frame_width=1, frame_color=color.black)
_row = 0
table.cell(stats_table, column=0, row=0,
text="Green Candles", text_halign=text.align_left, text_size=size.normal, text_color=color.black, bgcolor=color.green)
table.cell(stats_table, column=1, row=0,
text="", bgcolor=color.green)
table.cell(stats_table, column=0, row=1,
text="Max % Open/Close", text_halign=text.align_left, text_valign=text.align_top, text_color=color.black, text_size=size.normal, bgcolor=color.green)
table.cell(stats_table, column=1, row=1,
text=tostring(max_percentage_open_close_green)+"%\n( "+tostring(max_percentage_open_close_green_date)+" )", text_halign=text.align_left, text_color=color.black, text_size=size.normal, bgcolor=color.green)
table.cell(stats_table, column=0, row=2,
text="Max "+tostring(syminfo.currency)+" Open/Close", text_halign=text.align_left, text_valign=text.align_top, text_color=color.black, text_size=size.normal, bgcolor=color.green)
table.cell(stats_table, column=1, row=2,
text=tostring(max_absolute_open_close_green)+" "+tostring(syminfo.currency)+"\n( "+tostring(max_absolute_open_close_green_date)+" )", text_halign=text.align_left, text_color=color.black, text_size=size.normal, bgcolor=color.green)
table.cell(stats_table, column=0, row=3,
text="Max % Low/High", text_halign=text.align_left, text_valign=text.align_top, text_color=color.black, text_size=size.normal, bgcolor=color.green)
table.cell(stats_table, column=1, row=3,
text=tostring(max_percentage_high_low_green)+"%\n( "+tostring(max_percentage_high_low_green_date)+" )", text_halign=text.align_left, text_color=color.black, text_size=size.normal, bgcolor=color.green)
table.cell(stats_table, column=0, row=4,
text="Max "+tostring(syminfo.currency)+" Low/High", text_halign=text.align_left, text_valign=text.align_top, text_color=color.black, text_size=size.normal, bgcolor=color.green)
table.cell(stats_table, column=1, row=4,
text=tostring(max_absolute_high_low_green)+" "+tostring(syminfo.currency)+"\n( "+tostring(max_absolute_high_low_green_date)+" )", text_halign=text.align_left, text_color=color.black, text_size=size.normal, bgcolor=color.green)
table.cell(stats_table, column=0, row=5,
text="Red Candles", text_halign=text.align_left, text_size=size.normal, text_color=color.black, bgcolor=#FF9494)
table.cell(stats_table, column=1, row=5, text="", bgcolor=#FF9494)
table.cell(stats_table, column=0, row=6,
text="Max % Open/Close", text_halign=text.align_left, text_valign=text.align_top, text_color=color.black, text_size=size.normal, bgcolor=#FF9494)
table.cell(stats_table, column=1, row=6,
text=tostring(max_percentage_open_close_red)+"%\n( "+tostring(max_percentage_open_close_red_date)+" )", text_halign=text.align_left, text_color=color.black, text_size=size.normal, bgcolor=#FF9494)
table.cell(stats_table, column=0, row=7,
text="Max "+tostring(syminfo.currency)+" Open/Close", text_halign=text.align_left, text_valign=text.align_top, text_color=color.black, text_size=size.normal, bgcolor=#FF9494)
table.cell(stats_table, column=1, row=7,
text=tostring(max_absolute_open_close_red)+" "+tostring(syminfo.currency)+"\n( "+tostring(max_absolute_open_close_red_date)+" )", text_halign=text.align_left, text_color=color.black, text_size=size.normal, bgcolor=#FF9494)
table.cell(stats_table, column=0, row=8,
text="Max % High/Low", text_halign=text.align_left, text_valign=text.align_top, text_color=color.black, text_size=size.normal, bgcolor=#FF9494)
table.cell(stats_table, column=1, row=8,
text=tostring(max_percentage_high_low_red)+"%\n( "+tostring(max_percentage_open_close_red_date)+" )", text_halign=text.align_left, text_color=color.black, text_size=size.normal, bgcolor=#FF9494)
table.cell(stats_table, column=0, row=9,
text="Max "+tostring(syminfo.currency)+" High/Low", text_halign=text.align_left, text_valign=text.align_top, text_color=color.black, text_size=size.normal, bgcolor=#FF9494)
table.cell(stats_table, column=1, row=9,
text=tostring(max_absolute_high_low_red)+" "+tostring(syminfo.currency)+"\n( "+tostring(max_absolute_high_low_red_date)+" )", text_halign=text.align_left, text_color=color.black, text_size=size.normal, bgcolor=#FF9494)
|
world stage index | https://www.tradingview.com/script/cmjem6ps/ | trader_aaa111 | https://www.tradingview.com/u/trader_aaa111/ | 24 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kattsu
//@version=5
indicator('world stage index', overlay=false)
//40symbols
//"TVC:SHCOMP" is revised to "SSE:000001"
s1 = request.security('OSE:NK2251!', '', close)
s2 = request.security('DJ:DJI', '', close)
s3 = request.security('NASDAQ:IXIC', '', close)
s4 = request.security('SP:SPX', '', close)
s5 = request.security('XETR:DAX', '', close)
s6 = request.security('TVC:CAC40', '', close)
s7 = request.security('TVC:UKX', '', close)
s8 = request.security('TSX:TSX', '', close)
s9 = request.security('SSE:000001', '', close)
s10 = request.security('SZSE:399001', '', close)
s11 = request.security('TVC:HSI', '', close)
s12 = request.security('TWSE:TAIEX', '', close)
s13 = request.security('BSE:SENSEX', '', close)
s14 = request.security('OANDA:SG30SGD', '', close)
s15 = request.security('INDEX:KSI', '', close)
s16 = request.security('SET:SET', '', close)
s17 = request.security('INDEX:SX5E', '', close)
s18 = request.security('INDEX:FTSEMIB', '', close)
s19 = request.security('SIX:SMI', '', close)
s20 = request.security('BME:IBC', '', close)
s21 = request.security('EURONEXT:BEL20', '', close)
s22 = request.security('TVC:AEX', '', close)
s23 = request.security('OMXCOP:OMXC25', '', close)
s24 = request.security('ATHEX:GD', '', close)
s25 = request.security('ASX:XJO', '', close)
s26 = request.security('TVC:NZ50G', '', close)
s27 = request.security('IDX:COMPOSITE', '', close)
s28 = request.security('FTSEMYX:FBMKLCI', '', close)
s29 = request.security('BMFBOVESPA:IBOV', '', close)
s30 = request.security('BMV:ME', '', close)
s31 = request.security('BVL:SPBLPGPT', '', close)
s32 = request.security('TVC:SA40', '', close)
s33 = request.security('MOEX:IMOEX', '', close)
s34 = request.security('GPW:WIG20', '', close)
s35 = request.security('OMXHEX:OMXH25', '', close)
s36 = request.security('OMXSTO:OMXS30', '', close)
s37 = request.security('DFM:DFMGI', '', close)
s38 = request.security('TADAWUL:TASI', '', close)
s39 = request.security('QSE:GNRI', '', close)
s40 = request.security('EGX:EGX30', '', close)
//ema5,20,40 of each symbols
As1 = ta.ema(s1, 5)
Bs1 = ta.ema(s1, 20)
Cs1 = ta.ema(s1, 40)
As2 = ta.ema(s2, 5)
Bs2 = ta.ema(s2, 20)
Cs2 = ta.ema(s2, 40)
As3 = ta.ema(s3, 5)
Bs3 = ta.ema(s3, 20)
Cs3 = ta.ema(s3, 40)
As4 = ta.ema(s4, 5)
Bs4 = ta.ema(s4, 20)
Cs4 = ta.ema(s4, 40)
As5 = ta.ema(s5, 5)
Bs5 = ta.ema(s5, 20)
Cs5 = ta.ema(s5, 40)
As6 = ta.ema(s6, 5)
Bs6 = ta.ema(s6, 20)
Cs6 = ta.ema(s6, 40)
As7 = ta.ema(s7, 5)
Bs7 = ta.ema(s7, 20)
Cs7 = ta.ema(s7, 40)
As8 = ta.ema(s8, 5)
Bs8 = ta.ema(s8, 20)
Cs8 = ta.ema(s8, 40)
As9 = ta.ema(s9, 5)
Bs9 = ta.ema(s9, 20)
Cs9 = ta.ema(s9, 40)
As10 = ta.ema(s10, 5)
Bs10 = ta.ema(s10, 20)
Cs10 = ta.ema(s10, 40)
As11 = ta.ema(s11, 5)
Bs11 = ta.ema(s11, 20)
Cs11 = ta.ema(s11, 40)
As12 = ta.ema(s12, 5)
Bs12 = ta.ema(s12, 20)
Cs12 = ta.ema(s12, 40)
As13 = ta.ema(s13, 5)
Bs13 = ta.ema(s13, 20)
Cs13 = ta.ema(s13, 40)
As14 = ta.ema(s14, 5)
Bs14 = ta.ema(s14, 20)
Cs14 = ta.ema(s14, 40)
As15 = ta.ema(s15, 5)
Bs15 = ta.ema(s15, 20)
Cs15 = ta.ema(s15, 40)
As16 = ta.ema(s16, 5)
Bs16 = ta.ema(s16, 20)
Cs16 = ta.ema(s16, 40)
As17 = ta.ema(s17, 5)
Bs17 = ta.ema(s17, 20)
Cs17 = ta.ema(s17, 40)
As18 = ta.ema(s18, 5)
Bs18 = ta.ema(s18, 20)
Cs18 = ta.ema(s18, 40)
As19 = ta.ema(s19, 5)
Bs19 = ta.ema(s19, 20)
Cs19 = ta.ema(s19, 40)
As20 = ta.ema(s20, 5)
Bs20 = ta.ema(s20, 20)
Cs20 = ta.ema(s20, 40)
As21 = ta.ema(s21, 5)
Bs21 = ta.ema(s21, 20)
Cs21 = ta.ema(s21, 40)
As22 = ta.ema(s22, 5)
Bs22 = ta.ema(s22, 20)
Cs22 = ta.ema(s22, 40)
As23 = ta.ema(s23, 5)
Bs23 = ta.ema(s23, 20)
Cs23 = ta.ema(s23, 40)
As24 = ta.ema(s24, 5)
Bs24 = ta.ema(s24, 20)
Cs24 = ta.ema(s24, 40)
As25 = ta.ema(s25, 5)
Bs25 = ta.ema(s25, 20)
Cs25 = ta.ema(s25, 40)
As26 = ta.ema(s26, 5)
Bs26 = ta.ema(s26, 20)
Cs26 = ta.ema(s26, 40)
As27 = ta.ema(s27, 5)
Bs27 = ta.ema(s27, 20)
Cs27 = ta.ema(s27, 40)
As28 = ta.ema(s28, 5)
Bs28 = ta.ema(s28, 20)
Cs28 = ta.ema(s28, 40)
As29 = ta.ema(s29, 5)
Bs29 = ta.ema(s29, 20)
Cs29 = ta.ema(s29, 40)
As30 = ta.ema(s30, 5)
Bs30 = ta.ema(s30, 20)
Cs30 = ta.ema(s30, 40)
As31 = ta.ema(s31, 5)
Bs31 = ta.ema(s31, 20)
Cs31 = ta.ema(s31, 40)
As32 = ta.ema(s32, 5)
Bs32 = ta.ema(s32, 20)
Cs32 = ta.ema(s32, 40)
As33 = ta.ema(s33, 5)
Bs33 = ta.ema(s33, 20)
Cs33 = ta.ema(s33, 40)
As34 = ta.ema(s34, 5)
Bs34 = ta.ema(s34, 20)
Cs34 = ta.ema(s34, 40)
As35 = ta.ema(s35, 5)
Bs35 = ta.ema(s35, 20)
Cs35 = ta.ema(s35, 40)
As36 = ta.ema(s36, 5)
Bs36 = ta.ema(s36, 20)
Cs36 = ta.ema(s36, 40)
As37 = ta.ema(s37, 5)
Bs37 = ta.ema(s37, 20)
Cs37 = ta.ema(s37, 40)
As38 = ta.ema(s38, 5)
Bs38 = ta.ema(s38, 20)
Cs38 = ta.ema(s38, 40)
As39 = ta.ema(s39, 5)
Bs39 = ta.ema(s39, 20)
Cs39 = ta.ema(s39, 40)
As40 = ta.ema(s40, 5)
Bs40 = ta.ema(s40, 20)
Cs40 = ta.ema(s40, 40)
//criteria of stage 1
//A=ema05, B=ema20 , C=ema40
Sone(A, B, C) =>
if A >= B and B >= C
1
else
0
//criteria of stage 4
//A=ema05, B=ema20 , C=ema40
Sfour(A, B, C) =>
if C >= B and B >= A
1
else
0
//Assign each symbols to a function
Sone1 = Sone(As1, Bs1, Cs1)
Sone2 = Sone(As2, Bs2, Cs2)
Sone3 = Sone(As3, Bs3, Cs3)
Sone4 = Sone(As4, Bs4, Cs4)
Sone5 = Sone(As5, Bs5, Cs5)
Sone6 = Sone(As6, Bs6, Cs6)
Sone7 = Sone(As7, Bs7, Cs7)
Sone8 = Sone(As8, Bs8, Cs8)
Sone9 = Sone(As9, Bs9, Cs9)
Sone10 = Sone(As10, Bs10, Cs10)
Sone11 = Sone(As11, Bs11, Cs11)
Sone12 = Sone(As12, Bs12, Cs12)
Sone13 = Sone(As13, Bs13, Cs13)
Sone14 = Sone(As14, Bs14, Cs14)
Sone15 = Sone(As15, Bs15, Cs15)
Sone16 = Sone(As16, Bs16, Cs16)
Sone17 = Sone(As17, Bs17, Cs17)
Sone18 = Sone(As18, Bs18, Cs18)
Sone19 = Sone(As19, Bs19, Cs19)
Sone20 = Sone(As20, Bs20, Cs20)
Sone21 = Sone(As21, Bs21, Cs21)
Sone22 = Sone(As22, Bs22, Cs22)
Sone23 = Sone(As23, Bs23, Cs23)
Sone24 = Sone(As24, Bs24, Cs24)
Sone25 = Sone(As25, Bs25, Cs25)
Sone26 = Sone(As26, Bs26, Cs26)
Sone27 = Sone(As27, Bs27, Cs27)
Sone28 = Sone(As28, Bs28, Cs28)
Sone29 = Sone(As29, Bs29, Cs29)
Sone30 = Sone(As30, Bs30, Cs30)
Sone31 = Sone(As31, Bs31, Cs31)
Sone32 = Sone(As32, Bs32, Cs32)
Sone33 = Sone(As33, Bs33, Cs33)
Sone34 = Sone(As34, Bs34, Cs34)
Sone35 = Sone(As35, Bs35, Cs35)
Sone36 = Sone(As36, Bs36, Cs36)
Sone37 = Sone(As37, Bs37, Cs37)
Sone38 = Sone(As38, Bs38, Cs38)
Sone39 = Sone(As39, Bs39, Cs39)
Sone40 = Sone(As40, Bs40, Cs40)
Sfour1 = Sfour(As1, Bs1, Cs1)
Sfour2 = Sfour(As2, Bs2, Cs2)
Sfour3 = Sfour(As3, Bs3, Cs3)
Sfour4 = Sfour(As4, Bs4, Cs4)
Sfour5 = Sfour(As5, Bs5, Cs5)
Sfour6 = Sfour(As6, Bs6, Cs6)
Sfour7 = Sfour(As7, Bs7, Cs7)
Sfour8 = Sfour(As8, Bs8, Cs8)
Sfour9 = Sfour(As9, Bs9, Cs9)
Sfour10 = Sfour(As10, Bs10, Cs10)
Sfour11 = Sfour(As11, Bs11, Cs11)
Sfour12 = Sfour(As12, Bs12, Cs12)
Sfour13 = Sfour(As13, Bs13, Cs13)
Sfour14 = Sfour(As14, Bs14, Cs14)
Sfour15 = Sfour(As15, Bs15, Cs15)
Sfour16 = Sfour(As16, Bs16, Cs16)
Sfour17 = Sfour(As17, Bs17, Cs17)
Sfour18 = Sfour(As18, Bs18, Cs18)
Sfour19 = Sfour(As19, Bs19, Cs19)
Sfour20 = Sfour(As20, Bs20, Cs20)
Sfour21 = Sfour(As21, Bs21, Cs21)
Sfour22 = Sfour(As22, Bs22, Cs22)
Sfour23 = Sfour(As23, Bs23, Cs23)
Sfour24 = Sfour(As24, Bs24, Cs24)
Sfour25 = Sfour(As25, Bs25, Cs25)
Sfour26 = Sfour(As26, Bs26, Cs26)
Sfour27 = Sfour(As27, Bs27, Cs27)
Sfour28 = Sfour(As28, Bs28, Cs28)
Sfour29 = Sfour(As29, Bs29, Cs29)
Sfour30 = Sfour(As30, Bs30, Cs30)
Sfour31 = Sfour(As31, Bs31, Cs31)
Sfour32 = Sfour(As32, Bs32, Cs32)
Sfour33 = Sfour(As33, Bs33, Cs33)
Sfour34 = Sfour(As34, Bs34, Cs34)
Sfour35 = Sfour(As35, Bs35, Cs35)
Sfour36 = Sfour(As36, Bs36, Cs36)
Sfour37 = Sfour(As37, Bs37, Cs37)
Sfour38 = Sfour(As38, Bs38, Cs38)
Sfour39 = Sfour(As39, Bs39, Cs39)
Sfour40 = Sfour(As40, Bs40, Cs40)
//Sum of stage1
//divided by 0.4
//to displey from 0to 100
ST1 = Sone1 + Sone2 + Sone3 + Sone4 + Sone5 + Sone6 + Sone7 + Sone8 + Sone9 + Sone10 + Sone11 + Sone12 + Sone13 + Sone14 + Sone15 + Sone16 + Sone17 + Sone18 + Sone19 + Sone20 + Sone21 + Sone22 + Sone23 + Sone24 + Sone25 + Sone26 + Sone27 + Sone28 + Sone29 + Sone30 + Sone31 + Sone32 + Sone33 + Sone34 + Sone35 + Sone36 + Sone37 + Sone38 + Sone39 + Sone40
plot(ST1 / 0.4, color=#ffd70050, style=plot.style_area)
//Sum of stage4
//divided by 0.4
//to displey from 0to 100
ST4 = Sfour1 + Sfour2 + Sfour3 + Sfour4 + Sfour5 + Sfour6 + Sfour7 + Sfour8 + Sfour9 + Sfour10 + Sfour11 + Sfour12 + Sfour13 + Sfour14 + Sfour15 + Sfour16 + Sfour17 + Sfour18 + Sfour19 + Sfour20 + Sfour21 + Sfour22 + Sfour23 + Sfour24 + Sfour25 + Sfour26 + Sfour27 + Sfour28 + Sfour29 + Sfour30 + Sfour31 + Sfour32 + Sfour33 + Sfour34 + Sfour35 + Sfour36 + Sfour37 + Sfour38 + Sfour39 + Sfour40
plot(ST4 / 0.4, color=#1e90ff50, style=plot.style_area)
//R=ratio of stage1/4
//2.5times to displey from 0 to 100
//Because R is almost between 0 and 40
R = ST1 / ST4 * 2.5
plot(R, color=color.new(color.red, 20), style=plot.style_line, linewidth=2)
//center line
hline(50, title='50', color=color.black, linestyle=hline.style_solid, linewidth=2, editable=true)
//80% and 20% line
hline(80, title='50', color=color.green, linestyle=hline.style_solid, linewidth=1, editable=true)
hline(20, title='50', color=color.green, linestyle=hline.style_solid, linewidth=1, editable=true)
//ずらっと40個並べないで、ループ化したコードにしたい。今後の勉強課題。
|
HA,Renko, Linebreak,Kagi and Average all Charts Layouts in One | https://www.tradingview.com/script/Apzrq9Ex-HA-Renko-Linebreak-Kagi-and-Average-all-Charts-Layouts-in-One/ | exlux99 | https://www.tradingview.com/u/exlux99/ | 154 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © exlux99
//@version=4
study("Educational Plots",overlay=true)
// Function to securely and simply call `security()` so that it never repaints and never looks ahead.
f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
source=input(close)
ha = f_secureSecurity(heikinashi(syminfo.tickerid), timeframe.period, source)
renko_t = renko(syminfo.tickerid, "ATR", 10)
renko = f_secureSecurity(renko_t, timeframe.period, source)
lb = linebreak(syminfo.tickerid, 3)
linebreak= f_secureSecurity(lb, timeframe.period, source)
kg= kagi(syminfo.tickerid, 1)
kagi = f_secureSecurity(kg, timeframe.period, source)
plot(close, title='Close', color=color.blue, linewidth=1, style=plot.style_line)
plot(ha, title='Heikin Ashi', color=color.white, linewidth=1, style=plot.style_line)
plot(renko, title='Renko', color=color.green, linewidth=1, style=plot.style_line)
plot(linebreak, title='Linebreak', color=color.maroon, linewidth=1, style=plot.style_line)
plot(kagi, title='Kagi', color=color.purple, linewidth=1, style=plot.style_line)
average_close = (close+ha+renko+linebreak+kagi)/5
plot(average_close, title='AVERAGE', color=color.white, linewidth=4, style=plot.style_line)
|
Candle Volatility Index [by NicoadW] | https://www.tradingview.com/script/B9noFQ1p-Candle-Volatility-Index-by-NicoadW/ | NicoadW1990 | https://www.tradingview.com/u/NicoadW1990/ | 94 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © NicoadW1990
//@version=4
study("Candle Volatility Index")
src = input(close, title="Source")
maType = input(title="Volatility MA Type", options=["EMA", "SMA", "WMA", "VWMA", "ALMA", "HMA"] , defval = "SMA")
period=input(8, title="Volatility Period")
signal_maType = input(title="Signal MA Type", options=["EMA", "SMA", "WMA", "VWMA", "ALMA", "HMA"] , defval = "SMA")
signal_period=input(10, title="Signal Period")
Base=abs(src-src[1])
MA_Calc(MA_type,MA_source,MA_period) =>
float result = 0
if MA_type == "SMA" // Simple
result := sma(MA_source, MA_period)
if MA_type == "EMA" // Exponential
result := ema(MA_source, MA_period)
if MA_type == "WMA" // Weighted
result := wma(MA_source, MA_period)
if MA_type == "VWMA" // Volume Weighted
result := vwma(MA_source, MA_period)
if MA_type == "ALMA" // Arnaud Legoux
result := alma(MA_source, MA_period, .85, 6)
if MA_type == "HMA" // Hull
result := wma(2 * wma(MA_source, MA_period / 2) - wma(MA_source, MA_period), round(sqrt(MA_period)))
result
Volatility=MA_Calc(maType,Base,period)
Signal=MA_Calc(signal_maType,Volatility,signal_period)
plot(Volatility, style=plot.style_columns, color= Volatility>Signal ? color.blue : color.gray)
plot(Signal, color=color.black, linewidth=2) |
Forex Trading Sessions | https://www.tradingview.com/script/bvNw5ydF-Forex-Trading-Sessions/ | DasanC | https://www.tradingview.com/u/DasanC/ | 574 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EmpiricalFX
//@version=4
study("Forex Sessions",overlay=true)
//## Forex Trading Session
gp1 = "Forex Trading Sessions"
gp3 = "Session Configuration"
gp2 = "Additional Settings"
///Sessions
london = input(title="London Session", type=input.session, defval="0300-1200",group=gp1)
ny = input(title="New York Session", type=input.session, defval="0800-1700",group=gp1)
tokyo = input(title="Tokyo Session", type=input.session, defval="2000-0400",group=gp1)
sydney = input(title="Sydney Session", type=input.session, defval="1700-0200",group=gp1)
//Config
show_bg = input(true,"Show Background Colors",input.bool,group=gp2)
London = input(title="Show London Session", type=input.bool, defval=true,group=gp3)
LondonColor = input(color.new(color.green,95),"London Color",input.color,group=gp3)
NY = input(title="Show New York Session", type=input.bool, defval=true,group=gp3)
NYColor = input(color.new(color.red,95),"New York Color",input.color,group=gp3)
Tokyo = input(title="Show Tokyo Session", type=input.bool, defval=false,group=gp3)
AsiaColor = input(color.new(color.yellow,95),"Tokyo Color", input.color,group=gp3)
Sydney = input(title="Show Sydney Session", type=input.bool, defval=false,group=gp3)
SydneyColor = input(color.new(color.navy,95),"Sydney Color",input.color,group=gp3)
//Additional
auto = input(false,"Automatic Pair Detection",input.bool,group=gp2,tooltip="If succesful, will override manual settings below.\nLondon = CHF, EUR, GBP\nNew York = CAD, USD, XAU\nTokyo = JPY\nSydney = AUD, NZD")
//Find target substring using slices
indexOf2(str, target) =>
// 0..n-1
arr = str.split(str, "")
// n
len1 = array.size(arr)
len2 = str.length(target)
res = len2 > 0 ? -1 : 0
// both arr, target are not empty
if len1 >= len2 and len2 > 0
// can't use array.indexof(arr, target) because there are multiple chars in target string
for i = 0 to len1 - len2
// compare each substring of str of target length with target string
// arr slice from start_pos to end_pos, not including end_pos, start_pos < end_pos otherwise error!
slice = array.slice(arr, i, i + len2)
if array.join(slice, "") == target
res := i
break
res
//Detection of bar within session
is_session(sess) =>
not na(time("D", sess))
//Create a Vertical Line
vline(BarIndex, Color, LineStyle, LineWidth) => // Verticle Line Function, ≈50-54 lines maximum allowable per indicator
// return = line.new(BarIndex, 0.0, BarIndex, 100.0, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=false) and RSI, Stochastic, etc...
// return = line.new(BarIndex, -1.0, BarIndex, 1.0, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=false) and +/-1.0 oscillators
return = line.new(BarIndex, low - tr, BarIndex, high + tr, xloc.bar_index, extend.both, color.new(Color,0), LineStyle, LineWidth) // Suitable for study(overlay=true)
if(auto)
pair = syminfo.ticker
AUD = indexOf2(pair,"AUD")!= -1
CAD = indexOf2(pair,"CAD")!= -1
CHF = indexOf2(pair,"CHF")!= -1
EUR = indexOf2(pair,"EUR")!= -1
GBP = indexOf2(pair,"GBP")!= -1
JPY = indexOf2(pair,"JPY")!= -1
NZD = indexOf2(pair,"NZD")!= -1
USD = indexOf2(pair,"USD")!= -1
XAU = indexOf2(pair,"XAU")!= -1
if(AUD or CAD or CHF or EUR or GBP or JPY or USD or XAU)
London := (GBP or EUR or CHF) and London
NY := (USD or CAD or XAU) and NY
Tokyo := (JPY) and Tokyo
Sydney := (AUD or NZD) and Sydney
//London
londonSession = is_session(london)
if(London)
if(londonSession and not londonSession[1])
vline(bar_index,LondonColor,line.style_dashed,1)
if(not londonSession and londonSession[1])
vline(bar_index,LondonColor,line.style_solid,1)
bgcolor((londonSession and London and show_bg)?LondonColor:na,title="London Session",editable=false)
//New York
nySession = is_session(ny)
if(NY)
if(nySession and not nySession[1])
vline(bar_index,NYColor,line.style_dashed,1)
if(not nySession and nySession[1])
vline(bar_index,NYColor,line.style_solid,1)
bgcolor((nySession and NY and show_bg)?NYColor:na,title="NY Session",editable=false)
//Tokyo
tokyoSession = is_session(tokyo)
if(Tokyo)
if( tokyoSession and not tokyoSession[1])
vline(bar_index,AsiaColor,line.style_dashed,1)
if(not tokyoSession and tokyoSession[1])
vline(bar_index,AsiaColor,line.style_solid,1)
bgcolor((tokyoSession and Tokyo and show_bg)?AsiaColor:na,title="Tokyo Session",editable=false)
//Sydney
sydneySession = is_session(sydney)
if(Sydney)
if(sydneySession and not sydneySession[1])
vline(bar_index,SydneyColor,line.style_dashed,1)
if(not sydneySession and sydneySession[1])
vline(bar_index,SydneyColor,line.style_solid,1)
bgcolor((sydneySession and Sydney and show_bg)?SydneyColor:na,title="Sydney Session",editable=false) |
HiLo Indicator | https://www.tradingview.com/script/H6ivjHE3-HiLo-Indicator/ | VolvloV | https://www.tradingview.com/u/VolvloV/ | 104 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © VolvloV
//@version=4
study("HiLo Indicator")
tl = input(title="Time Length", defval=400)
fw = input(title="Fast WMA",defval=100)
lw = input(title="Long WMA",defval=300)
lo= close-lowest(close,tl)
hi= highest(close,tl)-close
a1 = wma(lo,fw)
a2 = wma(lo,lw)
a3 = wma(hi,fw)
a4 = wma(hi,lw)
p1 = plot(a1,color=color.lime)
p2 = plot(a2,color=color.yellow,transp=75)
p3 = plot(a3,color=color.red)
//p4 = plot(a4,color=color.red,transp=75)
color c_fill = color.new(wma(lo,fw) > wma(lo,lw) ? color.lime : color.yellow,80)
color c_fill2 = color.new(a1 > a3 ? color.lime : color.red,90)
fill(p1,p3,color=c_fill2,transp=90)
d = crossover(a1,a2) and hi>lo
e = crossover(a1,a3)
f = crossunder(a1,a3)
g = crossover(a1,a2) and hi<lo
plotshape(d, style=shape.circle,color=color.green,size=size.tiny,location=location.bottom,text="Turn Around")
plotshape(g, style=shape.circle,color=color.yellow,size=size.tiny,location=location.top,text="Entry")
//plotshape(f, style=shape.circle,color=color.red,size=size.tiny,location=location.top,text="Bear X")
alertcondition(d, title='Turn Around', message='Possible Turn Around!')
alertcondition(e, title='Bull X', message='Bull X')
alertcondition(f, title='Bear X', message='Bear X')
alertcondition(g,title='Entry',message='Entry')
a1d = (a1+a1[1])/2
a3d = (a3+a3[1])/2
Area = sum(a1d-a3d,100)
//plot(Area/100)
|
Multiple Anchored VWAP [Morty] | https://www.tradingview.com/script/RozwDHQA-Multiple-Anchored-VWAP-Morty/ | M0rty | https://www.tradingview.com/u/M0rty/ | 1,285 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © M0rty
//@version=4
study("Multiple Anchored VWAP [Morty]", overlay=true, resolution="", resolution_gaps=true)
// ---------------------------------------------------------------------------
// inputs
show_label = input(true, "Show labels")
show1 = input(true, "aVWAP №1", inline="aVWAP #1")
src1 = input(hlc3, "", type=input.source, inline="aVWAP #1")
color1 = input(#f6c309, "", inline="aVWAP #1")
date1 = input(title="Date", type=input.time, defval=timestamp("2021-07-21T00:00+00:00"), inline="aVWAP #1")
show2 = input(true, "aVWAP №2", inline="aVWAP #2")
src2 = input(hlc3, "", type=input.source, inline="aVWAP #2")
color2 = input(#fb9800, "", inline="aVWAP #2")
date2 = input(title="Date", type=input.time, defval=timestamp("2021-08-05T00:00+00:00"), inline="aVWAP #2")
show3 = input(false, "aVWAP №3", inline="aVWAP #3")
src3 = input(hlc3, "", type=input.source, inline="aVWAP #3")
color3 = input(#fb6500, "", inline="aVWAP #3")
date3 = input(title="Date", type=input.time, defval=timestamp("2021-09-07T00:00+00:00"), inline="aVWAP #3")
show4 = input(false, "aVWAP №4", inline="aVWAP #4")
src4 = input(hlc3, "", type=input.source, inline="aVWAP #4")
color4 = input(#f60c0c, "", inline="aVWAP #4")
date4 = input(title="Date", type=input.time, defval=timestamp("2021-05-19T00:00+00:00"), inline="aVWAP #4")
// ---------------------------------------------------------------------------
// function to calculate Anchored VWAP
f_avwap(src, date) =>
start = time >= date and time[1] < date
sumSrc = src * volume
sumVol = volume
sumSrc := start ? sumSrc : sumSrc + sumSrc[1]
sumVol := start ? sumVol : sumVol + sumVol[1]
sumSrc / sumVol
// ---------------------------------------------------------------------------
// plot anchored vwap
plot(show1 ? f_avwap(src1, date1) : na, color=color1, title="aVWAP №1")
plot(show2 ? f_avwap(src2, date2) : na, color=color2, title="aVWAP №2")
plot(show3 ? f_avwap(src3, date3) : na, color=color3, title="aVWAP №3")
plot(show4 ? f_avwap(src4, date4) : na, color=color4, title="aVWAP №4")
// ---------------------------------------------------------------------------
// plot labels
plotshape(show_label and show1 ? time >= date1 and time[1] < date1 : na, text='aVWAP №1',
textcolor=color.white, color=color.new(color1, 35), location=location.belowbar, style=shape.labelup, size=size.small)
plotshape(show_label and show2 ? time >= date2 and time[1] < date2 : na, text='aVWAP №2',
textcolor=color.white, color=color.new(color2, 35), location=location.belowbar, style=shape.labelup, size=size.small)
plotshape(show_label and show3 ? time >= date3 and time[1] < date3 : na, text='aVWAP №3',
textcolor=color.white, color=color.new(color3, 35), location=location.belowbar, style=shape.labelup, size=size.small)
plotshape(show_label and show4 ? time >= date4 and time[1] < date4 : na, text='aVWAP №4',
textcolor=color.white, color=color.new(color4, 35), location=location.belowbar, style=shape.labelup, size=size.small)
|
RSI - Dynamic Overbought/Oversold Range | https://www.tradingview.com/script/4G2JhyzF-RSI-Dynamic-Overbought-Oversold-Range/ | Trendoscope | https://www.tradingview.com/u/Trendoscope/ | 854 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed
// __ __ __ __ __ __ __ __ __ __ __ _______ __ __ __
// / | / | / | _ / |/ | / \ / | / | / \ / | / | / \ / \ / | / |
// $$ | $$ | ______ $$ | / \ $$ |$$ |____ ______ $$ \ /$$ | __ __ _______ _$$ |_ $$ \ $$ | ______ _$$ |_ $$$$$$$ | ______ $$ \ $$ | ______ _____ ____ ______ ____$$ |
// $$ |__$$ | / \ $$ |/$ \$$ |$$ \ / \ $$$ \ /$$$ |/ | / | / |/ $$ | $$$ \$$ | / \ / $$ | $$ |__$$ | / \ $$$ \$$ | / \ / \/ \ / \ / $$ |
// $$ $$ |/$$$$$$ |$$ /$$$ $$ |$$$$$$$ |/$$$$$$ |$$$$ /$$$$ |$$ | $$ |/$$$$$$$/ $$$$$$/ $$$$ $$ |/$$$$$$ |$$$$$$/ $$ $$< /$$$$$$ |$$$$ $$ | $$$$$$ |$$$$$$ $$$$ |/$$$$$$ |/$$$$$$$ |
// $$$$$$$$ |$$ $$ |$$ $$/$$ $$ |$$ | $$ |$$ | $$ |$$ $$ $$/$$ |$$ | $$ |$$ \ $$ | __ $$ $$ $$ |$$ | $$ | $$ | __ $$$$$$$ |$$ $$ |$$ $$ $$ | / $$ |$$ | $$ | $$ |$$ $$ |$$ | $$ |
// $$ | $$ |$$$$$$$$/ $$$$/ $$$$ |$$ | $$ |$$ \__$$ |$$ |$$$/ $$ |$$ \__$$ | $$$$$$ | $$ |/ |$$ |$$$$ |$$ \__$$ | $$ |/ |$$ |__$$ |$$$$$$$$/ $$ |$$$$ |/$$$$$$$ |$$ | $$ | $$ |$$$$$$$$/ $$ \__$$ |
// $$ | $$ |$$ |$$$/ $$$ |$$ | $$ |$$ $$/ $$ | $/ $$ |$$ $$/ / $$/ $$ $$/ $$ | $$$ |$$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$$ |$$ $$ |$$ | $$ | $$ |$$ |$$ $$ |
// $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ $$$$$$$/ $$$$/ $$/ $$/ $$$$$$/ $$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$$$$/
//
//
//
//@version=5
indicator('RSI - Dynamic Overbought/Oversold Range', shorttitle='RSI-DR')
resolution = input.timeframe('', title='Resolution', group='RSI')
source = input.source(close, title='Source', group='RSI')
length = input.int(14, title='Length', group='RSI')
repaint = input.bool(true, title='Repaint', group='RSI')
stickToRange = input.bool(true, title='Sticky Range', group='RSI')
method = input.string('highlow', title='Detection Method', group='Overbought/Oversold Range', options=['highlow', 'sma', 'ema', 'rma', 'hma', 'wma', 'vwma', 'swma'])
rangeLength = input.int(50, step=10, title='Length', group='Overbought/Oversold Range')
f_security(_sym, _res, _src, _rep) =>
request.security(_sym, _res, _src[not _rep and barstate.isrealtime ? 1 : 0])[_rep or barstate.isrealtime ? 0 : 1]
f_get_ma(source, method, rangeLength) =>
method == 'sma' ? ta.sma(source, rangeLength) : method == 'ema' ? ta.ema(source, rangeLength) : method == 'rma' ? ta.rma(source, rangeLength) : method == 'hma' ? ta.hma(source, rangeLength) : method == 'wma' ? ta.wma(source, rangeLength) : method == 'vwma' ? ta.vwma(source, rangeLength) : method == 'swma' ? ta.swma(source) : method == 'high' ? ta.highest(source, rangeLength) : method == 'low' ? ta.lowest(source, rangeLength) : na
f_rsi_high(source, length, method, rangeLength) =>
f_get_ma(ta.highest(ta.rsi(source, length), rangeLength), method == 'highlow' ? 'low' : method, length)
f_rsi_low(source, length, method, rangeLength) =>
f_get_ma(ta.lowest(ta.rsi(source, length), rangeLength), method == 'highlow' ? 'high' : method, length)
rsi = f_security(syminfo.tickerid, resolution, ta.rsi(source, length), repaint)
rsiHigh = f_security(syminfo.tickerid, resolution, f_rsi_high(source, length, method, rangeLength), repaint)
rsiLow = f_security(syminfo.tickerid, resolution, f_rsi_low(source, length, method, rangeLength), repaint)
highCrossover = rsi[1] >= rsiHigh[1]
lowCrossover = rsi[1] <= rsiLow[1]
if stickToRange and not(highCrossover or lowCrossover)
rsiHigh := nz(rsiHigh[1], rsiHigh)
rsiLow := nz(rsiLow[1], rsiLow)
rsiLow
plot(rsi, title='RSI', color=color.new(color.blue, 0))
plot(rsiHigh, title='Overbought', color=color.new(color.red, 0))
plot(rsiLow, title='Oversold', color=color.new(color.green, 0))
|
Nifty yield curve | https://www.tradingview.com/script/Sp4E3whX-Nifty-yield-curve/ | aftabmk | https://www.tradingview.com/u/aftabmk/ | 30 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © aftabmk
//@version=4
study("yeild curve")
//ad() =>sign(close - close[1])
m1 = nz(security("TVC:IN10Y", timeframe.period,close))
m2 = nz(security("TVC:IN03MY", timeframe.period,close))
m3=(m1-m2)
u1 = nz(security("TVC:US10Y", timeframe.period,close))
u2 = nz(security("TVC:US03MY", timeframe.period,close))
u3=(u1-u2)
plot(m3,title="Indian yield curve",color=color.new(color.teal,20), linewidth=3)
plot(u3,title="US yield curve",color=color.new(color.yellow,20), linewidth=3)
hline(0)
colorin = m3<0 ? color.teal : na
colorus = u3<0 ? color.yellow : na
bgcolor(colorus)
bgcolor(colorin)
|
VolT by empowerT | https://www.tradingview.com/script/DbWvZcL6-VolT-by-empowerT/ | empowerT | https://www.tradingview.com/u/empowerT/ | 86 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//
// VolT by empowerT https://www.tradingview.com/u/empowerT/
// ver 1.0
// modifications and 'VolT' concept © by empowerT
//
//@version=4
study(title="VolT by empowerT", shorttitle="VolT by empowerT", format=format.volume)
showMA = input(true)
slen=input(21, title="SMA Length")
vol1=input(1, title="Volume SMA Level #1 X")
vol2=input(2, title="Volume SMA Level #2 X")
vol3=input(5, title="Volume SMA Level #3 X")
v1 = volume* vol1
v2 = volume * vol2
v3 = volume * vol3
showv = input(true, title="Show Volume Levels?")
barColorsOnPrevClose = input(title="Color bars based on previous close", type=input.bool, defval=true)
palette = barColorsOnPrevClose ? close[1] > close ? color.red : color.green : open > close ? color.red : color.green
plot(showMA ? sma(v3,slen) : na, style=plot.style_area, color=color.new(color.aqua,75), title="Volume MA #3")
plot(showMA ? sma(v2,slen) : na, style=plot.style_area, color=color.new(color.blue,75), title="Volume MA #2")
plot(volume, color = color.new(palette,25), style=plot.style_columns, title="Volume")
plot(showMA ? sma(v1,slen) : na, style=plot.style_area, color=color.new(color.yellow,75), title="Volume MA #1")
var line voll1 = na
if showv
voll1 := line.new(time + 115000, sma(v1,slen), time + 1000000, sma(v1,slen), color=color.new(color.green, 45), style=line.style_dotted, width=1, xloc = xloc.bar_time)
label label1 = label.new(time + 175000, sma(v1,slen), tostring(vol1) + 'X', textcolor=color.new(color.green, 45), style=label.style_none, xloc = xloc.bar_time)
line.delete(voll1[1])
label.delete(label1[1])
var line voll2 = na
if showv
voll2 := line.new(time + 115000, sma(v2,slen), time + 1000000, sma(v2,slen), color=color.new(color.green, 45), style=line.style_dotted, width=1, xloc = xloc.bar_time)
label label2 = label.new(time + 175000, sma(v2,slen), tostring(vol2) + 'X', textcolor=color.new(color.green, 45), style=label.style_none, xloc = xloc.bar_time)
line.delete(voll2[1])
label.delete(label2[1])
var line voll3 = na
if showv
voll3 := line.new(time + 115000, sma(v3,slen), time + 1000000, sma(v3,slen), color=color.new(color.green, 45), style=line.style_dotted, width=1, xloc = xloc.bar_time)
label label5 = label.new(time + 175000, sma(v3,slen), tostring(vol3) + 'X', textcolor=color.new(color.green, 45), style=label.style_none, xloc = xloc.bar_time)
line.delete(voll3[1])
label.delete(label5[1])
var line vol = na
if showv
vol := line.new(time + 1000, sma(v1,slen), time + 10000, sma(v1,slen), color=color.new(color.yellow, 5), style=line.style_dotted, width=1, xloc = xloc.bar_time)
label label5 = label.new(time + 60000, volume, tostring((v1/(sma(v1,slen))*100), "##") +'%', textcolor=color.new(color.yellow, 5), style=label.style_none, xloc = xloc.bar_time)
line.delete(vol[1])
label.delete(label5[1])
|
RSI Candle with Advanced RSI fomula | https://www.tradingview.com/script/qGkm9uzR-RSI-Candle-with-Advanced-RSI-fomula/ | Dicargo_Beam | https://www.tradingview.com/u/Dicargo_Beam/ | 277 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Dicargo_Beam
//@version=4
study("RSI Candle with Advanced RSI fomula")
usev21 = input(false,"")
usev2 = input(false,"\nPlease use new version 'RSI Candle Advanced V2'\n")
usev22 = input(false,"")
src = close
len = input(14,"Length")
ad = input(true,"RSI Advanced ?? (Recommend)")
cdob = input("Candle",title="Candle or Bar or Line?",options=["Candle","Bar","Line"])
uc = input(color.green,"Up Color")
dc = input(color.red,"Down Color")
_rsi(src, len) =>
u = max(src - src[1], 0) // upward change
d = max(src[1] - src, 0) // downward change
rs = rma(u, len) / rma(d, len)
res = 100 - 100 / (1 + rs)
_rma(src, length) =>
a = 1/length
sum = 0.0
sum := na(sum[1]) ? sma(src, length) : a * src + (1 - a) * nz(sum[1])
//_rma = a*src + (1-a) * _rma[1]
//_rma_next = a * src_next + (1-a) * _rma
u = max(src - src[1], 0)
d = max(src[1] - src, 0)
a = 1/len
ruh = a * max(high-close[1],0) + (1-a) * rma(u,len)[1]
rdh = (1-a)*rma(d,len)[1]
rul = (1-a)*rma(u,len)[1]
rdl = a * max(close[1]-low,0) + (1-a) * rma(d,len)[1]
function(rsi,len) =>
f = -pow(abs(abs(rsi-50)-50),1+(pow(len/14,0.618)-1))/pow(50,(pow(len/14,0.618)-1))+50
rsiadvanced = if rsi>50
f+50
else
-f+50
rsiha = 100 - 100/(1+ruh/rdh)
rsila = 100 - 100/(1+rul/rdl)
rsia = rsi(src,len)
rsih = if ad
function(rsiha,len)
else
rsiha
rsil = if ad
function(rsila,len)
else
rsila
rsi = if ad
function(rsia,len)
else
rsia
col = change(rsi)>0? uc:dc
colc = if cdob == "Candle"
col
colb = if cdob == "Bar"
col
cold = if cdob == "Line"
col
plotcandle(rsi[1],rsih,rsil,rsi,color=colc,wickcolor=colc,bordercolor=colc)
plotbar(rsi[1],rsih,rsil,rsi,color=colb)
plot(rsi,color=cold)
ob = hline(70,"OB")
os = hline(30,"OS")
hline(50,"Balance")
fill(ob,os,color=color.purple)
|
Exponential MA Channel, Daily Timeframe (Crypto) | https://www.tradingview.com/script/uPjqluug-Exponential-MA-Channel-Daily-Timeframe-Crypto/ | memotyka9009 | https://www.tradingview.com/u/memotyka9009/ | 66 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © memotyka9009
//@version=4
study(title="Moving Average (Exponential)", shorttitle="Channel", overlay=true, resolution="")
src = input(close, title="Source")
offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)
// define ema timeframes
ma21 = input(21, minval=1, title="Length")
ma53 = input(53, minval=1, title="Length")
ma100 = input(100, minval=1, title="Length")
// use 'ema' function to create output for each ema
out1 = ema(src, ma21)
out2 = ema(src, ma53)
out3 = ema(src, ma100)
// plot the middle channel
ema_blue = plot(out1, color=color.blue, title="MA21", offset=offset)
ema_yellow = plot(out1*1.195, color=color.yellow, title="MA21", offset=offset)
ema_orng = plot(out1*.8995, color=color.orange, title="MA21", offset=offset)
// plot the top band (green)
top1 = plot(out3*1.85, color=color.green, title="MA100", offset=offset)
top2 = plot(out3*2.5, color=color.green, title="MA100", offset=offset)
// plot the bottom band (red)
bottom1 = plot(out2*.8995, color=color.red, title="MA53", offset=offset)
bottom2 = plot(out3*.6, color=color.red, title="MA100", offset=offset)
// fill in colors between
fill(top1, top2, color.rgb(0,200,10,88))
fill(ema_yellow, ema_orng, color.rgb(0,75,100,75))
fill(bottom1, bottom2, color.rgb(100,0,0,80)) |
Session/Day VWAP & Std Dev Bands | https://www.tradingview.com/script/MNsrD1HA-Session-Day-VWAP-Std-Dev-Bands/ | Koalafied_3 | https://www.tradingview.com/u/Koalafied_3/ | 338 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TJ_667
// Koalafied VWAP Session/Day
// VWAP and Standard Deviation Bands for intra-day sessions.
// Intra-day sessions be default are set to
// - Asia session
// - London Session
// - New York Session
// Day broken up as a 24 hour period consists of different market participents and therefore different behaviour.
// Daily VWAP and Standard Deviation Bands (1 & 2) can be overlayed.
//@version=5
indicator('Session VWAP', '', true)
// ---------- Functions ---------- //
// TradingView vwap function. Taken out stdev calcs to put in seperate function.
computeVWAP(src, isNewPeriod) =>
var float sumSrcVol = na
var float sumVol = na
var float sumSrcSrcVol = na
sumSrcVol := isNewPeriod ? src * volume : src * volume + sumSrcVol[1]
sumVol := isNewPeriod ? volume : volume + sumVol[1]
// sumSrcSrcVol calculates the dividend of the equation that is later used to calculate the standard deviation
sumSrcSrcVol := isNewPeriod ? volume * math.pow(src, 2) : volume * math.pow(src, 2) + sumSrcSrcVol[1]
_vwap = sumSrcVol / sumVol
variance = sumSrcSrcVol / sumVol - math.pow(_vwap, 2)
variance := variance < 0 ? 0 : variance
stDev = math.sqrt(variance)
[_vwap, stDev]
// Standard Deviation Band calculation function
compute_stDEV(_vwap, stDev, stDevMultiplier_1, stDevMultiplier_2) =>
upperBand_2 = _vwap + stDev * stDevMultiplier_2
upperBand_1 = _vwap + stDev * stDevMultiplier_1
lowerBand_1 = _vwap - stDev * stDevMultiplier_1
lowerBand_2 = _vwap - stDev * stDevMultiplier_2
[upperBand_2, upperBand_1, lowerBand_1, lowerBand_2]
// Label function from sbtnc - Daily Weekly Monthly Opens script
f_drawLabel(_x, _y, _text, _textcolor, _style, _size) =>
var _label = label.new(x=_x, y=_y, text=_text, textcolor=_textcolor, style=_style, size=_size, xloc=xloc.bar_time)
label.set_xy(_label, _x, _y)
//-------------------- Inputs --------------------//
showvS = input(true, 'Show Session VWAP')
showStd_S = input(false, 'Show Session Std Dev Bands')
showvD = input(true, 'Show Daily VWAP')
showStd_D = input(false, 'Show Daily Std Dev Bands')
showD_label = input(true, 'Show Daily Labels')
showS_label = input(true, 'Show Session Labels')
stDevMultiplier_1 = input(1.0, "StDev mult 1")
stDevMultiplier_2 = input(2.0, "StDev mult 2")
src = input(hlc3, "VWAP Source")
off_mult = input(10, 'Label offset')
var DEFAULT_LABEL_SIZE = size.small
var DEFAULT_LABEL_STYLE = label.style_none
ll_offset = timenow + math.round(ta.change(time) * off_mult)
// Session Times - Time decleration code taken from Single Prints - Session Initial Balances - Frien_dd
Asia_session_full = input.session('0000-0800', 'Asia Session')
London_session_full = input.session('0800-1430', 'London Session')
NY_session_full = input.session('1430-0000', 'NY Session')
timeIsAllowed_Asia_full = time(timeframe.period, Asia_session_full + ':1234567')
timeIsAllowed_London_full = time(timeframe.period, London_session_full + ':1234567')
timeIsAllowed_NY_full = time(timeframe.period, NY_session_full + ':1234567')
//-------------------- VWAP Calculations --------------------//
// Asia
p_Asia = hlc3 * volume
p_Asia := timeIsAllowed_Asia_full and not timeIsAllowed_Asia_full[1] ? hlc3 * volume : p_Asia[1] + hlc3 * volume
vol_Asia = 0.0
vol_Asia := timeIsAllowed_Asia_full and not timeIsAllowed_Asia_full[1] ? volume : vol_Asia[1] + volume
v_Asia = p_Asia / vol_Asia
mv_Asia = v_Asia
A_vwap = mv_Asia
Sn_Asia = 0.0
Sn_Asia := timeIsAllowed_Asia_full and not timeIsAllowed_Asia_full[1] ? 0 : Sn_Asia[1] + volume * (hlc3 - v_Asia[1]) * (hlc3 - mv_Asia)
std_Asia = math.sqrt(Sn_Asia / vol_Asia)
// London
p_London = hlc3 * volume
p_London := timeIsAllowed_London_full and not timeIsAllowed_London_full[1] ? hlc3 * volume : p_London[1] + hlc3 * volume
vol_London = 0.0
vol_London := timeIsAllowed_London_full and not timeIsAllowed_London_full[1] ? volume : vol_London[1] + volume
v_London = p_London / vol_London
mv_London = v_London
L_vwap = mv_London
Sn_London = 0.0
Sn_London := timeIsAllowed_London_full and not timeIsAllowed_London_full[1] ? 0 : Sn_London[1] + volume * (hlc3 - v_London[1]) * (hlc3 - mv_London)
std_London = math.sqrt(Sn_London / vol_London)
// NY
p_NY = hlc3 * volume
p_NY := timeIsAllowed_NY_full and not timeIsAllowed_NY_full[1] ? hlc3 * volume : p_NY[1] + hlc3 * volume
vol_NY = 0.0
vol_NY := timeIsAllowed_NY_full and not timeIsAllowed_NY_full[1] ? volume : vol_NY[1] + volume
v_NY = p_NY / vol_NY
mv_NY = v_NY
NY_vwap = mv_NY
Sn_NY = 0.0
Sn_NY := timeIsAllowed_NY_full and not timeIsAllowed_NY_full[1] ? 0 : Sn_NY[1] + volume * (hlc3 - v_NY[1]) * (hlc3 - mv_NY)
std_NY = math.sqrt(Sn_NY / vol_NY)
// Plot VWAP
A = plot(showvS and timeIsAllowed_Asia_full ? A_vwap : na, title='Asia VWAP', color=color.new(color.yellow, 0), linewidth=1, style=plot.style_linebr)
f_drawLabel(ll_offset, showS_label and showvS and timeIsAllowed_Asia_full ? A_vwap : na, ' --- vAsia ', color.yellow, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
L = plot(showvS and timeIsAllowed_London_full ? L_vwap : na, title='London VWAP', color=color.new(color.blue, 0), linewidth=1, style=plot.style_linebr)
f_drawLabel(ll_offset, showS_label and showvS and timeIsAllowed_London_full ? L_vwap : na, ' --- vLondon ', color.blue, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
N = plot(showvS and timeIsAllowed_NY_full ? NY_vwap : na, title='New York VWAP', color=color.new(color.red, 0), linewidth=1, style=plot.style_linebr)
f_drawLabel(ll_offset, showS_label and showvS and timeIsAllowed_NY_full ? NY_vwap : na, ' --- vNY ', color.red, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
//-------------------- Plot Standard Deviation Bands --------------------//
[s2up_A, s1up_A, s1dn_A, s2dn_A] = compute_stDEV(A_vwap, std_Asia, stDevMultiplier_1, stDevMultiplier_2)
[s2up_L, s1up_L, s1dn_L, s2dn_L] = compute_stDEV(L_vwap, std_London, stDevMultiplier_1, stDevMultiplier_2)
[s2up_NY, s1up_NY, s1dn_NY, s2dn_NY] = compute_stDEV(NY_vwap, std_NY, stDevMultiplier_1, stDevMultiplier_2)
// Asia Standard Deviation Bands
sd2up_A = plot(showStd_S and timeIsAllowed_Asia_full ? s2up_A : na, title='VWAP_Asia - STDEV +2', color=color.new(color.red, 80), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_Asia_full ? s2up_A : na, ' --- vA SD+2 ', color.red, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
sd1up_A = plot(showStd_S and timeIsAllowed_Asia_full ? s1up_A : na, title='VWAP_Asia - STDEV +1', color=color.new(color.gray, 70), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_Asia_full ? s1up_A : na, ' --- vA SD+1 ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
sd1dn_A = plot(showStd_S and timeIsAllowed_Asia_full ? s1dn_A : na, title='VWAP_Asia - STDEV -1', color=color.new(color.gray, 70), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_Asia_full ?s1dn_A : na, ' --- vA SD-1 ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
sd2dn_A = plot(showStd_S and timeIsAllowed_Asia_full ? s2dn_A : na, title='VWAP_Asia - STDEV -2', color=color.new(color.blue, 80), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_Asia_full ? s2dn_A : na, ' --- vA SD-2 ', color.blue, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
// London Standard Deviation Bands
sd2up_L = plot(showStd_S and timeIsAllowed_London_full ? s2up_L : na, title='VWAP_London - STDEV +2', color=color.new(color.red, 80), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_London_full ? s2up_L : na, ' --- vL SD+2 ', color.red, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
sd1up_L = plot(showStd_S and timeIsAllowed_London_full ? s1up_L : na, title='VWAP_London - STDEV +1', color=color.new(color.gray, 70), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_London_full ? s1up_L : na, ' --- vL SD+1 ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
sd1dn_L = plot(showStd_S and timeIsAllowed_London_full ? s1dn_L : na, title='VWAP_London - STDEV -1', color=color.new(color.gray, 70), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_London_full ? s1dn_L : na, ' --- vL SD-1 ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
sd2dn_L = plot(showStd_S and timeIsAllowed_London_full ? s2dn_L : na, title='VWAP_London - STDEV -2', color=color.new(color.blue, 80), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_London_full ? s2dn_L : na, ' --- vL SD-2 ', color.blue, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
// NY Standard Deviation Bands
sd2up_NY = plot(showStd_S and timeIsAllowed_NY_full ? s2up_NY : na, title='VWAP_NY - STDEV +2', color=color.new(color.red, 80), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_NY_full ? s2up_NY : na, ' --- vNY SD+2 ', color.red, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
sd1up_NY = plot(showStd_S and timeIsAllowed_NY_full ? s1up_NY : na, title='VWAP_NY - STDEV +1', color=color.new(color.gray, 70), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_NY_full ? s1up_NY : na, ' --- vNY SD+1 ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
sd1dn_NY = plot(showStd_S and timeIsAllowed_NY_full ?s1dn_NY : na, title='VWAP_NY - STDEV -1', color=color.new(color.gray, 70), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_NY_full ? s1dn_NY : na, ' --- vNY SD-1 ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
sd2dn_NY = plot(showStd_S and timeIsAllowed_NY_full ? s2dn_NY : na, title='VWAP_NY - STDEV -2', color=color.new(color.blue, 80), style=plot.style_linebr, linewidth=3)
f_drawLabel(ll_offset, showS_label and showStd_S and timeIsAllowed_NY_full ? s2dn_NY : na, ' --- vNY SD-2 ', color.blue, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
//-------------------- VWAP Day --------------------//
timeChange(period) =>
ta.change(time(period))
newSessionD = timeChange("D")
[vD, stdevD] = computeVWAP(src, newSessionD)
// Standard deviation calculations
[s2up_D, s1up_D, s1dn_D, s2dn_D] = compute_stDEV(vD, stdevD, stDevMultiplier_1, stDevMultiplier_2)
// VWAP
plot(showvD and not showvS ? vD : na, title='VWAP - Daily', color=color.new(color.gray, 0), style=plot.style_linebr, linewidth=1)
plot(showvD and showvS and not timeIsAllowed_Asia_full ? vD : na, title='VWAP - Daily', color=color.new(color.gray, 0), style=plot.style_linebr, linewidth=1)
f_drawLabel(ll_offset, showD_label and showvD and not showvS ? vD : na, ' --- vD ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
f_drawLabel(ll_offset, showD_label and showvD and showvS and not timeIsAllowed_Asia_full ? vD : na, ' --- vD ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
// Std Dev
plot(showStd_D ? s1up_D : na, title='VWAP Day - STDEV +1', color=color.new(color.gray, 30), style=plot.style_circles, linewidth=1)
f_drawLabel(ll_offset, showD_label and showStd_D and not showStd_S ? s1up_D : na, ' --- vD SD+1 ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
f_drawLabel(ll_offset, showD_label and showStd_D and showStd_S and not timeIsAllowed_Asia_full ? s1up_D : na, ' --- vD SD+1 ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
plot(showStd_D ? s1dn_D : na, title='VWAP Day - STDEV -1', color=color.new(color.gray, 30), style=plot.style_circles, linewidth=1)
f_drawLabel(ll_offset, showD_label and showStd_D and not showStd_S ? s1dn_D : na, ' --- vD SD-1 ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
f_drawLabel(ll_offset, showD_label and showStd_D and showStd_S and not timeIsAllowed_Asia_full ? s1dn_D : na, ' --- vD SD-1 ', color.gray, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
plot(showStd_D ? s2up_D : na, title='VWAP Day - STDEV +2', color=color.new(color.red, 50), style=plot.style_circles, linewidth=1)
f_drawLabel(ll_offset, showD_label and showStd_D and not showStd_S ? s2up_D : na, ' --- vD SD+2 ', color.red, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
f_drawLabel(ll_offset, showD_label and showStd_D and showStd_S and not timeIsAllowed_Asia_full ? s2up_D : na, ' --- vD SD+2 ', color.red, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
plot(showStd_D ? s2dn_D : na, title='VWAP Day - STDEV -2', color=color.new(color.blue, 50), style=plot.style_circles, linewidth=1)
f_drawLabel(ll_offset, showD_label and showStd_D and not showStd_S ? s2dn_D : na, ' --- vD SD-2 ', color.blue, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
f_drawLabel(ll_offset, showD_label and showStd_D and showStd_S and not timeIsAllowed_Asia_full ? s2dn_D : na, ' --- vD SD-2 ', color.blue, DEFAULT_LABEL_STYLE, DEFAULT_LABEL_SIZE)
|
Trading Range Finder | https://www.tradingview.com/script/RgKjPYNK-Trading-Range-Finder/ | jamiedubauskas | https://www.tradingview.com/u/jamiedubauskas/ | 80 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jamiedubauskas
//@version=4
study(title = "Trading Range Finder", shorttitle = "RANGE FINDER", overlay = false, max_lines_count = 500)
// ADX components
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
up = change(high)
down = -change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = rma(tr, len)
plus = fixnan(100 * rma(plusDM, len) / truerange)
minus = fixnan(100 * rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
// range ADX threshold
sidewaysThreshold = input(title = "ADX Sideways Threshold (20 for equities, 25 for crypto)", type = input.integer, minval = 0, defval = 20)
// plotting the ADX indicator and threshold line
plot(sig, color=color.red, title="ADX")
hline(sidewaysThreshold, title = "Sideways Threshold", color = color.new(color.white, 50), linestyle = hline.style_dashed, linewidth = 2)
// boolean expression to see if the ADX is below the sideways threshold
bool isSideways = sig < sidewaysThreshold
bgcolor(isSideways ? color.new(color.gray, 70) : na)
// adding the option to color the bars when in a trading range
useBarColor = input(title = "Color candles?", type = input.bool, defval = false)
bColor = isSideways ? color.new(#Fffb07, 0) : na
barcolor(useBarColor ? bColor : na)
|
Multiply 2 Symbols | https://www.tradingview.com/script/VAIuFBHR-Multiply-2-Symbols/ | arosca | https://www.tradingview.com/u/arosca/ | 25 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © arosca
//@version=4
study("Multiply 2 Symbols")
symbol1 = input(defval="BTCUSD", title="Symbol 1", type=input.symbol)
symbol2 = input(defval="USDEUR", title="Symbol 2", type=input.symbol)
as = security(symbol1, timeframe.period, close)
bs = security(symbol2, timeframe.period, close)
plot(as * bs, title="MUL", color=color.blue) |
st_long | https://www.tradingview.com/script/Ze2pLZ8S-st-long/ | IntelTrading | https://www.tradingview.com/u/IntelTrading/ | 98 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Alferow
//@version=4
study('st_long', overlay = true, precision = 5)
dep = input(300.00, title = 'risk on deal')
pr1 = input(47500.0, title = 'price enter')
tk = input(51400.0, title = 'price take')
of = input(100.0, title = 'exceeding $')
m = input(2.0, minval = 0.10, step = 0.1, title = 'martingale')
l = input(5, minval = 2, step = 1, title = 'leverage')
n = input(4, minval = 3, maxval = 5, title = 'number enters')
com = (1 - 0.01*input(0.07, title = 'commission %'))
pos = input(title="Position table", type=input.bool, defval=true)
txt = input(title="Text size", type=input.bool, defval=true)
k1 = pr1 >= 100.0 ? 3 : pr1 >= 10.0 and pr1 < 100.0 ? 2 : pr1 >= 1.0 and pr1 < 10.0 ? 1 : 0
k2 = pr1 >= 100.0 ? 0.0005 : pr1 >= 10.0 and pr1 < 100.0 ? 0.005 : pr1 >= 1.0 and pr1 < 10.0 ? 0.05 : 0.5
k3 = pr1 >= 100.0 ? 1 : pr1 >= 1.0 and pr1 < 100.0 ? 2 : 5
k4 = pos == true ? position.bottom_right : position.top_right
k5 = txt == true ? size.auto : size.large
h = (1 - (1/l))
summ = m == 1 ? dep/n : (dep * (m - 1)/(pow(m, n) - 1))
d1 = l*summ*com
d2 = d1*m
d3 = d2*m
d4 = d3*m
d5 = d4*m
v1 = round(d1/pr1 - k2, k1)
pr2 = of + pr1*h
v2 = round(d2/pr2 - k2, k1)
pr3 = of + h*(pr1 * v1 + pr2*v2)/((v1 + v2))
v3 = round(d3/pr3 - k2, k1)
pr4 = of + h*(pr1 * v1 + pr2*v2 + pr3*v3)/((v1 + v2 + v3))
v4 = round(d4/pr4 - k2, k1)
pr5 = of + h*(pr1 * v1 + pr2*v2 + pr3*v3 + pr4*v4)/((v1 + v2 + v3 + v4))
v5 = round(d5/pr5 - k2, k1)
pr6 = of + h*(pr1 * v1 + pr2*v2 + pr3*v3 + pr4*v4 + pr5*v5)/((v1 + v2 + v3 + v4 + v5))
av1 = pr1
av2 = (pr1 * v1 + pr2*v2)/(v1 + v2)
av3 = (pr1 * v1 + pr2*v2 + pr3*v3)/(v1 + v2 + v3)
av4 = (pr1 * v1 + pr2*v2 + pr3*v3 + pr4*v4)/(v1 + v2 + v3 + v4)
av5 = (pr1 * v1 + pr2*v2 + pr3*v3 + pr4*v4 + pr5*v5)/(v1 + v2 + v3 + v4 + v5)
p1 = v1*(tk - pr1)*com
p2 = (v1 + v2)*(tk - av2)*com
p3 = (v1 + v2+ v3)*(tk - av3)*com
p4 = (v1 + v2+ v3 + v4)*(tk - av4)*com
p5 = (v1 + v2+ v3 + v4 + v5)*(tk - av5)*com
var testTable = table.new(position = k4, columns = 5, rows = 7, border_color = color.black, bgcolor = color.white, border_width = 1)
if barstate.islast and n == 5
table.cell(table_id = testTable, column = 0, row = 0, text = " ", text_size = size.large, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 0, text = "Price enter", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 0, text = "Volume", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 0, text = "Money, $", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 0, text = "Profit, $", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 1, text = "1 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 2, text = "2 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 3, text = "3 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 4, text = "4 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 5, text = "5 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 6, text = "liquid", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 1, text = tostring(round(pr1, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 2, text = tostring(round(pr2, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 3, text = tostring(round(pr3, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 4, text = tostring(round(pr4, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 5, text = tostring(round(pr5, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 6, text = tostring(round(pr6, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 1, text = tostring(round(v1, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 2, text = tostring(round(v2, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 3, text = tostring(round(v3, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 4, text = tostring(round(v4, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 5, text = tostring(round(v5, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 1, text = tostring(round(d1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 2, text = tostring(round(d2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 3, text = tostring(round(d3, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 4, text = tostring(round(d4, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 5, text = tostring(round(d5, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 1, text = tostring(round(p1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 2, text = tostring(round(p2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 3, text = tostring(round(p3, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 4, text = tostring(round(p4, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 5, text = tostring(round(p5, 2)), text_size = k5, text_color = color.black)
if barstate.islast and n == 4
table.cell(table_id = testTable, column = 0, row = 0, text = " ", text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 0, text = "Price enter", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 0, text = "Volume", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 0, text = "Money, $", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 0, text = "Profit, $", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 1, text = "1 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 2, text = "2 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 3, text = "3 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 4, text = "4 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 5, text = "liquid", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 1, text = tostring(round(pr1, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 2, text = tostring(round(pr2, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 3, text = tostring(round(pr3, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 4, text = tostring(round(pr4, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 5, text = tostring(round(pr5, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 1, text = tostring(round(v1, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 2, text = tostring(round(v2, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 3, text = tostring(round(v3, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 4, text = tostring(round(v4, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 1, text = tostring(round(d1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 2, text = tostring(round(d2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 3, text = tostring(round(d3, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 4, text = tostring(round(d4, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 1, text = tostring(round(p1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 2, text = tostring(round(p2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 3, text = tostring(round(p3, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 4, text = tostring(round(p4, 2)), text_size = k5, text_color = color.black)
if barstate.islast and n == 3
table.cell(table_id = testTable, column = 0, row = 0, text = " ", text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 0, text = "Price enter", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 0, text = "Volume", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 0, text = "Money, $", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 0, text = "Profit, $", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 1, text = "1 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 2, text = "2 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 3, text = "3 deal", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 4, text = "liquid", bgcolor=color.green, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 1, text = tostring(round(pr1, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 2, text = tostring(round(pr2, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 3, text = tostring(round(pr3, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 4, text = tostring(round(pr4, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 1, text = tostring(round(v1, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 2, text = tostring(round(v2, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 3, text = tostring(round(v3, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 1, text = tostring(round(d1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 2, text = tostring(round(d2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 3, text = tostring(round(d3, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 1, text = tostring(round(p1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 2, text = tostring(round(p2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 3, text = tostring(round(p3, 2)), text_size = k5, text_color = color.black)
|
ADX and DI-Bolarinwa | https://www.tradingview.com/script/3lHxer7D-ADX-and-DI-Bolarinwa/ | omowarebola | https://www.tradingview.com/u/omowarebola/ | 45 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © omowarebola
//@version=4
study("ADX and DI-Bolarinwa")
len = input(14)
th = input(25)
TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0
SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = 0.0
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus
DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
ADX = rma(DX, len)
plot(DIPlus, color=color.green, title="DI+")
plot(DIMinus, color=color.red, title="DI-")
plot(ADX, color=color.navy, title="ADX")
hline(th, color=color.yellow) |
Trend System Multiple Moving Averages Rating | https://www.tradingview.com/script/t1UU1sgW-Trend-System-Multiple-Moving-Averages-Rating/ | exlux99 | https://www.tradingview.com/u/exlux99/ | 264 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © exlux99
//@version=4
study("Multiple MA Rating", overlay = true)
////////////////////////////GENERAL INPUTS//////////////////////////////////////
line10= input(defval=20, title="Length 1", minval=1)
//==========DEMA
getDEMA(src, len) =>
dema = 2 * ema(src,len) - ema(ema(src,len),len)
dema
//==========HMA
getHULLMA(src, len) =>
hullma = wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len)))
hullma
//==========KAMA
getKAMA(src, len, k1, k2) =>
change = abs(change(src, len))
volatility = sum(abs(change(src)), len)
efficiency_ratio = volatility != 0 ? change / volatility : 0
kama = 0.0
fast = 2 / (k1 + 1)
slow = 2 / (k2 + 1)
smooth_const = pow(efficiency_ratio * (fast - slow) + slow, 2)
kama := nz(kama[1]) + smooth_const * (src - nz(kama[1]))
kama
//==========TEMA
getTEMA(src, len) =>
e = ema(src, len)
tema = 3 * (e - ema(e, len)) + ema(ema(e, len), len)
tema
//==========ZLEMA
getZLEMA(src, len) =>
zlemalag_1 = (len - 1) / 2
zlemadata_1 = src + (src - src[zlemalag_1])
zlema = ema(zlemadata_1, len)
zlema
//==========FRAMA
getFRAMA(src, len) =>
Price = src
N = len
if N % 2 != 0
N := N + 1
N
N1 = 0.0
N2 = 0.0
N3 = 0.0
HH = 0.0
LL = 0.0
Dimen = 0.0
alpha = 0.0
Filt = 0.0
N3 := (highest(N) - lowest(N)) / N
HH := highest(N / 2 - 1)
LL := lowest(N / 2 - 1)
N1 := (HH - LL) / (N / 2)
HH := high[N / 2]
LL := low[N / 2]
for i = N / 2 to N - 1 by 1
if high[i] > HH
HH := high[i]
HH
if low[i] < LL
LL := low[i]
LL
N2 := (HH - LL) / (N / 2)
if N1 > 0 and N2 > 0 and N3 > 0
Dimen := (log(N1 + N2) - log(N3)) / log(2)
Dimen
alpha := exp(-4.6 * (Dimen - 1))
if alpha < .01
alpha := .01
alpha
if alpha > 1
alpha := 1
alpha
Filt := alpha * Price + (1 - alpha) * nz(Filt[1], 1)
if bar_index < N + 1
Filt := Price
Filt
Filt
//==========VIDYA
getVIDYA(src, len) =>
mom = change(src)
upSum = sum(max(mom, 0), len)
downSum = sum(-min(mom, 0), len)
out = (upSum - downSum) / (upSum + downSum)
cmo = abs(out)
alpha = 2 / (len + 1)
vidya = 0.0
vidya := src * alpha * cmo + nz(vidya[1]) * (1 - alpha * cmo)
vidya
//==========JMA
getJMA(src, len, power, phase) =>
phase_ratio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : phase / 100 + 1.5
beta = 0.45 * (len - 1) / ( 0.45 * (len - 1) + 2)
alpha = pow(beta, power)
MA1=0.0, Det0=0.0, MA2=0.0, Det1=0.0, JMA=0.0
MA1 := (1 - alpha) * src + alpha * nz(MA1[1])
Det0 := (src - MA1) * (1 - beta) + beta * nz(Det0[1])
MA2 := MA1 + phase_ratio * Det0
Det1 := (MA2 - nz(JMA[1])) * pow(1 - alpha,2) + pow(alpha,2) * nz(Det1[1])
JMA := nz(JMA[1]) + Det1
JMA
//==========T3
getT3(src, len, vFactor) =>
ema1 = ema(src, len)
ema2 = ema(ema1,len)
ema3 = ema(ema2,len)
ema4 = ema(ema3,len)
ema5 = ema(ema4,len)
ema6 = ema(ema5,len)
c1 = -1 * pow(vFactor,3)
c2 = 3*pow(vFactor,2) + 3*pow(vFactor,3)
c3 = -6*pow(vFactor,2) - 3*vFactor - 3*pow(vFactor,3)
c4 = 1 + 3*vFactor + pow(vFactor,3) + 3*pow(vFactor,2)
T3 = c1*ema6 + c2*ema5 + c3*ema4 + c4*ema3
T3
//==========TRIMA
getTRIMA(src, len) =>
N = len + 1
Nm = round( N / 2 )
TRIMA = sma(sma(src, Nm), Nm)
TRIMA
sma_10 = sma(close, line10)
ema_10 = ema(close, line10)
wma_10 = wma(close, line10)
alma_10 = alma(close,line10, 0.85, 6)
smma_10 = rma(close,line10)
lsma_10 = linreg(close, line10, 0)
vwma_10 = vwma(close,line10)
dema_10 = getDEMA(close,line10)
hullma_10 = getHULLMA(close,line10)
kama_10= getKAMA(close,line10,2,30)
frama_10 = getFRAMA(close,line10)
vidya_10 = getVIDYA(close,line10)
jma_10= getJMA(close,line10,2,50)
tema_10= getTEMA(close,line10)
zlema_10= getZLEMA(close,line10)
t3_10 = getT3(close,line10,0.7)
trima_10 = getTRIMA (close,line10)
//-------------- MOVING AVERAGES CALCULATION
sma_10_index =0.0
ema_10_index =0.0
wma_10_index =0.0
alma_10_index =0.0
smma_10_index =0.0
lsma_10_index =0.0
vwma_10_index =0.0
dema_10_index =0.0
hullma_10_index =0.0
kama_10_index =0.0
frama_10_index =0.0
vidya_10_index =0.0
jma_10_index =0.0
tema_10_index =0.0
zlema_10_index =0.0
t3_10_index =0.0
trima_10_index =0.0
//sma
if sma_10 >= close
sma_10_index := 1
sma_10_index
if sma_10 < close
sma_10_index := -1
sma_10_index
//ema
if ema_10 >= close
ema_10_index := 1
ema_10_index
if ema_10 < close
ema_10_index := -1
ema_10_index
//wma
if wma_10 >= close
wma_10_index := 1
wma_10_index
if wma_10 < close
wma_10_index := -1
wma_10_index
//alma
if alma_10 >= close
alma_10_index := 1
alma_10_index
if alma_10 < close
alma_10_index := -1
alma_10_index
//smma
if smma_10 >= close
smma_10_index := 1
smma_10_index
if smma_10 < close
smma_10_index := -1
smma_10_index
//lsma
if lsma_10 >= close
lsma_10_index := 1
lsma_10_index
if lsma_10 < close
lsma_10_index := -1
lsma_10_index
//vwma
if vwma_10 >= close
vwma_10_index := 1
vwma_10_index
if vwma_10 < close
vwma_10_index := -1
vwma_10_index
//dema
if dema_10 >= close
dema_10_index := 1
dema_10_index
if dema_10 < close
dema_10_index := -1
dema_10_index
//hullma
if hullma_10 >= close
hullma_10_index := 1
hullma_10_index
if hullma_10 < close
hullma_10_index := -1
hullma_10_index
//kama
if kama_10 >= close
kama_10_index := 1
kama_10_index
if kama_10 < close
kama_10_index := -1
kama_10_index
//frama
if frama_10 >= close
frama_10_index := 1
frama_10_index
if frama_10 < close
frama_10_index := -1
frama_10_index
//vidya
if vidya_10 >= close
vidya_10_index := 1
vidya_10_index
if vidya_10 < close
vidya_10_index := -1
vidya_10_index
//jma
if jma_10 >= close
jma_10_index := 1
jma_10_index
if jma_10 < close
jma_10_index := -1
jma_10_index
//tema
if tema_10 >= close
tema_10_index := 1
tema_10_index
if tema_10 < close
tema_10_index := -1
tema_10_index
//zlema
if zlema_10 >= close
zlema_10_index := 1
zlema_10_index
if zlema_10 < close
zlema_10_index := -1
zlema_10_index
//trima
if trima_10 >= close
trima_10_index := 1
trima_10_index
if trima_10 < close
trima_10_index := -1
trima_10_index
//t3
if t3_10 >= close
t3_10_index := 1
t3_10_index
if t3_10 < close
t3_10_index := -1
t3_10_index
// ////////////////////////////PLOTTING////////////////////////////////////////////
avg_10 = (sma_10+ema_10+wma_10+dema_10+alma_10+hullma_10+smma_10+lsma_10+kama_10+tema_10+zlema_10+frama_10+vidya_10+jma_10+t3_10+vwma_10+trima_10) /17
avg_10_index = (sma_10_index+ema_10_index+wma_10_index+dema_10_index+alma_10_index+hullma_10_index+smma_10_index+lsma_10_index+kama_10_index+tema_10_index+zlema_10_index+frama_10_index+vidya_10_index+jma_10_index+t3_10_index+vwma_10_index+trima_10_index) /-17
plot(avg_10, color = avg_10>avg_10[1] ? color.lime : color.red, linewidth=4)
posInput = input(title="Position", defval="Top Right", options=["Bottom Left", "Bottom Right", "Top Left", "Top Right"])
var pos = posInput == "Bottom Left" ? position.bottom_left : posInput == "Bottom Right" ? position.bottom_right : posInput == "Top Left" ? position.top_left : posInput == "Top Right" ? position.top_right : na
var table perfTable = table.new(pos, 2, 4, border_width = 3)
text_size = input("AUTO", "Text Size:", options=["AUTO", "TINY","SMALL", "NORMAL", "LARGE", "HUGE"])
table_size = input(6, "Table Width:")
text = size.auto
if text_size == "TINY"
text := size.tiny
if text_size == "SMALL"
text := size.small
if text_size == "NORMAL"
text := size.normal
if text_size == "LARGE"
text := size.large
if text_size == "HUGE"
text := size.huge
LIGHTTRANSP = 90
AVGTRANSP = 80
HEAVYTRANSP = 70
f_fillCell(_table, _column, _row, _value, _timeframe, _c_color) =>
//_c_color = color.blue//close > open ? i_posColor : i_negColor
_transp = HEAVYTRANSP//abs(_value) > 10 ? HEAVYTRANSP : abs(_value) > 5 ? AVGTRANSP : LIGHTTRANSP
_cellText = tostring(_value, "#.## %")
table.cell(_table, _column, _row, _cellText, bgcolor = color.new(_c_color, _transp), text_color = _c_color, width = table_size)
table.cell_set_text_size(perfTable, 1, 0, text)
table.cell_set_text_size(perfTable, 1, 1, text)
//table.cell_set_text_size(perfTable, 0, 2, text)
if barstate.islast
table.cell(perfTable, 0, 0, "Rating confirmation 0-100 Long | -100-0 Short", text_color=color.white, text_size=text, bgcolor=color.blue)
f_fillCell(perfTable, 0, 1, (avg_10_index*100)/100 , "% confirmation", (avg_10_index*100)/100 >0? color.lime : color.red )
|
st_own_candle | https://www.tradingview.com/script/HBY1sBr8-st-own-candle/ | IntelTrading | https://www.tradingview.com/u/IntelTrading/ | 57 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Alferow
//@version=4
study("st_own_candle")
ps = input(4, title = 'short period')
pb = input(24, title = 'long period')
cl = sma(close, ps) - sma(close, pb)
op = sma(open, ps) - sma(open, pb)
hi = sma(high, ps) - sma(high, pb)
lo = sma(low, ps) - sma(low, pb)
plotcandle(op, hi, lo, cl, title='NewCandle', color = op < cl ? color.green : color.red) |
MACD Plus | https://www.tradingview.com/script/E7OdL9qw/ | OskarGallard | https://www.tradingview.com/u/OskarGallard/ | 790 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OskarGallard
//@version=5
indicator(title='MACD Plus', shorttitle='MACD Plus')
// Function to select the type of source
get_src(Type) =>
if Type == 'VWAP'
ta.vwap
else if Type == 'Close'
close
else if Type == 'Open'
open
else if Type == 'HL2'
hl2
else if Type == 'HLC3'
hlc3
else if Type == 'OHLC4'
ohlc4
else if Type == 'HLCC4'
hlcc4
else if Type == 'High'
high
else if Type == 'Low'
low
else if Type == 'vwap(Close)'
ta.vwap(close)
else if Type == 'vwap(Open)'
ta.vwap(open)
else if Type == 'vwap(High)'
ta.vwap(high)
else if Type == 'vwap(Low)'
ta.vwap(low)
else if Type == 'AVG(vwap(H,L))'
math.avg(ta.vwap(high), ta.vwap(low))
else if Type == 'AVG(vwap(O,C))'
math.avg(ta.vwap(open), ta.vwap(close))
else if Type == 'OBV' // On Balance Volume
ta.obv
else if Type == 'AccDist' // Accumulation Distribution
ta.accdist
else if Type == 'PVT' // Price Volume Trend
ta.pvt
// Inputs - MACD
res = input.timeframe('', 'Indicator Time Frame')
fast_length = input.int(12, 'Fast Length', inline='Length')
slow_length = input.int(26, 'Slow Length', inline='Length')
sma_source = input.string('EMA', 'Oscillator MA Type', inline='Oscillator', options=['SMA', 'EMA', 'WMA', 'Median', 'DWMA', 'New-WMA', 'VWMA', 'DVWMA', 'VAMA', 'HMA', 'ALMA', 'LSMA', 'Wild', 'JMA', 'COVWMA', 'FRAMA', 'Zero Lag', 'Tillson T3', 'VIDYA', 'KAMA', 'CTI', 'RMA', 'DEMA', 'TEMA', 'SWMA', 'RSI EMA', 'ADX MA'])
src = input.string('Close', 'Source', inline='Oscillator', options=['VWAP', 'Close', 'Open', 'HL2', 'HLCC4', 'HLC3', 'OHLC4', 'High', 'Low', 'vwap(Close)', 'vwap(Open)', 'vwap(High)', 'vwap(Low)', 'AVG(vwap(H,L))', 'AVG(vwap(O,C))', 'OBV', 'AccDist', 'PVT'])
signal_length = input.int(9, 'Signal Smoothing', minval=1, maxval=50, inline='Signal')
ma_signal = input.string('EMA', 'Line MA Type', inline='Signal', options=['SMA', 'EMA', 'WMA', 'Median', 'DWMA', 'New-WMA', 'VWMA', 'DVWMA', 'VAMA', 'HMA', 'ALMA', 'LSMA', 'Wild', 'JMA', 'COVWMA', 'FRAMA', 'Zero Lag', 'Tillson T3', 'VIDYA', 'KAMA', 'CTI', 'RMA', 'DEMA', 'TEMA', 'SWMA', 'RSI EMA', 'ADX MA'])
// Show Plots T/F
show_macd = input.bool(true, 'Show MACD Lines', inline='SP10')
show_macd_LW = input.int(2, 'MACD Width', minval=0, maxval=5, inline='SP11')
show_signal_LW = input.int(1, 'Signal Width', minval=0, maxval=5, inline='SP11')
show_Hist = input.bool(true, 'Show Histogram', inline='SP20')
show_hist_LW = input.int(1, '-- Width', minval=0, maxval=5, inline='SP20')
show_trend = input.bool(true, 'Show MACD Lines w/ Trend Color', inline='SP30')
show_HB = input.bool(false, 'Show Highlight Price Bars', inline='SP50')
show_cross = input.bool(false, 'Show BackGround on Cross', inline='SP50')
show_dots = input.bool(false, 'Show Circle on Cross', inline='SP60')
show_dots_LW = input.int(7, '-- Width', minval=0, maxval=7, inline='SP60')
show_macd_bg = input.bool(true, "MACD Background")
show_macd_bar = input.bool(true, "MACD Bar Colors")
// MACD Lines colors
col_macd = input.color(#FFAB62, 'MACD Line ', inline='CS1')
col_signal = input.color(#00CED1, 'Signal Line ', inline='CS1')
col_trnd_Up = input.color(#80FF00, 'Trend Up ', inline='CS2')
col_trnd_Dn = input.color(#FF0000, 'Trend Down ', inline='CS2')
// Histogram Colors
col_grow_above = input.color(#8080FF, 'Above Grow', inline='Hist10')
col_fall_above = input.color(#353568, 'Fall', inline='Hist10')
col_grow_below = input.color(#FF8080, 'Below Grow', inline='Hist20')
col_fall_below = input.color(#683535, 'Fall', inline='Hist20')
// Alerts T/F Inputs
alert_Long = input.bool(false, 'MACD Cross Up', group='Alerts', inline='Alert10')
alert_Short = input.bool(false, 'MACD Cross Dn', group='Alerts', inline='Alert10')
alert_Long_A = input.bool(false, 'MACD Cross Up & > 0', group='Alerts', inline='Alert20')
alert_Short_B = input.bool(false, 'MACD Cross Dn & < 0', group='Alerts', inline='Alert20')
// Divergences
divergence = input.string('Histogram', "Divergence on Histogram or MACD Line?", options = ['Histogram', 'MACD'], group="Divergences")
plotBull = input.bool(true, "Plot Bullish", inline="bull", group="Divergences")
plotHiddenBull = input.bool(false, "Plot Hidden Bullish", inline="bull", group="Divergences")
bullColor = input.color(color.new(#77DD77, 0), " Color", inline="bull", group="Divergences")
plotBear = input.bool(true, "Plot Bearish", inline="bear", group="Divergences")
plotHiddenBear = input.bool(false, "Plot Hidden Bearish", inline="bear", group="Divergences")
bearColor = input.color(color.new(#FF6347, 0), " Color", inline="bear", group="Divergences")
lbR = input.int(5, "Pivot Lookback Right", group="Divergences")
lbL = input.int(5, "Pivot Lookback Left", group="Divergences")
rangeUpper = input.int(60, "Max of Lookback Range", group="Divergences")
rangeLower = input.int(5, "Min of Lookback Range", group="Divergences")
// Input - The Expert Trend Locator - XTL
candles_XTL = input.bool(false, title='Use XTL Bars Color', group='[XTL] Expert Trend Locator')
period_xtl = input.int(35, title='Length', minval=2, inline='xtl', group='[XTL] Expert Trend Locator')
MA_Type2 = input.string('ALMA', title='Type', inline='xtl', group='[XTL] Expert Trend Locator', options=['SMA', 'EMA', 'WMA', 'DWMA', 'Median', 'VWMA', 'DVWMA', 'New-WMA', 'VAMA', 'HMA', 'ALMA', 'LSMA', 'Wild', 'JMA', 'Zero Lag', 'Tillson T3', 'VIDYA', 'KAMA', 'CTI', 'RMA', 'DEMA', 'TEMA', 'SWMA', 'COVWMA', 'FRAMA', 'RSI EMA', 'ADX MA'])
src_xtl = input.string('HLC3', title='Source', inline='xtl', group='[XTL] Expert Trend Locator', options=['VWAP', 'Close', 'Open', 'HL2', 'HLCC4', 'HLC3', 'OHLC4', 'High', 'Low', 'vwap(Close)', 'vwap(Open)', 'vwap(High)', 'vwap(Low)', 'AVG(vwap(H,L))', 'AVG(vwap(O,C))', 'OBV', 'AccDist', 'PVT'])
fixed_Value = input.int(37, title='Threshold Level', minval=10, group='[XTL] Expert Trend Locator', inline='xtl2')
uTrad = input.bool(false, title='Use the traditional CCI formula', group='[XTL] Expert Trend Locator', inline='xtl2')
color_xtlUP = input.color(#00BFFF, 'Trend Up', group='[XTL] Expert Trend Locator', inline='ColXTL')
color_xtlNe = input.color(#FFFFFF, 'Neutral', group='[XTL] Expert Trend Locator', inline='ColXTL')
color_xtlDN = input.color(#FF4000, 'Trend Down', group='[XTL] Expert Trend Locator', inline='ColXTL')
detect_bull = input.bool(false, "◁ Alert: Bullish Trend", inline="alert_xtl", group="[XTL] Expert Trend Locator")
detect_bear = input.bool(false, "◁ Alert: Bearish Trend", inline="alert_xtl", group="[XTL] Expert Trend Locator")
// Input - Squeeze Pro
length_sqz = input.int(20, title='Length', minval=1, step=1, inline='S', group='Squeeze Pro')
src_sqz = input.string('OHLC4', title='Source', inline='S', group='Squeeze Pro', options=['VWAP', 'Close', 'Open', 'HL2', 'HLCC4', 'HLC3', 'OHLC4', 'High', 'Low', 'vwap(Close)', 'vwap(Open)', 'vwap(High)', 'vwap(Low)', 'AVG(vwap(H,L))', 'AVG(vwap(O,C))', 'OBV', 'AccDist', 'PVT'])
bbmatype = input.string('SMA', title='Bollinger Bands Calculation Type', group='Squeeze Pro', options=['SMA', 'EMA', 'WMA', 'LSMA', 'ALMA', 'New-WMA', 'VAMA', 'JMA', 'HMA', 'KAMA', 'RMA', 'DEMA', 'TEMA', 'VWMA', 'SWMA', 'Wild', 'Median', 'COVWMA', 'FRAMA'])
kcmatype = input.string('EMA', title='Keltner Channel Calculation Type', group='Squeeze Pro', options=['SMA', 'EMA', 'WMA', 'LSMA', 'ALMA', 'New-WMA', 'VAMA', 'JMA', 'HMA', 'KAMA', 'RMA', 'DEMA', 'TEMA', 'VWMA', 'SWMA', 'Wild', 'Median', 'COVWMA', 'FRAMA'])
color_H = input.color(#FFE500, 'High Squeeze', group='Squeeze Pro', inline='ColSQZ')
color_O = input.color(#FF4000, 'Medium Squeeze', group='Squeeze Pro', inline='ColSQZ')
color_L = input.color(#727272, 'Low Squeeze', group='Squeeze Pro', inline='ColSQZ')
// Input - Directional Movement Index
lenSig = input.int(14, 'ADX Smoothing', minval=1, maxval=50, inline='len1', group='Directional Movement Index')
lenDi = input.int(14, 'DI Length', minval=1, inline='len1', group='Directional Movement Index')
keyLevel = input.int(23, 'Strong Trend Theshold', group='Directional Movement Index')
weakTrend = input.int(15, 'Weak Trend Theshold', group='Directional Movement Index')
histLabel = input.int(0, 'Historical Label Readings', minval=0, inline='dmi', group='Directional Movement Index')
hideLabel = input.bool(false, 'Hide DMI Label', inline='dmi', group='Directional Movement Index')
detect_bull_dmi = input.bool(false, '◁ Alert: Bullish Trend', inline='alert_dmi', group='Directional Movement Index')
detect_bear_dmi = input.bool(false, '◁ Alert: Bearish Trend', inline='alert_dmi', group='Directional Movement Index')
// Input - Williams Vix Fix
sbcFilt = input.bool(true, 'Show Signal For Filtered Entry [▲ FE ]', group='Williams Vix Fix') // Use FILTERED Criteria
sbcAggr = input.bool(true, 'Show Signal For AGGRESSIVE Filtered Entry [▲ AE ]', group='Williams Vix Fix') // Use FILTERED Criteria
sbc = input.bool(true, 'Show Signal if WVF WAS True and IS Now False [▼]', group='Williams Vix Fix') // Use Original Criteria
sbcc = input.bool(true, 'Show Signal if WVF IS True [▼]', group='Williams Vix Fix') // Use Original Criteria
alert_AE = input.bool(false, '◁ Alert: [AGGRESSIVE Entry]', inline='AlertVF', group='Williams Vix Fix')
alert_FE = input.bool(false, '◁ Alert: [Filtered Entry]', inline='AlertVF', group='Williams Vix Fix')
pd = input.int(22, 'LookBack Period Standard Deviation High', group='Williams Vix Fix')
bbl = input.int(20, 'Bolinger Band Length', group='Williams Vix Fix')
mult = input.float(2.0, 'Bollinger Band Standard Devaition Up', minval=1, maxval=5, group='Williams Vix Fix')
lb = input.int(50, 'Look Back Period Percentile High', group='Williams Vix Fix')
ph = input.float(.85, 'Highest Percentile - 0.90=90%, 0.95=95%, 0.99=99%', group='Williams Vix Fix')
ltLB = input.int(40, minval=25, maxval=99, title='Long-Term Look Back Current Bar Has To Close Below This Value OR Medium Term--Default=40', group='Williams Vix Fix')
mtLB = input.int(14, minval=10, maxval=20, title='Medium-Term Look Back Current Bar Has To Close Below This Value OR Long Term--Default=14', group='Williams Vix Fix')
str = input.int(3, minval=1, maxval=9, title='Entry Price Action Strength--Close > X Bars Back---Default=3', group='Williams Vix Fix')
// Kaufman's Adaptive Moving Average
fast = 0.666 // KAMA Fast End
slow = 0.0645 // KAMA Slow End
kama(x, t) =>
dist = math.abs(x[0] - x[1])
signal = math.abs(x - x[t])
noise = math.sum(dist, t)
effr = noise != 0 ? signal / noise : 1
sc = math.pow(effr * (fast - slow) + slow, 2)
KAma = x
KAma := nz(KAma[1]) + sc * (x - nz(KAma[1]))
KAma
// Jurik Moving Average of @everget
jma(src, length, power, phase) =>
phaseRatio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : phase / 100 + 1.5
beta = 0.45 * (length - 1) / (0.45 * (length - 1) + 2)
alpha = math.pow(beta, power)
Jma = 0.0
e0 = 0.0
e0 := (1 - alpha) * src + alpha * nz(e0[1])
e1 = 0.0
e1 := (src - e0) * (1 - beta) + beta * nz(e1[1])
e2 = 0.0
e2 := (e0 + phaseRatio * e1 - nz(Jma[1])) * math.pow(1 - alpha, 2) + math.pow(alpha, 2) * nz(e2[1])
Jma := e2 + nz(Jma[1])
Jma
cti(sm, src, cd) =>
di = (sm - 1.0) / 2.0 + 1.0
c1 = 2 / (di + 1.0)
c2 = 1 - c1
c3 = 3.0 * (cd * cd + cd * cd * cd)
c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
i1 = 0.0
i2 = 0.0
i3 = 0.0
i4 = 0.0
i5 = 0.0
i6 = 0.0
i1 := c1 * src + c2 * nz(i1[1])
i2 := c1 * i1 + c2 * nz(i2[1])
i3 := c1 * i2 + c2 * nz(i3[1])
i4 := c1 * i3 + c2 * nz(i4[1])
i5 := c1 * i4 + c2 * nz(i5[1])
i6 := c1 * i5 + c2 * nz(i6[1])
bfr = -cd * cd * cd * i6 + c3 * i5 + c4 * i4 + c5 * i3
bfr
a = 0.618
T3ma(src, Len) =>
e1 = ta.ema(src, Len)
e2 = ta.ema(e1, Len)
e3 = ta.ema(e2, Len)
e4 = ta.ema(e3, Len)
e5 = ta.ema(e4, Len)
e6 = ta.ema(e5, Len)
C1 = -a * a * a
C2 = 3 * a * a + 3 * a * a * a
C3 = -6 * a * a - 3 * a - 3 * a * a * a
C4 = 1 + 3 * a + a * a * a + 3 * a * a
C1 * e6 + C2 * e5 + C3 * e4 + C4 * e3
VIDYA(src, Len) =>
mom = ta.change(src)
upSum = math.sum(math.max(mom, 0), Len)
downSum = math.sum(-math.min(mom, 0), Len)
out = (upSum - downSum) / (upSum + downSum)
cmo = math.abs(out)
alpha = 2 / (Len + 1)
vidya = 0.0
vidya := src * alpha * cmo + nz(vidya[1]) * (1 - alpha * cmo)
vidya
// ZLEMA: Zero Lag
zema(_src, _len) =>
alpha = (_len - 1) / 2
zlema0 = _src + _src - _src[alpha]
zlemaF = ta.ema(zlema0, _len)
zlemaF
// ADX Weighted Moving Average of @Duyck
adx_weighted_ma(_src, _period) =>
[_diplus, _diminus, _adx] = ta.dmi(17, 14)
_vol_sum = 0.0
_adx_sum = 0.0
for i = 0 to _period
_vol_sum := _src[i] * _adx[i] + _vol_sum
_adx_sum := _adx[i] + _adx_sum
_volwma = _vol_sum / _adx_sum
// COVWMA - Coefficient of Variation Weighted Moving Average of @DonovanWall
covwma(a, b) =>
cov = ta.stdev(a, b) / ta.sma(a, b)
cw = a*cov
covwma = math.sum(cw, b) / math.sum(cov, b)
// FRAMA - Fractal Adaptive Moving Average of @DonovanWall
w = -4.6 // "Coefficient (if FRAMA)"
frama(a, b) =>
frama = 0.0
n3 = (ta.highest(high, b) - ta.lowest(low, b))/b
hd2 = ta.highest(high, b/2)
ld2 = ta.lowest(low, b/2)
n2 = (hd2 - ld2)/(b/2)
n1 = (hd2[b/2] - ld2[b/2])/(b/2)
dim = (n1 > 0) and (n2 > 0) and (n3 > 0) ? (math.log(n1 + n2) - math.log(n3))/math.log(2) : 0
alpha = math.exp(w*(dim - 1))
sc = (alpha < 0.01 ? 0.01 : (alpha > 1 ? 1 : alpha))
frama := ta.cum(1)<=2*b ? a : (a*sc) + nz(frama[1])*(1 - sc)
frama
// EMA RSI Adaptive of @glaz
rsi_ema(src, period) =>
RsiPeriod = 14
ema = 0.0
RSvoltl = math.abs(ta.rsi(close, RsiPeriod)-50)+1.0
multi = (5.0+100.0/RsiPeriod) / (0.06+0.92*RSvoltl+0.02*math.pow(RSvoltl,2))
pdsx = multi*period
alpha = 2.0 /(1.0+pdsx)
ema := nz(ema[1])+alpha*(ta.sma(close, period)-nz(ema[1]))
ema
// VAMA - Volume Adjusted Moving Average of @allanster
vama(_src,_len,_fct,_rul,_nvb) => // vama(source,length,factor,rule,sample)
tvb = 0, tvb := _nvb == 0 ? nz(tvb[1]) + 1 : _nvb // total volume bars used in sample
tvs = _nvb == 0 ? ta.cum(volume) : math.sum(volume, _nvb) // total volume in sample
v2i = volume / ((tvs / tvb) * _fct) // ratio of volume to increments of volume
wtd = _src*v2i // weighted prices
nmb = 1 // initialize number of bars summed back
wtdSumB = 0.0 // initialize weighted prices summed back
v2iSumB = 0.0 // initialize ratio of volume to increments of volume summed back
for i = 1 to _len * 10 // set artificial cap for strict to VAMA length * 10 to help reduce edge case timeout errors
strict = _rul ? false : i == _len // strict rule N bars' v2i ratios >= vama length, else <= vama length
wtdSumB := wtdSumB + nz(wtd[i-1]) // increment number of bars' weighted prices summed back
v2iSumB := v2iSumB + nz(v2i[i-1]) // increment number of bars' v2i's summed back
if v2iSumB >= _len or strict // if chosen rule met
break // break (exit loop)
nmb := nmb + 1 // increment number of bars summed back counter
nmb // number of bars summed back to fulfill volume requirements or vama length
wtdSumB // number of bars' weighted prices summed back
v2iSumB // number of bars' v2i's summed back
vama = (wtdSumB - (v2iSumB - _len) * _src[nmb]) / _len // volume adjusted moving average
// New WMA
NWMA(_src, _n1) =>
fast_n = int(_n1 / 2)
lambda = _n1 / fast_n
alpha = lambda * (_n1 - 1) / (_n1 - lambda)
ma1 = ta.wma(_src, _n1)
ma2 = ta.wma(ma1, fast_n)
nwma = (1 + alpha) * ma1 - alpha * ma2
ma(MAType, MASource, MAPeriod) =>
if MAPeriod > 0
if MAType == 'SMA'
ta.sma(MASource, MAPeriod)
else if MAType == 'EMA'
ta.ema(MASource, MAPeriod)
else if MAType == 'WMA'
ta.wma(MASource, MAPeriod)
else if MAType == 'RMA'
ta.rma(MASource, MAPeriod)
else if MAType == 'HMA'
ta.hma(MASource, MAPeriod)
else if MAType == 'DEMA'
e = ta.ema(MASource, MAPeriod)
2 * e - ta.ema(e, MAPeriod)
else if MAType == 'TEMA'
e = ta.ema(MASource, MAPeriod)
3 * (e - ta.ema(e, MAPeriod)) + ta.ema(ta.ema(e, MAPeriod), MAPeriod)
else if MAType == 'VWMA'
ta.vwma(MASource, MAPeriod)
else if MAType == 'ALMA'
ta.alma(MASource, MAPeriod, .85, 6)
else if MAType == 'CTI'
cti(MAPeriod, MASource, 0)
else if MAType == 'KAMA'
kama(MASource, MAPeriod)
else if MAType == 'SWMA'
ta.swma(MASource)
else if MAType == 'JMA'
jma(MASource, MAPeriod, 2, 50)
else if MAType == 'LSMA' // Least Squares
ta.linreg(MASource, MAPeriod, 0)
else if MAType == 'Wild'
wild = MASource
wild := nz(wild[1]) + (MASource - nz(wild[1])) / MAPeriod
wild
else if MAType == 'Tillson T3'
T3ma(MASource, MAPeriod)
else if MAType == 'VIDYA'
VIDYA(MASource, MAPeriod)
else if MAType == 'DWMA'
ta.wma(ta.wma(MASource, MAPeriod), MAPeriod) // Double Weighted Moving Average
else if MAType == 'DVWMA'
ta.vwma(ta.vwma(MASource, MAPeriod), MAPeriod) // Double Volume-Weighted Moving Average
else if MAType == 'Zero Lag'
zema(MASource, MAPeriod)
else if MAType == "Median"
ta.median(MASource, MAPeriod)
else if MAType == "RSI EMA"
rsi_ema(MASource, MAPeriod)
else if MAType == "ADX MA"
adx_weighted_ma(MASource, MAPeriod)
else if MAType == "COVWMA"
covwma(MASource, MAPeriod)
else if MAType == "FRAMA"
frama(MASource, MAPeriod)
else if MAType == "VAMA"
factor = 0.67
vama(MASource, MAPeriod, factor, true, 0)
else if MAType == "New-WMA"
NWMA(MASource, MAPeriod)
//_____________________________________________________________________________________________
// Based on "CM MACD Custom Indicator - Multiple Time Frame - V2" - Author: @ChrisMoody
// https://www.tradingview.com/script/XFr7xHqZ-CM-MACD-Custom-Indicator-Multiple-Time-Frame-V2/
//_____________________________________________________________________________________________
// Calculating
src_ma = get_src(src)
fast_media = ma(sma_source, src_ma, fast_length)
slow_media = ma(sma_source, src_ma, slow_length)
fast_ma = request.security(syminfo.tickerid, res, fast_media)
slow_ma = request.security(syminfo.tickerid, res, slow_media)
macd = fast_ma - slow_ma
signal = request.security(syminfo.tickerid, res, ma(ma_signal, macd, signal_length))
hist = (macd - signal)*2
// MACD Trend and Cross Up/Down conditions
trend_up = macd > signal
trend_dn = macd < signal
cross_UP = signal[1] >= macd[1] and signal < macd
cross_DN = signal[1] <= macd[1] and signal > macd
cross_UP_A = signal[1] >= macd[1] and signal < macd and macd > 0
cross_DN_B = signal[1] <= macd[1] and signal > macd and macd < 0
// Condition that changes Color of MACD Line if Show Trend is turned on..
trend_col = show_trend and trend_up ? col_trnd_Up : trend_up ? col_macd : show_trend and trend_dn ? col_trnd_Dn : trend_dn ? col_macd : na
// Var Statements for Histogram Color Change
var bool histA_IsUp = false
var bool histA_IsDown = false
var bool histB_IsDown = false
var bool histB_IsUp = false
histA_IsUp := hist == hist[1] ? histA_IsUp[1] : hist > hist[1] and hist > 0
histA_IsDown := hist == hist[1] ? histA_IsDown[1] : hist < hist[1] and hist > 0
histB_IsDown := hist == hist[1] ? histB_IsDown[1] : hist < hist[1] and hist <= 0
histB_IsUp := hist == hist[1] ? histB_IsUp[1] : hist > hist[1] and hist <= 0
hist_col = histA_IsUp ? col_grow_above : histA_IsDown ? col_fall_above : histB_IsDown ? col_grow_below : histB_IsUp ? col_fall_below : color.silver
color_macd = (macd < signal) and (macd >= 0) ? col_fall_above : (macd > signal) and (macd >= 0) ? col_grow_above : (macd > signal) and (macd < 0) ? col_fall_below : (macd < signal) and (macd < 0) ? col_grow_below : color.silver
// Plot Statements
// Background Color
bgcolor(show_cross and cross_UP ? color.new(col_trnd_Up, 70) : na, editable=false)
bgcolor(show_cross and cross_DN ? color.new(col_trnd_Dn, 70) : na, editable=false)
//Highlight Price Bars
barcolor(show_HB and trend_up ? col_trnd_Up : na, title='Trend Up', offset=0, editable=false)
barcolor(show_HB and trend_dn ? col_trnd_Dn : na, title='Trend Dn', offset=0, editable=false)
// Regular Plots
plot(show_Hist and hist ? hist : na, 'Histogram', color.new(hist_col, 0), style=plot.style_columns, linewidth=show_hist_LW)
plot(show_macd and signal ? signal : na, 'Signal', color.new(col_signal, 0), style=plot.style_line, linewidth=show_signal_LW)
plot(show_macd and macd ? macd : na, 'MACD', color.new(trend_col, 0), style=plot.style_line, linewidth=show_macd_LW)
hline(0, '0 Line', color.new(color.gray, 0), linestyle=hline.style_dotted, linewidth=1, editable=false)
plot(show_dots and cross_UP ? signal : na, 'Up Dots', color.new(trend_col, 80), style=plot.style_circles, linewidth=show_dots_LW, editable=false)
plot(show_dots and cross_DN ? signal : na, 'Down Dots', color.new(trend_col, 80), style=plot.style_circles, linewidth=show_dots_LW, editable=false)
bgcolor(show_macd_bg ? color.new(color_macd, 90) : na, title = "MACD Background")
barcolor(show_macd_bar ? color.new(color_macd, 0) : na, title = "MACD Bar Colors")
// Alerts
if alert_Long and cross_UP
alert('Symbol = (' + syminfo.tickerid + ') \n TimeFrame = (' + timeframe.period + ') \n Current Price (' + str.tostring(close) + ') \n MACD Crosses Up.', alert.freq_once_per_bar_close)
if alert_Short and cross_DN
alert('Symbol = (' + syminfo.tickerid + ') \n TimeFrame = (' + timeframe.period + ') \n Current Price (' + str.tostring(close) + ') \n MACD Crosses Down.', alert.freq_once_per_bar_close)
//Alerts - Stricter Condition - Only Alerts When MACD Crosses UP & MACD > 0 -- Crosses Down & MACD < 0
if alert_Long_A and cross_UP_A
alert('Symbol = (' + syminfo.tickerid + ') \n TimeFrame = (' + timeframe.period + ') \n Current Price (' + str.tostring(close) + ') \n MACD > 0 And Crosses Up.', alert.freq_once_per_bar_close)
if alert_Short_B and cross_DN_B
alert('Symbol = (' + syminfo.tickerid + ') \n TimeFrame = (' + timeframe.period + ') \n Current Price (' + str.tostring(close) + ') \n MACD < 0 And Crosses Down.', alert.freq_once_per_bar_close)
// Divergences
hiddenBullColor = color.new(bullColor, 70)
hiddenBearColor = color.new(bearColor, 70)
textColor = color.white
noneColor = color.new(color.white, 100)
osc = show_Hist and divergence == 'Histogram' ? hist : (show_macd ? macd : na)
plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
bars = ta.barssince(cond == true)
rangeLower <= bars and bars <= rangeUpper
//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
// Price: Lower Low
priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
bullCond = plotBull and priceLL and oscHL and plFound
plot(
plFound ? osc[lbR] : na,
offset=-lbR,
title="Regular Bullish",
linewidth=2,
color=(bullCond ? bullColor : noneColor)
)
plotshape(
bullCond ? osc[lbR] : na,
offset=-lbR,
title="Regular Bullish Label",
text=" R ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=#000000
)
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
// Price: Higher Low
priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound
plot(
plFound ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bullish",
linewidth=2,
color=(hiddenBullCond ? hiddenBullColor : noneColor)
)
plotshape(
hiddenBullCond ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bullish Label",
text=" H ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=color.black
)
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
// Price: Higher High
priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
bearCond = plotBear and priceHH and oscLH and phFound
plot(
phFound ? osc[lbR] : na,
offset=-lbR,
title="Regular Bearish",
linewidth=2,
color=(bearCond ? bearColor : noneColor)
)
plotshape(
bearCond ? osc[lbR] : na,
offset=-lbR,
title="Regular Bearish Label",
text=" R ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
// Price: Lower High
priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)
hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound
plot(
phFound ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bearish",
linewidth=2,
color=(hiddenBearCond ? hiddenBearColor : noneColor)
)
plotshape(
hiddenBearCond ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bearish Label",
text=" H ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
//______________________________________________________________________________
// The Expert Trend Locator - XTL
// https://www.tradingview.com/script/UcBJKm4O/
//______________________________________________________________________________
media = ma(MA_Type2, get_src(src_xtl), period_xtl)
cciNT = (get_src(src_xtl) - media) / (0.015 * ta.dev(get_src(src_xtl), period_xtl))
cciT = (get_src(src_xtl) - media) / (0.015 * ta.dev(math.abs(get_src(src_xtl) - media), period_xtl))
values = uTrad ? cciT : cciNT
var color color_XTL = na
if values < -fixed_Value
color_XTL := color_xtlDN // Bear
color_XTL
if -fixed_Value <= values and values <= fixed_Value
color_XTL := color_xtlNe // Neutral
color_XTL
if values > fixed_Value
color_XTL := color_xtlUP // Bull
color_XTL
cond_bull_xtl = detect_bull and ta.crossover(values, fixed_Value)
cond_bear_xtl = detect_bear and ta.crossunder(values, -fixed_Value)
if cond_bull_xtl
alert('Symbol = (' + syminfo.tickerid + ') \n TimeFrame = (' + timeframe.period + ') \n Current Price (' + str.tostring(close) + ') \n Bullish Trend [XTL].', alert.freq_once_per_bar_close)
if cond_bear_xtl
alert('Symbol = (' + syminfo.tickerid + ') \n TimeFrame = (' + timeframe.period + ') \n Current Price (' + str.tostring(close) + ') \n Bearish Trend [XTL].', alert.freq_once_per_bar_close)
barcolor(candles_XTL ? color_XTL : na, title='XTL [Expert Trend Locator]')
//______________________________________________________________________________
// Squeeze Momentum [Plus]
// https://www.tradingview.com/script/3mQBizyn/
//______________________________________________________________________________
// Bollinger Bands Basis Line
basis = ma(bbmatype, get_src(src_sqz), length_sqz)
// Keltner Channel Basis Line
basiskc = ma(kcmatype, get_src(src_sqz), length_sqz)
// Keltner Channel Range
range_1 = ma(kcmatype, ta.tr, length_sqz)
// Bollinger Bands Multiplier
multBB = 2.0
// Keltner Channel Low Multiplier
multlowKC = 2.0
// Keltner Channel Mid Multiplier
multmidKC = 1.5
// Keltner Channel High Multiplier
multhighKC = 1.0
// Bollinger Bands
dev = multBB * ta.stdev(get_src(src_sqz), length_sqz)
upperBB = basis + dev
lowerBB = basis - dev
// Keltner Channel Bands Low
upperKCl = basiskc + range_1 * multlowKC
lowerKCl = basiskc - range_1 * multlowKC
// Keltner Channel Bands Mid
upperKCm = basiskc + range_1 * multmidKC
lowerKCm = basiskc - range_1 * multmidKC
// Keltner Channel Bands High
upperKCh = basiskc + range_1 * multhighKC
lowerKCh = basiskc - range_1 * multhighKC
//Squeeze On
lowsqz = lowerBB > lowerKCl and upperBB < upperKCl
lsf = lowsqz == false
midsqz = lowerBB > lowerKCm and upperBB < upperKCm
msf = midsqz == false
highsqz = lowerBB > lowerKCh and upperBB < upperKCh
hsf = highsqz == false
//Squeeze Dot Colors
sqz_color = highsqz ? color_H : midsqz ? color_O : lowsqz ? color_L : na
//Squeeze Dot Plot Above
sqzpro = highsqz ? highsqz : midsqz ? midsqz : lowsqz ? lowsqz : na
plotshape(sqzpro, 'Squeeze Pro', shape.circle, location.top, sqz_color)
//_____________________________________________________________________________________
// Based on "Williams_Vix_Fix_V3_Upper_Text_Plots" - Author: @ChrisMoody
// https://www.tradingview.com/script/1ffumXy5-CM-Williams-Vix-Fix-V3-Upper-Text-Plots/
// https://www.ireallytrade.com/newsletters/VIXFix.pdf
//_____________________________________________________________________________________
// Williams Vix Fix Formula
wvf = (ta.highest(close, pd) - low) / ta.highest(close, pd) * 100
sDev = mult * ta.stdev(wvf, bbl)
midLine = ta.sma(wvf, bbl)
lowerBand = midLine - sDev
upperBand = midLine + sDev
rangeHigh = ta.highest(wvf, lb) * ph
// Filtered Criteria
upRange = low > low[1] and close > high[1]
upRange_Aggr = close > close[1] and close > open[1]
// Filtered Criteria
filtered = (wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and wvf < upperBand and wvf < rangeHigh
filtered_Aggr = (wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and not(wvf < upperBand and wvf < rangeHigh)
// Alerts Criteria
alert1 = wvf >= upperBand or wvf >= rangeHigh ? 1 : 0
alert2 = (wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and wvf < upperBand and wvf < rangeHigh ? 1 : 0
cond_FE = upRange and close > close[str] and (close < close[ltLB] or close < close[mtLB]) and filtered
alert3 = cond_FE ? 1 : 0
cond_AE = upRange_Aggr and close > close[str] and (close < close[ltLB] or close < close[mtLB]) and filtered_Aggr
alert4 = cond_AE ? 1 : 0
plotshape(sbcc and alert1 ? alert1 : na, 'WVF Is True', shape.triangledown, location.bottom, color.new(#80FF00, 60), size=size.tiny)
plotshape(sbc and alert2 ? alert2 : na, 'WVF Was True - Now False', shape.triangledown, location.bottom, color.new(color.teal, 60), size=size.tiny)
plotshape(sbcAggr and alert4 ? alert4 : na, 'Aggressive Entry', shape.triangleup, location.bottom, color.new(#80FF00, 20), textcolor=color.new(#80FF00, 20), text='AE', size=size.tiny)
plotshape(sbcFilt and alert3 ? alert3 : na, 'Filtered Entry', shape.triangleup, location.bottom, color.new(#80FF00, 20), textcolor=color.new(#80FF00, 20), text='FE', size=size.tiny)
if alert_AE and cond_AE
alert('Symbol = (' + syminfo.tickerid + ') \n TimeFrame = (' + timeframe.period + ') \n Current Price (' + str.tostring(close) + ') \n Aggressive Entry [VixFix].', alert.freq_once_per_bar_close)
if alert_FE and cond_FE
alert('Symbol = (' + syminfo.tickerid + ') \n TimeFrame = (' + timeframe.period + ') \n Current Price (' + str.tostring(close) + ') \n Filtered Entry [VixFix].', alert.freq_once_per_bar_close)
//___________________________________________________________________________________
// Colored Directional Movement Index (CDMI) by @dgtrd and @OskarGallard
//___________________________________________________________________________________
[diplus, diminus, adxValue] = ta.dmi(lenDi, lenSig)
// J. Welles Wilder, developer of DMI, believed that a DMI reading above 25 indicated a strong trend,
// while a reading below 20 indicated a weak or non-existent trend.
dmiBull = diplus >= diminus and adxValue >= keyLevel
dmiBear = diplus < diminus and adxValue >= keyLevel
dmiWeak = adxValue < keyLevel and adxValue > weakTrend
slope_positive = adxValue > adxValue[1]
diCross = bar_index - ta.valuewhen(ta.cross(diplus, diminus), bar_index, 0)
strong = slope_positive ? "Strong" : " "
weak_up_dn = dmiWeak ? (diplus >= diminus ? "[uptrend]" : "[downtrend]") : ""
// Label
lbStat = histLabel > 0 ? "\n\n Timeframe: " + timeframe.period + ", " + str.tostring(histLabel) + " bar(s) earlier historical value.-":
"\n\n Timeframe: " + timeframe.period + ", last di cross " + str.tostring(diCross) + " bar(s) before.-"
adxMom = slope_positive ? " ▲ Growing | Previous ADX: " + str.tostring(adxValue[1], "#.##") + ")\n» " : " ▼ Falling | Previous ADX(" + str.tostring(adxValue[1], "#.##") + ")\n» "
diStat = diplus >= diminus ? "diPlus(" + str.tostring(diplus, "#.##") + ") >= diMinus(" + str.tostring(diminus, "#.##") + ")" :
"diPlus(" + str.tostring(diplus, "#.##") + ") < diMinus(" + str.tostring(diminus, "#.##") + ")"
dmiText = dmiBull ? strong + " Bullish\n» ADX(" + str.tostring(adxValue, "#.##") + ")" + adxMom + diStat:
dmiBear ? strong + " Bearish\n» ADX(" + str.tostring(adxValue, "#.##") + ")" + adxMom + diStat:
dmiWeak ? "Weak " + weak_up_dn + "\n» ADX(" + str.tostring(adxValue, "#.##") + ")" + adxMom + diStat:
"No Trend\n» ADX(" + str.tostring(adxValue, "#.##") + ")" + adxMom + diStat
oneDay = 24 * 60 * 60 * 1000
barsAhead = 3
onward = if timeframe.ismonthly
barsAhead * oneDay * 30
else if timeframe.isweekly
barsAhead * oneDay * 7
else if timeframe.isdaily
barsAhead * oneDay
else if timeframe.isminutes
barsAhead * oneDay * timeframe.multiplier / 1440
else if timeframe.isseconds
barsAhead * oneDay * timeframe.multiplier / 86400
else
0
dmiColor = dmiBull ? (slope_positive ? #006400 : color.green) :
dmiBear ? (slope_positive ? #910000 : color.red) :
dmiWeak ? (slope_positive ? color.black : color.gray) :
(slope_positive ? #DAA80A : #FFC40C)
// Colored DMI
plotshape(diplus >= diminus, '+DI > -DI', shape.triangleup, location.bottom, dmiColor)
plotshape(diplus < diminus, '+DI < -DI', shape.triangledown, location.bottom, dmiColor)
alert_dmiBull = detect_bull_dmi and diplus >= diminus and ta.crossover(adxValue, keyLevel)
alert_dmiBear = detect_bear_dmi and diplus < diminus and ta.crossover(adxValue, keyLevel)
if alert_dmiBull
alert('Symbol = (' + syminfo.tickerid + ') \n TimeFrame = (' + timeframe.period + ') \n Current Price (' + str.tostring(close) + ') \n Bullish Trend [DMI].', alert.freq_once_per_bar_close)
if alert_dmiBear
alert('Symbol = (' + syminfo.tickerid + ') \n TimeFrame = (' + timeframe.period + ') \n Current Price (' + str.tostring(close) + ') \n Bearish Trend [DMI].', alert.freq_once_per_bar_close)
// Label
if not hideLabel
label dmiLabel = label.new(time, 0, text="DMI reading: " + dmiText[histLabel] + lbStat
,tooltip=" ◁ how to read colored dmi ▷\n* triangle shapes:\n ▲- bullish : diplus >= diminus\n ▼- bearish : diplus < diminus\n* colors:\n green - bullish trend : adx >= keyLevel and di+ > di-\n red - bearish trend : adx >= keyLevel and di+ < di- \n gray - weak trend : weekTrend < adx < keyLevel\n yellow - no trend : adx < weekTrend\n* color density:\n darker : adx growing\n lighter : adx falling "
,color=dmiColor[histLabel], xloc=xloc.bar_time, style=label.style_label_left, textcolor=adxValue[histLabel] < weakTrend ? color.black : color.white, textalign=text.align_left)
label.set_x(dmiLabel, label.get_x(dmiLabel) + onward)
label.delete(dmiLabel[1])
|
Funds Inflow Near Closing Bell | https://www.tradingview.com/script/doKobdb4-Funds-Inflow-Near-Closing-Bell/ | Qpxcaro | https://www.tradingview.com/u/Qpxcaro/ | 23 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Qpxcaro
//@version=4
// Investment funds often execute their oreders in the last 30 minutes of a daily trading session
// This script approximates inflow/outflow of professionally managed money into a given security
// IMPORTANT! Must be plotted on a timeframe with DAILY resolution (can be applied to other timeframes as well, but results will be nonsensical)
study("Funds Inflow Near Closing Bell")
period = input(title="Minutes before closing bell", type=input.resolution, defval="30")
c = security(syminfo.tickerid, period, close)
o = security(syminfo.tickerid, period, open)
h = security(syminfo.tickerid, period, high)
l = security(syminfo.tickerid, period, low)
v = security(syminfo.tickerid, period, volume)
float todays_imbalance = 0.0
todays_imbalance := v * (c - o) / (h - l) // previously (log(c) - log(o)) * v * (o + c) / 2.0
_series = 0.0
_series := nz(_series[1], 1) + todays_imbalance
plot(_series, style=plot.style_line) |
st_renko | https://www.tradingview.com/script/vS3QFz6Y-st-renko/ | IntelTrading | https://www.tradingview.com/u/IntelTrading/ | 108 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © IntelTrading
//@version=4
study("st_renko", overlay = true)
p = input(600, title = 'period range')
n = input(20.0, title = 'divisions')
h = highest(high, p)
l = lowest(low, p)
d = h - l
f = d/n
var r = l
var g = l + f
for i = 1 to n
if ohlc4 > l + f*i
r := l + f*i
g := l + f*(i + 1)
if ohlc4 < l + f*i
r := l + f * (i - 1)
g := l + f*i
var a = 0
if r < r[1]
a := 1
if r > r[1]
a := 0
p1 = plot(r, color = color.green, linewidth = 2)
p2 = plot(g, color = color.red, linewidth = 2)
fill(p1, p2, color = a == 1 ? color.red : color.green, transp = 70)
|
Trend System Oscillator Averages Rating | https://www.tradingview.com/script/ew8f3yep-Trend-System-Oscillator-Averages-Rating/ | exlux99 | https://www.tradingview.com/u/exlux99/ | 123 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © exlux99
//@version=4
study("Multiple Oscillator Rating", overlay = true)
src=close
//-------------- FUNCTIONS
dirmov(len) =>
up = change(high)
down = -change(low)
plusDM = na(up) ? na : up > down and up > 0 ? up : 0
minusDM = na(down) ? na : down > up and down > 0 ? down : 0
truerange = rma(tr, len)
plus = fixnan(100 * rma(plusDM, len) / truerange)
minus = fixnan(100 * rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
adx
// ATR
atr = rma(tr(true), 14)
sma = sma(atr, 20)
atrTrending = if atr > sma
true
else
false
// ADX
adxlen = 14
dilen = 14
sig = adx(dilen, adxlen)
adxTrending = if sig > 20
true
else
false
// RSI
up = rma(max(change(close), 0), 14)
down = rma(-min(change(close), 0), 14)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiTrending = if rsi > 60 or rsi < 40
true
else
false
rsi_len = 14//input(14, minval=1, title="RSI Length")
//STOCH K
stoch_length =14// input(14, minval=1, title="STOCH Length")
stoch_smoothK = 8//input(8, minval=1, title="STOCH K")
//CCI
cci_len = 20//input(20, minval=1, title="CCI Length")
//ADI
//adxlen =14// input(14, title="ADX Smoothing")
//dilen = 14//input(14, title="DI Length")
//Momentum
momentum_len = 10//input(10, minval=1, title="Momentum Length")
//MACD
macd_fast = 12//input(12, type=input.integer, title="MACD fast")
macd_slow = 26//input(27, type=input.integer, title="MACD slow")
//Stochrsi fast
smoothK = 5//input(5, minval=1, title="STOCHRSI smoothK")
smoothD = 5//input(5, minval=1, title="STOCHRSI smoothD")
lengthRSI = 14//input(14, minval=1, title="RSI Length")
lengthStoch = 14//input(14, minval=1, title="STOCH Length")
//William Percentage Range
wpr_length = 14//input(14, minval=1, title="William Perc Range Length")
//Ultimate Oscillator
uo_length7 = 7//input(7, minval=1, title="UO Length 7")
uo_length14 = 14//input(14, minval=1, title="UO Length 14")
uo_length28 = 28//input(28, minval=1, title="UO Length 28")
//-------------- OSCILLATORS CALCULATION
rsi_index = 0.0
stoch_index = 0.0
adx_index = 0.0
cci_index = 0.0
ao_index = 0.0
macd_index = 0.0
mom_index = 0.0
stochrsi_index = 0.0
wpr_index = 0.0
bp_index = 0.0
uo_index = 0.0
//RSI
// up = rma(max(change(src), 0), rsi_len)
// down = rma(-min(change(src), 0), rsi_len)
// rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
if rsi >= 80
rsi_index := -1
rsi_index
if rsi <= 20
rsi_index := 1
rsi_index
//STOCH K
stoch_k = sma(stoch(close, high, low, stoch_length), stoch_smoothK)
if stoch_k >= 80
stoch_index := -1
stoch_index
if stoch_k <= 20
stoch_index := 1
stoch_index
//CCI
cci_ma = sma(src, cci_len)
cci = (src - cci_ma) / (0.015 * dev(src, cci_len))
if cci >= 100
stoch_index := -1
stoch_index
if cci <= -100
stoch_index := 1
stoch_index
//ADX
adx_calc = adx(dilen, adxlen)
//if adx_calc >= 20 and crossover( )
// adx_index = -1
//if adx_calc >= 20 and crossover( )
// adx__index = 1
//Awesome Oscilator
ao = sma(hl2, 5) - sma(hl2, 34)
if ao >= 0
ao_index := -1
ao_index
if ao <= 0
ao_index := 1
ao_index
//Momentum
mom = src - src[momentum_len]
if mom >= 0
mom_index := -1
mom_index
if mom <= 0
mom_index := 1
mom_index
//MACD
macd = ema(close, macd_fast) - ema(close, macd_slow)
if macd >= 0
macd_index := -1
macd_index
if macd <= 0
macd_index := 1
macd_index
//STOCHRSI FAST
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
if k >= 80
stochrsi_index := -1
stochrsi_index
if k <= 20
stochrsi_index := 1
stochrsi_index
//Williams Percent Range (14)
wpr_upper = highest(wpr_length)
wpr_lower = lowest(wpr_length)
wpr_out = 100 * (close - wpr_upper) / (wpr_upper - wpr_lower)
if wpr_out >= -20
stochrsi_index := -1
stochrsi_index
if wpr_out <= -80
stochrsi_index := 1
stochrsi_index
//BullBearPower
//TBD
//Ultimate Oscillator (7, 14, 28)
average(bp, tr_, length) =>
sum(bp, length) / sum(tr_, length)
high_ = max(high, close[1])
low_ = min(low, close[1])
bp = close - low_
tr_ = high_ - low_
avg7 = average(bp, tr_, uo_length7)
avg14 = average(bp, tr_, uo_length14)
avg28 = average(bp, tr_, uo_length28)
uo_out = 100 * (4 * avg7 + 2 * avg14 + avg28) / 7
if uo_out >= 50
uo_index := 1
uo_index
if uo_out <= 50
uo_index := -1
uo_index
oscillators_index = (rsi_index + stoch_index + adx_index + cci_index + stochrsi_index + ao_index +
mom_index + macd_index + wpr_index + uo_index) / 10
posInput = input(title="Position", defval="Top Right", options=["Bottom Left", "Bottom Right", "Top Left", "Top Right"])
var pos = posInput == "Bottom Left" ? position.bottom_left : posInput == "Bottom Right" ? position.bottom_right : posInput == "Top Left" ? position.top_left : posInput == "Top Right" ? position.top_right : na
var table perfTable = table.new(pos, 2, 4, border_width = 3)
text_size = input("AUTO", "Text Size:", options=["AUTO", "TINY","SMALL", "NORMAL", "LARGE", "HUGE"])
table_size = input(6, "Table Width:")
text = size.auto
if text_size == "TINY"
text := size.tiny
if text_size == "SMALL"
text := size.small
if text_size == "NORMAL"
text := size.normal
if text_size == "LARGE"
text := size.large
if text_size == "HUGE"
text := size.huge
LIGHTTRANSP = 90
AVGTRANSP = 80
HEAVYTRANSP = 70
f_fillCell(_table, _column, _row, _value, _timeframe, _c_color) =>
//_c_color = color.blue//close > open ? i_posColor : i_negColor
_transp = HEAVYTRANSP//abs(_value) > 10 ? HEAVYTRANSP : abs(_value) > 5 ? AVGTRANSP : LIGHTTRANSP
_cellText = tostring(_value, "#.## %")
table.cell(_table, _column, _row, _cellText, bgcolor = color.new(_c_color, _transp), text_color = _c_color, width = table_size)
table.cell_set_text_size(perfTable, 1, 0, text)
table.cell_set_text_size(perfTable, 1, 1, text)
//table.cell_set_text_size(perfTable, 0, 2, text)
if barstate.islast
table.cell(perfTable, 0, 0, "Rating confirmation 0-100 Long | -100-0 Short", text_color=color.white, text_size=text, bgcolor=color.blue)
f_fillCell(perfTable, 0, 1, (oscillators_index*100)/100 , "% confirmation", (oscillators_index*100)/100 >0? color.lime : color.red )
|
Alpha Active Addresses from Glassnode | https://www.tradingview.com/script/SadPatLc-Alpha-Active-Addresses-from-Glassnode/ | mehran_khanjan | https://www.tradingview.com/u/mehran_khanjan/ | 18 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mehran_khanjan
//@version=4
study(title = 'Alpha Active Addresses from Glassnode' , shorttitle = 'Alpha Active Addr')
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** Inputs ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
_use_sma = input(type = input.bool , title = 'Use Simple Moving Average Instead of Real Value' , defval = false , group = 'Simple Moving Average')
_sma_length = input(type = input.integer , title = 'Simple Moving Average Length' , defval = 7 , group = 'Simple Moving Average')
_use_ema = input(type = input.bool , title = 'Use Exponential Moving Average Instead of Real Value' , defval = false , group = 'Exponential Moving Average')
_ema_length = input(type = input.integer , title = 'Exponential Moving Average Length' , defval = 7 , group = 'Exponential Moving Average')
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** Global Calcualtions ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
// *
// * Get Active Addresses Data
// *
_active_addresses = security('XTVCBTC_ACTIVEADDRESSES' , timeframe.period , _use_ema ? ema(close , _ema_length) : _use_sma ? sma(close , _sma_length) : close)
// *
// * Draw Lines
// *
plot(_active_addresses , style = plot.style_columns) |
Risk Management Tool [LuxAlgo] | https://www.tradingview.com/script/fLtr5XhT-Risk-Management-Tool-LuxAlgo/ | LuxAlgo | https://www.tradingview.com/u/LuxAlgo/ | 3,597 | study | 4 | CC-BY-NC-SA-4.0 | // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=4
study("Risk Management Tool [LuxAlgo]",overlay=true)
pos_type = input('Long','Position Type',options=['Long','Short'])
acc_size = input(1000.,'Account Size',minval=0)
risk = input(2.,'Risk ',minval=0,inline='risk')
risk_type = input('%','',options=['%','USD'],inline='risk')
entry_price = input(40000.,'Entry Price',confirm=true)
entry_cross = input(false,'Entry From Cross',inline='entry')
cross_src = input(open,"",inline='entry')
//----
tp = input(5.,'Take Profit',minval=0
,group='Take Profit/Stop Loss',inline='tp',confirm=true)
tp_type = input('%','',options=['ATR','%','Price','Range']
,group='Take Profit/Stop Loss',inline='tp',confirm=true)
//----
sl = input(5.,'Stop Loss ',minval=0
,group='Take Profit/Stop Loss',inline='sl',confirm=true)
sl_type = input('%','',options=['ATR','%','Price','Range']
,group='Take Profit/Stop Loss',inline='sl',confirm=true)
//----
profit_col = input(color.new(#009688,80),'Profit Color'
,group='Style',inline='col')
loss_col = input(color.new(#f44336,80),'Loss Color'
,group='Style',inline='col')
//------------------------------------------------------------------------------
tp_val = 0.
sl_val = 0.
entry = 0.
pos = pos_type == 'Long' ? 1 : -1
if entry_cross
entry := valuewhen(cross(close,cross_src)[1],open,0)
else
entry := entry_price
tp_range = highest(max(round(tp),1)) - lowest(max(round(tp),1))
sl_range = highest(max(round(sl),1)) - lowest(max(round(sl),1))
if tp_type == 'ATR'
tp_val := entry + atr(max(round(tp),1))*pos
else if tp_type == '%'
tp_val := entry + tp/100*entry*pos
else if tp_type == 'Price'
tp_val := tp
else if tp_type == 'Range'
tp_val := entry + (tp_range)*pos
if sl_type == 'ATR'
sl_val := entry - atr(max(round(sl),1))*pos
else if sl_type == '%'
sl_val := entry - sl/100*entry*pos
else if sl_type == 'Price'
sl_val := sl
else if sl_type == 'Range'
sl_val := entry - (sl_range)*pos
//------------------------------------------------------------------------------
open_pl = (close - entry)*pos
position_size = 0.
RR = abs((tp_val-entry)/(sl_val-entry))
if risk_type == '%'
position_size := risk/100*acc_size/((entry-sl_val)*pos)
else
position_size := risk/((entry-sl_val)*pos)
//------------------------------------------------------------------------------
n = bar_index
var tbl = table.new(position.bottom_right,2,3)
if barstate.islast
box.delete(box.new(n,tp_val,n+100,entry,bgcolor=profit_col,border_width=0)[1])
box.delete(box.new(n,entry,n+100,sl_val,bgcolor=loss_col,border_width=0)[1])
label.delete(label.new(n+100,entry
,str.format('P&L : {0} {1} ({2,number,percent})',open_pl,syminfo.currency,open_pl/entry)
,color=open_pl>0?profit_col:loss_col
,style=label.style_label_left,textcolor=color.gray,textalign=text.align_left)[1])
if tp
label.delete(label.new(n+100,tp_val
,str.format('TP : {0} ({1,number,percent})',tp_val,(tp_val-entry)/entry)
,color=profit_col
,style=label.style_label_left,textcolor=color.gray,textalign=text.align_left)[1])
if sl
label.delete(label.new(n+100,sl_val
,str.format('TSL : {0} ({1,number,percent})',sl_val,(entry-sl_val)/entry)
,color=loss_col
,style=label.style_label_left,textcolor=color.gray,textalign=text.align_left)[1])
table.cell(tbl,0,0,'Risk/Reward',text_color=color.gray,text_halign=text.align_center)
table.cell(tbl,1,0,tostring(RR,'#.####'),text_color=color.gray,text_halign=text.align_center)
table.cell(tbl,0,1,'Position Size',text_color=color.gray,text_halign=text.align_center)
table.cell(tbl,1,1,tostring(position_size,'#.####')+' '+syminfo.basecurrency
,text_color=color.gray,text_halign=text.align_center)
//------------------------------------------------------------------------------
Close = plot(close,editable=false,display=display.none)
Entry = plot(entry,editable=false,display=display.none)
fill(Close,Entry,color=open_pl>0?profit_col:loss_col)
plotchar(open_pl,'Rolling Open PL%','',location.abovebar,open_pl > 0 ? profit_col : loss_col) |
st_short | https://www.tradingview.com/script/rUcXaFRj-st-short/ | IntelTrading | https://www.tradingview.com/u/IntelTrading/ | 68 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Alferow
//@version=4
study('st_short', overlay = true, precision = 5)
dep = input(300.00, title = 'risk on deal')
pr1 = input(46000.24, title = 'price enter')
tk = input(45000.0, title = 'price take')
of = input(100.0, title = 'exceeding $')
m = input(2.0, minval = 0.10, step = 0.1, title = 'martingale')
l = input(5, minval = 2, step = 1, title = 'leverage')
n = input(4, minval = 3, maxval = 5, title = 'number enters')
com = (1 - 0.01*input(0.07, title = 'commission %'))
pos = input(title="Position table", type=input.bool, defval=true)
txt = input(title="Text size", type=input.bool, defval=true)
k1 = pr1 >= 100.0 ? 3 : pr1 >= 10.0 and pr1 < 100.0 ? 2 : pr1 >= 1.0 and pr1 < 10.0 ? 1 : 0
k2 = pr1 >= 100.0 ? 0.0005 : pr1 >= 10.0 and pr1 < 100.0 ? 0.005 : pr1 >= 1.0 and pr1 < 10.0 ? 0.05 : 0.5
k3 = pr1 >= 100.0 ? 1 : pr1 >= 1.0 and pr1 < 100.0 ? 4 : 5
k4 = pos == true ? position.bottom_right : position.top_right
k5 = txt == true ? size.auto : size.large
h = (1 + (1/l))
summ = m == 1 ? dep/n : (dep * (m - 1)/(pow(m, n) - 1))
d1 = l*summ*com
d2 = d1*m
d3 = d2*m
d4 = d3*m
d5 = d4*m
v1 = round(d1/pr1 - k2, k1)
pr2 = -of + pr1*h
v2 = round(d2/pr2 - k2, k1)
pr3 = -of + h*(pr1 * v1 + pr2*v2)/((v1 + v2))
v3 = round(d3/pr3 - k2, k1)
pr4 = -of + h*(pr1 * v1 + pr2*v2 + pr3*v3)/((v1 + v2 + v3))
v4 = round(d4/pr4 - k2, k1)
pr5 = -of + h*(pr1 * v1 + pr2*v2 + pr3*v3 + pr4*v4)/((v1 + v2 + v3 + v4))
v5 = round(d5/pr5 - k2, k1)
pr6 = -of + h*(pr1 * v1 + pr2*v2 + pr3*v3 + pr4*v4 + pr5*v5)/((v1 + v2 + v3 + v4 + v5))
av1 = pr1
av2 = (pr1 * v1 + pr2*v2)/(v1 + v2)
av3 = (pr1 * v1 + pr2*v2 + pr3*v3)/(v1 + v2 + v3)
av4 = (pr1 * v1 + pr2*v2 + pr3*v3 + pr4*v4)/(v1 + v2 + v3 + v4)
av5 = (pr1 * v1 + pr2*v2 + pr3*v3 + pr4*v4 + pr5*v5)/(v1 + v2 + v3 + v4 + v5)
p1 = v1*(pr1 - tk)*com
p2 = (v1 + v2)*(av2 - tk)*com
p3 = (v1 + v2+ v3)*(av3 - tk)*com
p4 = (v1 + v2+ v3 + v4)*(av4 - tk)*com
p5 = (v1 + v2+ v3 + v4 + v5)*(av5 - tk)*com
var testTable = table.new(position = k4, columns = 5, rows = 7, border_color = color.black, bgcolor = color.white, border_width = 1)
if barstate.islast and n == 5
table.cell(table_id = testTable, column = 0, row = 0, text = " ", text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 0, text = "Price enter", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 0, text = "Volume", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 0, text = "Money, $", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 0, text = "Profit, $", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 1, text = "1 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 2, text = "2 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 3, text = "3 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 4, text = "4 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 5, text = "5 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 6, text = "liquid", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 1, text = tostring(round(pr1, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 2, text = tostring(round(pr2, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 3, text = tostring(round(pr3, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 4, text = tostring(round(pr4, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 5, text = tostring(round(pr5, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 6, text = tostring(round(pr6, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 1, text = tostring(round(v1, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 2, text = tostring(round(v2, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 3, text = tostring(round(v3, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 4, text = tostring(round(v4, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 5, text = tostring(round(v5, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 1, text = tostring(round(d1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 2, text = tostring(round(d2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 3, text = tostring(round(d3, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 4, text = tostring(round(d4, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 5, text = tostring(round(d5, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 1, text = tostring(round(p1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 2, text = tostring(round(p2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 3, text = tostring(round(p3, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 4, text = tostring(round(p4, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 5, text = tostring(round(p5, 2)), text_size = k5, text_color = color.black)
if barstate.islast and n == 4
table.cell(table_id = testTable, column = 0, row = 0, text = " ", text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 0, text = "Price enter", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 0, text = "Volume", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 0, text = "Money, $", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 0, text = "Profit, $", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 1, text = "1 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 2, text = "2 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 3, text = "3 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 4, text = "4 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 5, text = "liquid", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 1, text = tostring(round(pr1, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 2, text = tostring(round(pr2, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 3, text = tostring(round(pr3, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 4, text = tostring(round(pr4, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 5, text = tostring(round(pr5, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 1, text = tostring(round(v1, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 2, text = tostring(round(v2, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 3, text = tostring(round(v3, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 4, text = tostring(round(v4, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 1, text = tostring(round(d1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 2, text = tostring(round(d2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 3, text = tostring(round(d3, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 4, text = tostring(round(d4, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 1, text = tostring(round(p1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 2, text = tostring(round(p2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 3, text = tostring(round(p3, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 4, text = tostring(round(p4, 2)), text_size = k5, text_color = color.black)
if barstate.islast and n == 3
table.cell(table_id = testTable, column = 0, row = 0, text = " ", text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 0, text = "Price enter", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 0, text = "Volume", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 0, text = "Money, $", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 0, text = "Profit, $", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 1, text = "1 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 2, text = "2 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 3, text = "3 deal", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 0, row = 4, text = "liquid", bgcolor=color.red, text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 1, text = tostring(round(pr1, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 2, text = tostring(round(pr2, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 3, text = tostring(round(pr3, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 1, row = 4, text = tostring(round(pr4, k3)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 1, text = tostring(round(v1, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 2, text = tostring(round(v2, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 2, row = 3, text = tostring(round(v3, k1)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 1, text = tostring(round(d1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 2, text = tostring(round(d2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 3, row = 3, text = tostring(round(d3, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 1, text = tostring(round(p1, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 2, text = tostring(round(p2, 2)), text_size = k5, text_color = color.black)
table.cell(table_id = testTable, column = 4, row = 3, text = tostring(round(p3, 2)), text_size = k5, text_color = color.black)
|
EM_RSI Gradient Candles | https://www.tradingview.com/script/vYQ98bfL-EM-RSI-Gradient-Candles/ | EffyewMoney | https://www.tradingview.com/u/EffyewMoney/ | 143 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EffyewMoney
//@version=4
study(title="EM's RSI Gradient Candles", overlay = true, shorttitle="EM's RSI Gradient Candles")
//TradingView standard RSI calculation
src = close, len = input(14, minval=1, title="RSI Length")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
//User settings (RSI setting is in RSI section above)
emalength = input(defval = 12, title = "EMA Length", type = input.integer)
labelson = input(true, title = "Labels On/Off", group = "Label Settings", inline = "1")
labelhist = input(true, title = "Show Past Labels", group = "Label Settings", inline = "1")
//Defining ranges by 10% increments
tier1 = rsi <= 10
tier2 = rsi > 10 and rsi <= 20
tier3 = rsi > 20 and rsi <= 30
tier4 = rsi > 30 and rsi <= 40
tier5 = rsi > 40 and rsi <= 50
tier6 = rsi > 50 and rsi <= 60
tier7 = rsi > 60 and rsi <= 70
tier8 = rsi > 70 and rsi <= 80
tier9 = rsi > 80 and rsi <= 90
tier10 = rsi >= 90
//Assign color based on range
barcolor(tier10 ? #0A2900 : na)
barcolor(tier9 ? #175a01 : na)
barcolor(tier8 ? #259b00 : na)
barcolor(tier7 ? #57FF1F : na)
barcolor(tier6 ? #AFE79C : na)
barcolor(tier5 ? #FF8585 : na)
barcolor(tier4 ? #FF4747 : na)
barcolor(tier3 ? #CC0000 : na)
barcolor(tier2 ? #8F0000 : na)
barcolor(tier1 ? #3D0000 : na)
//Calculate RSI EMA
rsiema = ema(rsi, emalength)
//Identify RSI/EMA crosses
rsicrossover = rsi > rsiema and rsi[1] <= rsiema[1]
rsicrossunder = rsi < rsiema and rsi[1] >= rsiema[1]
//Create Labels
if(labelson and rsicrossover)
labeluptext = tostring("RSI over EMA")
LabelUp = label.new(x = bar_index, y = na, text = labeluptext, yloc = yloc.abovebar, color = input((color.lime), group = "Label Settings", inline = "2"), textcolor = color.white, style = label.style_triangleup, size = size.small)
//Delete old labels
if(labelhist == false)
label.delete(LabelUp[1])
if(labelson and rsicrossunder)
labeldowntext = tostring("RSI under EMA")
LabelDown = label.new(x = bar_index, y = na, text = labeldowntext, yloc = yloc.belowbar, color = input((color.red), group = "Label Settings", inline = "2"), textcolor = color.white, style = label.style_triangledown, size = size.small)
if(labelhist == false)
label.delete(LabelDown[1])
//Enable the following settings to turn on matching wicks and borders.
//Warning: due to limitations of pine script it WILL require more patience when choosing settings. A workaround exists, but it's extra effort, not as pretty, and still sometimes flashes the wrong colors on mouseover
//Workaround: Place the indicator at the top of the object tree. Disable each Bar Color box you don't want to see, then find the corresponding slot in the plotcandle section and set the opacity to 0%
//Wick and Border color reference
//wickcol = input(false, title = "Matching Wick and Borders")
//color wicknborder = tier1 ? #3D0000 : tier2 ? #8F0000 : tier3 ? #CC0000 : tier4 ? #FF4747 : tier5 ? #FF8585 : tier6 ? #AFE79C : tier7 ? #57FF1F : tier8 ? #259b00 : tier9 ? #175a01 : tier10 ? #0A2900 : na
//Set borders and wicks to match candle colors.
//plotcandle(wickcol ? open : na, wickcol ? high : na, wickcol ? low : na, wickcol ? close : na, wickcolor = wicknborder, bordercolor = wicknborder, color = wicknborder) |
Bollinger Bands With User Selectable MA | https://www.tradingview.com/script/GSGjv1cX-Bollinger-Bands-With-User-Selectable-MA/ | animecummer | https://www.tradingview.com/u/animecummer/ | 208 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator('Bollinger Bands with User Selectable MA',
shorttitle='BBands - User Selectable MA',
overlay=true,
timeframe="",
timeframe_gaps=true)
//INPUT
lsmaoffset = input.int(title='Least Squares MA Only - LS Offset', defval=0, group='Special MA Settings', inline='02')
almaoffset = input.float(title='ALMA Offset', defval=0.85, step=0.01, group='Special MA Settings', inline='03')
almasigma = input.float(title='Sigma', defval=6, group='Special MA Settings', inline='03')
a1 = input.float(title='Tillson T3 Volume Factor', defval=0.7, group='Special MA Settings', inline='5', step=0.001)
f_ehma(_Source, _length) =>
_return = ta.ema(2 * ta.ema(_Source, _length / 2) - ta.ema(_Source, _length), math.round(math.sqrt(_length)))
_return
f_tema(_Source, _length) =>
_out = 3 * (ta.ema(_Source, _length) - ta.ema(ta.ema(_Source, _length), _length)) + ta.ema(ta.ema(ta.ema(_Source, _length), _length), _length)
_out
f_t3(_source, _length, _a1) =>
_output = (-_a1 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(ta.ema(ta.ema(ta.ema(_source, _length), _length), _length), _length), _length), _length)) + (3 * _a1 * _a1 + 3 * _a1 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(ta.ema(ta.ema(_source, _length), _length), _length), _length), _length)) + (-6 * _a1 * _a1 - 3 * _a1 - 3 * _a1 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(ta.ema(_source, _length), _length), _length), _length)) + (1 + 3 * _a1 + _a1 * _a1 * _a1 + 3 * _a1 * _a1) * (ta.ema(ta.ema(ta.ema(_source, _length), _length), _length))
_output
donchian(_length) =>
math.avg(ta.lowest(_length), ta.highest(_length))
MA(source, length, type) =>
type == 'SMA' ? ta.sma(source, length) :
type == 'Donchian' ? donchian(length) :
type == 'EMA' ? ta.ema(source, length) :
type == 'SMMA (RMA)' ? ta.rma(source, length) :
type == 'WMA' ? ta.wma(source, length) :
type == 'VWMA' ? ta.vwma(source, length) :
type == 'HMA' ? ta.hma(source, length) :
type == 'EHMA' ? f_ehma(source, length) :
type == 'TEMA' ? f_tema(source, length) :
type == 'ALMA' ? ta.alma(source, length, almaoffset, almasigma) :
type == 'Tillson T3' ? f_t3(source, length, a1) :
type == 'LSMA' ? ta.linreg(source, length, lsmaoffset) :
na
BB_type = input.string('SMA', 'Basis', inline='1',
options=['SMMA (RMA)',
'SMA',
'Donchian',
'Tillson T3',
'EMA',
'VWMA',
'WMA',
'EHMA',
'ALMA',
'LSMA',
'HMA',
'TEMA'],
group='Bollinger Band Calculation Settings')
BBSource = input.source(close, '', group='Bollinger Band Calculation Settings', inline='1')
BBPeriod = input.int(20, '', minval=1, step=1, group='Bollinger Band Calculation Settings', inline='1')
stdevMultiple = input.float(2, '# of Standard Deviations', minval=1, step=0.1, group='Bollinger Band Calculation Settings', inline='3')
realoffset = input.int(0, 'Basic Plot Offset', minval=-500, maxval=500, group='Bollinger Band Calculation Settings', inline='4')
//MORE OPTIONS
colorbasis = input.bool(defval=true, title='Modify Basis Color with trend?', group='Color Settings', inline='10')
color basiscolor = input.color(color.new(color.orange, 0), '', group='Color Settings', inline='10')
colorbands = input.bool(defval=true, title='Fill Bands Color with trend?', group='Color Settings', inline='11')
filltransp = input.int(95, 'Rainbow Fill Transparency', minval=0, maxval=100, group='Color Settings', inline='4')
color regularbands = input.color(color.rgb(33, 150, 243, 95), '', group='Color Settings', inline='11')
color upband = input.color(color.new(color.red, 0), '', group='Color Settings', inline='11')
color dnband = input.color(color.new(color.green, 0), '', group='Color Settings', inline='11')
colorcandles = input.bool(defval=true, title='Alternate Colors for Band Touch?', group='Color Settings', inline='12')
color coloroverheated = input.color(color.new(color.yellow, 0), '', group='Color Settings', inline='12')
color coloroversold = input.color(color.new(color.fuchsia, 0), '', group='Color Settings', inline='12')
//BASIS
realbasis = MA(BBSource, BBPeriod, BB_type)
//PLOT
var grad = array.new_color(na)
if barstate.isfirst
array.push(grad, color.gray)
array.push(grad, #ff00ff)
array.push(grad, #ff00f7)
array.push(grad, #ff00ef)
array.push(grad, #ff00e8)
array.push(grad, #ff00e0)
array.push(grad, #ff00d8)
array.push(grad, #ff00d1)
array.push(grad, #ff00ca)
array.push(grad, #ff00c2)
array.push(grad, #ff00bb)
array.push(grad, #ff00b4)
array.push(grad, #ff00ae)
array.push(grad, #ff00a7)
array.push(grad, #ff00a1)
array.push(grad, #ff009a)
array.push(grad, #ff0094)
array.push(grad, #ff008e)
array.push(grad, #ff0088)
array.push(grad, #ff0383)
array.push(grad, #ff147d)
array.push(grad, #ff1f78)
array.push(grad, #ff2773)
array.push(grad, #ff2e6e)
array.push(grad, #ff356a)
array.push(grad, #ff3b65)
array.push(grad, #ff4061)
array.push(grad, #ff455d)
array.push(grad, #ff4959)
array.push(grad, #ff4e55)
array.push(grad, #ff5252)
array.push(grad, #ff5a4e)
array.push(grad, #ff6349)
array.push(grad, #ff6b44)
array.push(grad, #ff743f)
array.push(grad, #ff7d3a)
array.push(grad, #ff8634)
array.push(grad, #ff8f2e)
array.push(grad, #ff9827)
array.push(grad, #ffa120)
array.push(grad, #ffab17)
array.push(grad, #ffb40b)
array.push(grad, #ffbe00)
array.push(grad, #ffc700)
array.push(grad, #ffd000)
array.push(grad, #ffda00)
array.push(grad, #ffe300)
array.push(grad, #ffec00)
array.push(grad, #fff600)
array.push(grad, #ffff00)
array.push(grad, #ffff00)
array.push(grad, #eefd1d)
array.push(grad, #ddfb2d)
array.push(grad, #ccf83a)
array.push(grad, #bcf546)
array.push(grad, #adf150)
array.push(grad, #9eee59)
array.push(grad, #8fea62)
array.push(grad, #81e66a)
array.push(grad, #74e172)
array.push(grad, #66dc79)
array.push(grad, #5ad87f)
array.push(grad, #4dd385)
array.push(grad, #41cd8a)
array.push(grad, #36c88f)
array.push(grad, #2cc393)
array.push(grad, #24bd96)
array.push(grad, #1fb798)
array.push(grad, #1eb299)
array.push(grad, #21ac9a)
array.push(grad, #26a69a)
array.push(grad, #26a99d)
array.push(grad, #26aca0)
array.push(grad, #26afa3)
array.push(grad, #26b1a6)
array.push(grad, #25b4aa)
array.push(grad, #25b7ad)
array.push(grad, #25bab0)
array.push(grad, #24bdb3)
array.push(grad, #24c0b6)
array.push(grad, #24c3ba)
array.push(grad, #23c6bd)
array.push(grad, #23c9c0)
array.push(grad, #22ccc4)
array.push(grad, #21cfc7)
array.push(grad, #20d2ca)
array.push(grad, #20d5ce)
array.push(grad, #1fd8d1)
array.push(grad, #1edbd4)
array.push(grad, #1cded8)
array.push(grad, #1be1db)
array.push(grad, #1ae4df)
array.push(grad, #18e7e2)
array.push(grad, #17eae6)
array.push(grad, #15ede9)
array.push(grad, #12f0ed)
array.push(grad, #10f3f0)
array.push(grad, #0df6f4)
array.push(grad, #09f9f8)
array.push(grad, #04fcfb)
array.push(grad, #00ffff)
rsival = math.round(ta.rsi(realbasis, BBPeriod))
gradcolor = array.get(grad, rsival)
basecolor = colorbasis ? gradcolor : basiscolor
p0 = plot(realbasis, title='Bollinger Bands MA Line', color=basecolor, linewidth=1, offset=realoffset)
//Standard Deviation
stdDeviation = stdevMultiple * ta.stdev(BBSource, BBPeriod)
upperBand = if BB_type == 'Donchian'
ta.highest(BBPeriod)
else
realbasis + stdDeviation
lowerBand = if BB_type == 'Donchian'
ta.lowest(BBPeriod)
else
realbasis - stdDeviation
//bands plots
p1 = plot(upperBand, title='Upper Band', color=colorbands ? basecolor : upband, linewidth=1, offset=realoffset)
p2 = plot(lowerBand, title='Lower Band', color=colorbands ? basecolor : dnband, linewidth=1, offset=realoffset)
bollingerfill = color.new(gradcolor, filltransp)
bollingercolor = colorbands ? bollingerfill : regularbands
fill(p1, p2, color=bollingercolor, title='Bollinger Bands Fill')
//Color Candles
down = open > close
up = close > open
overheated = not down and high > upperBand
oversold = not up and low < lowerBand
iff_1 = oversold ? coloroversold : na
touchcolor = overheated ? coloroverheated : iff_1
candlecolors2 = colorcandles ? touchcolor : na
barcolor(candlecolors2, title='Band Touches')
//Alerts
alertcondition(overheated != 0, 'High Band Touch', 'High Band Touch')
alertcondition(oversold != 0, 'Low Band Touch', 'Low Band Touch') |
Rolling EMAVWAP with Standard Deviation Bands | https://www.tradingview.com/script/sU2VFlfE-Rolling-EMAVWAP-with-Standard-Deviation-Bands/ | pmk07 | https://www.tradingview.com/u/pmk07/ | 147 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pmk07
//@version=5
indicator(title='emaVWAP', overlay=true)
// Inputs
// Rolling
log_sv = input(false, title='Log space')
src_in = input (hlc3, title='Source')
src = log_sv ? math.log(src_in) : src_in
rolling_period = input(100, title='Rolling VWAP Period')
rolling_sv = input(true, title='Show Rolling VWAP')
b1_r = input.float(1.0, title='Band 1 multiplier', step=0.1)
b2_r = input.float(2.0, title='Band 2 multiplier', step=0.1)
b3_r = input.float(3.0, title='Band 3 multiplier', step=0.1)
b4_r = input.float(4.0, title='Band 4 multiplier', step=0.1)
b1_r_std_sv = input(false, title='Show Rolling VWAP STDEV Band 1')
b2_r_std_sv = input(false, title='Show Rolling VWAP STDEV Band 2')
b3_r_std_sv = input(false, title='Show Rolling VWAP STDEV Band 3')
b4_r_std_sv = input(false, title='Show Rolling VWAP STDEV Band 4')
// Calcs
xema(src, len) =>
alpha = 2 / (len + 1)
sum = 0.0
sum := alpha * src + (1 - alpha) * nz(sum[1])
sum
rVWAP(length) =>
p = xema(src * volume, length)
vol = xema(volume, length)
v = p / vol
sn = xema(volume * (src - nz(v[1])) * (src - v), length)
std = math.sqrt(sn / vol)
[v, std]
[vwap_r, std_r] = rVWAP(rolling_period)
b1_r_std_up = vwap_r + b1_r * std_r
b1_r_std_dn = vwap_r - b1_r * std_r
b2_r_std_up = vwap_r + b2_r * std_r
b2_r_std_dn = vwap_r - b2_r * std_r
b3_r_std_up = vwap_r + b3_r * std_r
b3_r_std_dn = vwap_r - b3_r * std_r
b4_r_std_up = vwap_r + b4_r * std_r
b4_r_std_dn = vwap_r - b4_r * std_r
// Plots
//VWAP
plot(rolling_sv == true ? (log_sv ? math.exp(vwap_r) : vwap_r) : na, title='Rolling VWAP', color=color.new(color.teal, 0), linewidth=1)
//BANDs
b1_r_std_up_plot = plot(b1_r_std_sv or b2_r_std_sv ? (log_sv ? math.exp(b1_r_std_up) : b1_r_std_up) : na, title='Rolling VWAP STDEV1', color=na, linewidth=1, editable=false, display=display.none)
b1_r_std_dn_plot = plot(b1_r_std_sv or b2_r_std_sv ? (log_sv ? math.exp(b1_r_std_dn) : b1_r_std_dn) : na, title='Rolling VWAP STDEV1', color=na, linewidth=1, editable=false, display=display.none)
b2_r_std_up_plot = plot(b2_r_std_sv or b3_r_std_sv ? (log_sv ? math.exp(b2_r_std_up) : b2_r_std_up) : na, title='Rolling VWAP STDEV2', color=na, linewidth=1, editable=false, display=display.none)
b2_r_std_dn_plot = plot(b2_r_std_sv or b3_r_std_sv ? (log_sv ? math.exp(b2_r_std_dn) : b2_r_std_dn) : na, title='Rolling VWAP STDEV2', color=na, linewidth=1, editable=false, display=display.none)
b3_r_std_up_plot = plot(b3_r_std_sv or b4_r_std_sv ? (log_sv ? math.exp(b3_r_std_up) : b3_r_std_up) : na, title='Rolling VWAP STDEV3', color=na, linewidth=1, editable=false, display=display.none)
b3_r_std_dn_plot = plot(b3_r_std_sv or b4_r_std_sv ? (log_sv ? math.exp(b3_r_std_dn) : b3_r_std_dn) : na, title='Rolling VWAP STDEV3', color=na, linewidth=1, editable=false, display=display.none)
b4_r_std_up_plot = plot(b4_r_std_sv ? (log_sv ? math.exp(b4_r_std_up) : b4_r_std_up) : na, title='Rolling VWAP STDEV4', color=na, linewidth=1, editable=false, display=display.none)
b4_r_std_dn_plot = plot(b4_r_std_sv ? (log_sv ? math.exp(b4_r_std_dn) : b4_r_std_dn) : na, title='Rolling VWAP STDEV4', color=na, linewidth=1, editable=false, display=display.none)
fill(b1_r_std_up_plot, b1_r_std_dn_plot, title='Rolling VWAP STDEV1', color=color.new(color.teal, 90))
fill(b2_r_std_dn_plot, b1_r_std_dn_plot, title='Rolling VWAP STDEV2', color=color.new(color.teal, 75))
fill(b3_r_std_dn_plot, b2_r_std_dn_plot, title='Rolling VWAP STDEV3', color=color.new(color.teal, 60))
fill(b4_r_std_dn_plot, b3_r_std_dn_plot, title='Rolling VWAP STDEV4', color=color.new(color.teal, 45))
fill(b2_r_std_up_plot, b1_r_std_up_plot, title='Rolling VWAP STDEV2', color=color.new(color.teal, 75))
fill(b3_r_std_up_plot, b2_r_std_up_plot, title='Rolling VWAP STDEV3', color=color.new(color.teal, 60))
fill(b4_r_std_up_plot, b3_r_std_up_plot, title='Rolling VWAP STDEV4', color=color.new(color.teal, 45))
|
Delta Barcode | https://www.tradingview.com/script/zqojfVNF-Delta-Barcode/ | RicardoSantos | https://www.tradingview.com/u/RicardoSantos/ | 152 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos
//@version=4
study("Delta Barcode", max_lines_count=110)
color c00 = input(#ffaf90)
color c01 = input(#4a148c)
int ammount_bar_lines = 100
int ammount_extra_lines = 3
int total_lines = ammount_bar_lines + ammount_extra_lines
var float[] deltas = array.new_float(ammount_bar_lines)
var line[] lines = array.new_line(total_lines)
var label la = label.new(bar_index, 0.0, '', style=label.style_circle, size=size.tiny) // label for debug
float max = 0.0
float min = 0.0
// color functions:
f_rgb_clamp(_value) => (255.0 + _value) % 255.0
f_lerp(_cola, _colb, _r) => _cola + (_colb - _cola) * _r
f_col(_i)=>color.rgb(f_rgb_clamp(f_lerp(color.r(c00), color.r(c01), _i)), f_rgb_clamp(f_lerp(color.g(c00), color.g(c01), _i)), f_rgb_clamp(f_lerp(color.b(c00), color.b(c01), _i)), 0)
// expects a sample with the deltas(distance) to mean.
f_kurtosis(_sample)=>
int _size = array.size(_sample)
float _x2 = 0.0
float _x4 = 0.0
for _i = 0 to _size-1
float _xi = array.get(_sample, _i)
_x2 += pow(_xi, 2)
_x4 += pow(_xi, 4)
(_x4 / _size) / pow(_x2 / _size, 2)
// initialize new lines once:
if barstate.isfirst
for _i = 0 to total_lines-1
_line = line.new(bar_index, 0.0, bar_index, 0.0, width=4)
array.set(lines, _i, _line)
// update new values:
if bar_index > ammount_bar_lines
// update stats:
for _i=1 to ammount_bar_lines
_delta = close-close[_i]
if _delta > max
max := _delta
if _delta < min
min := _delta
_col = f_col((_delta-min) / (max-min)) //_delta >= 0.0 ? color.green : color.maroon
array.set(deltas, _i-1, _delta)
line _line = array.get(lines, _i-1)
line.set_xy1(_line, bar_index-_i, 0.0)
line.set_xy2(_line, bar_index-_i, 1.0)
line.set_color(_line, _col)
// update drawings:
float _mean = array.avg(deltas)
float _mode = nz(array.mode(deltas), 0.0)
float _std = array.stdev(deltas)
float _skew = 0.5 + max(-0.5, min(0.5, 0.20 * ((_mean - _mode) / _std)))
float _kurt = min(1.0, abs(0.2 * ((99.0 / (98.0 * 97.0)) * (101.0 * (f_kurtosis(deltas) - 3.0) + 6.0)) ))//excess sample kurtosis
line _sline = array.get(lines, ammount_bar_lines)
line _kline_u = array.get(lines, ammount_bar_lines+1)
line _kline_l = array.get(lines, ammount_bar_lines+2)
color _skew_col = f_col(_skew)
line.set_xy1(_sline, bar_index, _skew)
line.set_xy2(_sline, bar_index+10, _skew)
line.set_width(_sline, 2)
line.set_color(_sline, _skew_col)
line.set_xy1(_kline_u, bar_index, 1 - (1.0 - _skew) * _kurt)
line.set_xy2(_kline_u, bar_index+10, _skew)
line.set_width(_kline_u, 1)
line.set_color(_kline_u, f_col(_kurt))
line.set_xy1(_kline_l, bar_index, _skew * _kurt)
line.set_xy2(_kline_l, bar_index+10, _skew)
line.set_width(_kline_l, 1)
line.set_color(_kline_l, f_col(_kurt))
label.set_xy(la, bar_index+10, _skew)
label.set_color(la, _skew_col)
label.set_tooltip(la, str.format('Skewness: {0}\nKurtosis: {1}', _skew, _kurt)) |
st_market_phase | https://www.tradingview.com/script/c2RyZiAQ-st-market-phase/ | IntelTrading | https://www.tradingview.com/u/IntelTrading/ | 131 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Alferow
//@version=4
study("st_market_phase", overlay = true)
p = input(24, title = 'period')
s = (lowest(low, p) + highest(high, p))*0.5
var t = 0
if s > s[1]
t := 1
if s < s[1]
t := 0
st = t == 1 ? s - 0.1*ema(s, p) : s + 0.1*ema(s, p)
col = st < close ? color.green : color.red
p1 = plot(close)
p2 = plot(st)
fill(p1, p2, color = col)
|
Alpha SOPR Indicator | https://www.tradingview.com/script/SgegBJr4-Alpha-SOPR-Indicator/ | mehran_khanjan | https://www.tradingview.com/u/mehran_khanjan/ | 41 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mehran_khanjan
//@version=4
study(title = 'Alpha SOPR Indicator')
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** Inputs ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
crypto_currency = input(title = 'Cryptocurrencies' , options = ['Bitcoin' , 'Ethereum' , 'Litecoin'] , defval = 'Bitcoin')
percentage_of_deviation = input(type = input.float , title = 'Percentage of Deviation' , defval = 3.0)
background_color = input(type = input.bool , title = 'Use Background for Deviation Bands' , defval = false)
use_sma = input(type = input.bool , title = 'Use Simple Moving Average Instead of Real Value' , defval = false , group = 'Simple Moving Average')
sma_length = input(type = input.integer , title = 'Simple Moving Average Length' , defval = 7 , group = 'Simple Moving Average')
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** Global Calcualtions ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
// ****************** ******************
// *
// * Get SOPR Data
// *
_symbol = crypto_currency == 'Ethereum' ? 'XTVCETH_SOPR' : crypto_currency == 'Litecoin' ? 'XTVCLTC_SOPR' : 'XTVCBTC_SOPR'
_sopr = security(_symbol, 'D', use_sma ? sma(close , sma_length) : close)
// *
// * Calculate Deviation Levels
// *
_up_level = 1 + (percentage_of_deviation / 100)
_down_level = 1 - (percentage_of_deviation / 100)
// *
// * Set Background
// *
final_background_color = background_color == false ? na : _sopr > _up_level ? color.new(color.red , 20) : _sopr < _down_level ? color.new(color.lime , 20) : na
bgcolor(final_background_color)
// *
// * Draw Lines
// *
plot(_sopr)
hline(price = 1.00, title = 'Base Line', color = #787B86) |
Trend Master | https://www.tradingview.com/script/RDcSFRg3-Trend-Master/ | Kent_RichProFit_93 | https://www.tradingview.com/u/Kent_RichProFit_93/ | 570 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Kent_RichProFit_93
//@version=5
indicator('Trend Master', overlay=false, precision=3)
//revision 1, removed Heikin Ashi candles
//revision 2, 22Nov21, convert to scripts version 5. Table size adjustable. Allow input on Trend Moving Average Length.
/////////////////////////////////
//Input
/////////////////////////////////
gr1 = 'Table'
ind = input.bool(title='Show Table', defval=true, inline='00', group=gr1)
alert = input(title='Show alerts ', defval=true,inline='00', group=gr1)
text_size = input.string(title='Table Text Size:', options=['AUTO', 'TINY', 'SMALL', 'NORMAL', 'LARGE', 'HUGE'], defval='SMALL', inline='01', group=gr1)
w = input.int(title='/ Table Width:', defval=6, minval=4, maxval=20, inline='01', group=gr1)
gr2 = 'Trend Options'
tm_op = input.string(title='Select Trend Master Options', options=['EMA', 'HMA', 'SMA', 'WMA'], defval='HMA', inline='02', group = gr2)
tm_ma_len = input.int(13, title='Trend Master Moving Average Length', tooltip='Default Model : HMA, Default Trend Moving Average Lenght = 13',minval=1, inline='02', group = gr2)
gr3 = 'Rainbows'
rb = input(title='click to show rainbow', defval=false, group=gr3)
/////////////////////////////////
//Source
/////////////////////////////////
can_src = (3 * close + 2 * open + high + low) / 7
can_ohlc4 = ohlc4
/////////////////////////////////
//Trend Master
/////////////////////////////////
TM_src = can_src
TM_ohlc4 = can_ohlc4
TM_src_MAs = tm_op == 'EMA' ? ta.ema(TM_src, 7) : tm_op == 'SMA' ? ta.sma(TM_src, 7) : tm_op == 'WMA' ? ta.wma(TM_src, 7) : tm_op == 'HMA' ? ta.hma(TM_src, 7) : na
TM = ta.linreg(TM_src_MAs, 7, 0)
TM_color = TM > TM[1] ? color.new(#39FF14, 0) : color.new(#EB4C42, 0) //color.new(#FFB7C5,0) //color.new(#EB4C42,10)
plotcandle(TM, TM, TM[1], TM[1], title='Trend Master', color=TM_color)
/////////////////////////////////
//Moving Average of Trend Master
/////////////////////////////////
sma_tm = ta.sma(TM, tm_ma_len)
plot(sma_tm, title='Moving Average of Trend Master', color=color.new(color.purple, 0))
/////////////////////////////////
//Rainbows
/////////////////////////////////
tm1e = (ta.ema(TM_ohlc4, 3) + ta.ema(TM_ohlc4, 6) + ta.ema(TM_ohlc4, 9)) / 3
tm1s = (ta.sma(TM_ohlc4, 3) + ta.sma(TM_ohlc4, 6) + ta.sma(TM_ohlc4, 9)) / 3
tm1w = (ta.wma(TM_ohlc4, 3) + ta.wma(TM_ohlc4, 6) + ta.wma(TM_ohlc4, 9)) / 3
tm1h = (ta.hma(TM_ohlc4, 3) + ta.hma(TM_ohlc4, 6) + ta.hma(TM_ohlc4, 9)) / 3
tm1 = tm_op == 'EMA' ? tm1e : tm_op == 'SMA' ? tm1s : tm_op == 'WMA' ? tm1w : tm_op == 'HMA' ? tm1h : na
ftm1 = ta.linreg(tm1, 6, 0)
ftm1_c = ftm1 >= ftm1[1] ? color.new(#39FF14, 0) : color.new(#EB4C42, 50)
plot(rb ? ftm1 : na, title='Rainbow 1', style=plot.style_cross, color=ftm1_c)
tm2e = (ta.ema(TM_ohlc4, 5) + ta.ema(TM_ohlc4, 10) + ta.ema(TM_ohlc4, 20)) / 3
tm2s = (ta.sma(TM_ohlc4, 5) + ta.sma(TM_ohlc4, 10) + ta.sma(TM_ohlc4, 20)) / 3
tm2w = (ta.wma(TM_ohlc4, 5) + ta.wma(TM_ohlc4, 10) + ta.wma(TM_ohlc4, 20)) / 3
tm2h = (ta.hma(TM_ohlc4, 5) + ta.hma(TM_ohlc4, 10) + ta.hma(TM_ohlc4, 20)) / 3
tm2 = tm_op == 'EMA' ? tm2e : tm_op == 'SMA' ? tm2s : tm_op == 'WMA' ? tm2w : tm_op == 'HMA' ? tm2h : na
ftm2 = ta.linreg(tm2, 6, 0)
ftm2_c = ftm2 >= ftm2[1] ? color.new(#39FF14, 0) : color.new(#EB4C42, 50)
ftm2_t = ftm2 >= ftm2[1] ? ftm2 : na
plot(rb ? ftm2 : na, title='Rainbow 2', style=plot.style_cross, color=ftm2_c)
tm3e = (ta.ema(TM_ohlc4, 7) + ta.ema(TM_ohlc4, 14) + ta.ema(TM_ohlc4, 28)) / 3
tm3s = (ta.sma(TM_ohlc4, 7) + ta.sma(TM_ohlc4, 14) + ta.sma(TM_ohlc4, 28)) / 3
tm3w = (ta.wma(TM_ohlc4, 7) + ta.wma(TM_ohlc4, 14) + ta.wma(TM_ohlc4, 28)) / 3
tm3h = (ta.hma(TM_ohlc4, 7) + ta.hma(TM_ohlc4, 14) + ta.hma(TM_ohlc4, 28)) / 3
tm3 = tm_op == 'EMA' ? tm3e : tm_op == 'SMA' ? tm3s : tm_op == 'WMA' ? tm3w : tm_op == 'HMA' ? tm3h : na
ftm3 = ta.linreg(tm3, 6, 0)
ftm3_c = ftm3 >= ftm3[1] ? color.new(#39FF14, 0) : color.new(#EB4C42, 50)
plot(rb ? ftm3 : na, title='Rainbow 3', style=plot.style_cross, color=ftm3_c)
tm4e = (ta.ema(TM_ohlc4, 9) + ta.ema(TM_ohlc4, 18) + ta.ema(TM_ohlc4, 36)) / 3
tm4s = (ta.sma(TM_ohlc4, 9) + ta.sma(TM_ohlc4, 18) + ta.sma(TM_ohlc4, 36)) / 3
tm4w = (ta.wma(TM_ohlc4, 9) + ta.wma(TM_ohlc4, 18) + ta.wma(TM_ohlc4, 36)) / 3
tm4h = (ta.hma(TM_ohlc4, 9) + ta.hma(TM_ohlc4, 18) + ta.hma(TM_ohlc4, 36)) / 3
tm4 = tm_op == 'EMA' ? tm4e : tm_op == 'SMA' ? tm4s : tm_op == 'WMA' ? tm4w : tm_op == 'HMA' ? tm4h : na
ftm4 = ta.linreg(tm4, 6, 0)
ftm4_c = ftm4 >= ftm4[1] ? color.new(#39FF14, 0) : color.new(#EB4C42, 50)
plot(rb ? ftm4 : na, title='Rainbow 4', style=plot.style_cross, color=ftm4_c)
tm5e = (ta.ema(TM_ohlc4, 11) + ta.ema(TM_ohlc4, 22) + ta.ema(TM_ohlc4, 44)) / 3
tm5s = (ta.sma(TM_ohlc4, 11) + ta.sma(TM_ohlc4, 22) + ta.sma(TM_ohlc4, 44)) / 3
tm5w = (ta.wma(TM_ohlc4, 11) + ta.wma(TM_ohlc4, 22) + ta.wma(TM_ohlc4, 44)) / 3
tm5h = (ta.hma(TM_ohlc4, 11) + ta.hma(TM_ohlc4, 22) + ta.hma(TM_ohlc4, 44)) / 3
tm5 = tm_op == 'EMA' ? tm5e : tm_op == 'SMA' ? tm5s : tm_op == 'WMA' ? tm5w : tm_op == 'HMA' ? tm5h : na
ftm5 = ta.linreg(tm5, 6, 0)
ftm5_c = ftm5 >= ftm5[1] ? color.new(#39FF14, 0) : color.new(#EB4C42, 50)
plot(rb ? ftm5 : na, title='Rainbow 5', style=plot.style_cross, color=ftm5_c)
tm6e = (ta.ema(TM_ohlc4, 13) + ta.ema(TM_ohlc4, 26) + ta.ema(TM_ohlc4, 52)) / 3
tm6s = (ta.sma(TM_ohlc4, 13) + ta.sma(TM_ohlc4, 26) + ta.sma(TM_ohlc4, 52)) / 3
tm6w = (ta.wma(TM_ohlc4, 13) + ta.wma(TM_ohlc4, 26) + ta.wma(TM_ohlc4, 52)) / 3
tm6h = (ta.hma(TM_ohlc4, 13) + ta.hma(TM_ohlc4, 26) + ta.hma(TM_ohlc4, 52)) / 3
tm6 = tm_op == 'EMA' ? tm6e : tm_op == 'SMA' ? tm6s : tm_op == 'WMA' ? tm6w : tm_op == 'HMA' ? tm6h : na
ftm6 = ta.linreg(tm6, 6, 0)
ftm6_c = ftm6 >= ftm6[1] ? color.new(#39FF14, 0) : color.new(#EB4C42, 50)
plot(rb ? ftm6 : na, title='Rainbow 6', style=plot.style_cross, color=ftm6_c)
tm7e = (ta.ema(TM_ohlc4, 21) + ta.ema(TM_ohlc4, 34) + ta.ema(TM_ohlc4, 68)) / 3
tm7s = (ta.sma(TM_ohlc4, 21) + ta.sma(TM_ohlc4, 34) + ta.sma(TM_ohlc4, 68)) / 3
tm7w = (ta.wma(TM_ohlc4, 21) + ta.wma(TM_ohlc4, 34) + ta.wma(TM_ohlc4, 68)) / 3
tm7h = (ta.hma(TM_ohlc4, 21) + ta.hma(TM_ohlc4, 34) + ta.hma(TM_ohlc4, 68)) / 3
tm7 = tm_op == 'EMA' ? tm7e : tm_op == 'SMA' ? tm7s : tm_op == 'WMA' ? tm7w : tm_op == 'HMA' ? tm7h : na
ftm7 = ta.linreg(tm7, 6, 0)
ftm7_c = ftm7 >= ftm7[1] ? color.new(#39FF14, 0) : color.new(#EB4C42, 50)
plot(rb ? ftm7 : na, title='Rainbow 7', style=plot.style_cross, color=ftm7_c)
/////////////////////////////////
//Alerts
/////////////////////////////////
//Turn Green or Turn Red Labels
tm_turn_t = TM[2] > TM[1] and TM > TM[1] ? 'G' : TM[2] < TM and TM < TM[1] ? 'R' : na
tm_label_c = TM[2] > TM[1] and TM > TM[1] ? color.new(color.green, 0) : TM[2] < TM and TM < TM[1] ? color.new(color.red, 0) : na
tm_yloc = TM[2] > TM[1] and TM > TM[1] ? 0.9 * TM : TM[2] < TM and TM < TM[1] ? 1.05 * TM : na
tm_turn_label = alert?label.new(bar_index, tm_yloc, style=label.style_none, text=tm_turn_t, textcolor=tm_label_c):na
/////////////////////////////////
//indicator table
var table QTable = table.new(position.middle_right, 5, 5, border_width=1)
text_1 = size.auto
if text_size == 'TINY'
text_1 := size.tiny
text_1
if text_size == 'SMALL'
text_1 := size.small
text_1
if text_size == 'NORMAL'
text_1 := size.normal
text_1
if text_size == 'LARGE'
text_1 := size.large
text_1
if text_size == 'HUGE'
text_1 := size.huge
text_1
tm_type = tm_op == 'EMA' ? 'EMA' : tm_op == 'SMA' ? 'SMA Model' : tm_op == 'WMA Modle' ? 'WMA Model' : tm_op == 'HMA' ? 'HMA Model' : na
f_fillCell_00(_table, _column, _row, _label) =>
_cellText_00 = ind ? _label : na
_cellColor_00 = ind ? color.new(color.yellow, 0) : na
table.cell(_table, _column, _row, _cellText_00, bgcolor=_cellColor_00, text_color=color.black, width=w)
table.cell_set_text_size(QTable, 0, 0, text_1)
table.cell_set_text_size(QTable, 0, 1, text_1)
if barstate.islast
f_fillCell_00(QTable, 0, 0, 'Trend Master')
f_fillCell_00(QTable, 0, 1, tm_type)
tm_t = TM[2] > TM[1] and TM > TM[1] ? 'Turn Green' : TM > TM[1] ? 'Green' : TM[2] < TM and TM < TM[1] ? 'Turn Red' : TM < TM[1] ? 'Red' : na
f_fillCell_11(_table, _column, _row, _label) =>
_cellText_11 = ind ? _label : na
_cellColor_11 = ind ? TM_color : na
table.cell(_table, _column, _row, _cellText_11, bgcolor=_cellColor_11, text_color=color.black, width=w)
table.cell_set_text_size(QTable, 0, 2, text_1)
if barstate.islast
f_fillCell_11(QTable, 0, 2, tm_t)
|
Keltner Center Of Gravity Channel ( KeltCOG ) | https://www.tradingview.com/script/vnpB6Jmq-Keltner-Center-Of-Gravity-Channel-KeltCOG/ | eykpunter | https://www.tradingview.com/u/eykpunter/ | 406 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © eykpunter
//@version=5
indicator(title='Keltner Center Of Gravity Channel', shorttitle='KeltCOG', overlay=true)
//calculate or set lookback
//inputs
jz = input.bool(title="toggle channel mode (off) supertrend mode (on)", defval=false, group='main settings')
bz = input.bool(title="show both channel and supertrend modes", defval=false, group='main settings')
zz = input.bool(title="Show outer zones combined with supertrend", defval=false, group='main settings')
nzz = not zz //condition to ditch inner zones
naz = jz or bz or zz? true: false //condition to show patches and nearby fib
az = bz or zz? true: jz? false: true //condition to show standard channel
autotttext="Script uses timeframe to set lookback - month and week: 14, day: 21, 4hour and 3hour:28, 1hour and 45min: 35, 15min: 42, 5min and 3min: 49, 1min: 56"
autowish = input.bool(title='automatic lookback adjustment to timeframe', tooltip=autotttext, defval=true, group='main settings')
per = 14 //initialize per
setper = 14 //initialize setper
tf = timeframe.period
setper := tf == 'M' ? 14 : tf == 'W' ? 14 : tf == 'D' ? 21 : tf == '240' ? 28 : tf == '180' ? 28 : tf == '120' ? 35 : tf == '60' ? 35 : tf == '45' ? 35 : tf == '30' ? 42 : tf == '15' ? 42 : tf == '5' ? 49 : tf == '3' ? 49 : tf == '1' ? 56 : 14
per := autowish ? setper : input.int(title='manual lookback when auto is off', defval=10, minval=2, group='main settings')
//calculate or set width (i.e. COG to border)
settttext="if set, script calculates multiplier as follows: 2 plus lookback/25 minus 6/lookback"
setwish = input.bool(title='automatic width multiplier adjustment to lookback period',tooltip=settttext, defval=true, group='main settings')
varwidth = 2.00 //initialize variable width
formula = math.round(2 + per / 25 - 6 / per, 1) //Script uses this formula to adapt Width (i.e COG to border) to look back period
varwidth := setwish ? formula : input.float(2.0, title='Manual width multiplier (i.e. COG to border) when auto is off', step=0.1, minval=1, group='main settings')
//activate feedback labels
feedbwish = input(title='show #lookback and width feedback label on chart', defval=true, group='labels')
centwish = input(title='show width of channel (volatility) as percent of price', defval=true, group='labels')
centshortwish = input(title='width (volatility) in ##.# % format', defval=false, group='labels')
//activate extra lines
plushiwish = input.bool(title='show extra keltner line above channel', defval=false, group='extra lines')
pluslowish = input.bool(title='show extra keltner line below channel', defval=false, group='extra lines')
hmawish = input.bool(title='show last 20 of 40 period Hull Moving Average', defval = false, group='extra lines')
//Calculate values for channel lines
dis = ta.atr(per) //Keltner channels have lines spaced by average true range
horizontal = false //Initialize horizontal boolean. New values only calculated when the COG (Center of Gravity) changes
donhigh = ta.highest(high, per) //COG calculated using values of Donchian channel
donlow = ta.lowest(low, per)
cent = (donhigh + donlow) / 2 //center line not plotted, used calculation of widthpercent
donrange = donhigh - donlow
fiblow = donlow + donrange * 0.236 //Low fibonacci line
L4 = donlow + donrange * 0.382 //coglow=donlow+donrange*0.382 //L4=Coglow Actually a Center Low fibonacci line in my donchian fibonacci channel
L3 = donlow + donrange * 0.618 //coghigh=donlow+donrange*0.618 //L3=Coghigh center high fibonacci
fibhigh = donlow + donrange * 0.764 //high fibonacci line
L2 = L3 //innerhigh=coghigh//initialize first Keltner line above COG
L1 = L3 //outerhigh=coghigh//initialize second Keltner line abvoe COG
L5 = L4 //innerlow=coglow//initialize first Keltner below COG
L6 = L4 //outerlow=coglow//initialize second Kelner below COG
outhighplus = L3 //=coghigh//initialize extra high line above COG
outlowplus = L4 //coglow//initialize extra low line below COG
horizontal := L4 == L4[1] ? true : false //coglow==coglow[1]?true: false//set horizontal COG changes result in Keltner changes, otherwize Keltner is horizontal
L2 := fibhigh //: horizontal ? L2[1] : L3 + 0.5 * dis //innerhigh:= fibwish?fibhigh: horizontal?innerhigh[1]: coghigh+0.5*dis//L2=Innerhigh set innerhigh using fibwish or horizontal as criterium
L1 := horizontal ? L1[1] : L3 + varwidth * dis //outerhigh:= horizontal?outerhigh[1]: coghigh+varwidth*dis//L1=Outerhigh
outhighplus := plushiwish ? L1 + 2 * dis : na //outerhigh+2*dis : na
L5 := fiblow //: horizontal ? L5[1] : L4 - 0.5 * dis //innerlow:= fibwish?fiblow: horizontal?innerlow[1]: coglow-0.5*dis//L5=Innerlow set innerlow using fibwish or horizontal
L6 := horizontal ? L6[1] : L4 - varwidth * dis //outerlow:= horizontal?outerlow[1]: coglow-varwidth*dis//L6=Outerlow
outlowplus := pluslowish ? L6 - 2 * dis : na //outerlow-2*dis : na
//values for extra HMA40
hma40 = hmawish? ta.hma(close, 40): na //40 period Hull Moving Average calculated when wished for
//define values for permanent lines (standard channel)
outerhigh = az? L1 : na
innerhigh = az? L2 : na
coghigh = az and nzz? L3 : na
coglow = az and nzz? L4 : na
innerlow = az? L5 : na
outerlow = az? L6 : na
//define plots of permanent lines (channel mode)
pphi = plot(outhighplus, title='extra high line', color=color.new(color.olive, 20))
pohi = plot(outerhigh, title='outerhigh', color=color.new(color.purple, 30))
pihi = plot(innerhigh, title='innerhigh', color=color.new(color.blue, 30))
pchi = plot(coghigh, title='coghigh', color=color.new(color.gray, 20))
pclo = plot(coglow, title='coglow', color=color.new(color.gray, 20))
pilo = plot(innerlow, title='innerlow', color=color.new(color.red, 30))
polo = plot(outerlow, title='outerlow', color=color.new(color.purple, 30))
pplo = plot(outlowplus, title='extra low line', color=color.new(color.olive, 20))
//define fills between permanent lines (area)
fill(pohi, pihi, title='uptrend area', color= nzz? color.new(color.blue, 70):color.new(color.blue, 90))
fill(pchi, pihi, title='look up area', color= color.new(color.green, 70))
fill(pchi, pclo, title='center area', color= color.new(color.gray, 90))
fill(pclo, pilo, title='look down area', color= color.new(color.yellow, 70))
fill(pilo, polo, title='downtrend area', color= nzz?color.new(color.red, 80): color.new(color.red,90))
//define values for patch lines (super trend mode)
CL1 = naz and high > L2 //condition to show L1 as outhi
CL2 = naz and high > L3 and low < L1 //condition to show L2 as inhi
CL3 = naz and high > L4 and low < L2 //condition to show L3 as cogbase
CL4 = naz and high > L5 and low < L3 //condition to show L4 as cogl
CL5 = naz and high > L6 and low < L4 //condition to show L5 as inlow
CL6 = naz and low < L5 //condition to show L6 as outlow
outhi = CL1 ? math.min(L1, math.max(high, high[1], high[2], high[3], high[4])) : na //patchline continues a few periods after a higher high
inhi = CL2 ? L2 : na
coghi = CL3 ? L3 : na
cogl = CL4 ? L4 : na
inlow = CL5 ? L5 : na
outlow = CL6 ? math.max(L6, math.min(low, low[1], low[2], low[3], low[4])) : na //patchline continues a few periods after a lower low
support= CL6 ? L5 : CL5 ? L5 : CL4 ? L4 : CL3 ? L3 : CL2 ? L2 : CL1 ? L2 : na //level for nearby supportive fib
resist= CL1 ? L2 : CL2 ? L2 : CL3 ? L3 : CL4 ? L4 : CL5 ? L5 : CL6 ? L5 : na //level for nearby resistive fib
//supertrend
mid = naz? hl2 : na //midle value of bar
up=mid-(varwidth*dis) //same settings as channel used
up1 = naz? nz(up[1],up) :na
up := naz? close[1] > up1 ? math.max(up,up1) : up : na
dn=mid+(varwidth*dis)
dn1 = naz? nz(dn[1], dn) :na
dn := naz? close[1] < dn1 ? math.min(dn, dn1) : dn : na
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
supres = naz? trend == 1? support: resist: na
//define plots for supertrend mode
upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
supresPlot = plot(supres, title="Support/Resistance Level", style=plot.style_stepline, linewidth=1, color=trend==1?color.lime: color.maroon)
//define fills between supertrend lines
fill(upPlot,supresPlot, title="uptrend highlighter", color=color.new(#faec6a, 75))
fill(dnPlot,supresPlot, title="downtrend highlighter", color=color.new(#db9758, 85))
//define plots of patch lines
pohir = plot(outhi, title='outhi', display=display.none)
pihir = plot(inhi, title='inhi', display=display.none)
pchir = plot(coghi, title='coghi', display=display.none)
pclor = plot(cogl, title='cogl', display=display.none)
pilor = plot(inlow, title='inlow', display=display.none)
polor = plot(outlow, title='outlow', display=display.none)
//define fills between patch lines (patches)
fill(pohir, pihir, title='go up patch', color= color.new(color.blue, 65))
fill(pchir, pihir, title='look up patch', color= color.new(color.green, 65))
fill(pchir, pclor, title='doubt patch', color= color.new(color.gray, 65))
fill(pclor, pilor, title='look down patch', color= color.new(color.orange, 65))
fill(pilor, polor, title='go down patch', color= color.new(color.red, 65))
//extra HMA40
plot(hma40, title='HMA', color=color.rgb(190,123,45,0), linewidth=3, show_last=20)
//define feedback label
var table feedback = table.new(position=position.bottom_left, columns=1, rows=2)
lbtext = autowish ? 'KeltCOG lookback = ' + str.tostring(per) + ' (script), COG to border multiplier (with ATR) ' : 'KeltCOG lookback = ' + str.tostring(per) + ' (user), COG to border multiplier (with ATR) '
witext = setwish ? str.tostring(varwidth) + ' (script)' : str.tostring(varwidth) + ' (user)'
if feedbwish == true
table.cell(feedback, row=0, column=0, text=lbtext + witext, bgcolor=color.silver)
else if feedbwish == false
table.clear(feedback, 0, 0, 0, 0)
//define width percent label
wide = L1 - L6 //outerhigh-outerlow
percent = math.round(wide / cent * 100, 1)
var table width = table.new(position=position.bottom_right, columns=1, rows=2)
petext = 'KeltCOG width (volatility measure) ' + str.tostring(percent) + ' %'
pestext = str.tostring(percent) + ' %'
if centwish == true
table.cell(width, row=0, column=0, text=centshortwish ? pestext : petext, text_color=color.black, bgcolor=color.silver, text_size=size.normal) //upper cell contains text
table.cell(width, row=1, column=0, text="|", bgcolor=color.new(color.white,100), text_color=color.new(color.white,100), text_size=size.normal) //lower cell made invisible
else if centwish == false
table.clear(width, 0, 0, 0, 0)
|
Matrix Altcoin Perpetual A-B | https://www.tradingview.com/script/vb0zYcTd/ | emreyavuz84 | https://www.tradingview.com/u/emreyavuz84/ | 26 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Implemented by © emreyavuz84
// RSI collector for Perpertual coins of A - B
//@version=5
indicator('Matrix Altcoin Perpetual A-B')
ort = input(14)
perp1 = request.security('Binance:1inchusdtperp', timeframe.period, close)
perp2 = request.security('Binance:aaveusdtperp', timeframe.period, close)
perp3 = request.security('Binance:adausdtperp', timeframe.period, close)
perp4 = request.security('Binance:akrousdtperp', timeframe.period, close)
perp5 = request.security('Binance:algousdtperp', timeframe.period, close)
perp6 = request.security('Binance:aliceusdtperp', timeframe.period, close)
perp7 = request.security('Binance:alphausdtperp', timeframe.period, close)
perp8 = request.security('Binance:ankrusdtperp', timeframe.period, close)
perp9 = request.security('Binance:atausdtperp', timeframe.period, close)
perp10 = request.security('Binance:atomusdtperp', timeframe.period, close)
perp11 = request.security('Binance:audiousdtperp', timeframe.period, close)
perp12 = request.security('Binance:avaxusdtperp', timeframe.period, close)
perp13 = request.security('Binance:axsusdtperp', timeframe.period, close)
perp14 = request.security('Binance:bakeusdtperp', timeframe.period, close)
perp15 = request.security('Binance:balusdtperp', timeframe.period, close)
perp16 = request.security('Binance:bandusdtperp', timeframe.period, close)
perp17 = request.security('Binance:batusdtperp', timeframe.period, close)
perp18 = request.security('Binance:bchusdtperp', timeframe.period, close)
perp19 = request.security('Binance:belusdtperp', timeframe.period, close)
perp20 = request.security('Binance:blzusdtperp', timeframe.period, close)
perp21 = request.security('Binance:bnbusdtperp', timeframe.period, close)
perp22 = request.security('Binance:btcusdtperp', timeframe.period, close)
perp23 = request.security('Binance:btsusdtperp', timeframe.period, close)
perp24 = request.security('Binance:1000bttcusdtperp', timeframe.period, close)
rsi1 = ta.rsi(perp1, ort)
rsi2 = ta.rsi(perp2, ort)
rsi3 = ta.rsi(perp3, ort)
rsi4 = ta.rsi(perp4, ort)
rsi5 = ta.rsi(perp5, ort)
rsi6 = ta.rsi(perp6, ort)
rsi7 = ta.rsi(perp7, ort)
rsi8 = ta.rsi(perp8, ort)
rsi9 = ta.rsi(perp9, ort)
rsi10 = ta.rsi(perp10, ort)
rsi11 = ta.rsi(perp11, ort)
rsi12 = ta.rsi(perp12, ort)
rsi13 = ta.rsi(perp13, ort)
rsi14 = ta.rsi(perp14, ort)
rsi15 = ta.rsi(perp15, ort)
rsi16 = ta.rsi(perp16, ort)
rsi17 = ta.rsi(perp17, ort)
rsi18 = ta.rsi(perp18, ort)
rsi19 = ta.rsi(perp19, ort)
rsi20 = ta.rsi(perp20, ort)
rsi21 = ta.rsi(perp21, ort)
rsi22 = ta.rsi(perp22, ort)
rsi23 = ta.rsi(perp23, ort)
rsi24 = ta.rsi(perp24, ort)
plot(rsi1, color=rsi1 >= rsi1[1] ? rsi1[1] >= rsi1[2] ? #00ff00 : #00aa00 : rsi1[1] < rsi1[2] ? #ff0000 : #aa0000, title='1INCH', transp=70)
plot(rsi2, color=rsi2 >= rsi2[1] ? rsi2[1] >= rsi2[2] ? #00ff00 : #00aa00 : rsi2[1] < rsi2[2] ? #ff0000 : #aa0000, title='AAVE', transp=70)
plot(rsi3, color=rsi3 >= rsi3[1] ? rsi3[1] >= rsi3[2] ? #00ff00 : #00aa00 : rsi3[1] < rsi3[2] ? #ff0000 : #aa0000, title='ADA', transp=70)
plot(rsi4, color=rsi4 >= rsi4[1] ? rsi4[1] >= rsi4[2] ? #00ff00 : #00aa00 : rsi4[1] < rsi4[2] ? #ff0000 : #aa0000, title='AKRO', transp=70)
plot(rsi5, color=rsi5 >= rsi5[1] ? rsi5[1] >= rsi5[2] ? #00ff00 : #00aa00 : rsi5[1] < rsi5[2] ? #ff0000 : #aa0000, title='ALGO', transp=70)
plot(rsi6, color=rsi6 >= rsi6[1] ? rsi6[1] >= rsi6[2] ? #00ff00 : #00aa00 : rsi6[1] < rsi6[2] ? #ff0000 : #aa0000, title='ALICE', transp=70)
plot(rsi7, color=rsi7 >= rsi7[1] ? rsi7[1] >= rsi7[2] ? #00ff00 : #00aa00 : rsi7[1] < rsi7[2] ? #ff0000 : #aa0000, title='ALPHA', transp=70)
plot(rsi8, color=rsi8 >= rsi8[1] ? rsi8[1] >= rsi8[2] ? #00ff00 : #00aa00 : rsi8[1] < rsi8[2] ? #ff0000 : #aa0000, title='ANKR', transp=70)
plot(rsi9, color=rsi9 >= rsi9[1] ? rsi9[1] >= rsi9[2] ? #00ff00 : #00aa00 : rsi9[1] < rsi9[2] ? #ff0000 : #aa0000, title='ATA', transp=70)
plot(rsi10, color=rsi10 >= rsi10[1] ? rsi10[1] >= rsi10[2] ? #00ff00 : #00aa00 : rsi10[1] < rsi10[2] ? #ff0000 : #aa0000, title='ATOM', transp=70)
plot(rsi11, color=rsi11 >= rsi11[1] ? rsi11[1] >= rsi11[2] ? #00ff00 : #00aa00 : rsi11[1] < rsi11[2] ? #ff0000 : #aa0000, title='AUDIO', transp=70)
plot(rsi12, color=rsi12 >= rsi12[1] ? rsi12[1] >= rsi12[2] ? #00ff00 : #00aa00 : rsi12[1] < rsi12[2] ? #ff0000 : #aa0000, title='AVAX', transp=70)
plot(rsi13, color=rsi13 >= rsi13[1] ? rsi13[1] >= rsi13[2] ? #00ff00 : #00aa00 : rsi13[1] < rsi13[2] ? #ff0000 : #aa0000, title='AXS', transp=70)
plot(rsi14, color=rsi14 >= rsi14[1] ? rsi14[1] >= rsi14[2] ? #00ff00 : #00aa00 : rsi14[1] < rsi14[2] ? #ff0000 : #aa0000, title='BAKE', transp=70)
plot(rsi15, color=rsi15 >= rsi15[1] ? rsi15[1] >= rsi15[2] ? #00ff00 : #00aa00 : rsi15[1] < rsi15[2] ? #ff0000 : #aa0000, title='BAL', transp=70)
plot(rsi16, color=rsi16 >= rsi16[1] ? rsi16[1] >= rsi16[2] ? #00ff00 : #00aa00 : rsi16[1] < rsi16[2] ? #ff0000 : #aa0000, title='BAND', transp=70)
plot(rsi17, color=rsi17 >= rsi17[1] ? rsi17[1] >= rsi17[2] ? #00ff00 : #00aa00 : rsi17[1] < rsi17[2] ? #ff0000 : #aa0000, title='BAT', transp=70)
plot(rsi18, color=rsi18 >= rsi18[1] ? rsi18[1] >= rsi18[2] ? #00ff00 : #00aa00 : rsi18[1] < rsi18[2] ? #ff0000 : #aa0000, title='BCH', transp=70)
plot(rsi19, color=rsi19 >= rsi19[1] ? rsi19[1] >= rsi19[2] ? #00ff00 : #00aa00 : rsi19[1] < rsi19[2] ? #ff0000 : #aa0000, title='BEL', transp=70)
plot(rsi20, color=rsi20 >= rsi20[1] ? rsi20[1] >= rsi20[2] ? #00ff00 : #00aa00 : rsi20[1] < rsi20[2] ? #ff0000 : #aa0000, title='BLZ', transp=70)
plot(rsi21, color=rsi21 >= rsi21[1] ? rsi21[1] >= rsi21[2] ? #00ff00 : #00aa00 : rsi21[1] < rsi21[2] ? #ff0000 : #aa0000, title='BNB', transp=70)
plot(rsi22, color=rsi22 >= rsi22[1] ? rsi22[1] >= rsi22[2] ? #00ff00 : #00aa00 : rsi22[1] < rsi22[2] ? #ff0000 : #aa0000, title='BTC', transp=70)
plot(rsi23, color=rsi23 >= rsi23[1] ? rsi23[1] >= rsi23[2] ? #00ff00 : #00aa00 : rsi23[1] < rsi23[2] ? #ff0000 : #aa0000, title='BTS', transp=70)
plot(rsi24, color=rsi24 >= rsi24[1] ? rsi24[1] >= rsi24[2] ? #00ff00 : #00aa00 : rsi24[1] < rsi24[2] ? #ff0000 : #aa0000, title='1000BTTC', transp=70)
c1 = input(color.lime, title='1INCH')
var label1 = label.new(0, rsi1, text='1inch', style=label.style_none, textalign=text.align_right, textcolor=c1, size=size.normal)
label.set_x(label1, 0)
label.set_xloc(label1, time, xloc.bar_time)
label.set_y(label1, rsi1)
c2 = input(color.white, title='AAVE')
var label2 = label.new(0, rsi2, text='aave', style=label.style_none, textalign=text.align_right, textcolor=c2, size=size.normal)
label.set_x(label2, 0)
label.set_xloc(label2, time, xloc.bar_time)
label.set_y(label2, rsi2)
c3 = input(color.gray, title='ADA')
var label3 = label.new(0, rsi3, text='ada', style=label.style_none, textalign=text.align_right, textcolor=c3, size=size.normal)
label.set_x(label3, 0)
label.set_xloc(label3, time, xloc.bar_time)
label.set_y(label3, rsi3)
c4 = input(color.gray, title='AKRO')
var label4 = label.new(0, rsi4, text='akro', style=label.style_none, textalign=text.align_right, textcolor=c4, size=size.normal)
label.set_x(label4, 0)
label.set_xloc(label4, time, xloc.bar_time)
label.set_y(label4, rsi4)
c5 = input(color.white, title='ALGO')
var label5 = label.new(0, rsi5, text='algo', style=label.style_none, textalign=text.align_right, textcolor=c5, size=size.normal)
label.set_x(label5, 0)
label.set_xloc(label5, time, xloc.bar_time)
label.set_y(label5, rsi5)
c6 = input(color.gray, title='ALICE')
var label6 = label.new(0, rsi6, text='alice', style=label.style_none, textalign=text.align_right, textcolor=c6, size=size.normal)
label.set_x(label6, 0)
label.set_xloc(label6, time, xloc.bar_time)
label.set_y(label6, rsi6)
c7 = input(color.gray, title='ALPHA')
var label7 = label.new(0, rsi7, text='alpha', style=label.style_none, textalign=text.align_right, textcolor=c7, size=size.normal)
label.set_x(label7, 0)
label.set_xloc(label7, time, xloc.bar_time)
label.set_y(label7, rsi7)
c8 = input(color.white, title='ANKR')
var label8 = label.new(0, rsi8, text='ankr', style=label.style_none, textalign=text.align_right, textcolor=c8, size=size.normal)
label.set_x(label8, 0)
label.set_xloc(label8, time, xloc.bar_time)
label.set_y(label8, rsi8)
c9 = input(color.gray, title='ATA')
var label9 = label.new(0, rsi9, text='ata', style=label.style_none, textalign=text.align_right, textcolor=color.white, size=size.normal)
label.set_x(label9, 0)
label.set_xloc(label9, time, xloc.bar_time)
label.set_y(label9, rsi9)
c10 = input(color.white, title='ATOM')
var label10 = label.new(0, rsi10, text='atom', style=label.style_none, textalign=text.align_right, textcolor=c10, size=size.normal)
label.set_x(label10, 0)
label.set_xloc(label10, time, xloc.bar_time)
label.set_y(label10, rsi10)
c11 = input(color.gray, title='AUDIO')
var label11 = label.new(0, rsi11, text='audio', style=label.style_none, textalign=text.align_right, textcolor=c11, size=size.normal)
label.set_x(label11, 0)
label.set_xloc(label11, time, xloc.bar_time)
label.set_y(label11, rsi11)
c12 = input(color.white, title='AVAX')
var label12 = label.new(0, rsi12, text='avax', style=label.style_none, textalign=text.align_right, textcolor=c12, size=size.normal)
label.set_x(label12, 0)
label.set_xloc(label12, time, xloc.bar_time)
label.set_y(label12, rsi12)
c13 = input(color.gray, title='AXS')
var label13 = label.new(0, rsi13, text='axs', style=label.style_none, textalign=text.align_right, textcolor=c13, size=size.normal)
label.set_x(label13, 0)
label.set_xloc(label13, time, xloc.bar_time)
label.set_y(label13, rsi13)
c14 = input(color.white, title='BAKE')
var label14 = label.new(0, rsi14, text='bake', style=label.style_none, textalign=text.align_right, textcolor=c14, size=size.normal)
label.set_x(label14, 0)
label.set_xloc(label14, time, xloc.bar_time)
label.set_y(label14, rsi14)
c15 = input(color.gray, title='BAL')
var label15 = label.new(0, rsi15, text='bal', style=label.style_none, textalign=text.align_right, textcolor=c15, size=size.normal)
label.set_x(label15, 0)
label.set_xloc(label15, time, xloc.bar_time)
label.set_y(label15, rsi15)
c16 = input(color.white, title='BAND')
var label16 = label.new(0, rsi16, text='band', style=label.style_none, textalign=text.align_right, textcolor=c16, size=size.normal)
label.set_x(label16, 0)
label.set_xloc(label16, time, xloc.bar_time)
label.set_y(label16, rsi16)
c17 = input(color.gray, title='BAT')
var label17 = label.new(0, rsi17, text='bat', style=label.style_none, textalign=text.align_right, textcolor=c17, size=size.normal)
label.set_x(label17, 0)
label.set_xloc(label17, time, xloc.bar_time)
label.set_y(label17, rsi17)
c18 = input(color.gray, title='BCH')
var label18 = label.new(0, rsi18, text='bch', style=label.style_none, textalign=text.align_right, textcolor=c18, size=size.normal)
label.set_x(label18, 0)
label.set_xloc(label18, time, xloc.bar_time)
label.set_y(label18, rsi18)
c19 = input(color.white, title='BEL')
var label19 = label.new(0, rsi19, text='bel', style=label.style_none, textalign=text.align_right, textcolor=c19, size=size.normal)
label.set_x(label19, 0)
label.set_xloc(label19, time, xloc.bar_time)
label.set_y(label19, rsi19)
c20 = input(color.gray, title='BLZ')
var label20 = label.new(0, rsi20, text='blz', style=label.style_none, textalign=text.align_right, textcolor=c20, size=size.normal)
label.set_x(label20, 0)
label.set_xloc(label20, time, xloc.bar_time)
label.set_y(label20, rsi20)
c21 = input(color.white, title='BNB')
var label21 = label.new(0, rsi21, text='bnb', style=label.style_none, textalign=text.align_right, textcolor=c21, size=size.normal)
label.set_x(label21, 0)
label.set_xloc(label21, time, xloc.bar_time)
label.set_y(label21, rsi21)
c22 = input(color.white, title='BTC')
var label22 = label.new(0, rsi22, text='btc', style=label.style_none, textalign=text.align_right, textcolor=c22, size=size.normal)
label.set_x(label22, 0)
label.set_xloc(label22, time, xloc.bar_time)
label.set_y(label22, rsi22)
c23 = input(color.gray, title='BTS')
var label23 = label.new(0, rsi23, text='bts', style=label.style_none, textalign=text.align_right, textcolor=c23, size=size.normal)
label.set_x(label23, 0)
label.set_xloc(label23, time, xloc.bar_time)
label.set_y(label23, rsi23)
c24 = input(color.white, title='1000BTTC')
var label24 = label.new(0, rsi24, text='bttc', style=label.style_none, textalign=text.align_right, textcolor=c24, size=size.normal)
label.set_x(label24, 0)
label.set_xloc(label24, time, xloc.bar_time)
label.set_y(label24, rsi24)
band1 = hline(70, color=#00ff00)
band0 = hline(30, color=#ff0000)
|
Posty Pivots | https://www.tradingview.com/script/w5W1XuUr-Posty-Pivots/ | Serge_Trades | https://www.tradingview.com/u/Serge_Trades/ | 1,755 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Serge_Trades
//@version=5
indicator(title='Posty Pivots', shorttitle='Posty Pivots', overlay=true)
text_R6 = 'Bullish Target 2'
text_R5 = 'Bullish Target 1'
text_R1 = 'R1'
text_R2 = 'R2'
text_R4 = 'Bear Last Stand'
text_R35 = 'Bearish Reversal High'
text_R3 = 'Bearish Reversal Low'
text_R3R35 = 'Bearish Reversal Zone'
text_S1 = 'S1'
text_S2 = 'S2'
text_S6 = 'Bearish Target 2'
text_S5 = 'Bearish Target 1'
text_S4 = 'Bull Last Stand'
text_S35 = 'Bullish Reversal Low'
text_S3 = 'Bullish Reversal High'
text_S3S35 = 'Bullish Reversal Zone'
text_TC = 'TC'
text_BC = 'BC'
text_CP = 'CP'
text_PP_Close = 'Close'
text_PP_High = 'High'
text_PP_Low = 'Low'
t_d = 'D'
t_w = 'W'
t_m = 'M'
t_q = '3M'
t_y = '12M'
t_d_lt = '1440'
tooltip_last_traded = 'Use last traded price instead of settlement price. Relevant only for daily pivots on futures.'
//***Start of local functions definiton***
draw_line(_x1, _y1, _x2, _y2, _xloc, _extend, _color, _style, _width) =>
dline = line.new(x1=_x1, y1=_y1, x2=_x2, y2=_y2, xloc=_xloc, extend=_extend, color=_color, style=_style, width=_width)
line.delete(dline[1])
draw_box(_left, _top, _right, _bottom, _color, _width, _style, _extend, _xloc, _bgcolor) =>
dbox = box.new(left=_left, top=_top, right=_right, bottom=_bottom, border_color=_color, border_width=_width, border_style=_style, extend=_extend, xloc=_xloc, bgcolor=_bgcolor)
box.delete(dbox[1])
draw_label(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor, _size, _textalign, _tooltip) =>
dlabel = label.new(x=_x, y=_y, text=_text, xloc=_xloc, yloc=_yloc, color=_color, style=_style, textcolor=_textcolor, size=_size, textalign=_textalign, tooltip=_tooltip)
label.delete(dlabel[1])
//If security is futures - replace the ticker with continuous contract
tickerid_func() =>
tickerid = syminfo.prefix + ':' + syminfo.tickerid
if syminfo.type == 'futures'
tickerid := syminfo.prefix + ':' + syminfo.root + '1!'
//Workaround to disable color management on the standard tab Style for plots
//Custom inputs for colors should be used instead
transp_func() =>
transp_0 = 0
//Timeframe to request data
t_func(t, use_last_traded) =>
t_temp = t
if use_last_traded
if t == t_d
t_temp := t_d_lt
t_temp
//***End of local functions definiton***
//***Start of Inputs
var labels_enabled = input.bool(defval=true, title='Show labels')
var t = input.string(title='Timeframe for pivots', defval=t_d, options=[t_d, t_w, t_m, t_q, t_y])
var use_last_traded = input.bool(defval=false, title='Use Last Traded Price for Close', tooltip=tooltip_last_traded)
var plot_history = input.bool(defval=true, title='Historical pivots', group='Plotting depth')
var next_period = input.bool(defval=false, title='Next period pivots', group='Plotting depth')
var lower_cams = input.bool(defval=false, title='Lower order Camarillas', group='Additional levels')
var CPR = input.bool(defval=false, title='Central Pivot Range', group='Additional levels')
var pp_hlc = input.bool(defval=false, title='Posty Pivots H/L/C', group='Additional levels')
var color_R6 = input.color(defval=color.new(color.green,0), title=text_R6, group='Colors')
var color_R5 = input.color(defval=color.new(color.green,0), title=text_R5, group='Colors')
var color_R4 = input.color(defval=color.new(color.green,0), title=text_R4, group='Colors')
var color_R35 = input.color(defval=color.new(color.red,80), title=text_R3R35, group='Colors')
var color_R2 = input.color(defval=color.new(color.olive,0), title=text_R2, group='Colors')
var color_R1 = input.color(defval=color.new(color.orange,0), title=text_R1, group='Colors')
var color_S6 = input.color(defval=color.new(color.red,0), title=text_S6, group='Colors')
var color_S5 = input.color(defval=color.new(color.red,0), title=text_S5, group='Colors')
var color_S4 = input.color(defval=color.new(color.red,0), title=text_S4, group='Colors')
var color_S35 = input.color(defval=color.new(color.green,80), title=text_S3S35, group='Colors')
var color_S2 = input.color(defval=color.new(color.olive,0), title=text_S2, group='Colors')
var color_S1 = input.color(defval=color.new(color.orange,0), title=text_S1, group='Colors')
var color_CP = input.color(defval=color.new(color.purple,95), title='Central Pivot Range', group='Colors')
var color_close = input.color(defval=color.new(#00C0FF,0), title=text_PP_Close, group='Colors')
var color_high = input.color(defval=color.new(#00C0FF,0), title=text_PP_High, group='Colors')
var color_low = input.color(defval=color.new(#00C0FF,0), title=text_PP_Low, group='Colors')
//***End of Inputs
//Get data
shigh = request.security(tickerid_func(), t_func(t, use_last_traded), high[1], barmerge.gaps_off, barmerge.lookahead_on)
slow = request.security(tickerid_func(), t_func(t, use_last_traded), low[1], barmerge.gaps_off, barmerge.lookahead_on)
sclose = request.security(tickerid_func(), t_func(t, use_last_traded), close[1], barmerge.gaps_off, barmerge.lookahead_on)
start_time = request.security(tickerid_func(), t_func(t, use_last_traded), time_close[1], barmerge.gaps_off, barmerge.lookahead_on)
r = shigh - slow
//Get next period data
n_shigh = request.security(tickerid_func(), t_func(t, use_last_traded), high[0], barmerge.gaps_off, barmerge.lookahead_on)
n_slow = request.security(tickerid_func(), t_func(t, use_last_traded), low[0], barmerge.gaps_off, barmerge.lookahead_on)
n_sclose = request.security(tickerid_func(), t_func(t, use_last_traded), close[0], barmerge.gaps_off, barmerge.lookahead_on)
n_r = n_shigh - n_slow
//Calculate time coordinates for the next period plot
n_last_close = request.security(tickerid_func(), t_func(t, use_last_traded), time_close[1], barmerge.gaps_off, barmerge.lookahead_on)
n_last_open = request.security(tickerid_func(), t_func(t, use_last_traded), time_close[2], barmerge.gaps_off, barmerge.lookahead_on)
n_duration = n_last_close - n_last_open
n_next_open = n_last_close + n_duration
n_next_close = n_next_open + 3 * 86400000
//Calculate pivots
R6 = shigh / slow * sclose //Bull target 2
R4 = sclose + r * (1.1 / 2) //Bear Last Stand
R3 = sclose + r * (1.1 / 4) //Bear Reversal Low
R5 = R4 + 1.168 * (R4 - R3) //Bull Target 1
R35 = R4 - (R4 - R3) / 2 //Bear Reversal High
R2 = sclose + r * (1.1 / 6)
R1 = sclose + r * (1.1 / 12)
S1 = sclose - r * (1.1 / 12)
S2 = sclose - r * (1.1 / 6)
S3 = sclose - r * (1.1 / 4) //Bull Reversal High
S4 = sclose - r * (1.1 / 2) //Bull Last Stand
S6 = sclose - (R6 - sclose) //Bear Target 2
S35 = S3 - (S3 - S4) / 2 //Bull Reversal Low
S5 = S4 - 1.168 * (S3 - S4) //Bear Target 1
//Calculate CPR
CP = (shigh + slow + sclose) / 3
BC = (shigh + slow) / 2
TC = CP - BC + CP
//Calculate next period pivots
n_R6 = n_shigh / n_slow * n_sclose //Bull target 2
n_R4 = n_sclose + n_r * (1.1 / 2) //Bear Last Stand
n_R3 = n_sclose + n_r * (1.1 / 4) //Bear Reversal Low
n_R5 = n_R4 + 1.168 * (n_R4 - n_R3) //Bull Target 1
n_R35 = n_R4 - (n_R4 - n_R3) / 2 //Bear Reversal High
n_R2 = n_sclose + n_r * (1.1 / 6)
n_R1 = n_sclose + n_r * (1.1 / 12)
n_S1 = n_sclose - n_r * (1.1 / 12)
n_S2 = n_sclose - n_r * (1.1 / 6)
n_S3 = n_sclose - n_r * (1.1 / 4) //Bull Reversal High
n_S4 = n_sclose - n_r * (1.1 / 2) //Bull Last Stand
n_S6 = n_sclose - (n_R6 - n_sclose) //Bear Target 2
n_S35 = n_S3 - (n_S3 - n_S4) / 2 //Bull Reversal Low
n_S5 = n_S4 - 1.168 * (n_S3 - n_S4) //Bear Target 1
//Calculate next period CPR
n_CP = (n_shigh + n_slow + n_sclose) / 3
n_BC = (n_shigh + n_slow) / 2
n_TC = n_CP - n_BC + n_CP
float _R1 = na
float _R2 = na
float _R6 = na
float _R5 = na
float _R4 = na
float _R35 = na
float _R3 = na
float _S3 = na
float _S35 = na
float _S4 = na
float _S5 = na
float _S6 = na
float _S1 = na
float _S2 = na
float _TC = na
float _CP = na
float _BC = na
float _PP_H = na
float _PP_L = na
float _PP_C = na
//*********************
//***Start of plotting*
//Decide if we can show the chart:
//Daily levels should be visible on intraday chart only,
//Weekly levels should be visible on daily chart and lower,
//And so on...
var show_chart = false
if timeframe.isintraday
show_chart := true
else if timeframe.isdaily
show_chart := switch t
t_w => true
t_m => true
t_q => true
t_y => true
else if timeframe.isweekly
show_chart := switch t
t_m => true
t_q => true
t_y => true
else if timeframe.ismonthly
if timeframe.period == t_m
show_chart := switch t
t_q => true
t_y => true
else if timeframe.period == t_q and t == t_y
show_chart := true
if show_chart == false
runtime.error("Pivots timeframe is too low for this chart. Please lower the chart's resolution or choose higher timeframe for the pivots.")
//Plot all days
if show_chart and plot_history
_R6 := R6
_R5 := R5
_R4 := R4
_R35 := R35
_R3 := R3
_S3 := S3
_S35 := S35
_S4 := S4
_S5 := S5
_S6 := S6
if show_chart and plot_history and lower_cams
_S1 := S1
_S2 := S2
_R1 := R1
_R2 := R2
if show_chart and plot_history and CPR
_TC := TC
_CP := CP
_BC := BC
if show_chart and plot_history and pp_hlc
_PP_C := sclose
_PP_H := shigh
_PP_L := slow
//Bull (R levels)
plot(_R6, title=text_R6, color=color_R6, linewidth=1) //Bull target 2
plot(_R5, title=text_R5, color=color_R5, linewidth=1) //Bull Target 1
plot(_R4, title=text_R4, color=color_R4, linewidth=2) //Bear Last Stand
plot_R35 = plot(_R35, title=text_R35, color=color.new(color_R35,transp_func()), linewidth=1)
plot_R3 = plot(_R3, title=text_R3, color=color.new(color_R35,transp_func()), linewidth=1)
fill(plot_R35, plot_R3, color_R35, title=text_R3R35) //Bear Reversal Zone
plot(_R1, title=text_R1, color=color_R1, linewidth=1) //R1
plot(_R2, title=text_R2, color=color_R2, linewidth=1) //R2
//Bear (S levels)
plot_S3 = plot(_S3, title=text_S3, color=color.new(color_S35,transp_func()), linewidth=1)
plot_S35 = plot(_S35, title=text_S35, color=color.new(color_S35,transp_func()), linewidth=1)
fill(plot_S3, plot_S35, color_S35, title=text_S3S35) //Bull Reversal Zone
plot(_S4, title=text_S4, color=color_S4, linewidth=2) //Bull Last Stand
plot(_S5, title=text_S5, color=color_S5, linewidth=1) //Bear Target 1
plot(_S6, title=text_S6, color=color_S6, linewidth=1) //Bear Target 2
plot(_S1, title=text_S1, color=color_S1, linewidth=1) //S1
plot(_S2, title=text_S2, color=color_S2, linewidth=1) //S2
//CPR
plot(_CP, title=text_CP, color=color.new(color_CP,transp_func()), linewidth=2)
plotBC = plot(_BC, title=text_BC, color=color.new(color_CP,transp_func()), linewidth=1)
plotTC = plot(_TC, title=text_TC, color=color.new(color_CP,transp_func()), linewidth=1)
fill(plotBC, plotTC, color_CP, title='CPR')
//PP HLC
plot(_PP_C, title=text_PP_Close, color=color_close, linewidth=1)
plot(_PP_H, title=text_PP_High, color=color_high, linewidth=1)
plot(_PP_L, title=text_PP_Low, color=color_low, linewidth=1)
////Plot today only
if show_chart and not plot_history
draw_line(start_time, R6, time, R6, xloc.bar_time, extend.none, color_R6, line.style_solid, 1) //Bull target 2
draw_line(start_time, R5, time, R5, xloc.bar_time, extend.none, color_R5, line.style_solid, 1) //Bull Target 1
draw_line(start_time, R4, time, R4, xloc.bar_time, extend.none, color_R4, line.style_solid, 2) //Bear Last Stand
draw_line(start_time, R3, time, R3, xloc.bar_time, extend.none, color.new(color_R35,transp_func()), line.style_solid, 1) //Bear Reversal Low
draw_line(start_time, R35, time, R35, xloc.bar_time, extend.none, color.new(color_R35,transp_func()), line.style_solid, 1) //Bear Reversal High
draw_box(start_time, R35, time, R3, color.new(color_R35,100), 1, line.style_solid, extend.none, xloc.bar_time, color_R35) //Bear Reversal Zone
draw_line(start_time, S3, time, S3, xloc.bar_time, extend.none, color.new(color_S35,transp_func()), line.style_solid, 1) //Bull Reversal Low
draw_line(start_time, S35, time, S35, xloc.bar_time, extend.none, color.new(color_S35,transp_func()), line.style_solid, 1) //Bull Reversal High
draw_box(start_time, S3, time, S35, color.new(color_S35,100), 1, line.style_solid, extend.none, xloc.bar_time, color_S35) //Bull Reversal Zone
draw_line(start_time, S4, time, S4, xloc.bar_time, extend.none, color_S4, line.style_solid, 2) //Bull Last Stand
draw_line(start_time, S5, time, S5, xloc.bar_time, extend.none, color_S5, line.style_solid, 1) //Bear Target 1
draw_line(start_time, S6, time, S6, xloc.bar_time, extend.none, color_S6, line.style_solid, 1) //Bear Target 2
if show_chart and not plot_history and lower_cams //Lower order Canmarillas
draw_line(start_time, R1, time, R1, xloc.bar_time, extend.none, color_R1, line.style_solid, 1) //R1
draw_line(start_time, R2, time, R2, xloc.bar_time, extend.none, color_R2, line.style_solid, 1) //R2
draw_line(start_time, S1, time, S1, xloc.bar_time, extend.none, color_S1, line.style_solid, 1) //R1
draw_line(start_time, S2, time, S2, xloc.bar_time, extend.none, color_S2, line.style_solid, 1) //R2
if show_chart and not plot_history and CPR //CPR
draw_box(start_time, BC, time, TC, color.new(color_CP,100), 1, line.style_solid, extend.none, xloc.bar_time, color_CP) //Central Pivot Range
draw_line(start_time, CP, time, CP, xloc.bar_time, extend.none, color.new(color_CP,transp_func()), line.style_solid, 2) //Central Pivot
draw_line(start_time, BC, time, BC, xloc.bar_time, extend.none, color.new(color_CP,transp_func()), line.style_solid, 1) //Bottom Channel
draw_line(start_time, TC, time, TC, xloc.bar_time, extend.none, color.new(color_CP,transp_func()), line.style_solid, 1) //Top Channel
if show_chart and not plot_history and pp_hlc //PP High Low Close
draw_line(start_time, sclose, time, sclose, xloc.bar_time, extend.none, color_close, line.style_solid, 1) //PP Close
draw_line(start_time, shigh, time, shigh, xloc.bar_time, extend.none, color_high, line.style_solid, 1) //PP High
draw_line(start_time, slow, time, slow, xloc.bar_time, extend.none, color_low, line.style_solid, 1) //PP Low
////Plot next period
if show_chart and next_period
draw_line(n_next_open, n_R6, n_next_close, n_R6, xloc.bar_time, extend.none, color_R6, line.style_solid, 1) //Bull target 2
draw_line(n_next_open, n_R5, n_next_close, n_R5, xloc.bar_time, extend.none, color_R5, line.style_solid, 1) //Bull Target 1
draw_line(n_next_open, n_R4, n_next_close, n_R4, xloc.bar_time, extend.none, color_R4, line.style_solid, 2) //Bear Last Stand
draw_line(n_next_open, n_R3, n_next_close, n_R3, xloc.bar_time, extend.none, color.new(color_R35,transp_func()), line.style_solid, 1) //Bear Reversal Low
draw_line(n_next_open, n_R35, n_next_close, n_R35, xloc.bar_time, extend.none, color.new(color_R35,transp_func()), line.style_solid, 1) //Bear Reversal High
draw_box(n_next_open, n_R35, n_next_close, n_R3, color.new(color_R35,100), 1, line.style_solid, extend.none, xloc.bar_time, color_R35) //Bear Reversal Zone
draw_line(n_next_open, n_S3, n_next_close, n_S3, xloc.bar_time, extend.none, color.new(color_S35,transp_func()), line.style_solid, 1) //Bull Reversal Low
draw_line(n_next_open, n_S35, n_next_close, n_S35, xloc.bar_time, extend.none, color.new(color_S35,transp_func()), line.style_solid, 1) //Bull Reversal High
draw_box(n_next_open, n_S3, n_next_close, n_S35, color.new(color_S35,100), 1, line.style_solid, extend.none, xloc.bar_time, color_S35) //Bull Reversal Zone
draw_line(n_next_open, n_S4, n_next_close, n_S4, xloc.bar_time, extend.none, color_S4, line.style_solid, 2) //Bull Last Stand
draw_line(n_next_open, n_S5, n_next_close, n_S5, xloc.bar_time, extend.none, color_S5, line.style_solid, 1) //Bear Target 1
draw_line(n_next_open, n_S6, n_next_close, n_S6, xloc.bar_time, extend.none, color_S6, line.style_solid, 1) //Bear Target 2
if show_chart and next_period and lower_cams //Lower order Canmarillas
draw_line(n_next_open, n_R1, n_next_close, n_R1, xloc.bar_time, extend.none, color_R1, line.style_solid, 1) //R1
draw_line(n_next_open, n_R2, n_next_close, n_R2, xloc.bar_time, extend.none, color_R2, line.style_solid, 1) //R2
draw_line(n_next_open, n_S1, n_next_close, n_S1, xloc.bar_time, extend.none, color_S1, line.style_solid, 1) //R1
draw_line(n_next_open, n_S2, n_next_close, n_S2, xloc.bar_time, extend.none, color_S2, line.style_solid, 1) //R2
if show_chart and next_period and CPR //CPR
draw_box(n_next_open, n_BC, n_next_close, n_TC, color.new(color_CP,100), 1, line.style_solid, extend.none, xloc.bar_time, color_CP) //Central Pivot Range
draw_line(n_next_open, n_CP, n_next_close, n_CP, xloc.bar_time, extend.none, color.new(color_CP,transp_func()), line.style_solid, 2) //Central Pivot
draw_line(n_next_open, n_BC, n_next_close, n_BC, xloc.bar_time, extend.none, color.new(color_CP,transp_func()), line.style_solid, 1) //Bottom Channel
draw_line(n_next_open, n_TC, n_next_close, n_TC, xloc.bar_time, extend.none, color.new(color_CP,transp_func()), line.style_solid, 1) //Top Channel
if show_chart and next_period and pp_hlc //PP High Low Close
draw_line(n_next_open, n_sclose, n_next_close, n_sclose, xloc.bar_time, extend.none, color_close, line.style_solid, 1) //PP Close
draw_line(n_next_open, n_shigh, n_next_close, n_shigh, xloc.bar_time, extend.none, color_high, line.style_solid, 1) //PP High
draw_line(n_next_open, n_slow, n_next_close, n_slow, xloc.bar_time, extend.none, color_low, line.style_solid, 1) //PP Low
//***End of plotting***
//*********************
//*********************
//***Start of Labels***
label_R1 = ''
label_R2 = ''
label_R6 = ''
label_R5 = ''
label_R4 = ''
label_R3 = ''
label_R35 = ''
label_S6 = ''
label_S5 = ''
label_S4 = ''
label_S3 = ''
label_S35 = ''
label_S1 = ''
label_S2 = ''
label_TC = ''
label_CP = ''
label_BC = ''
label_PPC = ''
label_PPH = ''
label_PPL = ''
//Convert 3M/12M to Q/Y, 24H to D for labels
label_t = t + ' '
if t == t_q
label_t := 'Q '
else if t == t_y
label_t := 'Y '
else if t == t_d_lt
label_t := 'D '
if labels_enabled == true and not next_period
label_R1 := str.tostring(math.round_to_mintick(R1))
label_R2 := str.tostring(math.round_to_mintick(R2))
label_R6 := str.tostring(math.round_to_mintick(R6))
label_R5 := str.tostring(math.round_to_mintick(R5))
label_R4 := str.tostring(math.round_to_mintick(R4))
label_R35 := str.tostring(math.round_to_mintick(R35))
label_R3 := str.tostring(math.round_to_mintick(R3))
label_S6 := str.tostring(math.round_to_mintick(S6))
label_S5 := str.tostring(math.round_to_mintick(S5))
label_S4 := str.tostring(math.round_to_mintick(S4))
label_S35 := str.tostring(math.round_to_mintick(S35))
label_S3 := str.tostring(math.round_to_mintick(S3))
label_S1 := str.tostring(math.round_to_mintick(S1))
label_S2 := str.tostring(math.round_to_mintick(S2))
label_TC := str.tostring(math.round_to_mintick(TC))
label_CP := str.tostring(math.round_to_mintick(CP))
label_BC := str.tostring(math.round_to_mintick(BC))
label_PPC := str.tostring(sclose)
label_PPH := str.tostring(shigh)
label_PPL := str.tostring(slow)
else if labels_enabled == true and next_period
label_R1 := str.tostring(math.round_to_mintick(n_R1))
label_R2 := str.tostring(math.round_to_mintick(n_R2))
label_R6 := str.tostring(math.round_to_mintick(n_R6))
label_R5 := str.tostring(math.round_to_mintick(n_R5))
label_R4 := str.tostring(math.round_to_mintick(n_R4))
label_R35 := str.tostring(math.round_to_mintick(n_R35))
label_R3 := str.tostring(math.round_to_mintick(n_R3))
label_S6 := str.tostring(math.round_to_mintick(n_S6))
label_S5 := str.tostring(math.round_to_mintick(n_S5))
label_S4 := str.tostring(math.round_to_mintick(n_S4))
label_S35 := str.tostring(math.round_to_mintick(n_S35))
label_S3 := str.tostring(math.round_to_mintick(n_S3))
label_S1 := str.tostring(math.round_to_mintick(n_S1))
label_S2 := str.tostring(math.round_to_mintick(n_S2))
label_TC := str.tostring(math.round_to_mintick(n_TC))
label_CP := str.tostring(math.round_to_mintick(n_CP))
label_BC := str.tostring(math.round_to_mintick(n_BC))
label_PPC := str.tostring(n_sclose)
label_PPH := str.tostring(n_shigh)
label_PPL := str.tostring(n_slow)
string_R2 = ' (' + label_R2 + ')'
string_R1 = ' (' + label_R1 + ')'
string_R6 = ' (' + label_R6 + ')'
string_R5 = ' (' + label_R5 + ')'
string_R4 = ' (' + label_R4 + ')'
string_R3R35 = ' (' + label_R3 + ' - ' + label_R35 + ')'
string_S6 = ' (' + label_S6 + ')'
string_S5 = ' (' + label_S5 + ')'
string_S4 = ' (' + label_S4 + ')'
string_S3S35 = ' (' + label_S3 + ' - ' + label_S35 + ')'
string_S1 = ' (' + label_S1 + ')'
string_S2 = ' (' + label_S2 + ')'
string_TC = ' (' + label_TC + ')'
string_CP = ' (' + label_CP + ')'
string_BC = ' (' + label_BC + ')'
string_PPC = ' (' + label_PPC + ')'
string_PPH = ' (' + label_PPH + ')'
string_PPL = ' (' + label_PPL + ')'
//This period labels
if show_chart and labels_enabled == true and not next_period
draw_label(bar_index, R6, label_t + text_R6 + string_R6, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R6,transp_func()), size.normal, text.align_left, '') //Bull target 2
draw_label(bar_index, R5, label_t + text_R5 + string_R5, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R5,transp_func()), size.normal, text.align_left, '') //Bull Target 1
draw_label(bar_index, R4, label_t + text_R4 + string_R4, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R4,transp_func()), size.normal, text.align_left, '') //Bear Last Stand
draw_label(bar_index, R3 + (R35 - R3) / 2, label_t + text_R3R35 + string_R3R35, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R35,transp_func()), size.normal, text.align_left, '') //Bear Reversal Zone
draw_label(bar_index, S3 - (S3 - S35) / 2, label_t + text_S3S35 + string_S3S35, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S35,transp_func()), size.normal, text.align_left, '') //Bull Reversal Zone
draw_label(bar_index, S4, label_t + text_S4 + string_S4, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S4,transp_func()), size.normal, text.align_left, '') //Bull Last Stand
draw_label(bar_index, S5, label_t + text_S5 + string_S5, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S5,transp_func()), size.normal, text.align_left, '') //Bear Target 1
draw_label(bar_index, S6, label_t + text_S6 + string_S6, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S6,transp_func()), size.normal, text.align_left, '') //Bear Target 2
if show_chart and labels_enabled == true and lower_cams and not next_period
draw_label(bar_index, S1, label_t + text_S1 + string_S1, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S1,transp_func()), size.normal, text.align_left, '') //S1
draw_label(bar_index, S2, label_t + text_S2 + string_S2, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S2,transp_func()), size.normal, text.align_left, '') //S2
draw_label(bar_index, R1, label_t + text_R1 + string_R1, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R1,transp_func()), size.normal, text.align_left, '') //R1
draw_label(bar_index, R2, label_t + text_R2 + string_R2, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R2,transp_func()), size.normal, text.align_left, '') //R2
if show_chart and labels_enabled == true and CPR and not next_period
draw_label(bar_index, TC, label_t + text_TC + string_TC, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_CP,transp_func()), size.normal, text.align_left, '') //TC
draw_label(bar_index, BC, label_t + text_BC + string_BC, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_CP,transp_func()), size.normal, text.align_left, '') //BC
draw_label(bar_index, CP, label_t + text_CP + string_CP, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_CP,transp_func()), size.normal, text.align_left, '') //CP
if show_chart and labels_enabled == true and pp_hlc and not next_period
draw_label(bar_index, sclose, label_t + text_PP_Close + string_PPC, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_close,transp_func()), size.normal, text.align_left, '') //PP Close
draw_label(bar_index, shigh, label_t + text_PP_High + string_PPH, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_high,transp_func()), size.normal, text.align_left, '') //PP High
draw_label(bar_index, slow, label_t + text_PP_Low + string_PPL, xloc.bar_index, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_low,transp_func()), size.normal, text.align_left, '') //PP Low
//Next period labels
if show_chart and labels_enabled == true and next_period
draw_label(n_next_close, n_R6, label_t + text_R6 + string_R6, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R6,transp_func()), size.normal, text.align_left, '') //Bull target 2
draw_label(n_next_close, n_R5, label_t + text_R5 + string_R5, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R5,transp_func()), size.normal, text.align_left, '') //Bull Target 1
draw_label(n_next_close, n_R4, label_t + text_R4 + string_R4, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R4,transp_func()), size.normal, text.align_left, '') //Bear Last Stand
draw_label(n_next_close, n_R3 + (n_R35 - n_R3) / 2, label_t + text_R3R35 + string_R3R35, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R35,transp_func()), size.normal, text.align_left, '') //Bear Reversal Zone
draw_label(n_next_close, n_S3 - (n_S3 - n_S35) / 2, label_t + text_S3S35 + string_S3S35, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S35,transp_func()), size.normal, text.align_left, '') //Bull Reversal Zone
draw_label(n_next_close, n_S4, label_t + text_S4 + string_S4, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S4,transp_func()), size.normal, text.align_left, '') //Bull Last Stand
draw_label(n_next_close, n_S5, label_t + text_S5 + string_S5, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S5,transp_func()), size.normal, text.align_left, '') //Bear Target 1
draw_label(n_next_close, n_S6, label_t + text_S6 + string_S6, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S6,transp_func()), size.normal, text.align_left, '') //Bear Target 2
if show_chart and labels_enabled == true and lower_cams and next_period
draw_label(n_next_close, n_S1, label_t + text_S1 + string_S1, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S1,transp_func()), size.normal, text.align_left, '') //S1
draw_label(n_next_close, n_S2, label_t + text_S2 + string_S2, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_S2,transp_func()), size.normal, text.align_left, '') //S2
draw_label(n_next_close, n_R1, label_t + text_R1 + string_R1, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R1,transp_func()), size.normal, text.align_left, '') //R1
draw_label(n_next_close, n_R2, label_t + text_R2 + string_R2, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_R2,transp_func()), size.normal, text.align_left, '') //R2
if show_chart and labels_enabled == true and CPR and next_period
draw_label(n_next_close, n_TC, label_t + text_TC + string_TC, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_CP,transp_func()), size.normal, text.align_left, '') //TC
draw_label(n_next_close, n_BC, label_t + text_BC + string_BC, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_CP,transp_func()), size.normal, text.align_left, '') //BC
draw_label(n_next_close, n_CP, label_t + text_CP + string_CP, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_CP,transp_func()), size.normal, text.align_left, '') //CP
if show_chart and labels_enabled == true and pp_hlc and next_period
draw_label(n_next_close, n_sclose, label_t + text_PP_Close + string_PPC, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_close,transp_func()), size.normal, text.align_left, '') //PP Close
draw_label(n_next_close, n_shigh, label_t + text_PP_High + string_PPH, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_high,transp_func()), size.normal, text.align_left, '') //PP High
draw_label(n_next_close, n_slow, label_t + text_PP_Low + string_PPL, xloc.bar_time, yloc.price, color.new(color.white, 100), label.style_label_left, color.new(color_low,transp_func()), size.normal, text.align_left, '') //PP Low
//***End of Labels*****
//*********************
|
Colored RS(Relative Strength) | https://www.tradingview.com/script/Q4IzuqJW-Colored-RS-Relative-Strength/ | akhileshsaipangallu | https://www.tradingview.com/u/akhileshsaipangallu/ | 18 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © akhileshsaipangallu
//@version=4
study("Colored RS(Relative Strength)")
period_length = input(55, type=input.integer, minval=1, title="Period Length")
rs_ema_length = input(14, type=input.integer, minval=1, title="RS EMA length")
benchmark_index_input = input("NSE:NIFTY", type=input.symbol, title="Benchmark Index")
benchmark_index = security(benchmark_index_input, timeframe.period, close)
rs = ((close / close[period_length]) / (benchmark_index / benchmark_index[period_length])) - 1
// green
long_condition = (rs > 0) and (benchmark_index > benchmark_index[period_length])
// red
short_condition =(rs < 0) and (benchmark_index < benchmark_index[period_length])
// blue
strength_condition = (rs > 0) and (benchmark_index < benchmark_index[period_length])
// yellow
weak_condition = (rs < 0) and (benchmark_index > benchmark_index[period_length])
hline(0, color=color.black)
plot_color = long_condition ? color.green : short_condition ? color.red : weak_condition ? color.yellow : strength_condition ? color.blue : color.white
plot(series=rs, title="RS 55", color=color.black, linewidth=1)
bgcolor(plot_color, transp=45)
rs_ema = ema(rs, rs_ema_length)
plot(series=rs_ema, title="RS EMA", color=color.orange, linewidth=1)
|
Zigzag Trend/Divergence Detector | https://www.tradingview.com/script/vnzbp63L-Zigzag-Trend-Divergence-Detector/ | Trendoscope | https://www.tradingview.com/u/Trendoscope/ | 4,972 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed
// __ __ __ __ __ __ __ __ __ __ __ _______ __ __ __
// / | / | / | _ / |/ | / \ / | / | / \ / | / | / \ / \ / | / |
// $$ | $$ | ______ $$ | / \ $$ |$$ |____ ______ $$ \ /$$ | __ __ _______ _$$ |_ $$ \ $$ | ______ _$$ |_ $$$$$$$ | ______ $$ \ $$ | ______ _____ ____ ______ ____$$ |
// $$ |__$$ | / \ $$ |/$ \$$ |$$ \ / \ $$$ \ /$$$ |/ | / | / |/ $$ | $$$ \$$ | / \ / $$ | $$ |__$$ | / \ $$$ \$$ | / \ / \/ \ / \ / $$ |
// $$ $$ |/$$$$$$ |$$ /$$$ $$ |$$$$$$$ |/$$$$$$ |$$$$ /$$$$ |$$ | $$ |/$$$$$$$/ $$$$$$/ $$$$ $$ |/$$$$$$ |$$$$$$/ $$ $$< /$$$$$$ |$$$$ $$ | $$$$$$ |$$$$$$ $$$$ |/$$$$$$ |/$$$$$$$ |
// $$$$$$$$ |$$ $$ |$$ $$/$$ $$ |$$ | $$ |$$ | $$ |$$ $$ $$/$$ |$$ | $$ |$$ \ $$ | __ $$ $$ $$ |$$ | $$ | $$ | __ $$$$$$$ |$$ $$ |$$ $$ $$ | / $$ |$$ | $$ | $$ |$$ $$ |$$ | $$ |
// $$ | $$ |$$$$$$$$/ $$$$/ $$$$ |$$ | $$ |$$ \__$$ |$$ |$$$/ $$ |$$ \__$$ | $$$$$$ | $$ |/ |$$ |$$$$ |$$ \__$$ | $$ |/ |$$ |__$$ |$$$$$$$$/ $$ |$$$$ |/$$$$$$$ |$$ | $$ | $$ |$$$$$$$$/ $$ \__$$ |
// $$ | $$ |$$ |$$$/ $$$ |$$ | $$ |$$ $$/ $$ | $/ $$ |$$ $$/ / $$/ $$ $$/ $$ | $$$ |$$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$$ |$$ $$ |$$ | $$ | $$ |$$ |$$ $$ |
// $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ $$$$$$$/ $$$$/ $$/ $$/ $$$$$$/ $$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$$$$/
//
//
//
//@version=5
indicator('Zigzag Trend/Divergence Detector', shorttitle='Zigzag-Trend-Divergence', overlay=true, max_bars_back=1000, max_lines_count=500, max_labels_count=500)
useClosePrices = input.bool(true, title='Close Prices', group='Zigzag', inline='price')
waitForConfirmation = input.bool(false, title='Confirmed Pivots', group='Zigzag', inline='price')
pZigzagLength = input.int(5, step=1, minval=3, title='', group='Zigzag', inline='price')
pZigzagColor = input.color(color.rgb(251, 192, 45, 0), title='', group='Zigzag', inline='price')
oscillatorSource = input.string('RSI', title='Source', options=['CCI', 'CMO', 'COG', 'DMI', 'HIST', 'MACD', 'MFI', 'MOM', 'ROC', 'RSI', 'TSI', 'WPR', 'BB', 'KC', 'DC', 'ADC', 'External'], group='Oscillator', inline='osc')
externalSource = input.source(close, title='External Source', group='Oscillator', inline='osc')
oscillatorLength = input.int(22, title='Length', group='Oscillator', inline='osc2')
oscillatorShortLength = input.int(12, title='Fast', group='Oscillator', inline='osc2')
oscillatorLongLength = input.int(26, title='Slow', group='Oscillator', inline='osc2')
considerTrendBias = input.bool(true, title='Pivot History', group='Supertrend (Trend Bias)', inline='st')
supertrendHistory = input.int(4, step=1, title='', group='Supertrend (Trend Bias)', inline='st')
atrPeriods = input.int(22, title='ATR Length', step=5, group='Supertrend (Trend Bias)')
atrMult = input.float(1, step=0.5, title='ATR Multiplier', group='Supertrend (Trend Bias)')
colorCandles = input.bool(true, title='Color Candles', group='Supertrend (Trend Bias)', inline='1')
showSupertrend = input.bool(true, title='Plot Supertrend', group='Supertrend (Trend Bias)', inline='1')
showStatTable = input.bool(true, title='Max Rows', group='Stats and Display', inline='stats')
max_array_size = input.int(10, title='', step=5, minval=5, group='Stats and Display', inline='stats')
text_size = input.string(size.small, title='Size', options=[size.tiny, size.small, size.normal, size.large, size.huge, size.auto], group='Stats and Display', inline='stats')
showContinuation = input.bool(true, title='Continuation', group='Stats and Display', inline='display')
showIndeterminate = input.bool(true, title='Indeterminate', group='Stats and Display', inline='display')
showDivergence = input.bool(true, title='Divergence', group='Stats and Display', inline='display')
showHiddenDivergence = input.bool(true, title='Hidden Divergence', group='Stats and Display', inline='display')
alertContinuation = input.bool(false, title='Continuation', group='Alert', inline='alert')
alertIndeterminate = input.bool(false, title='Indeterminate', group='Alert', inline='alert')
alertDivergence = input.bool(true, title='Divergence', group='Alert', inline='alert')
alertHiddenDivergence = input.bool(true, title='Hidden Divergence', group='Alert', inline='alert')
startIndex = waitForConfirmation ? 1 : 0
donchian(rangeLength) =>
top = ta.highest(rangeLength)
bottom = ta.lowest(rangeLength)
middle = (top + bottom) / 2
[middle, top, bottom]
adoptive_donchian(rangeLength) =>
[middle, top, bottom] = donchian(rangeLength)
channelBreak = high >= top[1] or low <= bottom[1]
if not channelBreak
middle := nz(middle[1], middle)
top := nz(top[1], top)
bottom := nz(bottom[1], bottom)
bottom
[middle, top, bottom]
[macdLine, signalLine, histLine] = ta.macd(close, oscillatorShortLength, oscillatorLongLength, oscillatorShortLength)
[bbmiddle, bbupper, bblower] = ta.bb(close, oscillatorLength, 5)
[kcmiddle, kcupper, kclower] = ta.kc(close, oscillatorLength, 5, true)
[dcmiddle, dcupper, dclower] = donchian(oscillatorLength)
[adcmiddle, adcupper, adclower] = adoptive_donchian(oscillatorLength)
[diplus, diminus, adx] = ta.dmi(oscillatorLongLength, oscillatorShortLength)
oscillator = oscillatorSource == 'CCI' ? ta.cci(close, oscillatorLength) : oscillatorSource == 'CMO' ? ta.cmo(close, oscillatorLength) : oscillatorSource == 'COG' ? ta.cog(close, oscillatorLength) : oscillatorSource == 'DMI' ? adx : oscillatorSource == 'HIST' ? histLine : oscillatorSource == 'MACD' ? macdLine : oscillatorSource == 'MFI' ? ta.mfi(close, oscillatorLength) : oscillatorSource == 'MOM' ? ta.mom(close, oscillatorLength) : oscillatorSource == 'ROC' ? ta.roc(close, oscillatorLength) : oscillatorSource == 'RSI' ? ta.rsi(close, oscillatorLength) : oscillatorSource == 'TSI' ? ta.tsi(close, oscillatorShortLength, oscillatorLongLength) : oscillatorSource == 'WPR' ? ta.wpr(oscillatorLength) : oscillatorSource == 'BB' ? (close - bblower) / (bbupper - bblower) : oscillatorSource == 'KC' ? (close - kclower) / (kcupper - kclower) : oscillatorSource == 'DC' ? (close - dclower) / (dcupper - dclower) : oscillatorSource == 'ADC' ? (close - adclower) / (adcupper - adclower) : externalSource
var zigzagsupertrenddirs = array.new_int(1, 1)
var zigzagsupertrend = array.new_float(2, na)
var pZigzagPivots = array.new_float(0)
var pZigzagPivotBars = array.new_int(0)
var pZigzagPivotDirs = array.new_int(0)
var opZigzagPivots = array.new_float(0)
var opZigzagPivotDirs = array.new_int(0)
var pZigzagLines = array.new_line(0)
var pZigzagLabels = array.new_label(0)
f_initialize_supertrend(zigzagPivots) =>
dir = array.get(zigzagsupertrenddirs, 0)
buyStop = array.get(zigzagsupertrend, 0)
sellStop = array.get(zigzagsupertrend, 1)
tail = array.size(zigzagPivots) > 1 + supertrendHistory ? array.slice(zigzagPivots, 1, 1 + supertrendHistory) : array.new_float()
highest = array.max(tail)
lowest = array.min(tail)
atrDiff = ta.atr(atrPeriods) * atrMult
newBuyStop = lowest - atrDiff
newSellStop = highest + atrDiff
newDir = dir > 0 and close[1] < buyStop ? -1 : dir < 0 and close[1] > sellStop ? 1 : dir
newBuyStop := newDir > 0 ? math.max(nz(buyStop, newBuyStop), newBuyStop) : newBuyStop
newSellStop := newDir < 0 ? math.min(nz(sellStop, newSellStop), newSellStop) : newSellStop
array.set(zigzagsupertrenddirs, 0, newDir)
array.set(zigzagsupertrend, 0, newBuyStop)
array.set(zigzagsupertrend, 1, newSellStop)
[newDir, newBuyStop, newSellStop]
[supertrendDir, buyStop, sellStop] = f_initialize_supertrend(pZigzagPivots)
add_to_array(arr, val, maxItems) =>
array.unshift(arr, val)
if array.size(arr) > maxItems
array.pop(arr)
pivots(length, useAlternativeSource, source) =>
highsource = useAlternativeSource ? source : high
lowsource = useAlternativeSource ? source : low
float phigh = ta.highestbars(highsource, length) == 0 ? highsource : na
float plow = ta.lowestbars(lowsource, length) == 0 ? lowsource : na
[phigh, plow, bar_index, bar_index]
addnewpivot(zigzagpivots, zigzagpivotbars, zigzagpivotdirs, zigzagother, zigzagotherdir, value, otherSource, bar, dir) =>
newDir = dir
othDir = dir
if array.size(zigzagpivots) >= 2
LastPoint = array.get(zigzagpivots, 1)
newDir := dir * value > dir * LastPoint ? dir * 2 : dir
LastOther = array.get(zigzagother, 1)
othDir := dir * otherSource[bar_index - bar] > dir * LastOther ? dir * 2 : dir
othDir
add_to_array(zigzagpivots, value, max_array_size + startIndex)
add_to_array(zigzagpivotbars, bar, max_array_size + startIndex)
add_to_array(zigzagpivotdirs, newDir, max_array_size + startIndex)
add_to_array(zigzagother, otherSource[bar_index - bar], max_array_size + startIndex)
add_to_array(zigzagotherdir, othDir, max_array_size + startIndex)
zigzagcore(phigh, plow, phighbar, plowbar, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, zigzagother, zigzagotherdir, otherSource) =>
pDir = 1
newZG = false
doubleZG = phigh and plow
if array.size(zigzagpivots) >= 1
pDir := array.get(zigzagpivotdirs, 0)
pDir := pDir % 2 == 0 ? pDir / 2 : pDir
pDir
if (pDir == 1 and phigh or pDir == -1 and plow) and array.size(zigzagpivots) >= 1
pivot = array.shift(zigzagpivots)
pivotbar = array.shift(zigzagpivotbars)
pivotdir = array.shift(zigzagpivotdirs)
otherVal = array.shift(zigzagother)
otherDir = array.shift(zigzagotherdir)
value = pDir == 1 ? phigh : plow
bar = pDir == 1 ? phighbar : plowbar
useNewValues = value * pivotdir > pivot * pivotdir
value := useNewValues ? value : pivot
bar := useNewValues ? bar : pivotbar
otherVal := useNewValues ? otherSource : otherVal
newZG := newZG or useNewValues
addnewpivot(zigzagpivots, zigzagpivotbars, zigzagpivotdirs, zigzagother, zigzagotherdir, value, otherVal, bar, pDir)
if pDir == 1 and plow or pDir == -1 and phigh
value = pDir == 1 ? plow : phigh
bar = pDir == 1 ? plowbar : phighbar
dir = pDir == 1 ? -1 : 1
newZG := true
addnewpivot(zigzagpivots, zigzagpivotbars, zigzagpivotdirs, zigzagother, zigzagotherdir, value, otherSource, bar, dir)
[newZG, doubleZG]
zigzag(length, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, zigzagother, zigzagotherdir, useAlternativeSource, source, otherSource) =>
[phigh, plow, phighbar, plowbar] = pivots(length, useAlternativeSource, source)
zigzagcore(phigh, plow, phighbar, plowbar, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, zigzagother, zigzagotherdir, otherSource)
getSentimentByDivergenceAndBias(divergence, bias) =>
sentimentColor = divergence == 1 ? bias == 1 ? color.green : color.red : divergence == -1 ? bias == 1 ? color.lime : color.orange : divergence == -2 ? bias == 1 ? color.lime : color.orange : color.silver
sentiment = divergence == 0 ? '▣' : bias > 0 ? divergence == 1 ? '⬆' : divergence == -1 ? '⤴' : divergence == -2 ? '↗' : '⤮' : divergence == 1 ? '⬇' : divergence == -1 ? '⤵' : divergence == -2 ? '↘' : '⤭'
[sentiment, sentimentColor]
f_get_divergence(pDir, oDir, sDir) =>
divergence = pDir == oDir ? pDir % 2 == 0 and pDir / 2 == sDir or pDir % 2 != 0 and pDir != sDir ? 1 : 0 : pDir == 2 * oDir and oDir == sDir ? -1 : 2 * pDir == oDir and pDir == -sDir ? -2 : 0
divergenceIdentifier = divergence == 1 ? 'C' : divergence == -1 ? 'D' : divergence == -2 ? 'H' : 'I'
[divergence, divergenceIdentifier]
f_get_bias(pDir, oDir) =>
pDir == 2 and oDir == 2 ? 1 : pDir == -2 and oDir == -2 ? -1 : pDir > 0 ? -1 : pDir < 0 ? 1 : 0
draw_zg_line(idx1, idx2, zigzaglines, zigzaglabels, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, ozigzagpivotdirs, zigzagcolor, zigzagwidth, zigzagstyle) =>
if array.size(zigzagpivots) > idx2
y1 = array.get(zigzagpivots, idx1)
y2 = array.get(zigzagpivots, idx2)
x1 = array.get(zigzagpivotbars, idx1)
x2 = array.get(zigzagpivotbars, idx2)
pDir = array.get(zigzagpivotdirs, idx1)
oDir = array.get(ozigzagpivotdirs, idx1)
sDir = supertrendDir[bar_index - x1]
[divergence, divergenceIdentifier] = f_get_divergence(pDir, oDir, sDir)
bias = f_get_bias(pDir, oDir)
[sentiment, sentimentColor] = getSentimentByDivergenceAndBias(divergence, bias)
zline = line.new(x1=x1, y1=y1, x2=x2, y2=y2, color=zigzagcolor, width=zigzagwidth, style=zigzagstyle)
zlabel = label.new(x=x1, y=y1, xloc=xloc.bar_index, yloc=yloc.price, text=divergenceIdentifier, color=sentimentColor, style=pDir > 0 ? label.style_label_down : label.style_label_up, textcolor=color.black, size=size.small)
if array.size(zigzaglines) >= 1
lastLine = array.get(zigzaglines, 0)
if x2 == line.get_x2(lastLine) and y2 == line.get_y2(lastLine)
line.delete(array.shift(zigzaglines))
label.delete(array.shift(zigzaglabels))
if not showIndeterminate and divergence == 0 or not showContinuation and divergence == 1 or not showDivergence and divergence == -1 or not showHiddenDivergence and divergence == -2
label.delete(zlabel)
array.unshift(zigzaglines, zline)
array.unshift(zigzaglabels, zlabel)
if array.size(zigzaglines) > 500
line.delete(array.pop(zigzaglines))
label.delete(array.pop(zigzaglabels))
draw_zigzag(doubleZG, zigzaglines, zigzaglabels, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, ozigzagpivotdirs, zigzagcolor, zigzagwidth, zigzagstyle) =>
if doubleZG
draw_zg_line(startIndex + 1, startIndex + 2, zigzaglines, zigzaglabels, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, ozigzagpivotdirs, zigzagcolor, zigzagwidth, zigzagstyle)
if array.size(zigzagpivots) >= startIndex + 2
draw_zg_line(startIndex + 0, startIndex + 1, zigzaglines, zigzaglabels, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, ozigzagpivotdirs, zigzagcolor, zigzagwidth, zigzagstyle)
getCellColorByDirection(dir) =>
dir == 2 ? color.green : dir == 1 ? color.orange : dir == -1 ? color.lime : dir == -2 ? color.red : color.silver
getLabelByDirection(dir) =>
dir == 2 ? '⇈' : dir == 1 ? '↑' : dir == -1 ? '↓' : dir == -2 ? '⇊' : 'NA'
oscillator := nz(oscillator, close)
[pZG, pdZG] = zigzag(pZigzagLength, pZigzagPivots, pZigzagPivotBars, pZigzagPivotDirs, opZigzagPivots, opZigzagPivotDirs, useClosePrices, close, oscillator)
trendColor = supertrendDir > 0 ? color.lime : color.orange
barcolor(colorCandles ? trendColor : na)
plot(supertrendDir > 0 ? buyStop : sellStop, title='Supertrend', color=trendColor)
if pZG
draw_zigzag(pdZG, pZigzagLines, pZigzagLabels, pZigzagPivots, pZigzagPivotBars, pZigzagPivotDirs, opZigzagPivotDirs, pZigzagColor, 1, line.style_solid)
if barstate.islast and showStatTable
stats = table.new(position=position.top_right, columns=5, rows=max_array_size + startIndex + 2, border_width=1)
table.cell(table_id=stats, column=0, row=0, text='Bar Time', bgcolor=color.black, text_color=color.white, text_size=text_size)
table.cell(table_id=stats, column=1, row=0, text='Price', bgcolor=color.black, text_color=color.white, text_size=text_size)
table.cell(table_id=stats, column=2, row=0, text='Oscillator', bgcolor=color.black, text_color=color.white, text_size=text_size)
table.cell(table_id=stats, column=3, row=0, text='Trend', bgcolor=color.black, text_color=color.white, text_size=text_size)
table.cell(table_id=stats, column=4, row=0, text='Sentiment', bgcolor=color.black, text_color=color.white, text_size=text_size)
for i = startIndex to array.size(pZigzagPivotDirs) > 0 ? array.size(pZigzagPivotDirs) - 1 : na by 1
pBar = array.get(pZigzagPivotBars, i)
pDir = array.get(pZigzagPivotDirs, i)
oDir = array.get(opZigzagPivotDirs, i)
sDir = supertrendDir[bar_index - pBar]
[divergence, divergenceIdentifier] = f_get_divergence(pDir, oDir, sDir)
bias = f_get_bias(pDir, oDir)
[sentiment, sentimentColor] = getSentimentByDivergenceAndBias(divergence, bias)
if not showIndeterminate and divergence == 0 or not showContinuation and divergence == 1 or not showDivergence and divergence == -1 or not showHiddenDivergence and divergence == -2
continue
trendDirection = sDir > 0 ? '⇑' : '⇓'
trendColor = sDir > 0 ? color.green : color.red
barTime = time[bar_index - pBar]
barTimeString = str.tostring(year(barTime), '0000') + '/' + str.tostring(month(barTime), '00') + '/' + str.tostring(dayofmonth(barTime), '00') + (timeframe.isintraday ? '-' + str.tostring(hour(barTime), '00') + ':' + str.tostring(minute(barTime), '00') + ':' + str.tostring(second(barTime), '00') : '')
table.cell(table_id=stats, column=0, row=i + 1 - startIndex, text=barTimeString, bgcolor=getCellColorByDirection(pDir), text_size=text_size)
table.cell(table_id=stats, column=1, row=i + 1 - startIndex, text=getLabelByDirection(pDir), bgcolor=getCellColorByDirection(pDir), text_size=text_size)
table.cell(table_id=stats, column=2, row=i + 1 - startIndex, text=getLabelByDirection(oDir), bgcolor=getCellColorByDirection(oDir), text_size=text_size)
table.cell(table_id=stats, column=3, row=i + 1 - startIndex, text=trendDirection, bgcolor=trendColor, text_size=text_size)
table.cell(table_id=stats, column=4, row=i + 1 - startIndex, text=sentiment, bgcolor=sentimentColor, text_size=text_size)
if array.size(pZigzagPivotBars) > startIndex
lastPivotBar = array.get(pZigzagPivotBars, startIndex)
lPivotDir = array.get(pZigzagPivotDirs, startIndex)
lOscillatorDir = array.get(opZigzagPivotDirs, startIndex)
sDir = supertrendDir[bar_index - lastPivotBar]
[divergence, divergenceIdentifier] = f_get_divergence(lPivotDir, lOscillatorDir, sDir)
bias = f_get_bias(lPivotDir, lOscillatorDir)
[sentiment, sentimentColor] = getSentimentByDivergenceAndBias(divergence, bias)
isAlertBar = bar_index == lastPivotBar and startIndex == 0 or startIndex == 1 and lastPivotBar != lastPivotBar[1]
if isAlertBar and (alertIndeterminate and divergence == 0 or alertContinuation and divergence == 1 or alertDivergence and divergence == -1 or alertHiddenDivergence and divergence == -2)
sentimentText = divergence == 1 ? bias == 1 ? 'Bullish Continuation' : 'Bearish Continuation' : divergence == -1 ? bias == 1 ? 'Bullish Divergence' : 'Bearish Divergence' : divergence == -2 ? bias == 1 ? 'Bullish Hidden Divergence' : 'Bearish Hidden Divergence' : 'Indeterminate'
alert('Sentiment alert on ' + syminfo.tickerid + ' :: ' + sentimentText)
|
EPS_REVENUE_PSR indicator | https://www.tradingview.com/script/G1Fmiu1Y/ | kei525dow | https://www.tradingview.com/u/kei525dow/ | 54 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kei525dow
//@version=4
// Quarterly EPS, PER, total revenue(FQ) (in million unit), PSR can be shown as an indicator.
// Check only one indicator for the chart visibility.
// 四半期毎のEPS, PER, 年間売上, PSRをインジケーターとして表示することができます。
// チャートを見やすくするために1つのインジケーターを選択してください。//
study(title = "EPS_REVENUE_PSR indicator", shorttitle = "EPS_REVENUE_PSR")
// basic EPS
BEPS = financial(syminfo.tickerid, "EARNINGS_PER_SHARE_BASIC", "FQ")
DEPS = financial(syminfo.tickerid, "EARNINGS_PER_SHARE_DILUTED", "FQ")
BPER = close / BEPS
DPER = close / DEPS
// PSR
TSO = financial(syminfo.tickerid, "TOTAL_SHARES_OUTSTANDING", "FQ")
MarketCap = TSO * close
REV_Q = financial(syminfo.tickerid, "TOTAL_REVENUE", "FQ")
PSR = MarketCap / REV_Q / 4
// PLOT
plot(BEPS, title="Basic EPS", color=color.red, linewidth=2)
plot(DEPS, title="Diluted EPS", color=color.purple, linewidth=2)
plot(BPER, title="Basic PER", color=color.lime, linewidth=2)
plot(DPER, title="Diluted PER", color=color.green, linewidth=2)
plot(PSR, title="PSR", color=color.blue, linewidth=2)
plot(REV_Q/1e6, title="quarterly revenue(million unit)", color=color.aqua, linewidth=2)
|
Indicator: SMA/EMA (Multi timeframes) | https://www.tradingview.com/script/k2YecbBv-Indicator-SMA-EMA-Multi-timeframes/ | DojiEmoji | https://www.tradingview.com/u/DojiEmoji/ | 56 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DojiEmoji
//@version=5
indicator('MA on Alternative Timeframe', shorttitle='MA - Alt. TF [KL]', overlay=true)
tf_1W = input.timeframe('1M', title='For 1-week chart, show MA of: ')
tf_1D = input.timeframe('1W', title='For 1-day chart, show MA of: ')
tf_60 = input.timeframe('D', title='For 1-hour chart, show MA of: ')
tf_default = input.timeframe('D', title='For others (Default)')
tf = timeframe.period // tf = timeframe of the viewed chart
tf_alt = tf == '1W' ? tf_1W : tf == 'D' ? tf_1D : tf == '60' ? tf_60 : tf_default // alternative timeframe depends on 'tf'
type = input.string(defval='EMA', options=['EMA', 'SMA'], title='EMA/SMA')
len = input.int(defval=20, title='Moving Average Period', minval=1)
_data = type == 'EMA' ? ta.ema(close, len) : ta.sma(close, len)
data = request.security(syminfo.tickerid, tf_alt, _data)
plot(data, title='MA', color=color.new(color.orange, 50), linewidth=1, style=plot.style_line)
|
RTR Jimmy Momo Candles | https://www.tradingview.com/script/t6U9pOUd-RTR-Jimmy-Momo-Candles/ | InarTrades | https://www.tradingview.com/u/InarTrades/ | 257 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © InarTrades
//@version=4
study("RTR Jimmy Momo Candles",overlay=true)
//These zones are absolutely not "buy here sell here" areas. Context is key as with all levels,indicators, etc.
//Inputs
bodyAverageRange = input(6, title="Average Body Range")
volumeAverageRange = input(60, title="Volume Average Range")
changeBarColor = input(true, title="Change Bar Color",type=input.bool)
bodyStdDevs = input(2,title="Body Standard Deviations")
hotThreshold = input(2.0,title="Hot Volume Threshold")
showZones = input(true,title="Show Zones",type=input.bool)
showDots = input(true,title="Show Dots",type=input.bool)
zoneLookback = input(60,title="Bar Lookback for Zones")
l=low
h=high
v=volume
volumeAvg= sma(v,volumeAverageRange)
bt = max(close,open)
bb = min(close,open)
gapDown = bb[1] > h ? bb[1]-bt : 0
gapUp = bt[1] < l ? bb-bt[1] : 0
bodyTop = if gapUp > 0
bt
else if gapDown > 0
bb[1]
else
bt
bodyBottom = if gapUp > 0
bt[1]
else if gapDown > 0
bb
else
bb
c = if gapUp > 0
bodyTop
else if gapDown > 0
bodyBottom
else
close
o = bodyTop[1] < c ? min(bodyTop[1],open) : open
body = bodyTop - bodyBottom
bn = bar_index
isG = c > o
isR = c < o
bodySd = stdev(body, bodyAverageRange)
//hot bar logic
isHot = body > bodySd[1] * bodyStdDevs and v > volumeAvg * hotThreshold
//should show
shouldShow = if isG and isHot
true
else if isR and isHot
true
else
false
//dot value logic
dotVal = if shouldShow and isG
bodyBottom
else if shouldShow and isR
bodyTop
//dot color logic
dotColor = if shouldShow and isG and showDots
color.new(color.white,0)
else if shouldShow and isR and showDots
color.new(color.yellow,0)
else
color.new(color.white,100)
//wick value logic
wickVal = if shouldShow and isG
bodyTop[1] >= c ? l : min(l[0],l[1])
else if shouldShow and isR
bodyBottom[1] <= o ? h : max(h[0],h[1])
boxTopVal = if isG
dotVal
else if isR
wickVal
boxBotVal = if isG
wickVal
else if isR
dotVal
boxColor = if shouldShow and close > boxTopVal and showZones
color.new(color.green,50)
else if shouldShow and close < boxBotVal and showZones
color.new(color.red,50)
else
color.new(color.gray,100)
//zoneBox=box.new(left=bar_index,top=boxTopVal,right=bar_index+1,bottom=boxBotVal,extend=extend.right,bgcolor=boxColor,border_color=boxColor)
zoneBox = if shouldShow == true
box.new(left=bar_index,top=boxTopVal,right=bar_index+1,bottom=boxBotVal,extend=extend.right,bgcolor=boxColor,border_color=boxColor)
box.delete(zoneBox[zoneLookback])
barcol = if changeBarColor and shouldShow and isG
color.lime
else if changeBarColor and shouldShow and isR
color.orange
else if isG
color.teal
else if isR
color.red
//box.delete(zoneBox[1])
//plot dots
dot = plot(dotVal,style=plot.style_circles,linewidth=3,color=dotColor)
//plot wicks
wick = plot(wickVal,style=plot.style_circles,linewidth=3,color=dotColor)
//highlight important bars
barcolor(barcol)
|
LazerALERT V1 | https://www.tradingview.com/script/8X8OpH0n-LazerALERT-V1/ | livingdraculaog | https://www.tradingview.com/u/livingdraculaog/ | 124 | study | 5 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator('LaserALERT V1', shorttitle='LaserALERT', overlay=true, max_bars_back=4900)
import livingdraculaog/CandleStore/10 as CandleStore
////# import candle analytics
redCandle = CandleStore.redCandle()
greenCandle = CandleStore.greenCandle()
// _
// __| |___
// .' _| |__ '.u
// .' .- | -. '.
// .' | |( |\ | '.
// | < | | | | |
// '. | |( |/ | .'
// '. '-_|____-' .'
// '.________.'
//
//
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Desc: This script is designed to spot trade with weak signals and short/long with trend.
// // © livingdraculaog
// ////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////
// // Components Used in this Strategy
// // Features:
// // 1. RSI Support & Resistance - helps should where the ceiling and floor are as well as when an asset is overbought / oversold. Originally by DGT © dgtrd ()
// // 2. Triple Moving Average forcasting - helps predict death crosses and golden crosses
// // 3. Retracement price - if the current price exceeds this, it will continue in the same directio. Originally by TLB
// // 4. EMA Candle Colors with Volume-based opacity - helps show the strength and momentum of a candle
// // 5. Market Band and Pivot lines - to determine the long term trend
// // 6. Custom UI values and estimating profitably of any given position you may want to take.
// // 7. Wick Analysis
// ////////////////////////////////////////////////////////////////////
__groupUI = 'UI Display'
groupPivots = 'Scalping Length'
ScalpingDescription = 'This will change the time frame for Pivot lines and conseqently change every other estimate.'
showPivots = input.bool(defval=false, title='Scalping Lines 🔪', group=__groupUI, inline='00')
higherTF = input.timeframe('', title='Time Frame', inline='00', group=__groupUI, tooltip=ScalpingDescription)
showRSI = input.bool(defval=false, title='Show RSI', group=__groupUI, inline='01')
// useMAtable = input.bool(false, title="show MA", type=input.bool, group=__groupUI, inline="01")
useRetracement = input.bool(false, title='show Retracement', group=__groupUI, inline='01')
groupCustom = 'Custom Settings'
useQuantity = input.float(100.0, title='Quantity', group=groupCustom, inline='00')
useFEE = input.float(0.02, title='Fee', group=groupCustom, inline='00')
useRound = input.int(2, title='Round', group=groupCustom, inline='00')
useCustomEntry = input.float(1.0, title='Entry: ', group=groupCustom, inline='01')
useCustomExit = input.float(2.0, title='Exit: ', group=groupCustom, inline='01')
useCustom = input.bool(false, title='Use Custom?', group=groupCustom, inline='01')
_groupMA = 'MTF Triple MA Forcasting'
useMAline = input.bool(false, title='show MA', group=_groupMA, inline='00')
maForecast = input.bool(true, title=' Forecast', group=_groupMA, inline='00')
maResolution = input.timeframe('', title='', group=_groupMA, inline='00')
useMAwidth = input.int(2, title='', inline='00', group=_groupMA)
useEntryOptions = input.string("MA1","Entry↕", inline = "01", group =_groupMA, options = ["MA1","MA2","MA3","_pMA1a","_pMA1b","_pMA2a","_pMA2b","_pMA3a","_pMA3b"])
useExitOptions = input.string("MA2","EXIT↕", inline = "01", group =_groupMA, options = ["MA1","MA2","MA3","_pMA1a","_pMA1b","_pMA2a","_pMA2b","_pMA3a","_pMA3b"])
useforcast = input.int(2, title='forcast', inline='01', group=_groupMA)
ma1Color = input.color(title='MA1', defval=color.blue, group=_groupMA, inline='MA1')
ma1Type = input.string('EMA', title='', options=['DEMA', 'EMA', 'HMA', 'LSMA', 'MA', 'RMA', 'SMA', 'SWMA', 'TEMA', 'TMA', 'VWMA', 'WMA'], group=_groupMA, inline='MA1')
ma1Length = input.int(title='', defval=10, minval=1, group=_groupMA, inline='MA1')
ma1Source = input.source(title='', defval=close, group=_groupMA, inline='MA1')
ma2Color = input.color(title='MA2', defval=color.green, group=_groupMA, inline='MA2')
ma2Type = input.string('EMA', title='', options=['DEMA', 'EMA', 'HMA', 'LSMA', 'MA', 'RMA', 'SMA', 'SWMA', 'TEMA', 'TMA', 'VWMA', 'WMA'], group=_groupMA, inline='MA2')
ma2Length = input.int(title='', defval=50, minval=1, group=_groupMA, inline='MA2')
ma2Source = input.source(title='', defval=close, group=_groupMA, inline='MA2')
ma3Color = input.color(title='MA3', defval=color.red, group=_groupMA, inline='MA3')
ma3Type = input.string('EMA', title='', options=['DEMA', 'EMA', 'HMA', 'LSMA', 'MA', 'RMA', 'SMA', 'SWMA', 'TEMA', 'TMA', 'VWMA', 'WMA'], group=_groupMA, inline='MA3')
ma3Length = input.int(title='', defval=200, minval=1, group=_groupMA, inline='MA3')
ma3Source = input.source(title='', defval=close, group=_groupMA, inline='MA3')
__groupCandles = 'EMA Candles Settings'
////# Volume Candles
useVolume = input.bool(defval=true, title='Use Volume Opacity?', group=__groupCandles, inline='00')
volumeDown1 = input.int(100, 'Bearish: ', minval=1, group=__groupCandles, inline='01')
volumeDown2 = input.int(50, '', minval=1, group=__groupCandles, inline='01')
volumeDown3 = input.int(100, '', minval=1, group=__groupCandles, inline='01')
///
volumeUp1 = input.int(1, 'Bullish', minval=1, group=__groupCandles, inline='02')
volumeUp2 = input.int(1, '', minval=1, group=__groupCandles, inline='02')
volumeUp3 = input.int(1, '', minval=1, group=__groupCandles, inline='02')
////# Candle Colors
// weak trends
readCandleSticks = input.bool(defval=true, title='Use EMA Candles', group=__groupCandles, inline='03')
_emaDOWN = input.color(defval=color.new(#660000, 0), title='', inline='03', group=__groupCandles)
_StrongDown = input.color(defval=color.new(#004d40, 0), title='', inline='03', group=__groupCandles)
// neutral
_naCandle = input.color(defval=color.new(#ffffff, 0), title='', inline='03', group=__groupCandles)
// strong trends
_emaUP = input.color(defval=color.new(#009688, 0), title='', inline='03', group=__groupCandles)
_StrongUP = input.color(defval=color.new(#ffeb3b, 0), title='', inline='03', group=__groupCandles)
//
////# Display each
showEMAdown = input.bool(defval=false, title='Down ', inline='04', group=__groupCandles)
showStrongEMAdown = input.bool(defval=false, title='Strong Down ', inline='04', group=__groupCandles)
showEMAneutral = input.bool(defval=false, title='Neutral', inline='04', group=__groupCandles)
showEMAup = input.bool(defval=false, title='Up ', inline='04', group=__groupCandles)
showStrongEMAup = input.bool(defval=false, title='Strong Up ', inline='04', group=__groupCandles)
////#
candle = input.source(defval=close, title='Source', group=__groupCandles, inline='05')
fast = input.int(defval=5, title='Fast EMA', group=__groupCandles, inline='05') //Fast EMA Band
slow = input.int(defval=26, title='Slow EMA', group=__groupCandles, inline='05') //Slow EMA Band
length = input.int(21, 'volume', minval=1, group=__groupCandles, inline='05')
// ////# Retracement forcasting
__groupRetracement = 'Retracement'
ZZprd = input.int(defval=3, title='Retracement', minval=2, maxval=30, inline='00', group=__groupRetracement) // if res1 exists, set it to 30
zzlinestyle_ = input.string(defval='Dashed', title='Style', options=['Solid', 'Dashed', 'Dotted'], group=__groupRetracement, inline='00')
showlevels = input.bool(defval=true, title='Show', inline='00', group=__groupRetracement)
////////////////////////////////////////////////////////////////////}
////# Trend logic
////////////////////////////////////////////////////////////////////{
/////// LOGIC
C_DownTrend = true
C_UpTrend = true
var trendRule1 = 'SMA50'
var trendRule2 = 'SMA50, SMA200'
var trendRule = input.string(trendRule1, 'Detect Trend Based On', options=[trendRule1, trendRule2, 'No detection'], group=__groupCandles)
if trendRule == trendRule1
priceAvg = ta.sma(close, 50)
C_DownTrend := close < priceAvg
C_UpTrend := close > priceAvg
C_UpTrend
if trendRule == trendRule2
sma200 = ta.sma(close, 200)
sma50 = ta.sma(close, 50)
C_DownTrend := close < sma50 and sma50 < sma200
C_UpTrend := close > sma50 and sma50 > sma200
C_UpTrend
C_Len = 14 // ema depth for bodyAvg
C_ShadowPercent = 5.0 // size of shadows
C_ShadowEqualsPercent = 100.0
C_DojiBodyPercent = 5.0
C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick body
C_BodyHi = math.max(close, open)
C_BodyLo = math.min(close, open)
C_Body = C_BodyHi - C_BodyLo
C_BodyAvg = ta.ema(C_Body, C_Len)
C_SmallBody = C_Body < C_BodyAvg
C_LongBody = C_Body > C_BodyAvg
C_UpShadow = high - C_BodyHi
C_DnShadow = C_BodyLo - low
C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
C_WhiteBody = open < close
C_BlackBody = open > close
C_Range = high - low
C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
C_BodyMiddle = C_Body / 2 + C_BodyLo
C_ShadowEquals = C_UpShadow == C_DnShadow or math.abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100 < C_ShadowEqualsPercent and math.abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100 < C_ShadowEqualsPercent
C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
C_Doji = C_IsDojiBody and C_ShadowEquals
patternLabelPosLow = low - ta.atr(30) * 0.6
patternLabelPosHigh = high + ta.atr(30) * 0.6
////////////////////////////////////////////////////////////////////}
////# STANDARD Candlestick Pattern Recognition
////////////////////////////////////////////////////////////////////{
__groupCandlePatterns = 'Candle Patterns'
useEngulfing = input.bool(false, title="Engulfing", group=__groupCandlePatterns, inline="patterns")
useDoji = input.bool(false, title="Doji", group=__groupCandlePatterns, inline="patterns")
useHammer = input.bool(false, title="Hammer", group=__groupCandlePatterns, inline="patterns")
useHarami = input.bool(false, title="Harami", group=__groupCandlePatterns, inline="patterns")
useKicker = input.bool(false, title="Kicker", group=__groupCandlePatterns, inline="patterns")
useStars = input.bool(false, title="Stars", group=__groupCandlePatterns, inline="patterns")
EngulfingBullish = CandleStore._isEngulfingBullish()
EngulfingBearish = CandleStore._isEngulfingBearish()
dojiup = CandleStore.dojiup()
dojidown = CandleStore.dojidown()
Hammer = CandleStore.Hammer()
InvertedHammer = CandleStore.InvertedHammer()
BearishHarami = CandleStore.BearishHarami()
BullishHarami = CandleStore.BullishHarami()
BullishKicker = CandleStore.BullishKicker()
BearishKicker = CandleStore.BearishKicker()
EveningStar = CandleStore.EveningStar()
MorningStar = CandleStore.MorningStar()
ShootingStar = CandleStore.ShootingStar()
BullishBelt = CandleStore.BullishBelt()
HangingMan = CandleStore.HangingMan()
DarkCloudCover = CandleStore.DarkCloudCover()
plotshape(series = useEngulfing and EngulfingBullish ? bar_index : na, style=shape.triangleup, location=location.belowbar, text='Engulfing \n Bullish',textcolor=color.new(color.green, 0), color=color.new(color.green, 0))
plotshape(series = useEngulfing and EngulfingBearish ? bar_index : na, style=shape.triangledown, location=location.abovebar, text='Engulfing \n Bearish',textcolor=color.new(color.red, 0), color=color.new(color.red, 0))
plotshape(series = useDoji and dojiup ? bar_index : na, style=shape.triangledown, location=location.abovebar, text='Doji \n Up',textcolor=color.new(color.green, 0), color=color.new(color.green, 0))
plotshape(series = useDoji and dojidown ? bar_index : na, style=shape.triangledown, location=location.belowbar, text='Doji \n Down',textcolor=color.new(color.red, 0), color=color.new(color.red, 0))
plotshape(series = useHammer and Hammer ? bar_index : na, style=shape.triangledown, location=location.abovebar, text='Hammer',textcolor=color.new(color.green, 0), color=color.new(color.green, 0))
plotshape(series = useHammer and InvertedHammer ? bar_index : na, style=shape.triangledown, location=location.belowbar, text='InvertedHammer',textcolor=color.new(color.red, 0) , color=color.new(color.red, 0))
plotshape(series = useKicker and BullishKicker ? bar_index : na, style=shape.triangleup, location=location.belowbar, text='BullishKicker',textcolor=color.new(color.green, 0), color=color.new(color.green, 0))
plotshape(series = useKicker and BearishKicker ? bar_index : na, style=shape.triangledown, location=location.abovebar, text='BearishKicker',textcolor=color.new(color.red, 0), color=color.new(color.red, 0))
plotshape(series = useStars and MorningStar ? bar_index : na, style=shape.diamond, location=location.belowbar, text='MorningStar',textcolor=color.new(color.green, 0), color=color.new(color.yellow, 0))
plotshape(series = useStars and EveningStar ? bar_index : na, style=shape.diamond, location=location.abovebar, text='EveningStar',textcolor=color.new(color.red, 0), color=color.new(color.yellow, 0))
plotshape(series = useStars and ShootingStar ? bar_index : na, style=shape.diamond, location=location.belowbar, text='ShootingStar',textcolor=color.new(color.red, 0), color=color.new(color.yellow, 0))
plotshape(series = useHarami and BullishHarami ? bar_index : na, style=shape.triangleup, location=location.belowbar, text='BullishHarami',textcolor=color.new(color.green, 0), color=color.new(color.green, 0))
plotshape(series = useHarami and BearishHarami ? bar_index : na, style=shape.triangledown, location=location.abovebar, text='BearishHarami',textcolor=color.new(color.red, 0), color=color.new(color.red, 0))
////# CandleStick Inputs
__groupTheme = 'Theme Settings'
// CandleType = input(title = "Pattern Type", defval="Both", options=["Bullish", "Bearish", "Both"], group=__groupTheme)
label_color_StrongBullish = input.color(color.new(color.green, 1), 'Bull Band', inline='00', group=__groupTheme)
label_color_StrongBearish = input.color(color.new(#f20a05, 1), 'Bear Band', inline='00', group=__groupTheme)
label_color_bullish = input.color(color.new(color.green, 90), 'Bullish', group=__groupTheme, inline='01')
label_color_neutral = input.color(color.gray, 'Neutral', group=__groupTheme, inline='01')
label_color_bearish = input.color(color.new(color.red, 90), 'Bearish', group=__groupTheme, inline='01')
////# Types
_groupBullish = 'Bullish Legend'
showBullish = input.bool(defval=false, title='Show \n Bullish', inline='00', group=_groupBullish)
showBearishSell = input.bool(defval=false, title='Bearish \n Sell', inline='00', group=_groupBullish)
showYellow = input.bool(defval=false, title='Show Yellow Variations', inline='00', group=_groupBullish)
showVolumeBuy = input.bool(defval=false, title='Show \n Volume Buy', inline='00', group=_groupBullish)
_groupBearish = 'Bearish Legend'
showBearish = input.bool(defval=false, title='Show \n Bearish', inline='00', group=_groupBearish)
showBearishBuy = input.bool(defval=false, title='Bearish Buy ', inline='00', group=_groupBearish)
showGreen = input.bool(defval=false, title='Show Green ', inline='00', group=_groupBearish)
showVolumeSell = input.bool(defval=false, title='Show \n Volume Sell', inline='00', group=_groupBullish)
////#Hard Coded Values
_bearRowBG = color.new(color.red, 80)
////////////////////////////////////////////////////////////////////}
////# Wick Analysis
////////////////////////////////////////////////////////////////////{
// This Indicator measures the wick parts of candles and sum it up.
// Wick part of candle is a sign of strength that's why it measures the 60 bars of candles wick. then sum it up and converted it in percentage.
// The output is indicated in the last 10 candles. that's how simple this indicator is but very useful to analyze the strength of every candles.
// The upper numbers is the bear power.
// The lower numbers is the bull power.
wickDescription = 'This Indicator measures candle wick and sum it up. The UPPER numbers is the BEAR power and the LOWER numbers is the BULL power.'
useWick = input.bool(false, title='Wick Analysis', group=__groupUI, inline='02', tooltip=wickDescription)
bear = high - (open > close ? open : close)
bull = (open < close ? open : close) - low
barlength = close > open ? close - open : open - close
sumbarlenght = math.sum(barlength, 60)
sumbull = math.sum(bear, 60) / sumbarlenght * 100
sumbear = math.sum(bull, 60) / sumbarlenght * 100
bullPower_converted = str.tostring(math.floor(sumbull))
bearPower_converted = str.tostring(math.floor(sumbear))
////# wick
if useWick
bull_label = label.new(x=bar_index, y=na, text=bullPower_converted, yloc=yloc.belowbar, textcolor=color.red, style=label.style_none, size=size.normal)
bear_label = label.new(x=bar_index, y=na, text=bearPower_converted, yloc=yloc.abovebar, textcolor=color.green, style=label.style_none, size=size.normal)
bear_label
////
// threeGreenCandles = close[2] > open[2] and close[1] > open[1] and close > open
// sixGreen = close[5] > open[5] and close[4] > open[4] and close[3] > open[3] and close[2] > open[2] and close[1] > open[1] and close > open
// threeRedCandles = close[2] < open[2] and close[1] < open[1] and close < open
// sixRed = close[5] < open[5] and close[4] < open[4] and close[3] < open[3] and close[2] < open[2] and close[1] < open[1] and close < open
////////////////////////////////////////////////////////////////////}
////# EMA Candle
////////////////////////////////////////////////////////////////////{
//EMA CANDLESTICKS
fe = ta.ema(candle, fast)
se = ta.ema(candle, slow)
// NA
isFastOverSlow = fe > se
isCrossUnderSlow = ta.crossunder(candle, se) // NA UP?
isCrossOverSlow = ta.crossover(candle, se) // NA Down?
// BEAR
isStrongUp = candle > se // yellow
isDown = candle < fe // black
// BULL
isStrongDown = candle < se // dark green
isUp = candle > fe // green
////# Labels
_emaUPTip = 'when isFastOverSlow=false or isCrossUnderSlow=false and isUp=false'
_blackTip = 'Black is signals a DOWN Trend and used to sniffout bull traps (green candles with downward trend).\nBlack with RED is RED candle with down trend...\n Black with GREEN outline is a GREEN candle with down trend...'
_whiteTip = 'White signals the MIDDLE of a trend in either direction. It is generated when there is a Cross Under SLOW EMA BAND using```crossunder(CANDLE, SE)```...\nFor Reference:\nCANDLE default value is \'close\'...\nFE=ema(candle,fast)\nSE=ema(candle,slow). Conditional Logic:\n1. when isFastOverSlow=True and isCrossUnderSlow=True'
_redTip = 'Red is bad...'
_greenTip = 'Green is bad...'
_darkTip = 'Dark Green may signify a \'floor\' may berming...'
//// Coloring Algorithm ////
////# Volume
avrg = ta.sma(volume, length)
vold1 = volume > avrg * 1.5 and redCandle
vold2 = volume >= avrg * 0.5 and volume <= avrg * 1.5 and redCandle
vold3 = volume < avrg * 0.5 and redCandle
volu1 = volume > avrg * 1.5 and greenCandle
volu2 = volume >= avrg * 0.5 and volume <= avrg * 1.5 and greenCandle
volu3 = volume < avrg * 0.5 and greenCandle
//// Set the opacity based on the volume
// volume down?
cold1 = volumeDown1
cold2 = volumeDown2
cold3 = volumeDown3
// vol up?
hot1 = volumeUp1
hot2 = volumeUp2
hot3 = volumeUp3
////# Convert EMA colors to volume-based colors
createVolumeCandles(_color) =>
color = vold1 ? color.new(_color, cold1) : vold2 ? color.new(_color, cold2) : vold3 ? color.new(_color, cold3) : volu1 ? color.new(_color, hot1) : volu2 ? color.new(_color, hot2) : volu3 ? color.new(_color, hot3) : na
color
//// Pass in user selected color, than adjust opacity based on volume and return a new color
//// The returned color will than be passed into BC
___emaDOWN = useVolume ? createVolumeCandles(_emaDOWN) : _emaDOWN
___StrongDown = useVolume ? createVolumeCandles(_StrongDown) : _StrongDown
// neutral
___naCandle = useVolume ? createVolumeCandles(_naCandle) : _naCandle
// strong trends
___emaUP = useVolume ? createVolumeCandles(_emaUP) : _emaUP
___StrongUP = useVolume ? createVolumeCandles(_StrongUP) : _StrongUP
//// Coloring Algorithm ////
// outlineColors=
bc = isFastOverSlow ? isCrossUnderSlow ? ___naCandle : isUp ? ___emaUP : isStrongUp ? ___StrongUP : _naCandle : isCrossOverSlow ? ___naCandle : isDown ? ___emaDOWN : isStrongDown ? ___StrongDown : isUp ? isStrongUp ? ___StrongUP : na : na
// bc= isFastOverSlow ? isCrossUnderSlow ? _naCandle : isUp ? _emaUP : isStrongUp ? _StrongUP : _naCandle : isCrossOverSlow ? _naCandle : isDown ? _emaDOWN : isStrongDown ? _StrongDown : isUp ? isStrongUp ? _StrongUP :na :na
___blank = isFastOverSlow ? isCrossUnderSlow ? na : isUp ? na : isStrongUp ? na : na : isCrossOverSlow ? na : isDown ? na : isStrongDown ? na : isUp ? isStrongUp ? na : na : na
// variations for each
__isNA = isFastOverSlow ? isCrossUnderSlow ? true : isUp ? na : isStrongUp ? na : true : isCrossOverSlow ? true : isDown ? na : isStrongDown ? na : isUp ? isStrongUp ? na : na : na
__emaUP = isFastOverSlow ? isCrossUnderSlow ? na : isUp ? true : na ? na : na : isCrossOverSlow ? na : isDown ? na : isStrongDown ? na : isUp ? isStrongUp ? na : na : na
__isStrongUP = isFastOverSlow ? isCrossUnderSlow ? na : isUp ? na : isStrongUp ? true : na : isCrossOverSlow ? na : isDown ? na : isStrongDown ? na : isUp ? isStrongUp ? true : na : na
__emaDOWN = isFastOverSlow ? isCrossUnderSlow ? na : isUp ? na : isStrongUp ? na : na : isCrossOverSlow ? na : isDown ? true : isStrongDown ? na : isUp ? isStrongUp ? na : na : na
__isStrongDown = isFastOverSlow ? isCrossUnderSlow ? na : isUp ? na : isStrongUp ? na : na : isCrossOverSlow ? na : isDown ? na : isStrongDown ? true : isUp ? isStrongUp ? na : na : na
////# Label Candles
noCross = not isFastOverSlow and not isCrossUnderSlow
__notEMA = not __isNA and not __emaUP and not __isStrongUP and not __emaDOWN and not __isStrongDown
////////////////////////////////////////////////////////////////////
condition1 = __isStrongUP and EngulfingBullish
condition2 = __isStrongUP and greenCandle and EngulfingBullish
strongEngulfing = __isStrongUP and greenCandle and not EngulfingBearish
__falseUp = greenCandle and not __isStrongUP and not __emaUP
__falseUP2 = greenCandle and __isStrongDown
__DisplayYellowEngulfing = __isStrongUP and EngulfingBearish
__DisplayRedEngulfing = __isStrongDown and EngulfingBearish
__DisplayWhiteEngulfing = __isNA and EngulfingBearish
////# Volume Based Conditions
_VolumeBuy = __isStrongDown and volu1 and greenCandle
_VolumeSell = __isStrongUP and vold2 and redCandle
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////}
// Originally from ZZ Forecast Retracement © LonesomeTheBlue
////////////////////////////////////////////////////////////////////{
// check highesy/lowest levels and create zigzag
float _ph = ta.highestbars(high, ZZprd) == 0 ? high : na
float _pl = ta.lowestbars(low, ZZprd) == 0 ? low : na
var dir = 0
iff_1 = _pl and na(_ph) ? -1 : dir
dir := _ph and na(_pl) ? 1 : iff_1
var zigzag = array.new_float(0)
oldzigzag = array.new_float(2) // keep last point
////# init zigzag lines
var zzlines = array.new_line(0)
var zzlinestyle = line.style_dashed
////# variables to check if any circle broken
var bool uptbroken = false
var bool downtbroken = false
uptexist = false
downtexist = false
////# labels
var label upt_label = na
var label downt_label = na
////# definitions
width = (ta.highest(292) - ta.lowest(292)) / 107
var up_circle_lines = array.new_line(0)
var dn_circle_lines = array.new_line(0)
////# to get rid of consistency warning, keep close in a array
var cls = array.new_float(500, na)
array.unshift(cls, close)
array.pop(cls)
////# ZZ Utilities
add_to_zigzag(value, bindex) => //
array.unshift(zigzag, bindex)
array.unshift(zigzag, value)
if array.size(zigzag) > 8
array.pop(zigzag)
array.pop(zigzag)
update_zigzag(value, bindex) => //
if array.size(zigzag) == 0
add_to_zigzag(value, bindex)
else
if dir == 1 and value > array.get(zigzag, 0) or dir == -1 and value < array.get(zigzag, 0)
array.set(zigzag, 0, value)
array.set(zigzag, 1, bindex)
0.
///////////
// calculate location of y level in a point
calc_pos_circle_rad(center_y_lev, center_bindex, radius, cal_bindex) =>
loc_diff = math.abs(center_bindex - cal_bindex)
rad = math.sqrt(math.pow(radius, 2) - math.pow(loc_diff * width, 2))
rad
// draw uptrend circle until last candle
draw_up_circle(radius) =>
ind = dir == 1 ? 0 : 2
nxt = dir == 1 ? 2 : 4
broken = false
if showlevels and bar_index - 1 > array.get(zigzag, nxt + 1)
last_x = math.round(array.get(zigzag, nxt + 1))
last_y = array.get(zigzag, nxt)
for x = array.get(zigzag, nxt + 1) + 1 to bar_index - 1 by 1
yloc = array.get(zigzag, ind) - calc_pos_circle_rad(array.get(zigzag, ind), array.get(zigzag, ind + 1), radius, x)
if na(yloc)
break
if not na(yloc) and array.get(cls, math.round(bar_index - x)) < yloc
broken := true
break
array.push(up_circle_lines, line.new(x1=last_x, y1=last_y, x2=math.round(x), y2=yloc, color=color.lime, width=2))
last_x += 1
last_y := yloc
last_y
broken
//
// draw downtrend circle until last candle
draw_down_circle(radius) => //
ind = dir == 1 ? 2 : 0
nxt = dir == 1 ? 4 : 2
broken = false
if showlevels and bar_index - 1 > array.get(zigzag, nxt + 1)
last_x = math.round(array.get(zigzag, nxt + 1))
last_y = array.get(zigzag, nxt)
for x = array.get(zigzag, nxt + 1) + 1 to bar_index - 1 by 1
yloc = array.get(zigzag, ind) + calc_pos_circle_rad(array.get(zigzag, ind), array.get(zigzag, ind + 1), radius, x)
if na(yloc)
break
if not na(yloc) and array.get(cls, math.round(bar_index - x)) > yloc
broken := true
break
array.push(dn_circle_lines, line.new(x1=last_x, y1=last_y, x2=math.round(x), y2=yloc, color=color.red, width=2))
last_x += 1
last_y := yloc
last_y
broken
/////
Round_it(value) => math.round(value / syminfo.mintick) * syminfo.mintick
if array.size(zigzag) > 1
array.set(oldzigzag, 0, array.get(zigzag, 0))
array.set(oldzigzag, 1, array.get(zigzag, 1))
//
dirchanged = dir != dir[1]
if showlevels and _ph or _pl
if dirchanged
add_to_zigzag(dir == 1 ? _ph : _pl, bar_index)
else
update_zigzag(dir == 1 ? _ph : _pl, bar_index)
//
if barstate.isfirst //
zzlinestyle := zzlinestyle_ == 'Solid' ? line.style_solid : zzlinestyle_ == 'Dashed' ? line.style_dashed : line.style_dotted
array.push(zzlines, line.new(x1=bar_index, y1=close, x2=bar_index - 1, y2=close, style=zzlinestyle))
array.push(zzlines, line.new(x1=bar_index, y1=close, x2=bar_index - 1, y2=close, style=zzlinestyle))
//
var zzTOPValue = 0.0
var zzBOTTOMValue = 0.0
__BOTTOMlabel = 'if the current candle closes BELOW this, open a short'
__TOPlabel = 'if the current candle closes ABOVE this, open a long'
////# Retracement Logic
if array.size(zigzag) >= 6
// radius of circles
r1 = math.sqrt(math.pow(array.get(zigzag, 0) - array.get(zigzag, 2), 2) + math.pow((array.get(zigzag, 1) - array.get(zigzag, 3)) * width, 2))
r2 = math.sqrt(math.pow(array.get(zigzag, 2) - array.get(zigzag, 4), 2) + math.pow((array.get(zigzag, 3) - array.get(zigzag, 5)) * width, 2))
radius_up = dir == 1 ? r1 : r2
radius_down = dir == 1 ? r2 : r1
// draw uptrend circle if needed
if dirchanged or width != width[1] or dir == 1 and (array.get(zigzag, 0) != array.get(oldzigzag, 0) or array.get(zigzag, 1) != array.get(oldzigzag, 1))
uptbroken := false
if array.size(up_circle_lines) > 0
for x = 0 to array.size(up_circle_lines) - 1 by 1
line.delete(array.pop(up_circle_lines))
uptbroken := draw_up_circle(radius_up)
uptbroken
// draw downtrend circle if needed
if dirchanged or width != width[1] or dir == -1 and (array.get(zigzag, 0) != array.get(oldzigzag, 0) or array.get(zigzag, 1) != array.get(oldzigzag, 1))
downtbroken := false
if array.size(dn_circle_lines) > 0
for x = 0 to array.size(dn_circle_lines) - 1 by 1
line.delete(array.pop(dn_circle_lines))
downtbroken := draw_down_circle(radius_down)
downtbroken
// calculate/check and draw part of uptrend circle for last last
if not uptbroken
ind = dir == 1 ? 0 : 2
yloc = array.get(zigzag, ind) - calc_pos_circle_rad(array.get(zigzag, ind), array.get(zigzag, ind + 1), radius_up, bar_index)
if not na(yloc) and close >= yloc
uptexist := true
lasty = array.get(zigzag, ind) - calc_pos_circle_rad(array.get(zigzag, ind), array.get(zigzag, ind + 1), radius_up, bar_index - 1)
array.push(up_circle_lines, line.new(x1=bar_index - 1, y1=lasty, x2=bar_index, y2=yloc, color=color.lime, width=2))
if showlevels
label.delete(upt_label)
zzTOPValue := Round_it(yloc)
//# TODO: log time_close when close is >
upt_label := label.new(x=bar_index, y=yloc, text='Bottom Retracement: ' + str.tostring(zzTOPValue), color=color.lime, textcolor=color.black, style=label.style_label_up, tooltip=__BOTTOMlabel)
upt_label
if not na(yloc) and close < yloc
uptbroken := true
uptbroken
// calculate/check and draw part of downtrend circle for last last
if not downtbroken
ind = dir == 1 ? 2 : 0
yloc = array.get(zigzag, ind) + calc_pos_circle_rad(array.get(zigzag, ind), array.get(zigzag, ind + 1), radius_down, bar_index)
if not na(yloc) and close <= yloc
downtexist := true
lasty = array.get(zigzag, ind) + calc_pos_circle_rad(array.get(zigzag, ind), array.get(zigzag, ind + 1), radius_down, bar_index - 1)
array.push(dn_circle_lines, line.new(x1=bar_index - 1, y1=lasty, x2=bar_index, y2=yloc, color=color.red, width=2))
if showlevels
label.delete(downt_label)
zzBOTTOMValue := Round_it(yloc) //#
downt_label := label.new(x=bar_index, y=yloc, text='Top Retracement: ' + str.tostring(zzBOTTOMValue), color=color.red, textcolor=color.white, style=label.style_label_down, tooltip=__TOPlabel)
downt_label
if not na(yloc) and close > yloc
downtbroken := true
downtbroken
////////}
////////////////////////////////////////////////////////////////////}
////# RSI Support & Resistance by DGT © dgtrd
////////////////////////////////////////////////////////////////////{
////# Support & Resistance by DGT UI
groupSupportResistance = 'RSI Support & Resistance'
i_supportResistance = input.bool(true, "Support Resistance Lines", inline='options', group=groupSupportResistance)
i_fill = input.bool(false, "Bull/Bear Zones", inline='options', group=groupSupportResistance)
i_obos = input.bool(true, "Overbought/Oversold", inline='options 2', group=groupSupportResistance)
i_source = input.string('Price (close)', 'Source', options=['Price (close)', 'On Balance Volume (OBV)'], inline='RSI', group=groupSupportResistance)
i_length = input.int(14, ' Length', minval=1, inline='RSI', group=groupSupportResistance)
i_obThreshold = input.int(70, 'Overboght', minval=50, maxval=100, inline='Thresh', group=groupSupportResistance)
i_osThreshold = input.int(30, 'Oversold', minval=1, maxval=50, inline='Thresh', group=groupSupportResistance)
i_bullZone = input.int(60, 'Bull Zone', minval=50, maxval=65, inline='Zones', group=groupSupportResistance)
i_bearZone = input.int(40, 'Bear Zone', minval=35, maxval=50, inline='Zones', group=groupSupportResistance)
// Functions ════════════════════════════════════════════════════════════════════════════════════ //
f_getPrice(_osc, _thresh, _cross) =>
avgHigh = math.avg(high, close)
avgLow = math.avg(low, close)
var return_1 = 0.
if _cross == 'over' or _cross == 'both'
if ta.crossover(_osc, _thresh)
return_1 := avgHigh
return_1
if _cross == 'under' or _cross == 'both'
if ta.crossunder(_osc, _thresh)
return_1 := avgLow
return_1
return_1
// -Calculations ════════════════════════════════════════════════════════════════════════════════ //
oscillator = ta.rsi(i_source == 'Price (close)' ? close : ta.obv, i_length)
crossover_overbought = f_getPrice(oscillator, i_obThreshold, 'over')
crossunder_overbought = f_getPrice(oscillator, i_obThreshold, 'under')
bullZone = f_getPrice(oscillator, i_bullZone, 'both')
bearZone = f_getPrice(oscillator, i_bearZone, 'both')
crossover_oversold = f_getPrice(oscillator, i_osThreshold, 'over')
crossunder_oversold = f_getPrice(oscillator, i_osThreshold, 'under')
overBought = oscillator > i_obThreshold
RSIsell = i_obos and overBought
underBought = oscillator < i_osThreshold
RSIbuy = i_obos and underBought
// -Plotting ════════════════════════════════════════════════════════════════════════════════════ //
plot_crossover_overbought = plot(i_supportResistance and crossover_overbought > 0 ? crossover_overbought : na, 'Crossover Overbought', crossover_overbought == crossover_overbought[1] ? color.green : na, 1)
plot_crossunder_overbought = plot(i_supportResistance and crossunder_overbought > 0 ? crossunder_overbought : na, 'Crossunder Overbought', crossunder_overbought == crossunder_overbought[1] ? color.green : na, 1, plot.style_cross)
plot_bullZone = plot(i_supportResistance and bullZone > 0 ? bullZone : na, 'Cross Bull Zone', bullZone == bullZone[1] ? color.green : na, 1)
plot_bearZone = plot(i_supportResistance and bearZone > 0 ? bearZone : na, 'Cross Bear Zone', bearZone == bearZone[1] ? color.red : na, 1)
plot_crossover_oversold = plot(i_supportResistance and crossover_oversold > 0 ? crossover_oversold : na, 'Crossover Oversold', crossover_oversold == crossover_oversold[1] ? color.red : na, 1, plot.style_cross)
plot_crossunder_oversold = plot(i_supportResistance and crossunder_oversold > 0 ? crossunder_oversold : na, 'Crossunder Oversold', crossunder_oversold == crossunder_oversold[1] ? color.red : na, 2)
////# Create RSI Background
// overBought = (oscillator > i_obThreshold)
fill(plot_crossover_overbought, plot_bullZone, i_fill ? color.new(color.green, 90) : na)
plotshape(i_obos and overBought, 'Price Bars in Overbought Zone', shape.triangledown, location.abovebar, color.new(color.red, 0), size=size.small)
// underBought = (oscillator < i_osThreshold)
fill(plot_crossunder_oversold, plot_bearZone, i_fill ? color.new(color.red, 90) : na)
plotshape(i_obos and underBought, 'Price Bars in Oversold Zone', shape.triangleup, location.belowbar, color.new(color.green, 0), size=size.small)
////////////////////////////////////////////////////////////////////}
////# Multi Moving Average Forecast
////////////////////////////////////////////////////////////////////{
ma(_type, _src, _len) => //{
if _type == 'DEMA'
2 * ta.ema(_src, _len) - ta.ema(ta.ema(_src, _len), _len)
else if _type == 'EMA'
ta.ema(_src, _len)
else if _type == 'HMA'
ta.wma(2 * ta.wma(_src, _len / 2) - ta.wma(_src, _len), math.round(math.sqrt(_len)))
else if _type == 'LSMA'
3 * ta.wma(_src, _len) - 2 * ta.sma(_src, _len)
else if _type == 'MA'
ta.sma(_src, _len)
else if _type == 'RMA'
ta.rma(_src, _len)
else if _type == 'SMA'
smma = 0.0
smma := na(smma[1]) ? ta.sma(_src, _len) : (smma[1] * (_len - 1) + _src) / _len
smma
else if _type == 'SWMA'
ta.swma(_src)
else if _type == 'TEMA'
3 * ta.ema(_src, _len) - 3 * ta.ema(ta.ema(_src, _len), _len) + ta.ema(ta.ema(ta.ema(_src, _len), _len), _len)
else if _type == 'TMA'
ta.swma(ta.wma(_src, _len))
else if _type == 'VWMA'
ta.vwma(_src, _len)
else if _type == 'WMA'
ta.wma(_src, _len)
//}
ma_prediction(_type, _src, _period, _offset) => //{
(ma(_type, _src, _period - _offset) * (_period - _offset) + _src * _offset) / _period
//}
ma1 = request.security(syminfo.tickerid, maResolution, ma(ma1Type, ma1Source, ma1Length))
ma2 = request.security(syminfo.tickerid, maResolution, ma(ma2Type, ma2Source, ma2Length))
ma3 = request.security(syminfo.tickerid, maResolution, ma(ma3Type, ma3Source, ma3Length))
_MA1 = request.security(syminfo.tickerid, maResolution, ma_prediction(ma1Type, ma1Source, ma1Length, 1))
_pMA1a = request.security(syminfo.tickerid, maResolution, ma_prediction(ma1Type, ma1Source, ma1Length, 3))
_pMA1b = request.security(syminfo.tickerid, maResolution, ma_prediction(ma1Type, ma1Source, ma1Length, 5))
_pMA1c = request.security(syminfo.tickerid, maResolution, ma_prediction(ma1Type, ma1Source, ma1Length, useforcast))
_MA2 = request.security(syminfo.tickerid, maResolution, ma_prediction(ma2Type, ma2Source, ma2Length, 1))
_pMA2a = request.security(syminfo.tickerid, maResolution, ma_prediction(ma2Type, ma2Source, ma2Length, 3))
_pMA2b = request.security(syminfo.tickerid, maResolution, ma_prediction(ma2Type, ma2Source, ma2Length, useforcast))
_MA3 = request.security(syminfo.tickerid, maResolution, ma_prediction(ma3Type, ma3Source, ma3Length, 1))
_pMA3a = request.security(syminfo.tickerid, maResolution, ma_prediction(ma3Type, ma3Source, ma3Length, 3))
_pMA3b = request.security(syminfo.tickerid, maResolution, ma_prediction(ma3Type, ma3Source, ma3Length, useforcast))
plot(useMAline ? ma1 : na, title='MA 1', color=ma1Color, linewidth=1)
plot(useMAline ? ma2 : na, title='MA 2', color=ma2Color, linewidth=1)
plot(useMAline ? ma3 : na, title='MA 3', color=ma3Color, linewidth=1)
////////////////////////////////////////////////////////////////////}
////# PIVOT LINES Settings
////////////////////////////////////////////////////////////////////{
prevCloseHTF = request.security(syminfo.tickerid, higherTF, close[1], lookahead=barmerge.lookahead_on)
prevOpenHTF = request.security(syminfo.tickerid, higherTF, open[1], lookahead=barmerge.lookahead_on)
prevHighHTF = request.security(syminfo.tickerid, higherTF, high[1], lookahead=barmerge.lookahead_on)
prevLowHTF = request.security(syminfo.tickerid, higherTF, low[1], lookahead=barmerge.lookahead_on)
pLevel = (prevHighHTF + prevLowHTF + prevCloseHTF) / 3
r1Level = pLevel * 2 - prevLowHTF
s1Level = pLevel * 2 - prevHighHTF
r2Level = pLevel + prevHighHTF - prevLowHTF
s2Level = pLevel - (prevHighHTF - prevLowHTF)
r3Level = prevHighHTF + 2 * (pLevel - prevLowHTF)
s3Level = prevLowHTF - 2 * (prevHighHTF - pLevel)
////#2 Render Pivot lines
// Plot the pivot line, support and resistence
pColor = close > pLevel ? label_color_StrongBullish : label_color_StrongBearish
plot(pLevel, color=pColor, linewidth=3, style=plot.style_line, title='Pivot')
var line r1Line = na
var line pLine = na
var line s1Line = na
// Pivot Prices Labels
if pLevel[1] != pLevel
//add text attribute
label.new(showPivots == true ? bar_index : na, r3Level, 'R3', textcolor=color.white, style=label.style_none)
label.new(showPivots == true ? bar_index : na, r2Level, 'R2', textcolor=color.white, style=label.style_none)
label.new(showPivots == true ? bar_index : na, r1Level, 'R1', textcolor=color.white, style=label.style_none)
label.new(showPivots == true ? bar_index : na, pLevel, 'P', textcolor=color.white, style=label.style_none)
label.new(showPivots == true ? bar_index : na, s1Level, 'S1', textcolor=color.white, style=label.style_none)
label.new(showPivots == true ? bar_index : na, s2Level, 'S2', textcolor=color.white, style=label.style_none)
label.new(showPivots == true ? bar_index : na, s3Level, 'S3', textcolor=color.white, style=label.style_none)
////////////////////////////////////////////////////////////////////}
////# CUSTOM ENTRY INPUTS
////////////////////////////////////////////////////////////////////{
// useEntryOptions = input.string('MA1', 'Entry↕', inline='02', group=groupCustom, options=['MA1', 'MA2', 'MA3', '_pMA1a', '_pMA1b', '_pMA2a', '_pMA2b', '_pMA3a', '_pMA3b', 'Overbought', 'Bull Retracement', 'Resistance 1', 'Resistance 2', 'Resistance 3', 'Bull Zone', 'Pivot', 'Bear Zone', 'Bear Retracement', 'Support 1', 'Support 2', 'Support 3', 'Oversold'])
// useExitOptions = input.string('_pMA1b', 'EXIT↕', inline='02', group=groupCustom, options=['MA1', 'MA2', 'MA3', '_pMA1a', '_pMA1b', '_pMA2a', '_pMA2b', '_pMA3a', '_pMA3b', 'Overbought', 'Bull Retracement', 'Resistance 1', 'Resistance 2', 'Resistance 3', 'Bull Zone', 'Pivot', 'Bear Zone', 'Bear Retracement', 'Support 1', 'Support 2', 'Support 3', 'Oversold'])
// useOptions = input.bool(false, title='Position Calculator', group=groupCustom, inline='02')
////# POSITION Settings
group_pos = 'Table Position & Size & Colors'
rangetooltip = '0-100. Use 0 to auto-size height and width.'
string useTextSize = input.string('Large', 'Text Size', options=['Auto', 'Tiny', 'Small', 'Normal', 'Large', 'Huge'], group=groupCustom, inline='02')
string textSize = useTextSize == 'Auto' ? size.auto : useTextSize == 'Tiny' ? size.tiny : useTextSize == 'Small' ? size.small : useTextSize == 'Normal' ? size.normal : useTextSize == 'Large' ? size.large : size.huge
useStopOptions = input.string('MA3', 'Stop↕', inline='02', group=groupCustom, options=['MA1', 'MA2', 'MA3', '_pMA1a', '_pMA1b', '_pMA2a', '_pMA2b', '_pMA3a', '_pMA3b', 'Overbought', 'Bull Retracement', 'Resistance 1', 'Resistance 2', 'Resistance 3', 'Bull Zone', 'Pivot', 'Bear Zone', 'Bear Retracement', 'Support 1', 'Support 2', 'Support 3', 'Oversold'])
// useProfitOptions = input("MA2","Profit↕", inline = "02", group =groupCustom, options = ["MA1","MA2","MA3","_pMA1a","_pMA1b","_pMA2a","_pMA2b","_pMA3a","_pMA3b", "Overbought", "Bull Retracement", "Resistance 1", "Resistance 2", "Resistance 3", "Bull Zone", "Pivot", "Bear Zone", "Bear Retracement", "Support 1", "Support 2", "Support 3", "Oversold"])
////# Filter Logic
_useRound(_input) =>
math.round(_input, useRound)
_useOptions(_input) =>
_input == 'Bull Zone' ? _useRound(bullZone) : _input == 'Bear Zone' ? _useRound(bearZone) : _input == 'Overbought' ? _useRound(crossover_overbought) : _input == 'Oversold' ? _useRound(crossunder_oversold) : _input == 'Pivot' ? _useRound(pLevel) : _input == 'Support 1' ? _useRound(s1Level) : _input == 'Support 2' ? _useRound(s2Level) : _input == 'Support 3' ? _useRound(s3Level) : _input == 'Resistance 1' ? _useRound(r1Level) : _input == 'Resistance 2' ? _useRound(r2Level) : _input == 'Resistance 3' ? _useRound(r3Level) : _input == 'Bull Retracement' ? _useRound(zzBOTTOMValue) : _input == 'Bear Retracement' ? _useRound(zzTOPValue) : _input == 'MA1' ? _useRound(_MA1) : _input == 'MA2' ? _useRound(_MA2) : _input == 'MA3' ? math.round(_MA3, 2) : _input == '_pMA1a' ? _useRound(_pMA1a) : _input == '_pMA1b' ? _useRound(_pMA1b) : _input == '_pMA2a' ? _useRound(_pMA2a) : _input == '_pMA2b' ? _useRound(_pMA2b) : _input == '_pMA3a' ? _useRound(_pMA3a) : _input == '_pMA2b' ? _useRound(_pMA3a) : na
////# Tables
var table topTable = table.new(position.top_center, 15, 15, border_width=3)
var table topRightTable = table.new(position.top_right, 15, 15, border_width=3)
var table topLeftTable = table.new(position.top_right, 15, 15, border_width=3)
var table bottomTable = table.new(position.bottom_center, 15, 15, border_width=3)
var table middleTable = table.new(position.middle_right, 15, 15, border_width=3)
var table bottomRightTable = table.new(position.bottom_right, 15, 15, border_width=3)
var table bottomLeftTable = table.new(position.bottom_right, 15, 15, border_width=3)
var table table1 = table.new(position.bottom_left, 15, 15, border_width=3)
////# UI State Logic
___useEntryOptions = _useOptions(useEntryOptions)
___useExitOptions = _useOptions(useExitOptions)
___useStopOptions = _useOptions(useStopOptions)
// ___useProfitOptions = _useOptions(useProfitOptions)
printProfit(_buy, _sell) =>
_fee = useFEE
netBuy = _buy - _buy * _fee
netSell = _sell - _sell * _fee
netProfit = math.round(netSell - netBuy, useRound) * useQuantity
netProfit
////////////////////////////////////////////////////////////////////}
////# Strategy
////////////////////////////////////////////////////////////////////{
// ////# Set Limit Orders when retracement prices are hit
// var long = false
// var exitlong = false
// if downtexist[1] and not downtexist and uptexist
// long := true
// long
// if long and downtexist
// long := false
// exitlong := true
// exitlong
// var short = false
// // exitshort = false
// if uptexist[1] and not uptexist and downtexist
// short := true
// short
// if short and uptexist
// short := false
// exitshort := true
// exitshort
bullishMarket = close > pLevel and not(close < pLevel)
bearishMarket = close < pLevel
////
__bearishBuy = EngulfingBullish and __emaDOWN and showBearishBuy
__volumeBuy = _VolumeBuy and showVolumeBuy
// RSIbuy
strongBuy = isStrongDown and isUp
__long3x = strongBuy and greenCandle and volu1
__lowestBuy = __emaDOWN and greenCandle and showGreen and underBought
__volumeEngulfing = EngulfingBullish and volu2
showBearVolume = input.bool(defval=true, title = "Show \n Bearish Volume", inline = "Bearish", group=__groupCandlePatterns)
////
if showBullish
////# Identify GREEN types
if __bearishBuy
var _description = "Engulfing Bullish candle with low EMA..."
label.new(bar_index, patternLabelPosLow, text="Bearish \n Buy", style=label.style_label_up, color = color.yellow, textcolor=color.black,tooltip = _description)
if __volumeBuy
label.new(bar_index, patternLabelPosLow, text=str.tostring("Volume \n Buy"), style=label.style_label_up, color = color.yellow, textcolor=color.black)
if EngulfingBearish and __emaUP
var _description = "EngulfingBearish and __emaUP ..."
label.new(bar_index, patternLabelPosLow, text="Bearish \n Buy", style=label.style_label_up, color = color.yellow, textcolor=color.black,tooltip = _description)
if RSIbuy
var _description = "This candle should form when there is an RSI buy and volume buy"
label.new( bar_index, patternLabelPosLow, text="RSI\nVolume", style=label.style_label_up, color = color.green, textcolor=color.black, tooltip=_description)
if __lowestBuy
var _description = "This candle should form when there is a green candle with ema down not BullTrap. (The false up signal is still being isolated). "
label.new( bar_index, patternLabelPosLow, text="Buy\nLow", style=label.style_label_up, color = color.green, textcolor=color.black, tooltip=_description)
if __long3x
var _description = "This candle should form when there is a green candle with ema down"
label.new( bar_index, patternLabelPosLow, text="Long \n 3X", style=label.style_label_up, color = color.green, textcolor=color.black, tooltip=_description)
////# RSI
if RSIbuy // and greenCandle
label.new(bar_index , patternLabelPosLow, text="RSI \n BUY", style=label.style_label_up, color = color.green, textcolor=color.black)
////# Volume
if showBearVolume
if volu1
var _description = "volume"
label.new( bar_index, patternLabelPosLow, text="V1", style=label.style_label_up, color = color.green, textcolor=color.black, tooltip=_description)
if volu2
var _description = "volume"
label.new( bar_index, patternLabelPosLow, text="V2", style=label.style_label_up, color = color.green, textcolor=color.black, tooltip=_description)
if volu3
var _description = "volume"
label.new( bar_index, patternLabelPosLow, text="V3", style=label.style_label_up, color = color.green, textcolor=color.black, tooltip=_description)
if EngulfingBullish and volu2
var _description = "bullish volume engulfing"
label.new( bar_index, patternLabelPosLow, text="Volume \n Engulfing", style=label.style_label_down, color = color.green, textcolor=color.black, tooltip=_description)
////////////////////////////////////////////////////////////////////}
////# Bearish Strategy
////////////////////////////////////////////////////////////////////{
// //////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////
if showBearish
////# Identify YELLOW types
if __DisplayYellowEngulfing
var _description = "Bearish Close \n This occurs __isStrongUP and EngulfingBearish. If a daily candle begins to form this, it is often a STRONG BEARish signal."
label.new(bar_index , patternLabelPosHigh, text="Bearish \n Close Longs", style=label.style_label_down, color = color.yellow, textcolor=color.black,tooltip = _description)
if strongEngulfing and not EngulfingBearish
var _description = "StrongEngulfing and not Bearish Engulfing"
label.new(bar_index , patternLabelPosHigh, text="Bullish \n Close Longs", style=label.style_label_down, color = color.yellow, textcolor=color.black,tooltip = _description)
// if useEngulfing
// if strongEngulfing
// var _description = "Engulfing Bullish candle..."
// label.new(bar_index, patternLabelPosLow, text="YE", style=label.style_label_up, color = color.yellow, textcolor=color.black,tooltip = _description)
////# Volume
if _VolumeSell and showVolumeSell
label.new(bar_index, patternLabelPosLow, text=str.tostring("Close \n Short"), style=label.style_label_up, color = color.red, textcolor=color.black, tooltip="Close \n Short")
// var __volume = true
if showVolumeSell
if vold1
var _description = "volume"
label.new( bar_index, patternLabelPosLow, text="VD\n 1", style=label.style_label_up, color = color.red, textcolor=color.black, tooltip=_description)
if vold2
var _description = "volume"
label.new( bar_index, patternLabelPosLow, text="VD\n 2", style=label.style_label_up, color = color.red, textcolor=color.black, tooltip=_description)
if vold3
var _description = "volume"
label.new( bar_index, patternLabelPosLow, text="VD\n 3", style=label.style_label_up, color = color.red, textcolor=color.black, tooltip=_description)
if EngulfingBearish and vold1
var _description = "volume 1"
label.new( bar_index, patternLabelPosLow, text="Close\n Short", style=label.style_label_up, color = color.red, textcolor=color.black, tooltip=_description)
if EngulfingBearish and vold2
var _description = "volume 2"
label.new( bar_index, patternLabelPosLow, text="Close\n Short 2", style=label.style_label_up, color = color.red, textcolor=color.black, tooltip=_description)
if EngulfingBearish and vold3
var _description = "volume 3"
label.new( bar_index, patternLabelPosLow, text="Volume\n Engulfing 3", style=label.style_label_up, color = color.red, textcolor=color.black, tooltip=_description)
////////////////////////////////////////////////////////////////////}
////# WEBHOOKS
////////////////////////////////////////////////////////////////////{
// -Discord Bot Settings ════════════════════════════════════════════════════════════════════════════════════ //
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ZenAndTheArtOfTrading / www.PineScriptMastery.com
// study("Discord Alerts")
// Get user input
botName = input.string(title='Bot Name', defval='Laser-Eyes', tooltip='The display name for this webhook bot')
avatarURL = input.string(title='Avatar URL', defval='', tooltip='Your preferred Avatar image URL')
iconURL = input.string(title='Icon URL', defval='', tooltip='Your preferred message icon image URL')
titleURL = input.string(title='Title URL', defval='https://www.tradingview.com/chart/dotusdt', tooltip='Where you want the title of the message to link to')
useMessage = input.string(title='Message', defval='', tooltip='Optional message to add before the role tag & embed info')
role = input.string(title='Role ID', defval='', tooltip='The role ID you want to ping when this message is sent to discord (optional)')
embedColor = input.string(title='Embed Color', defval='', tooltip='Your embed color (decimal color only - not HEX or RGB!)')
volatility = input.bool(title='Volatility Alerts?', defval=true, tooltip='Turns on/off intraday volatility alerts')
// // Declare constant variables
var ROLE_ID = role == '' ? '' : ' (<@&' + role + '>)'
var ICON1_URL = syminfo.type == 'forex' ? 'https://theartoftrading.com/files/discord/flags/' + syminfo.basecurrency + '.png' : iconURL
var ICON2_URL = syminfo.type == 'forex' ? 'https://theartoftrading.com/files/discord/flags/' + syminfo.currency + '.png' : ''
var MARKET = syminfo.type == 'forex' or syminfo.type == 'crypto' ? syminfo.basecurrency : syminfo.ticker
// // Get market data to send to discord
mktChange = ta.change(close) / close[1] * 100
mktRSI = ta.rsi(close, 14)
// // Custom function to truncate (cut) excess decimal places
truncate(_number, _decimalPlaces) =>
_factor = math.pow(10, _decimalPlaces)
int(_number * _factor) / _factor
// // Custom function to convert pips into whole numbers
atr = ta.atr(14)
toWhole(_number) =>
_return = atr < 1.0 ? _number / syminfo.mintick / (10 / syminfo.pointvalue) : _number
_return := atr >= 1.0 and atr < 100.0 and syminfo.currency == 'JPY' ? _return * 100 : _return
_return
// // Generate discord embed JSON
// // https://courses.theartoftrading.com/pages/pine-script-mastery-source-code#discord
getDiscordEmbedJSON(_color, _author, _title, _url, _icon_url, _icon2_url, _footer, _description) =>
botTxt = '"username":"' + botName + '","avatar_url":"' + avatarURL + '",'
tagTxt = useMessage == '' and role == '' ? '' : '"content":"' + (useMessage == '' ? '' : useMessage + ' ') + ROLE_ID + '",'
returnString = '{' + botTxt + tagTxt + '"embeds":[{"title":"' + _title + '","url":"' + _url + '","color":' + _color + ',"description":"' + _description + '","author":{"name":"' + _author + '","url":"' + _url + '","icon_url":"' + _icon_url + '"},"footer":{"text":"' + _footer + '","icon_url":"' + _icon2_url + '"}}]}'
returnString
// Determine if we have a new bar starting - if so, send our Discord webhook alert
// var content = ""
if barstate.isconfirmed
timeframe = (timeframe.isintraday ? timeframe.period + ' minute' : timeframe.isdaily ? 'Daily' : timeframe.isweekly ? 'Weekly' : timeframe.ismonthly ? 'Monthly' : timeframe.period) + ' timeframe'
update = syminfo.ticker + ' ended ' + (mktChange > 0 ? 'up +' : 'down ') + str.tostring(truncate(mktChange, 2)) + '% on ' + timeframe + ' (RSI = ' + str.tostring(truncate(mktRSI, 2)) + ')'
gainLoss = toWhole(open - close)
footer = 'Price: ' + str.tostring(close) + ' (' + (gainLoss > 0 ? '+' : '') + str.tostring(gainLoss) + ' pips)'
gainColor = embedColor != '' ? embedColor : mktChange > 0 ? '65280' : '16711680'
content = getDiscordEmbedJSON(gainColor, 'Market Update', syminfo.ticker, titleURL, ICON1_URL, ICON2_URL, footer, update)
content
// table.cell(middleTable, 0, 3, "Market is Bullish ... \n"+tostring(content), text_size = textSize, width= 0, height= 0,text_color = color.green)
// alert(content, alert.freq_once_per_bar)
////# Real-Time?
if barstate.islast
////# Alerts
// __timeframe = (timeframe.isintraday ? timeframe.period + " minute" : timeframe.isdaily ? "Daily" : timeframe.isweekly ? "Weekly" : timeframe.ismonthly ? "Monthly" : timeframe.period) + " timeframe"
// __update = syminfo.ticker + " is " + (mktChange > 0 ? "up +" : "down ") + tostring(truncate(mktChange,2)) + "% [" + tostring(close) + "] on " + __timeframe + " (RSI = " + tostring(truncate(mktRSI,2)) + ")"
// __gainLoss = toWhole(open - close)
// __footer = "Price: " + tostring(close) + " (" + (__gainLoss > 0 ? "+" : "") + tostring(__gainLoss) + " pips)"
// __gainColor = (embedColor != "" ? embedColor : (mktChange > 0 ? "65280" : "16711680"))
// __content = getDiscordEmbedJSON(__gainColor, "High Volatility Alert", syminfo.ticker, titleURL, ICON1_URL, ICON2_URL, __footer, __update)
////# NEUTRAL Trend
if __isNA and showEMAneutral
var _description = 'ema is __isNA'
label.new(bar_index, patternLabelPosLow, text='\n NA \n', style=label.style_label_up, color=color.white, textcolor=color.black, tooltip=_description)
////# BULLISH Trend Labels
if bullishMarket == true
// table.cell(middleTable, 0, 3, "Market is Bullish ... \n"+tostring(floor(sumbull-sumbear)), text_size = textSize, width= 0, height= 0,text_color = color.green)
// if timeframe.period =="1"
// createEstimate(bottomTable,"Stop/Profit: ", 4, ___useStopOptions, ___useEntryOptions, ___useExitOptions, color.new(color.red, 80))
////# BULLISH labels
if isUp and showEMAup
var _description = 'ema is isUp'
label.new(bar_index, patternLabelPosLow, text='\n UP \n', style=label.style_label_up, color=color.green, textcolor=color.black, tooltip=_description)
////# BEARISH Trend
if bearishMarket == true
// table.cell(middleTable, 0, 3, " Market is Bearish ... \n"+tostring(floor(sumbear -sumbull)), text_size = textSize, width= 0, height= 0,text_color = color.red)
////# BEARISH labels
if isDown and showEMAdown
var _description = 'ema is isDown'
label.new(bar_index, patternLabelPosHigh, text='DOWN', style=label.style_label_down, color=color.red, textcolor=color.black, tooltip=_description)
alertcondition(EngulfingBullish and volu2 ? bar_index : na, "Bullish Volume Engulfing")
// plotshape(__isNA and showEMAneutral ? bar_index:na, location=location.abovebar, text="NA", color=color.white)
alertcondition(__isNA ? bar_index : na, 'NA', '\n{{exchange}}:{{ticker}}->\nPrice = {{close}},\nTime = {{time}}')
// plotshape(isDown and showEMAdown ? bar_index:na, style=shape.arrowdown,location=location.belowbar, text="down", color=color.red)
alertcondition(isDown ? bar_index : na, 'DOWN', '{"content": "Trend is... DOWN!", "tts": true }')
// plotshape(__isStrongDown and showStrongEMAdown ? bar_index:na, style=shape.arrowdown,location=location.abovebar, text="strong \n down", color=color.red)
alertcondition(__isStrongDown ? bar_index : na, 'Strong DOWN', '\n{{exchange}}:{{ticker}}->\nPrice = {{close}},\nTime = {{time}}')
// plotshape(isUp and showEMAup ? bar_index:na, style=shape.arrowup,location=location.belowbar, text="up", color=color.green)
alertcondition(isUp ? bar_index : na, 'UP', '{"content": "Trend is... UP!", "tts": true }')
// plotshape(isStrongUp and showStrongEMAup ? bar_index:na, style=shape.arrowup,location=location.belowbar, text="strong \n up", color=color.yellow)
alertcondition(isStrongUp ? bar_index : na, 'isStrongUp', '{"content": "Trend is... STRONG UP, set stoploss to s1Level and if you get stoplossed, consider DYOR on opening a short... !", "tts": true }')
////# Alert Conditions
//// https://www.tradingview.com/script/FPq2xKyZ-DiscordWebhookFunction/
import wlhm/DiscordWebhookFunction/1
// discordWebhookJSON(
// _username,
// _avatarImgUrl,
// _contentText,
// _bodyTitle,
// _descText,
// _bodyUrl,
// _embedCol,
// _timestamp,
// _authorName,
// _authorUrl,
// _authorIconUrl,
// _footerText,
// _footerIconUrl,
// _thumbImgUrl,
// _imageUrl)
// -RSI Alerts ════════════════════════════════════════════════════════════════════════════════════ //
// {"content": "HYDRA Trend is... UP...on the 1 Hour.", "tts": true }
alertcondition(ta.crossover(close, crossover_overbought), 'RSI Sell', 'Crossover Previous Overbought\n{{exchange}}:{{ticker}}->\nPrice = {{close}},\nTime = {{time}}')
alertcondition(ta.crossunder(close, crossunder_oversold), 'RSI Buy', 'Crossunder Previous Oversold\n{{exchange}}:{{ticker}}->\nPrice = {{close}},\nTime = {{time}}')
// -Volume Alerts ════════════════════════════════════════════════════════════════════════════════════ //
alertcondition(vold1 or vold2 or vold3, 'Volume Buy', '{"content": "volume SELLING conditions may be forming! \n This means that there is an Engulfing Bullish and vol up 2", "tts": true }')
alertcondition(volu1 or volu2 or volu3, 'Volume SELL', '{"content": "volume BUYING conditions may be forming! \n In theory, this should be a SHORT position... meaning that there is an Engulfing Bearish and vol down 2", "tts": true }')
alertcondition(EngulfingBearish ? bar_index : na, 'EngulfingBearish', '{"content": "Bearish Engulfing may be forming!", "tts": true }')
alertcondition(EngulfingBullish ? bar_index : na, 'EngulfingBullish', '{"content": "EngulfingBullish Engulfing may be forming!", "tts": true }')
alertcondition(__volumeEngulfing ? bar_index : na, 'volume Engulfing', '{"content": "volume Engulfing Engulfing may be forming! \n This means that there is an Engulfing Bullish and vol up 2", "tts": true }')
////# posible Reversal
alertcondition((bullishMarket or RSIbuy) and __isStrongDown and isUp and (volu1 or volu2 or volu3) ? bar_index : na, 'BULLISH Scalping Opportunity (1M)', '{"content": "On lower timefrrames such as the 1 minute ... the market looks Bullish because the current price is above the pivot line and on the RSI is oversold and there is possitive volume. Additionally the ema trend is moving between strong down and up which suggest a floor may have been reacheed... Always DYOR before opening a position because lower timeframes do not carry the same weight...", "tts": true }')
alertcondition((bearishMarket or RSIsell) and isStrongUp and isDown and (vold1 or vold2 or vold3) ? bar_index : na, 'BEARISH Scalping Opportunity (1M)', '{"content": "On lower timefrrames such as the 1 minute ... the market looks BEARISH because the current price is BELOW the pivot line and on the RSI is OVERBOUGHT and there is negitive volume. Additionally the ema trend is moving between strong up and DOWN which suggest a floor may have been reacheed... Always DYOR before opening a position because lower timeframes do not carry the same weight...", "tts": true }')
// {"content": "ETH Trend is... STRONG UP...on the 1 Hour. This indicates it may be too late to open a LONG so always DYOR", "tts": true }
// if (exitshort or (zzlong and not zzlong[1]) )
// strategy.entry("Long", strategy.long)
// if (exitlong or (zzshort and not zzshort[1]) )
// strategy.entry("Short", strategy.short)
////////////////////////////////////////////////////////////////////}
//# * HELLO STREAM...
// ⬆️ GREEN Triangle Pointed Up means, open long/er a long
// ✖️ Close the LONG, and consider a opening a short
// Retracements could become engulfing candles or reversals/breakouts, if the current price os below
////////////////////////////////////////////////////////////////////{
|
MACD - STOCH - RSI | https://www.tradingview.com/script/AL3NrxBl-MACD-STOCH-RSI/ | Clancy3gbh | https://www.tradingview.com/u/Clancy3gbh/ | 77 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Clancy3gbh
//@version=4
study(title="MACD - STOCH - RSI", shorttitle = "M.S.R v1", overlay = false, resolution = "")
// ▄▄▄▄▄
// ▐ MACD - STOCHSTIC - RSI all in one.
// ▐ Hope you enjoy.
// ▐ All feedback is good feedback.
// ▀▀▀▀▀
//══════════════════════════════════════════════════════════════════════════════
[macdline, signalline, macdhist] = macd(close, 12, 26, 9)
i_vol = input(false, 'Volume Bars', group = 'MACD Settings', tooltip = 'Changes histogram color if volume is above average.')
i_rsiSwitch = input(false, 'Overlay RSI | ----- |', group = 'RSI Settings', inline = '0')
i_switch = input(false, 'Overlay Stoch', group = "Stochastic Settings", inline = '0')
c_green = macdhist > macdhist [1] ? color.new(#03B108, 20) : color.new(#6DFF71, 20)
c_red = macdhist < macdhist [1] ? color.new(#890000, 20) : color.new(#FF6D6D, 20)
c_macd = macdhist > 0 ? c_green : c_red
avg = sum(volume, 10)/10
def = iff(volume > (avg * 2), 1, iff(volume > (avg * 1.5), 2, na))
c_defblue = def == 1 ? color.new(#0068B8, 20) : def == 2 ? color.new(#5FB9FF, 20) : c_macd
c_defyellow = def == 1 ? color.new(#550093, 20) : def == 2 ? color.new(#D398FF, 20) : c_macd
c_postmacd = macdhist > 0 ? c_defblue : c_defyellow
plot(i_rsiSwitch ? na : i_switch ? na : macdhist, "Histogram", style=plot.style_columns, color = i_vol ? c_postmacd : c_macd)
//══════════════════════════════════════════════════════════════════════════════
// ▄▄▄▄▄
// ▐ RSI overlay code. [3GBH]
// ▀▀▀▀▀
//══════════════════════════════════════════════════════════════════════════════
i_rsilvl = input(true, 'RSI levels', group = 'RSI Settings', tooltip = 'Shows RSI overbought and oversold levels when RSI enabled.')
i_cRsi = input(true, 'Basis Color', group = 'RSI Settings', inline = '0', tooltip = 'Middle line becomes GREEN / RED whether RSI is ABOVE / BELOW.')
i_ob = input(20, 'OB Level', group = 'RSI Settings', inline = '1')
i_os = input(-20, '| OS Level', group = 'RSI Settings', inline = '1')
//══════════════════════════════════════════════════════════════════════════════
f_src = rsi(close, 14)
f_rsi(src) =>
var float counter = 0.0
if src == 50
counter := 0
else if src >= 50.01
counter := src - 50
else if src <= 49.99
counter := src - 50
counter
rsi = f_rsi(f_src)
//══════════════════════════════════════════════════════════════════════════════
clr = rising(rsi, 1) ? color.new(#56FF7C, 40) : color.new(#FF5656, 40)
clr2 = rising(rsi, 1) ? color.new(#56FF7C, 80) : color.new(#FF5656, 80)
clr3 = rsi > 0 ? color.new(#56FF7C, 80) : color.new(#FF5656, 80)
plot(i_rsiSwitch ? rsi : na, color=clr)
// use this line ^ of code. ----- To toggle on/off the overlay
// and change the levels in the Overbought and Oversold inputs.
plot(i_rsiSwitch ? 0 : na, 'Middle', color = i_cRsi ? clr3 : clr2)
plot(i_rsiSwitch and i_rsilvl ? i_ob : na, 'OB', color = color.new(#d6d6d6, 80))
plot(i_rsiSwitch and i_rsilvl ? i_os : na, 'OS', color = color.new(#d6d6d6, 80))
//══════════════════════════════════════════════════════════════════════════════
// ▄▄▄▄▄
// ▐ STOCHASTIC overlay code. [3GBH]
// ▀▀▀▀▀
//══════════════════════════════════════════════════════════════════════════════
i_stlvl = input(true, ' STOCH levels', group = 'Stochastic Settings', tooltip = 'Shows STOCHASTIC overbought and oversold levels when STOCHASTIC enabled.')
periodK = input(14, "%K Length", group = "Stochastic Settings")
smoothK = input(1, "%K Smoothing", group = "Stochastic Settings")
periodD = input(3, "%D Smoothing", group = "Stochastic Settings")
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)
i_obST = input(35, 'OB Level', group = "Stochastic Settings", inline = '1')
i_osST = input(-35, '| OS Level', group = "Stochastic Settings", inline = '1')
//══════════════════════════════════════════════════════════════════════════════
f_src1 = k
f_src2 = d
f_stoch(src) =>
var float counter = 0.0
if src == 50
counter := 0
else if src >= 50.01
counter := src - 50
else if src <= 49.99
counter := src - 50
counter
stoch_k = f_stoch(f_src1)
stoch_d = f_stoch(f_src2)
//══════════════════════════════════════════════════════════════════════════════
plot(i_switch ? stoch_k : na, "%K", color = color.new(#2962FF, 66))
plot(i_switch ? stoch_d : na, "%D", color = color.new(#FF6D00, 70))
plot(i_switch and i_stlvl ? i_obST : na, "Upper Band", color = color.new(#B3B3B3, 60))
plot(i_switch and i_stlvl ? i_osST : na, "Lower Band", color = color.new(#B3B3B3, 60))
//══════════════════════════════════════════════════════════════════════════════
|
Chaikin Volume Accumulation Oscillator (VAO) | https://www.tradingview.com/script/Up19Cl7w-chaikin-volume-accumulation-oscillator-vao/ | GrannyCola | https://www.tradingview.com/u/GrannyCola/ | 29 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © GrannyCola
//@version=4
study("Chaikin Volume Accumulation Oscillator (VAO)")
len = input(2, minval=2, title="EMA Length")
va = (close - hl2) * volume
cumulated_va = cum(va)
smoothed_va = ema(cumulated_va, len)
osc = (cumulated_va - smoothed_va) / smoothed_va
ema_osc = ema(osc, len)
plot(osc, color=#FFFFFF)
plot(ema_osc, color=#FF0000)
//end |
vol_bracket | https://www.tradingview.com/script/IWWp8qKO-vol-bracket/ | voided | https://www.tradingview.com/u/voided/ | 60 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © voided
// This simple script shows an "N" standard deviation volatility bracket,
// anchored at the opening price of the current month, week, or quarter. This
// anchor is meant to coincide roughly with the expiration of options issued at
// the same interval. You can choose between a manually-entered IV or the
// hv30 volatility model.
//
// The table shows the "efficiency" which is the ratio of periods where price
// closed within the bracket (both), below the top bound (up), or above the
// bottom bound (down).
//
// This script is meant for the daily chart. It is not accurate on intraday
// charts.
//@version=4
study("vol_bracket", overlay = true)
// inputs
model = input(title = "model", options = [ "hv20", "iv" ], defval = "hv20")
iv = input(title = "iv", type = input.float, defval = 20.0) / 100
period = input(title = "period", options = [ "daily", "weekly", "monthly", "quarterly" ], defval = "daily")
stdevs = input(title = "stdevs", type = input.float, defval = 1.0)
// time for scaling bands
t = if period == "weekly"
sqrt(1.0 / 52)
else if period == "monthly"
sqrt(1.0 / 12)
else if period == "quarterly"
sqrt(1.0 / 4)
else if period == "daily"
sqrt(1.0 / 252)
// set mark
var float mark = 0
var int periods = 0
quarter = int(month(time_close) / 4)
new_day = true
new_week = weekofyear != weekofyear[1]
new_month = month(time_close) != month(time_close)[1]
new_quarter = quarter != quarter[1]
new_period = false
if (period == "weekly" and new_week) or (period == "monthly" and new_month) or (period == "quarterly" and new_quarter) or (period == "daily" and new_day)
mark := open
periods := periods + 1
new_period := true
else
mark := mark[1]
// hv30
r = log(close / close[1])
variance = pow(r, 2)
hv20 = sqrt(ema(variance, 20) * 252)
// choose model
v = if model == "hv20"
hv20
else if model == "iv"
iv
// set bracket
up = mark * (1 + v * t * stdevs)
down = mark * (1 - v * t * stdevs)
in_up = new_period and close[1] < up[1] ? 1 : 0
in_down = new_period and close[1] > down[1] ? 1 : 0
in_both = new_period and in_up == 1 and in_down == 1 ? 1 : 0
total_in_up = cum(in_up)
total_in_down = cum(in_down)
total_in_both = cum(in_both)
// table
if barstate.islast
var ot = table.new(position.top_right, 4, 3, bgcolor = color.white)
fmt = "#.##"
lbl_clr = color.new(color.green, 70)
table.cell(ot, 0, 0, "efficiency", bgcolor = lbl_clr)
table.cell(ot, 1, 0, "both", bgcolor = lbl_clr)
table.cell(ot, 2, 0, "up", bgcolor = lbl_clr)
table.cell(ot, 3, 0, "down", bgcolor = lbl_clr)
table.cell(ot, 0, 1, "percentage", bgcolor = lbl_clr)
table.cell(ot, 1, 1, tostring(total_in_both / periods * 100, fmt))
table.cell(ot, 2, 1, tostring(total_in_up / periods * 100, fmt))
table.cell(ot, 3, 1, tostring(total_in_down / periods * 100, fmt))
table.cell(ot, 0, 2, "count", bgcolor = lbl_clr)
table.cell(ot, 1, 2, tostring(total_in_both) + " / " + tostring(periods))
table.cell(ot, 2, 2, tostring(total_in_up) + " / " + tostring(periods))
table.cell(ot, 3, 2, tostring(total_in_down) + " / " + tostring(periods))
var ot2 = table.new(position.middle_right, 2, 1, bgcolor = color.white)
table.cell(ot2, 0, 0, model, bgcolor = lbl_clr)
table.cell(ot2, 1, 0, tostring(v, "#.###"))
// plot
bracket_style = period == "daily" ? plot.style_circles : plot.style_stepline
in_now = close < up and close > down
in_clr = color.blue
out_clr = color.fuchsia
plot(mark, color = color.new(color.gray, 60), style = bracket_style)
plot(up, color = in_now ? in_clr : out_clr, style = bracket_style)
plot(down, color = in_now ? in_clr : out_clr, style = bracket_style) |
Fishnet | https://www.tradingview.com/script/tPwEqpej/ | jhpotz123 | https://www.tradingview.com/u/jhpotz123/ | 31 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jhara
//@version=4
study("Fishnet", "FISH", true)
// Inputs
movingAverageType = input("sma", "Moving average type", options = ["sma", "ema"])
lowestMovingAverage = input(5, "Lowest moving average length", minval = 1)
stepSize = input(5, "Step size in between the moving averages", minval = 1)
numberOfMovingAverages = input(25, "Number of moving averages (1 - 64)", minval = 1, maxval = 64)
linewidth = input(2, "Linewidth (1 - 4)", minval = 1, maxval = 4)
movingAverage(type, closePrice, timePeriod) =>
if type == "sma"
sma(closePrice, timePeriod)
else if type == "ema"
ema(closePrice, timePeriod)
color0 = color.new(#CCCCCC, 50)
initialMovingAverage = movingAverage(movingAverageType, close, lowestMovingAverage)
plot(numberOfMovingAverages < 1 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 1) * stepSize) , "", color.new(#FC0010, 50), linewidth)
plot(numberOfMovingAverages < 2 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 2) * stepSize) , "", color.new(#FC0410, 50), linewidth)
plot(numberOfMovingAverages < 3 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 3) * stepSize) , "", color.new(#FC0810, 50), linewidth)
plot(numberOfMovingAverages < 4 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 4) * stepSize) , "", color.new(#FC0C10, 50), linewidth)
plot(numberOfMovingAverages < 5 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 5) * stepSize) , "", color.new(#FC1010, 50), linewidth)
plot(numberOfMovingAverages < 6 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 6) * stepSize) , "", color.new(#FC1410, 50), linewidth)
plot(numberOfMovingAverages < 7 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 7) * stepSize) , "", color.new(#FC1810, 50), linewidth)
plot(numberOfMovingAverages < 8 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 8) * stepSize) , "", color.new(#FC1C10, 50), linewidth)
plot(numberOfMovingAverages < 9 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 9) * stepSize) , "", color.new(#FC2010, 50), linewidth)
plot(numberOfMovingAverages < 10 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 10)* stepSize) , "", color.new(#FC2410, 50), linewidth)
plot(numberOfMovingAverages < 11 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 11)* stepSize) , "", color.new(#FC2810, 50), linewidth)
plot(numberOfMovingAverages < 12 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 12)* stepSize) , "", color.new(#FC2C10, 50), linewidth)
plot(numberOfMovingAverages < 13 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 13)* stepSize) , "", color.new(#FC3010, 50), linewidth)
plot(numberOfMovingAverages < 14 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 14)* stepSize) , "", color.new(#FC3410, 50), linewidth)
plot(numberOfMovingAverages < 15 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 15)* stepSize) , "", color.new(#FC3810, 50), linewidth)
plot(numberOfMovingAverages < 16 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 16)* stepSize) , "", color.new(#FC3C10, 50), linewidth)
plot(numberOfMovingAverages < 17 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 17)* stepSize) , "", color.new(#FC4010, 50), linewidth)
plot(numberOfMovingAverages < 18 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 18)* stepSize) , "", color.new(#FC4410, 50), linewidth)
plot(numberOfMovingAverages < 19 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 19)* stepSize) , "", color.new(#FC4810, 50), linewidth)
plot(numberOfMovingAverages < 20 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 20)* stepSize) , "", color.new(#FC4C10, 50), linewidth)
plot(numberOfMovingAverages < 21 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 21)* stepSize) , "", color.new(#FC5010, 50), linewidth)
plot(numberOfMovingAverages < 22 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 22)* stepSize) , "", color.new(#FC5410, 50), linewidth)
plot(numberOfMovingAverages < 23 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 23)* stepSize) , "", color.new(#FC5810, 50), linewidth)
plot(numberOfMovingAverages < 24 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 24)* stepSize) , "", color.new(#FC5C10, 50), linewidth)
plot(numberOfMovingAverages < 25 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 25)* stepSize) , "", color.new(#FC6010, 50), linewidth)
plot(numberOfMovingAverages < 26 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 26)* stepSize) , "", color.new(#FC6410, 50), linewidth)
plot(numberOfMovingAverages < 27 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 27)* stepSize) , "", color.new(#FC6810, 50), linewidth)
plot(numberOfMovingAverages < 28 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 28)* stepSize) , "", color.new(#FC6C10, 50), linewidth)
plot(numberOfMovingAverages < 29 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 29)* stepSize) , "", color.new(#FC7010, 50), linewidth)
plot(numberOfMovingAverages < 30 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 30)* stepSize) , "", color.new(#FC7410, 50), linewidth)
plot(numberOfMovingAverages < 31 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 31)* stepSize) , "", color.new(#FC7810, 50), linewidth)
plot(numberOfMovingAverages < 32 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 32)* stepSize) , "", color.new(#FC7C10, 50), linewidth)
plot(numberOfMovingAverages < 33 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 33)* stepSize) , "", color.new(#FC8010, 50), linewidth)
plot(numberOfMovingAverages < 34 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 34)* stepSize) , "", color.new(#FC8410, 50), linewidth)
plot(numberOfMovingAverages < 35 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 35)* stepSize) , "", color.new(#FC8810, 50), linewidth)
plot(numberOfMovingAverages < 36 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 36)* stepSize) , "", color.new(#FC8C10, 50), linewidth)
plot(numberOfMovingAverages < 37 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 37)* stepSize) , "", color.new(#FC9010, 50), linewidth)
plot(numberOfMovingAverages < 38 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 38)* stepSize) , "", color.new(#FC9410, 50), linewidth)
plot(numberOfMovingAverages < 39 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 39)* stepSize) , "", color.new(#FC9810, 50), linewidth)
plot(numberOfMovingAverages < 40 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 40)* stepSize) , "", color.new(#FC9C10, 50), linewidth)
plot(numberOfMovingAverages < 41 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 41)* stepSize) , "", color.new(#FCA010, 50), linewidth)
plot(numberOfMovingAverages < 42 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 42)* stepSize) , "", color.new(#FCA410, 50), linewidth)
plot(numberOfMovingAverages < 43 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 43)* stepSize) , "", color.new(#FCA810, 50), linewidth)
plot(numberOfMovingAverages < 44 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 44)* stepSize) , "", color.new(#FCAC10, 50), linewidth)
plot(numberOfMovingAverages < 45 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 45)* stepSize) , "", color.new(#FCB010, 50), linewidth)
plot(numberOfMovingAverages < 46 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 46)* stepSize) , "", color.new(#FCB410, 50), linewidth)
plot(numberOfMovingAverages < 47 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 47)* stepSize) , "", color.new(#FCB810, 50), linewidth)
plot(numberOfMovingAverages < 48 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 48)* stepSize) , "", color.new(#FCBC10, 50), linewidth)
plot(numberOfMovingAverages < 49 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 49)* stepSize) , "", color.new(#FCC010, 50), linewidth)
plot(numberOfMovingAverages < 50 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 50)* stepSize) , "", color.new(#FCC410, 50), linewidth)
plot(numberOfMovingAverages < 51 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 51)* stepSize) , "", color.new(#FCC810, 50), linewidth)
plot(numberOfMovingAverages < 52 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 52)* stepSize) , "", color.new(#FCCC10, 50), linewidth)
plot(numberOfMovingAverages < 53 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 53)* stepSize) , "", color.new(#FCD010, 50), linewidth)
plot(numberOfMovingAverages < 54 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 54)* stepSize) , "", color.new(#FCD410, 50), linewidth)
plot(numberOfMovingAverages < 55 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 55)* stepSize) , "", color.new(#FCD810, 50), linewidth)
plot(numberOfMovingAverages < 56 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 56)* stepSize) , "", color.new(#FCDC10, 50), linewidth)
plot(numberOfMovingAverages < 57 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 57)* stepSize) , "", color.new(#FCE010, 50), linewidth)
plot(numberOfMovingAverages < 58 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 58)* stepSize) , "", color.new(#FCE410, 50), linewidth)
plot(numberOfMovingAverages < 59 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 59)* stepSize) , "", color.new(#FCE810, 50), linewidth)
plot(numberOfMovingAverages < 60 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 60)* stepSize) , "", color.new(#FCEC10, 50), linewidth)
plot(numberOfMovingAverages < 61 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 61)* stepSize) , "", color.new(#FCF010, 50), linewidth)
plot(numberOfMovingAverages < 62 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 62)* stepSize) , "", color.new(#FCF410, 50), linewidth)
plot(numberOfMovingAverages < 63 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 63)* stepSize) , "", color.new(#FCF810, 50), linewidth)
plot(numberOfMovingAverages < 64 ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 64)* stepSize) , "", color.new(#FCFC10, 50), linewidth)
|
Gann Square 9 Price Line Helper (Experimental) | https://www.tradingview.com/script/nCfAeZuI-Gann-Square-9-Price-Line-Helper-Experimental/ | RozaniGhani-RG | https://www.tradingview.com/u/RozaniGhani-RG/ | 211 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RozaniGhani-RG
// Inspired by The Tunnel Thru The Air Or Looking Back From 1940, written by WD Gann
//
// Related build
// https://www.tradingview.com/script/WMeyD4Sy-Gann-Square-4-Cross-Cardinal-Table-Concept/
// https://www.tradingview.com/script/mEzLbIKm-Gann-Square-9-Cross-Cardinal-Table-Concept/
// https://www.tradingview.com/script/yH604xPv-Gann-Square-4-Table-Concept-Alternate-UI/
// https://www.tradingview.com/script/n0CPKM4g-Gann-Square-9-Table-Concept-Alternate-UI/
//@version=4
study("Gann Square 9 Price Line Helper (Experimental)", shorttitle = "GS9PLH_Experimental", overlay = true, max_bars_back = 5000, max_lines_count = 500, max_labels_count = 500)
// 0. Arrays
// 1. Variables and general inputs
// 2. Custom functions
// 3. if statament
// 4. Inputs for Cross and Cardinal
// 0. Arrays
// 0 1 2 3 4 5 6 7 8
arr_cross_0 = array.from(2, 11, 28, 53, 86, 127, 176, 233, 298)
arr_cross_90 = array.from(4, 15, 34, 61, 96, 139, 190, 249, 316)
arr_cross_180 = array.from(6, 19, 40, 69, 106, 151, 204, 265, 334)
arr_cross_270 = array.from(8, 23, 46, 77, 116, 163, 218, 281, 352)
arr_cardinal_45 = array.from(3, 13, 31, 57, 91, 133, 183, 241, 307)
arr_cardinal_135 = array.from(5, 17, 37, 65, 101, 145, 197, 257, 325)
arr_cardinal_225 = array.from(7, 21, 43, 73, 111, 157, 211, 273, 343)
arr_cardinal_315 = array.from(9, 25, 49, 81, 121, 169, 225, 289, 361)
// sort array
array.sort(arr_cross_0, order.descending)
array.sort(arr_cardinal_45, order.descending)
array.sort(arr_cross_90, order.descending)
// 1. Variables and general inputs
G0 = "Cross"
G1 = "Cross Cardinal"
G2 = " Cross Cardinal"
G3 = "Color"
show_table = input(true, "Show Table", inline = "Table")
input_pos = input("Left", "", options = ["Left", "Middle", "Right"], inline = "Table")
input_font = input("Normal", "", options = ["Tiny", "Small", "Normal", "Large", "Huge"], inline = "Table")
table_pos = input_pos == "Left" ? position.middle_left : input_pos == "Right" ? position.middle_right : position.middle_center
font = input_font == "Tiny" ? size.tiny : input_font == "Small" ? size.small :
input_font == "Large" ? size.large : input_font == "Huge" ? size.huge :
size.normal
var testTable = table.new(position = table_pos, columns = 21, rows = 21, bgcolor = color.black, border_width = 1)
n0 = input(0, "Line Position ", minval = 0, inline = "Line Position")
n1 = input(50, "", minval = 1, inline = "Line Position")
mult = input(1, "Fixed Gann Multiply ", options = [0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000, 100000])
style0 = input("Solid", "Line ", options = ["Solid", "Dash", "Dot"], group = G2, inline = "Line")
style1 = input("Dash", "", options = ["Solid", "Dash", "Dot"], group = G2, inline = "Line")
extend0 = input("None", "Extend", options = ["None", "Left", "Right", "Both"], group = G2, inline = "Extend")
extend1 = input("None", "", options = ["None", "Left", "Right", "Both"], group = G2, inline = "Extend")
title0 = input("On", "Title ", options = ["On", "Off"], group = G2, inline = "Title")
title1 = input("On", "", options = ["On", "Off"], group = G2, inline = "Title")
label0 = input("Normal", "Label ", options = ["Normal", "Reverse"], group = G2, inline = "Label")
label1 = input("Normal", "", options = ["Normal", "Reverse"], group = G2, inline = "Label")
input_col_cross = input(false, "Cross ", group = G3, inline = "Cross")
input_col_cross_0 = input(color.red, "", group = G3, inline = "Cross")
input_col_cross_1 = input(color.lime, "", tooltip = "Tick to reverse color", group = G3, inline = "Cross")
input_col_cardinal = input(false, "Cardinal", group = G3, inline = "Cardinal")
input_col_cardinal_0 = input(color.orange, "", group = G3, inline = "Cardinal")
input_col_cardinal_1 = input(color.teal, "", tooltip = "Tick to reverse color", group = G3, inline = "Cardinal")
col_cross_0 = input_col_cross ? input_col_cross_0 : input_col_cross_1
col_cross_1 = input_col_cross ? input_col_cross_1 : input_col_cross_0
col_cardinal_0 = input_col_cardinal ? input_col_cardinal_0 : input_col_cardinal_1
col_cardinal_1 = input_col_cardinal ? input_col_cardinal_1 : input_col_cardinal_0
bar0 = label0 == "Normal" ? bar_index[n0] + 5 : bar_index[n1]
bar1 = label1 == "Normal" ? bar_index[n0] + 5 : bar_index[n1]
pos0 = label0 == "Normal" ? label.style_label_left : label.style_label_right
pos1 = label1 == "Normal" ? label.style_label_left : label.style_label_right
// 2. Custom functions
cell_default(_column, _row, _id, _index)=>
table.cell(testTable, _column, _row, tostring(array.get(_id, _index)), bgcolor = color.gray, text_color = color.black, text_size = font)
fun_style(_style) => _style == "Solid" ? line.style_solid : _style == "Dash" ? line.style_dashed : line.style_dotted
fun_extend(_extend) => _extend == "None" ? extend.none : _extend == "Left" ? extend.left : _extend == "Right" ? extend.right : extend.both
cross_title() => title0 == "On" ? "Cross : " : na
cardinal_title() => title1 == "On" ? "Cardinal : " : na
line_new(_arr, _y, _color, _style) =>
line.new(x1 = bar_index[n1], y1 = array.get(_arr, _y) * mult, x2 = bar_index[n0], y2 = array.get(_arr, _y) * mult,
color = _color, style = _style)
label_new_0(_text, _arr, _y, _color) =>
label.new(x = bar0, y = array.get(_arr, _y) * mult,
text = _text + tostring(array.get(_arr, _y) * mult),
style = pos0,
color = _color,
textcolor = color.black, size = size.normal)
label_new_1(_text, _arr, _y, _color) =>
label.new(x = bar1, y = array.get(_arr, _y) * mult,
text = _text + tostring(array.get(_arr, _y) * mult),
style = pos1,
color = _color,
textcolor = color.black, size = size.normal)
// cross custom functions
fun_cross_line(_y) =>
var line id0 = na, line.delete(id0), id0 := line_new(arr_cross_0, _y, col_cross_0, fun_style(style0)), line.set_extend(id0, fun_extend(extend0))
var line id1 = na, line.delete(id1), id1 := line_new(arr_cross_90, _y, col_cross_1, fun_style(style0)), line.set_extend(id1, fun_extend(extend0))
var line id2 = na, line.delete(id2), id2 := line_new(arr_cross_180, _y, col_cross_0, fun_style(style0)), line.set_extend(id2, fun_extend(extend0))
var line id3 = na, line.delete(id3), id3 := line_new(arr_cross_270, _y, col_cross_1, fun_style(style0)), line.set_extend(id3, fun_extend(extend0))
fun_cross_label(_y) =>
var label id0 = na, label.delete(id0), id0 := label_new_0(cross_title(), arr_cross_0, _y, col_cross_0)
var label id1 = na, label.delete(id1), id1 := label_new_0(cross_title(), arr_cross_90, _y, col_cross_1)
var label id2 = na, label.delete(id2), id2 := label_new_0(cross_title(), arr_cross_180, _y, col_cross_0)
var label id3 = na, label.delete(id3), id3 := label_new_0(cross_title(), arr_cross_270, _y, col_cross_1)
cross_set(_y, _input, _column0, _row0, _column1, _row1, _column2, _row2, _column3, _row3) =>
if _input
if show_table
table.cell_set_bgcolor(testTable, _column0, _row0, col_cross_0)
table.cell_set_bgcolor(testTable, _column1, _row1, col_cross_1)
table.cell_set_bgcolor(testTable, _column2, _row2, col_cross_0)
table.cell_set_bgcolor(testTable, _column3, _row3, col_cross_1)
array.sort(arr_cross_0, order.ascending)
array.sort(arr_cross_90, order.ascending)
fun_cross_line(_y)
fun_cross_label(_y)
// cardinal custom functions
fun_cardinal_line(_y) =>
var line id0 = na, line.delete(id0), id0 := line_new(arr_cardinal_45, _y, col_cardinal_0, fun_style(style1)), line.set_extend(id0, fun_extend(extend1))
var line id1 = na, line.delete(id1), id1 := line_new(arr_cardinal_135, _y, col_cardinal_1, fun_style(style1)), line.set_extend(id1, fun_extend(extend1))
var line id2 = na, line.delete(id2), id2 := line_new(arr_cardinal_225, _y, col_cardinal_0, fun_style(style1)), line.set_extend(id2, fun_extend(extend1))
var line id3 = na, line.delete(id3), id3 := line_new(arr_cardinal_315, _y, col_cardinal_1, fun_style(style1)), line.set_extend(id3, fun_extend(extend1))
fun_cardinal_label(_y) =>
var label id0 = na, label.delete(id0), id0 := label_new_1(cardinal_title(), arr_cardinal_45, _y, col_cardinal_0)
var label id1 = na, label.delete(id1), id1 := label_new_1(cardinal_title(), arr_cardinal_135, _y, col_cardinal_1)
var label id2 = na, label.delete(id2), id2 := label_new_1(cardinal_title(), arr_cardinal_225, _y, col_cardinal_0)
var label id3 = na, label.delete(id3), id3 := label_new_1(cardinal_title(), arr_cardinal_315, _y, col_cardinal_1)
cardinal_set(_y, _input, _column0, _row0, _column1, _row1, _column2, _row2, _column3, _row3) =>
if _input
if show_table
table.cell_set_bgcolor(testTable, _column0, _row0, col_cardinal_0)
table.cell_set_bgcolor(testTable, _column1, _row1, col_cardinal_1)
table.cell_set_bgcolor(testTable, _column2, _row2, col_cardinal_0)
table.cell_set_bgcolor(testTable, _column3, _row3, col_cardinal_1)
array.sort(arr_cardinal_45, order.ascending)
fun_cardinal_line(_y)
fun_cardinal_label(_y)
// single custom functions
fun_cross_line_style_0(_arr, _y) =>
var line id = na, line.delete(id), id := line_new(_arr, _y, col_cross_0, fun_style(style0))
line.set_extend(id, fun_extend(extend0))
fun_cross_line_style_1(_arr, _y) =>
var line id = na, line.delete(id), id := line_new(_arr, _y, col_cross_1, fun_style(style0))
line.set_extend(id, fun_extend(extend0))
fun_cardinal_line_style_0(_arr, _y) =>
var line id = na, line.delete(id), id := line_new(_arr, _y, col_cardinal_0, fun_style(style1))
line.set_extend(id, fun_extend(extend1))
fun_cardinal_line_style_1(_arr, _y) =>
var line id = na, line.delete(id), id := line_new(_arr, _y, col_cardinal_1, fun_style(style1))
line.set_extend(id, fun_extend(extend1))
fun_cross_label_0(_text, _arr, _y) =>
var label id = na, label.delete(id), id := label_new_0(_text, _arr, _y, col_cross_0)
fun_cross_label_1(_text, _arr, _y) =>
var label id = na, label.delete(id), id := label_new_0(_text, _arr, _y, col_cross_1)
fun_cardinal_label_0(_text, _arr, _y) =>
var label id = na, label.delete(id), id := label_new_1(_text, _arr, _y, col_cardinal_0)
fun_cardinal_label_1(_text, _arr, _y) =>
var label id = na, label.delete(id), id := label_new_1(_text, _arr, _y, col_cardinal_1)
fun_cross_set_0(_input, _column, _row, _arr, _y) =>
if _input
if show_table
table.cell_set_bgcolor(testTable, _column, _row, col_cross_0)
array.sort(arr_cross_0, order.ascending)
array.sort(arr_cross_90, order.ascending)
array.sort(arr_cardinal_45, order.ascending)
fun_cross_line_style_0( _arr, _y)
fun_cross_label_0(cross_title(), _arr, _y)
fun_cross_set_1(_input, _column, _row, _arr, _y) =>
if _input
if show_table
table.cell_set_bgcolor(testTable, _column, _row, col_cross_1)
array.sort(arr_cross_0, order.ascending)
array.sort(arr_cross_90, order.ascending)
array.sort(arr_cardinal_45, order.ascending)
fun_cross_line_style_1( _arr, _y)
fun_cross_label_1(cross_title(), _arr, _y)
fun_cardinal_set_0(_input, _column, _row, _arr, _y) =>
if _input
if show_table
table.cell_set_bgcolor(testTable, _column, _row, col_cardinal_0)
array.sort(arr_cross_0, order.ascending)
array.sort(arr_cross_90, order.ascending)
array.sort(arr_cardinal_45, order.ascending)
fun_cardinal_line_style_0( _arr, _y)
fun_cardinal_label_0(cardinal_title(), _arr, _y)
fun_cardinal_set_1(_input, _column, _row, _arr, _y) =>
if _input
if show_table
table.cell_set_bgcolor(testTable, _column, _row, col_cardinal_1)
array.sort(arr_cross_0, order.ascending)
array.sort(arr_cross_90, order.ascending)
array.sort(arr_cardinal_45, order.ascending)
fun_cardinal_line_style_1( _arr, _y)
fun_cardinal_label_1(cardinal_title(), _arr, _y)
// 3. if statament
if barstate.islast
if show_table
for _id = 0 to 8
cell_default( _id, 9, arr_cross_0, _id)
cell_default( _id, _id, arr_cardinal_45, _id)
cell_default( 10, _id, arr_cross_90, _id)
cell_default(11 + _id, 8 - _id, arr_cardinal_135, _id)
cell_default(11 + _id, 9, arr_cross_180, _id)
cell_default(11 + _id, 11 + _id, arr_cardinal_225, _id)
cell_default( 10, 11 + _id, arr_cross_270, _id)
cell_default(8 - _id, 11 + _id, arr_cardinal_315, _id)
// 4. Inputs for Cross and Cardinal
// input cross 0 90 180 270
// id input c r c r c r c r
cross_0 = input(false, "2 4 6 8 ", group = G0, inline = "0"), cross_set(0, cross_0, 8, 9, 10, 8, 11, 9, 10, 11)
cross_1 = input(false, "11 15 19 23 ", group = G0, inline = "1"), cross_set(1, cross_1, 7, 9, 10, 7, 12, 9, 10, 12)
cross_2 = input(false, "28 34 40 46 ", group = G0, inline = "2"), cross_set(2, cross_2, 6, 9, 10, 6, 13, 9, 10, 13)
cross_3 = input(false, "53 61 69 77 ", group = G0, inline = "3"), cross_set(3, cross_3, 5, 9, 10, 5, 14, 9, 10, 14)
cross_4 = input(false, "86 96 106 116", group = G0, inline = "4"), cross_set(4, cross_4, 4, 9, 10, 4, 15, 9, 10, 15)
cross_5 = input(false, "127 139 151 163", group = G0, inline = "5"), cross_set(5, cross_5, 3, 9, 10, 3, 16, 9, 10, 16)
cross_6 = input(false, "176 190 204 218", group = G0, inline = "6"), cross_set(6, cross_6, 2, 9, 10, 2, 17, 9, 10, 17)
cross_7 = input(false, "233 249 265 281", group = G0, inline = "7"), cross_set(7, cross_7, 1, 9, 10, 1, 18, 9, 10, 18)
cross_8 = input(false, "298 316 334 352", group = G0, inline = "8"), cross_set(8, cross_8, 0, 9, 10, 0, 19, 9, 10, 19)
// arr_cross_0
cross_0_0 = input(false, "", group = G0, inline = "0"), fun_cross_set_0(cross_0_0, 8, 9, arr_cross_0, 0)
cross_0_1 = input(false, "", group = G0, inline = "1"), fun_cross_set_0(cross_0_1, 7, 9, arr_cross_0, 1)
cross_0_2 = input(false, "", group = G0, inline = "2"), fun_cross_set_0(cross_0_2, 6, 9, arr_cross_0, 2)
cross_0_3 = input(false, "", group = G0, inline = "3"), fun_cross_set_0(cross_0_3, 5, 9, arr_cross_0, 3)
cross_0_4 = input(false, "", group = G0, inline = "4"), fun_cross_set_0(cross_0_4, 4, 9, arr_cross_0, 4)
cross_0_5 = input(false, "", group = G0, inline = "5"), fun_cross_set_0(cross_0_5, 3, 9, arr_cross_0, 5)
cross_0_6 = input(false, "", group = G0, inline = "6"), fun_cross_set_0(cross_0_6, 2, 9, arr_cross_0, 6)
cross_0_7 = input(false, "", group = G0, inline = "7"), fun_cross_set_0(cross_0_7, 1, 9, arr_cross_0, 7)
cross_0_8 = input(false, "", group = G0, inline = "8"), fun_cross_set_0(cross_0_8, 0, 9, arr_cross_0, 8)
// arr_cross_90
cross_90_0 = input(false, "", group = G0, inline = "0"), fun_cross_set_1(cross_90_0, 10, 8, arr_cross_90, 0)
cross_90_1 = input(false, "", group = G0, inline = "1"), fun_cross_set_1(cross_90_1, 10, 7, arr_cross_90, 1)
cross_90_2 = input(false, "", group = G0, inline = "2"), fun_cross_set_1(cross_90_2, 10, 6, arr_cross_90, 2)
cross_90_3 = input(false, "", group = G0, inline = "3"), fun_cross_set_1(cross_90_3, 10, 5, arr_cross_90, 3)
cross_90_4 = input(false, "", group = G0, inline = "4"), fun_cross_set_1(cross_90_4, 10, 4, arr_cross_90, 4)
cross_90_5 = input(false, "", group = G0, inline = "5"), fun_cross_set_1(cross_90_5, 10, 3, arr_cross_90, 5)
cross_90_6 = input(false, "", group = G0, inline = "6"), fun_cross_set_1(cross_90_6, 10, 2, arr_cross_90, 6)
cross_90_7 = input(false, "", group = G0, inline = "7"), fun_cross_set_1(cross_90_7, 10, 1, arr_cross_90, 7)
cross_90_8 = input(false, "", group = G0, inline = "8"), fun_cross_set_1(cross_90_8, 10, 0, arr_cross_90, 8)
// arr_cross_180
cross_180_0 = input(false, "", group = G0, inline = "0"), fun_cross_set_0(cross_180_0, 11, 9, arr_cross_180, 0)
cross_180_1 = input(false, "", group = G0, inline = "1"), fun_cross_set_0(cross_180_1, 12, 9, arr_cross_180, 1)
cross_180_2 = input(false, "", group = G0, inline = "2"), fun_cross_set_0(cross_180_2, 13, 9, arr_cross_180, 2)
cross_180_3 = input(false, "", group = G0, inline = "3"), fun_cross_set_0(cross_180_3, 14, 9, arr_cross_180, 3)
cross_180_4 = input(false, "", group = G0, inline = "4"), fun_cross_set_0(cross_180_4, 15, 9, arr_cross_180, 4)
cross_180_5 = input(false, "", group = G0, inline = "5"), fun_cross_set_0(cross_180_5, 16, 9, arr_cross_180, 5)
cross_180_6 = input(false, "", group = G0, inline = "6"), fun_cross_set_0(cross_180_6, 17, 9, arr_cross_180, 6)
cross_180_7 = input(false, "", group = G0, inline = "7"), fun_cross_set_0(cross_180_7, 18, 9, arr_cross_180, 7)
cross_180_8 = input(false, "", group = G0, inline = "8"), fun_cross_set_0(cross_180_8, 19, 9, arr_cross_180, 8)
// arr_cross_270
cross_270_0 = input(false, "", group = G0, inline = "0"), fun_cross_set_1(cross_270_0, 10, 11, arr_cross_270, 0)
cross_270_1 = input(false, "", group = G0, inline = "1"), fun_cross_set_1(cross_270_1, 10, 12, arr_cross_270, 1)
cross_270_2 = input(false, "", group = G0, inline = "2"), fun_cross_set_1(cross_270_2, 10, 13, arr_cross_270, 2)
cross_270_3 = input(false, "", group = G0, inline = "3"), fun_cross_set_1(cross_270_3, 10, 14, arr_cross_270, 3)
cross_270_4 = input(false, "", group = G0, inline = "4"), fun_cross_set_1(cross_270_4, 10, 15, arr_cross_270, 4)
cross_270_5 = input(false, "", group = G0, inline = "5"), fun_cross_set_1(cross_270_5, 10, 16, arr_cross_270, 5)
cross_270_6 = input(false, "", group = G0, inline = "6"), fun_cross_set_1(cross_270_6, 10, 17, arr_cross_270, 6)
cross_270_7 = input(false, "", group = G0, inline = "7"), fun_cross_set_1(cross_270_7, 10, 18, arr_cross_270, 7)
cross_270_8 = input(false, "", group = G0, inline = "8"), fun_cross_set_1(cross_270_8, 10, 19, arr_cross_270, 8)
// input cardinal 45 135 225 315
// id input c r c r c r c r
cardinal_0 = input(false, "3 5 7 9 ", group = G1, inline = "9"), cardinal_set(0, cardinal_0, 8, 8, 11, 8, 11, 11, 8, 11)
cardinal_1 = input(false, "13 17 21 25 ", group = G1, inline = "10"), cardinal_set(1, cardinal_1, 7, 7, 12, 7, 12, 12, 7, 12)
cardinal_2 = input(false, "31 37 43 49 ", group = G1, inline = "11"), cardinal_set(2, cardinal_2, 6, 6, 13, 6, 13, 13, 6, 13)
cardinal_3 = input(false, "57 65 73 81 ", group = G1, inline = "12"), cardinal_set(3, cardinal_3, 5, 5, 14, 5, 14, 14, 5, 14)
cardinal_4 = input(false, "91 101 111 121", group = G1, inline = "13"), cardinal_set(4, cardinal_4, 4, 4, 15, 4, 15, 15, 4, 15)
cardinal_5 = input(false, "133 145 157 169", group = G1, inline = "14"), cardinal_set(5, cardinal_5, 3, 3, 16, 3, 16, 16, 3, 16)
cardinal_6 = input(false, "183 197 211 225", group = G1, inline = "15"), cardinal_set(6, cardinal_6, 2, 2, 17, 2, 17, 17, 2, 17)
cardinal_7 = input(false, "241 257 273 289", group = G1, inline = "16"), cardinal_set(7, cardinal_7, 1, 1, 18, 1, 18, 18, 1, 18)
cardinal_8 = input(false, "307 325 343 361", group = G1, inline = "17"), cardinal_set(8, cardinal_8, 0, 0, 19, 0, 19, 19, 0, 19)
// arr_cardinal_45
cardinal_45_0 = input(false, "", group = G1, inline = "9"), fun_cardinal_set_0(cardinal_45_0, 8, 8, arr_cardinal_45, 0)
cardinal_45_1 = input(false, "", group = G1, inline = "10"), fun_cardinal_set_0(cardinal_45_1, 7, 7, arr_cardinal_45, 1)
cardinal_45_2 = input(false, "", group = G1, inline = "11"), fun_cardinal_set_0(cardinal_45_2, 6, 6, arr_cardinal_45, 2)
cardinal_45_3 = input(false, "", group = G1, inline = "12"), fun_cardinal_set_0(cardinal_45_3, 5, 5, arr_cardinal_45, 3)
cardinal_45_4 = input(false, "", group = G1, inline = "13"), fun_cardinal_set_0(cardinal_45_4, 4, 4, arr_cardinal_45, 4)
cardinal_45_5 = input(false, "", group = G1, inline = "14"), fun_cardinal_set_0(cardinal_45_5, 3, 3, arr_cardinal_45, 5)
cardinal_45_6 = input(false, "", group = G1, inline = "15"), fun_cardinal_set_0(cardinal_45_6, 2, 2, arr_cardinal_45, 6)
cardinal_45_7 = input(false, "", group = G1, inline = "16"), fun_cardinal_set_0(cardinal_45_7, 1, 1, arr_cardinal_45, 7)
cardinal_45_8 = input(false, "", group = G1, inline = "17"), fun_cardinal_set_0(cardinal_45_8, 0, 0, arr_cardinal_45, 8)
// arr_cardinal_135
cardinal_135_0 = input(false, "", group = G1, inline = "9"), fun_cardinal_set_1(cardinal_135_0, 11, 8, arr_cardinal_135, 0)
cardinal_135_1 = input(false, "", group = G1, inline = "10"), fun_cardinal_set_1(cardinal_135_1, 12, 7, arr_cardinal_135, 1)
cardinal_135_2 = input(false, "", group = G1, inline = "11"), fun_cardinal_set_1(cardinal_135_2, 13, 6, arr_cardinal_135, 2)
cardinal_135_3 = input(false, "", group = G1, inline = "12"), fun_cardinal_set_1(cardinal_135_3, 14, 5, arr_cardinal_135, 3)
cardinal_135_4 = input(false, "", group = G1, inline = "13"), fun_cardinal_set_1(cardinal_135_4, 15, 4, arr_cardinal_135, 4)
cardinal_135_5 = input(false, "", group = G1, inline = "14"), fun_cardinal_set_1(cardinal_135_5, 16, 3, arr_cardinal_135, 5)
cardinal_135_6 = input(false, "", group = G1, inline = "15"), fun_cardinal_set_1(cardinal_135_6, 17, 2, arr_cardinal_135, 6)
cardinal_135_7 = input(false, "", group = G1, inline = "16"), fun_cardinal_set_1(cardinal_135_7, 18, 1, arr_cardinal_135, 7)
cardinal_135_8 = input(false, "", group = G1, inline = "17"), fun_cardinal_set_1(cardinal_135_8, 19, 0, arr_cardinal_135, 8)
// arr_cardinal_225
cardinal_225_0 = input(false, "", group = G1, inline = "9"), fun_cardinal_set_0(cardinal_225_0, 11, 11, arr_cardinal_225, 0)
cardinal_225_1 = input(false, "", group = G1, inline = "10"), fun_cardinal_set_0(cardinal_225_1, 12, 12, arr_cardinal_225, 1)
cardinal_225_2 = input(false, "", group = G1, inline = "11"), fun_cardinal_set_0(cardinal_225_2, 13, 13, arr_cardinal_225, 2)
cardinal_225_3 = input(false, "", group = G1, inline = "12"), fun_cardinal_set_0(cardinal_225_3, 14, 14, arr_cardinal_225, 3)
cardinal_225_4 = input(false, "", group = G1, inline = "13"), fun_cardinal_set_0(cardinal_225_4, 15, 15, arr_cardinal_225, 4)
cardinal_225_5 = input(false, "", group = G1, inline = "14"), fun_cardinal_set_0(cardinal_225_5, 16, 16, arr_cardinal_225, 5)
cardinal_225_6 = input(false, "", group = G1, inline = "15"), fun_cardinal_set_0(cardinal_225_6, 17, 17, arr_cardinal_225, 6)
cardinal_225_7 = input(false, "", group = G1, inline = "16"), fun_cardinal_set_0(cardinal_225_7, 18, 18, arr_cardinal_225, 7)
cardinal_225_8 = input(false, "", group = G1, inline = "17"), fun_cardinal_set_0(cardinal_225_8, 19, 19, arr_cardinal_225, 8)
// arr_cardinal_315
cardinal_315_0 = input(false, "", group = G1, inline = "9"), fun_cardinal_set_1(cardinal_315_0, 8, 11, arr_cardinal_315, 0)
cardinal_315_1 = input(false, "", group = G1, inline = "10"), fun_cardinal_set_1(cardinal_315_1, 7, 12, arr_cardinal_315, 1)
cardinal_315_2 = input(false, "", group = G1, inline = "11"), fun_cardinal_set_1(cardinal_315_2, 6, 13, arr_cardinal_315, 2)
cardinal_315_3 = input(false, "", group = G1, inline = "12"), fun_cardinal_set_1(cardinal_315_3, 5, 14, arr_cardinal_315, 3)
cardinal_315_4 = input(false, "", group = G1, inline = "13"), fun_cardinal_set_1(cardinal_315_4, 4, 15, arr_cardinal_315, 4)
cardinal_315_5 = input(false, "", group = G1, inline = "14"), fun_cardinal_set_1(cardinal_315_5, 3, 16, arr_cardinal_315, 5)
cardinal_315_6 = input(false, "", group = G1, inline = "15"), fun_cardinal_set_1(cardinal_315_6, 2, 17, arr_cardinal_315, 6)
cardinal_315_7 = input(false, "", group = G1, inline = "16"), fun_cardinal_set_1(cardinal_315_7, 1, 18, arr_cardinal_315, 7)
cardinal_315_8 = input(false, "", group = G1, inline = "17"), fun_cardinal_set_1(cardinal_315_8, 0, 19, arr_cardinal_315, 8)
|
Summary Checklist | https://www.tradingview.com/script/QzeLThZI-Summary-Checklist/ | prostaff97 | https://www.tradingview.com/u/prostaff97/ | 32 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © prostaff97
//@version=4
study("Summary Checklist")
hivol10=highest(volume,10)
//percentage of relative volume
pcnt=(volume/(sma(volume,50)))*100
// ATR comparison for Buyable Gap Up
is_upsidegap_valid = if((open > close[1]+atr(40)*0.75 ) and (volume / sma(volume,50)) > 1.5)
true
else
false
is_price_over50 = if (close >= sma(close,50))
true
else
false
is_ma50_great_ma200 = if (sma(close,50) >= sma(close,200))
true
else
false
is_time_sessiontime = if (timenow<time_close)
true
else
false
//projected volume and relative projected volume calculation
volume_projected = ((time_close-timenow)*volume/(23400000-(time_close-timenow))+volume)/1000000
b=sma(volume,50)
a = volume_projected*1000000/b
is_volume_projected = if (a > 1 )
true
else
false
text_= '==== TECHNICAL SUMMARY ==== \n \n'
text_ := text_ + '50 Day Average Volume = ' + tostring(b/1000000,'#.##') + 'M\n'
text_ := text_+ 'Current Day Volume = '+ tostring(volume/1000000,'#.##') + 'M \n'
text_ := text_ + 'Relative Volume = ' + tostring(pcnt,'#.##') + '% \n'
text_ := text_ + '\nIs it a Buyable Gap-up?' + (is_upsidegap_valid ? ' Yes\n ATR multiple is : ' : ' No \n ATR multiple is : ') + tostring((open-close[1])/atr(40),"#.##") + "\n"
text_ := text_ + "Volume Multiple is : " +tostring(volume/b,'#.##')
text_ := text_ + "\n \n Is Price Consolidating over 50SMA? " + (is_price_over50 ? 'Yes' : 'No')
text_ := text_ + "\n \n 50ma above 200ma? " + (is_ma50_great_ma200 ? 'Yes' : 'No') + "\n"
text_ := text_ + "Intraday Range is " + tostring((close-low)/(high-low)*100,"#.##") + " % \n\n"
text_ := text_ + " Projected Volume = " + (is_time_sessiontime ? tostring(volume_projected,"#.##") + "M \n" : " Session is over.\n")
text_ := text_ + "Relative Projection = " + (is_time_sessiontime ? tostring((is_volume_projected ? a*100 : a*100),"#.##") + "% \n" : " Session is over ")
bars_right = input(60, "x bars right", input.integer)
position = input(close, "Label position", input.source)
one_color = input(false, "Label only in one color", input.bool)
lab_color = input(#ffd010, "Label color", input.color)
text_color = input(color.black,"Text color",input.color)
t = timenow + round(change(time)*bars_right)
var label lab = na, label.delete(lab), lab := label.new(t, position, text = text_, style=label.style_label_center, yloc=yloc.price, xloc=xloc.bar_time, textalign=text.align_center, color=lab_color, textcolor=text_color )
|
My 1st indicator- Log(price/20w sma) | https://www.tradingview.com/script/WcJo8VHC-My-1st-indicator-Log-price-20w-sma/ | EdIrfan786xLin | https://www.tradingview.com/u/EdIrfan786xLin/ | 22 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © aliaman351
//@version=4
study("My 1st indicator- Log(price/20w sma)",shorttitle=" log(p/20w)")
price = input(close, title = "source")//price action
s = sma(price,20)
outputs = security(syminfo.tickerid, "W", s)
// main work
req = log (price/outputs)
plot(req,title="log(price/20sma")
bandh = hline(0.8, "upper Band", color=color.new(#787B86,0))
bandm = hline(0, "Middle Band", color=color.new(#787B86, 50))
bandl = hline(-0.4, "lower Band", color=color.new(#787B86,0)) |
Super D2 | https://www.tradingview.com/script/IXMKQTx9-Super-D2/ | dalderman6 | https://www.tradingview.com/u/dalderman6/ | 25 | study | 4 | MPL-2.0 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dalderman6
//@version=4
study("Super D2")
cOpen = open
cClose = close
cClose1 = close[1]
cHigh = high
cLow = low
// D price
dPrice = if (cOpen == cHigh)
cClose - cLow
else if (cOpen == cLow)
cHigh - cLow
else if (cClose1 > cOpen)
cHigh - cLow
else if (cClose1 < cOpen)
(cHigh - cOpen) + (cClose - cLow)
else
cClose - cLow
// O price
oPrice = if (cOpen == cHigh)
cHigh - cLow
else if (cOpen == cLow)
cHigh - cClose
else if (cClose1 > cOpen)
(cOpen - cLow) + (cHigh - cClose)
else if (cClose1 < cOpen)
cHigh - cLow
else
cHigh - cClose
// vol variables
dVol = if (dPrice + oPrice) == 0
0
else
dPrice / (dPrice + oPrice)
oVol = if (dPrice + oPrice) == 0
0
else
oPrice / (dPrice + oPrice)
// Media Variables
Media_periods = 40
dMedia = sma(dVol,Media_periods)
oMedia = sma(oVol,Media_periods)
// dD and dO variables
dD = if (dMedia == 0)
0
else
((dMedia / dMedia[1] - 1)) * 100
oD = if (oMedia == 0)
0
else
((oMedia / oMedia[1] - 1)) * 100
// Momentum variables
M1_periods = 40
dM1 = dD - dD[M1_periods]
oM1 = oD - oD[M1_periods]
M2_periods = 1
dM2 = dD - dD[M2_periods]
oM2 = oD - oD[M2_periods]
// M2 adjustments
dM2_abs = abs(dM2)
oM2_abs = abs(oM2)
M2_sum_periods = M1_periods - 1
dM2_sum = sma(dM2_abs, M2_sum_periods) * M2_sum_periods // Cumulative sum of M2_sum_Days periods
oM2_sum = sma(oM2_abs, M2_sum_periods) * M2_sum_periods // Cumulative sum of M2_sum_Days periods
// Efficiency Ratio
dEffRatio = if (dM2_sum == 0)
0
else
dM1 / dM2_sum
oEffRatio = if (oM2_sum == 0)
0
else
oM1 / oM2_sum
// Miscellianos Variables
Corto = 150.0
Corto_adj = 2 / ( 1 + Corto )
Lungo = 300.0
Lungo_adj = 2 / ( 1 + Lungo )
// Alpha
dAlpha = abs(dEffRatio) * (Lungo_adj - Corto_adj) + Corto_adj
oAlpha = abs(oEffRatio) * (Lungo_adj - Corto_adj) + Corto_adj
// ADA
dADA = 0.0
dADA := if (dAlpha < 1 and dAlpha > -1 and ( dAlpha[1]>1 or dAlpha[1]<0 ))
dD
else
nz(dADA[1]) * (1-dAlpha) + dD * dAlpha
oADA = 0.0
oADA := if (oAlpha < 1 and oAlpha > -1 and ( oAlpha[1]>1 or oAlpha[1]<0 ))
oD
else
nz(oADA[1]) * (1-oAlpha) + oD * oAlpha
ADA_diff = (dADA - oADA) * 100
ADA_diff_ema20 = sma(ADA_diff,15)
ADA_diff_sma50 = sma(ADA_diff,40)
ADA_diff_sma100 = sma(ADA_diff,90)
plot(ADA_diff , color = color.blue, title="Indicator")
plot(ADA_diff_ema20 , color=color.green, transp=65, title="20 ema")
plot(ADA_diff_sma50 , color=color.red, transp=65, title="50 sma")
plot(ADA_diff_sma100 , color = color.orange, transp=65, title="100 sma")
plot(0.0 , color = color.gray)
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.