Professional Documents
Culture Documents
SMC + WWAP
SMC + WWAP
indicator("SmC+ Mod by Ba
Gongz",overlay=true,max_bars_back=5000,max_labels_count=500,max_lines_count=500)
// ~~ Tooltips {
string t1 = "Set the pivot period"
string t2 = "Set the response period. A low value returns a short-term structure
and a high value returns a long-term structure. If you disable this option the
pivot length above will be used."
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Inputs {
prd = input.int(20,minval=1,title="Structure Period",tooltip=t1)
s1 = input.bool(true,title="Structure Response ", inline="resp")
resp = input.int(7,minval=1,title="",inline="resp",tooltip=t2)
bull = input.bool(true,"Bullish Structure ",inline="Bullish"), bull2 =
input.color(color.rgb(0,149, 116),"",inline="Bullish"), bull3 =
input.color(color.rgb(0, 149, 116),"",inline="Bullish")
bear = input.bool(true,"Bearish Structure ",inline="Bearish"), bear2 =
input.color(color.rgb(255, 34, 34),"",inline="Bearish"), bear3 =
input.color(color.rgb(255, 34, 34),"",inline="Bearish")
showPD = input.bool(true,"Premium & Discount",inline="pd"), prem =
input.color(color.new(color.rgb(255, 34, 34),80),"",inline="pd"), disc =
input.color(color.new(color.rgb(8, 236, 126),80),"",inline="pd")
hlloc = input.string("Right","", options=["Left","Right"],inline="pd")
var bool [] alert_bool = array.from(
input.bool(true,title="Ticker ID",group="Any alert() function call"),
input.bool(true,title="Timeframe",group="Any alert() function call"),
input.bool(true,title="Probability Percentage",group="Any alert() function call"))
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Variables {
b = bar_index
var Up = float(na)
var Dn = float(na)
var iUp = int(na)
var iDn = int(na)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Functions {
//Labels
CreateLabel(x,y,txt,col,z)=>
label.new(x,y,txt,textcolor=col,style=z?
label.style_label_down:label.style_label_up,color=color(na))
//Lines
CreateLine(x1,x2,y,col)=>
line.new(x1,x2,b,y,color=col)
//Current
Current(v)=>
str = ""
val1 = float(na)
val2 = float(na)
if v>=0
if v==1
str := "ˢᴹˢ: "
val1 := matrix.get(vals,0,1)
val2 := matrix.get(vals,0,3)
else if v==2
str := "ᴮᴹˢ: "
val1 := matrix.get(vals,1,1)
val2 := matrix.get(vals,1,3)
else if v>2
str := "ᴮᴹˢ : "
val1 := matrix.get(vals,2,1)
val2 := matrix.get(vals,2,3)
else if v<=0
if v==-1
str := "ˢᴹˢ: "
val1 := matrix.get(vals,3,1)
val2 := matrix.get(vals,3,3)
else if v==-2
str := "ᴮᴹˢ: "
val1 := matrix.get(vals,4,1)
val2 := matrix.get(vals,4,3)
else if v<-2
str := "ᴮᴹˢ: "
val1 := matrix.get(vals,5,1)
val2 := matrix.get(vals,5,3)
[str,val1,val2]
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Pivots {
Up := math.max(Up[1],high)
Dn := math.min(Dn[1],low)
pvtHi = ta.pivothigh(high,prd,prd)
pvtLo = ta.pivotlow(low,prd,prd)
if pvtHi
Up := pvtHi
if pvtLo
Dn := pvtLo
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Structure {
var pos = 0
if Up>Up[1]
iUp := b
centerBull = math.round(math.avg(iUp[1],b))
if pos<=0
if bull
CreateLabel(centerBull,Up[1],"ᶜᴴᵒᶜᴴ",bull3,true)
CreateLine(iUp[1],Up[1],Up[1],bull2)
pos := 1
matrix.set(vals,6,0,matrix.get(vals,6,0)+1)
else if pos==1 and Up>Up[1] and Up[1]==Up[s1?resp:prd]
if bull
CreateLabel(centerBull,Up[1],"ˢᴹˢ",bull3,true)
CreateLine(iUp[1],Up[1],Up[1],bull2)
pos := 2
matrix.set(vals,6,1,matrix.get(vals,6,1)+1)
else if pos>1 and Up>Up[1] and Up[1]==Up[s1?resp:prd]
if bull
CreateLabel(centerBull,Up[1],"ᴮᴹˢ",bull3,true)
CreateLine(iUp[1],Up[1],Up[1],bull2)
pos := pos + 1
matrix.set(vals,6,2,matrix.get(vals,6,2)+1)
else if Up<Up[1]
iUp := b-prd
if Dn<Dn[1]
iDn := b
centerBear = math.round(math.avg(iDn[1],b))
if pos>=0
if bear
CreateLabel(centerBear,Dn[1],"ᶜᴴᵒᶜᴴ ",bear3,false)
CreateLine(iDn[1],Dn[1],Dn[1],bear2)
pos := -1
matrix.set(vals,7,0,matrix.get(vals,7,0)+1)
else if pos==-1 and Dn<Dn[1] and Dn[1]==Dn[s1?resp:prd]
if bear
CreateLabel(centerBear,Dn[1],"ˢᴹˢ",bear3,false)
CreateLine(iDn[1],Dn[1],Dn[1],bear2)
pos := -2
matrix.set(vals,7,1,matrix.get(vals,7,1)+1)
else if pos<-1 and Dn<Dn[1] and Dn[1]==Dn[s1?resp:prd]
if bear
CreateLabel(centerBear,Dn[1],"ᴮᴹˢ",bear3,false)
CreateLine(iDn[1],Dn[1],Dn[1],bear2)
pos := pos - 1
matrix.set(vals,7,2,matrix.get(vals,7,2)+1)
else if Dn>Dn[1]
iDn := b-prd
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Probability Calculation {
if ta.change(pos)
//Results
if pos>0 and pos[1]>0 or pos<0 and pos[1]<0
if matrix.get(vals,8,0)<matrix.get(vals,8,1)
matrix.set(vals,8,2,matrix.get(vals,8,2)+1)
else
matrix.set(vals,8,3,matrix.get(vals,8,3)+1)
else
if matrix.get(vals,8,0)>matrix.get(vals,8,1)
matrix.set(vals,8,2,matrix.get(vals,8,2)+1)
else
matrix.set(vals,8,3,matrix.get(vals,8,3)+1)
//Score Calulation
//Variables
buC0 = matrix.get(vals,0,0)
buC1 = matrix.get(vals,0,2)
buS0 = matrix.get(vals,1,0)
buS1 = matrix.get(vals,1,2)
buB0 = matrix.get(vals,2,0)
buB1 = matrix.get(vals,2,2)
beC0 = matrix.get(vals,3,0)
beC1 = matrix.get(vals,3,2)
beS0 = matrix.get(vals,4,0)
beS1 = matrix.get(vals,4,2)
beB0 = matrix.get(vals,5,0)
beB1 = matrix.get(vals,5,2)
tbuC = matrix.get(vals,6,0)
tbuS = matrix.get(vals,6,1)
tbuB = matrix.get(vals,6,2)
tbeC = matrix.get(vals,7,0)
tbeS = matrix.get(vals,7,1)
tbeB = matrix.get(vals,7,2)
//Bull
if (pos[1]==1 or pos[1]==0) and pos<0
matrix.set(vals,0,0,buC0+1)
matrix.set(vals,0,1,math.round(((buC0+1)/tbuC)*100,2))
if (pos[1]==1 or pos[1]==0) and pos==2
matrix.set(vals,0,2,buC1+1)
matrix.set(vals,0,3,math.round(((buC1+1)/tbuC)*100,2))
if pos[1]==2 and pos<0
matrix.set(vals,1,0,buS0+1)
matrix.set(vals,1,1,math.round(((buS0+1)/tbuS)*100,2))
if pos[1]==2 and pos>2
matrix.set(vals,1,2,buS1+1)
matrix.set(vals,1,3,math.round(((buS1+1)/tbuS)*100,2))
if pos[1]>2 and pos<0
matrix.set(vals,2,0,buB0+1)
matrix.set(vals,2,1,math.round(((buB0+1)/tbuB)*100,2))
if pos[1]>2 and pos>pos[1]
matrix.set(vals,2,2,buB1+1)
matrix.set(vals,2,3,math.round(((buB1+1)/tbuB)*100,2))
//Bear
if (pos[1]==-1 or pos[1]==0) and pos>0
matrix.set(vals,3,0,beC0+1)
matrix.set(vals,3,1,math.round(((beC0+1)/tbeC)*100,2))
if (pos[1]==-1 or pos[1]==0) and pos==-2
matrix.set(vals,3,2,beC1+1)
matrix.set(vals,3,3,math.round(((beC1+1)/tbeC)*100,2))
if pos[1]==-2 and pos>0
matrix.set(vals,4,0,beS0+1)
matrix.set(vals,4,1,math.round(((beS0+1)/tbeS)*100,2))
if pos[1]==-2 and pos<-2
matrix.set(vals,4,2,beS1+1)
matrix.set(vals,4,3,math.round(((beS1+1)/tbeS)*100,2))
if pos[1]<-2 and pos>0
matrix.set(vals,5,0,beB0+1)
matrix.set(vals,5,1,math.round(((beB0+1)/tbeB)*100,2))
if pos[1]<-2 and pos<pos[1]
matrix.set(vals,5,2,beB1+1)
matrix.set(vals,5,3,math.round(((beB1+1)/tbeB)*100,2))
[str,val1,val2] = Current(pos)
array.set(txt,0,"ᶜᴴᵒᶜᴴ:"+str.tostring(val1,format.percent))
array.set(txt,1,str+str.tostring(val2,format.percent))
matrix.set(vals,8,0,val1)
matrix.set(vals,8,1,val2)
//Alerts
if array.includes(alert_bool,true)
st1 = syminfo.ticker
st2 = timeframe.period
st3 = str.tostring(array.join(txt,'\n'))
string [] str_vals = array.from(st1,st2,st3)
output = array.new_string()
for x=0 to array.size(alert_bool)-1
if array.get(alert_bool,x)
array.push(output,array.get(str_vals,x))
alert(array.join(output,'\n'),alert.freq_once_per_bar_close)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
PremiumTop = Up-(Up-Dn)*.1
PremiumBot = Up-(Up-Dn)*.25
DiscountTop = Dn+(Up-Dn)*.25
DiscountBot = Dn+(Up-Dn)*.1
MidTop = Up-(Up-Dn)*.45
MidBot = Dn+(Up-Dn)*.45
// ~~ Probability {
var prob1 =
label.new(na,na,na,color=color(na),textcolor=chart.fg_color,style=label.style_label
_left)
var prob2 =
label.new(na,na,na,color=color(na),textcolor=chart.fg_color,style=label.style_label
_left)
if barstate.islast
str1 = pos<0?array.get(txt,0):array.get(txt,1)
str2 = pos>0?array.get(txt,0):array.get(txt,1)
label.set_xy(prob1,b,Up)
label.set_text(prob1,str1)
label.set_xy(prob2,b,Dn)
label.set_text(prob2,str2)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Table {
if barstate.islast
//Calulate WinRatio
W = matrix.get(vals,8,2)
L = matrix.get(vals,8,3)
WR = math.round(W/(W+L)*100,2)
string [] tbl_vals = array.from("🟢: "+str.tostring(W),
"🔴: "+str.tostring(L),
"Profitability: "+str.tostring(WR,format.percent))
color [] tbl_col = array.from(color.teal,color.red,chart.fg_color)
for i=0 to 2
table.cell(matrix.get(tbl,0,0),0,i,array.get(tbl_vals,i),
text_halign=text.align_center,bgcolor=chart.bg_color,
text_color=array.get(tbl_col,i),text_size=size.auto)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
if not timeframe.isminutes
runtime.error("Timeframe must be intera day.")
type key
int m = minute
int h = hour
type tod
key TIME
float[] v
type data
float source
tod[] rel
type settings
data relative_rstdev
data relative_delta
data relative_position
key TIME
float multiplier_1
bool enable_1
float multiplier_2
bool enable_2
float multiplier_3
bool enable_3
bool extrapolate
string project_price
int sensitivity
int max_length
string center_style
int center_width
color center_color
string project_style
int projection_width
color projection_color
string dev_1_style
int dev_color_1_width
color dev_color_1
string dev_2_style
int dev_color_2_width
color dev_color_2
string dev_3_style
int dev_color_3_width
color dev_color_3
int alpha
key_to_hash(key TIME)=>
int hash = TIME.h * 60 + TIME.m
local_vol(float source)=>
if session.isfirstbar or session.isfirstbar_regular or
session.islastbar_regular[1]
1
else
math.sqrt(math.pow(source - source[1], 2.0)) + 1
abs_range(float source)=>
math.abs(clamp(source) - 0.5) * 2
dump(source)=>
if source.size() > 0
for i = source.size() - 1 to 0
source.remove(i).delete()
line_style(string style)=>
switch style
"Solid" => line.style_solid
"Dashed" => line.style_dashed
"Dotted" => line.style_dotted
=> line.style_solid
dump(extrapolations)
for i = 0 to projection_range
key new_key = advance_key(s.TIME, i)
int idx = bar_index + i
if current_sample == 0
float dev = s.relative_rstdev.get_average(new_key)
if s.enable_1
top_1.push(chart.point.new(na, idx, source + dev *
s.multiplier_1))
bottom_1.unshift(chart.point.new(na, idx, source - dev *
s.multiplier_1))
if s.enable_2
top_2.push(chart.point.new(na, idx, source + dev *
s.multiplier_2))
bottom_2.unshift(chart.point.new(na, idx, source - dev *
s.multiplier_2))
if s.enable_3
top_3.push(chart.point.new(na, idx, source + dev *
s.multiplier_3))
bottom_3.unshift(chart.point.new(na, idx, source - dev *
s.multiplier_3))
if s.project_price != "None"
float project = s.relative_position.get_average(new_key)
bool polarity = open < close
if s.project_price == "Polar"
projection_points.push(chart.point.new(na, idx, source +
nz((polarity ? 1 : -1) * project * dev * math.max(s.multiplier_3, s.multiplier_2,
s.multiplier_1))))
else
projection_points.push(chart.point.new(na, idx, source +
nz(project * dev * math.max(s.multiplier_3, s.multiplier_2, s.multiplier_1))))
projection_points_2.push(chart.point.new(na, idx, source -
nz(project * dev * math.max(s.multiplier_3, s.multiplier_2, s.multiplier_1))))
else
float percent = s.relative_delta.get_average(new_key)
float dev = s.relative_rstdev.get_average(new_key)
if s.enable_1
top_1.push(chart.point.new(na, idx, prev + dev *
s.multiplier_1))
bottom_1.unshift(chart.point.new(na, idx, prev - dev *
s.multiplier_1))
if s.enable_2
top_2.push(chart.point.new(na, idx, prev + dev *
s.multiplier_2))
bottom_2.unshift(chart.point.new(na, idx, prev - dev *
s.multiplier_2))
if s.enable_3
top_3.push(chart.point.new(na, idx, prev + dev *
s.multiplier_3))
bottom_3.unshift(chart.point.new(na, idx, prev - dev *
s.multiplier_3))
if s.project_price != "None"
float project = s.relative_position.get_average(new_key)
if s.project_price == "Polar"
projection_points.push(chart.point.new(na, idx, prev +
nz((direction ? 1 : -1) * project * dev * math.max(s.multiplier_3, s.multiplier_2,
s.multiplier_1))))
else
projection_points.push(chart.point.new(na, idx, prev +
nz(project * dev * math.max(s.multiplier_3, s.multiplier_2, s.multiplier_1))))
projection_points_2.push(chart.point.new(na, idx, prev -
nz(project * dev * math.max(s.multiplier_3, s.multiplier_2, s.multiplier_1))))
if s.project_price != "None"
extrapolations.push(polyline.new(projection_points, curved, false,
xloc.bar_index, s.projection_color, line_style = line_style(s.project_style),
line_width = s.projection_width))
if s.project_price == "Both"
extrapolations.push(polyline.new(projection_points_2, curved,
false, xloc.bar_index, s.projection_color, line_style =
line_style(s.project_style), line_width = s.projection_width))
if session.ismarket
trash(day_length, max_size)
day_length.unshift(samples)
if session.ispremarket
trash(premarket_length, max_size)
premarket_length.unshift(samples)
if session.ispostmarket
trash(postmarket_length, max_size)
postmarket_length.unshift(samples)
rvwap := sum / w
settings s = settings.new(
relative_rstdev
, relative_delta
, relative_position
, TIME
, multiplier_1
, enable_1
, multiplier_2
, enable_2
, multiplier_3
, enable_3
, extrapolate
, project_price
, sensitivity
, max_length
, center_style
, center_width
, center_color
, project_style
, projection_width
, projection_color
, dev_1_style
, dev_color_1_width
, dev_color_1
, dev_2_style
, dev_color_2_width
, dev_color_2
, dev_3_style
, dev_color_3_width
, dev_color_3
, alpha)
make_projection( // premarket
rvwap
, samples
, average_pre_length
, session.ispremarket
, s
)
make_projection( // postmarket
rvwap
, samples
, average_post_length
, session.ispostmarket
, s
)