- เทคนิคของ Indicator:
- ใช้ ATR ในการกำหนดช่วงราคาในระยะเวลาสั้น.
- คำนวณ Z-Score สำหรับเป้าหมาย ATR และวิเคราะห์ความถี่ที่ราคาสะสมที่ระดับค่าเบี่ยงเบนมาตรฐานนั้น.
- ผสานการวิเคราะห์การสะสมโดยปริมาณการซื้อขาย.
- ใช้ได้ทั้งในกรอบเวลาใหญ่และเล็ก.
- บอกสัญญาณซื้อและขาย:
- ใช้สำหรับ Swing Trading: ใช้ข้อมูลกรอบเวลาใหญ่เพื่อวิเคราะห์.
- ใช้สำหรับ Day Trading: ใช้ ATR display เพื่อดูช่วงราคาที่เหมาะสมในกรอบเวลาที่ต้องการ.
- ใช้งานในโปรแกรม TradingView https://www.tradingview.com/?aff_id=134641
- เปิดบัญชีทดลอง: การเริ่มต้นของ Passive Income https://bit.ly/3Sdkir2
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// /$$$$$$ /$$ /$$
// /$$__ $$ | $$ | $$
//| $$ \__//$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$$
//| $$$$$$|_ $$_/ /$$__ $$| $$ /$$//$$__ $$ /$$__ $$ /$$_____/|_ $$_/ /$$__ $$| $$ /$$//$$__ $$ /$$_____/
// \____ $$ | $$ | $$$$$$$$ \ $$/$$/| $$$$$$$$| $$ \__/| $$$$$$ | $$ | $$$$$$$$ \ $$/$$/| $$$$$$$$| $$$$$$
// /$$ \ $$ | $$ /$$| $$_____/ \ $$$/ | $$_____/| $$ \____ $$ | $$ /$$| $$_____/ \ $$$/ | $$_____/ \____ $$
//| $$$$$$/ | $$$$/| $$$$$$$ \ $/ | $$$$$$$| $$ /$$$$$$$/ | $$$$/| $$$$$$$ \ $/ | $$$$$$$ /$$$$$$$/
// \______/ \___/ \_______/ \_/ \_______/|__/ |_______/ \___/ \_______/ \_/ \_______/|_______/
// ___________________
// / \
// / _____ _____ \
// / / \ / \ \
// __/__/ \____/ \__\_____
//| ___________ ____|
// \_________/ \_________/
// \ /////// /
// \/////////
// © Steversteves
//@version=5
indicator("ATR Range Accumulation by Standard Deviation and Volume [SS]", shorttitle = "ATR SD and Vol [SS]", overlay=true)
// Groups
g1 = "Settings", g2 = "Options "
// Tooltips
t1 = "Will display the realtime chart levels by Volume or Standard Deviation Accumulation"
t2 = "Shows the total range Breakdown by Standard Deviation Accumulation"
t3 = "Shows the total range Breakdown by Volume over standard deviation accumulation"
timeframe = input.timeframe("", "Timeframe", group = g1)
len = input.int(500, "Lookback", group = g1)
showby = input.string("Standard Deviation", "Show Levels By", ["Standard Deviation", "Volume"], group = g2, tooltip = t1)
showtotal = input.bool(false, "Show Total Accumulation Breakdown", group = g2, tooltip = t2)
showvol = input.bool(false, "Show ATR SD Accumulation by Volume", group = g2, tooltip = t3)
[hi_rng, lo_rng, op, cl, z, avg, sd, vol] = request.security(syminfo.tickerid, timeframe, [high[1] - open[1], open[1] - low[1], open, close, (close - ta.sma(close,len)) / ta.stdev(close, len), ta.sma(close, len), ta.stdev(close, len), volume], lookahead = barmerge.lookahead_on)
hi_array = array.new<float>()
lo_array = array.new<float>()
cl_array = array.new<float>()
far() =>
array.new<float>()
for i = 0 to len
array.push(hi_array, hi_rng[i])
array.push(lo_array, lo_rng[i])
array.push(cl_array, cl[i])
hi_avg = array.avg(hi_array)
max_hi = array.max(hi_array)
hi_sd = array.stdev(hi_array)
lo_avg = array.avg(lo_array)
lo_max = array.max(lo_array)
color transp = color.new(color.white, 100)
color white = color.white
// z
avg_hi_z = (op + hi_avg - avg) / sd
max_hi_z = (op + max_hi - avg) / sd
avg_lo_z = (op - lo_avg - avg) / sd
max_lo_z = (op - lo_max - avg) / sd
if showby == "Standard Deviation"
bool above_hi_z = z >= avg_hi_z
bool above_max_hi = z >= max_hi_z
bool below_lo_z = z <= avg_lo_z
bool below_max_lo = z <= max_lo_z
int above_avghi_c = 0
int above_maxhi_c = 0
int belowavgloc = 0
int belowmaxloc = 0
for i = 0 to len
if above_hi_z[i]
above_avghi_c += 1
if above_max_hi[i]
above_maxhi_c += 1
if below_lo_z[i]
belowavgloc += 1
if below_max_lo[i]
belowmaxloc += 1
avg_hi_perc = math.round((above_avghi_c / len) * 100, 2)
max_hi_perc = math.round((above_maxhi_c / len) * 100, 2)
avg_lo_perc = math.round((belowavgloc / len) * 100, 2)
max_lo_perc = math.round((belowmaxloc / len) * 100, 2)
var line hi_avg_lin = na, var line hi_max_lin = na, var line lo_avg_lin = na, var line lo_max_lin = na
var label hi_avg_lbl = na, var label lo_avg_lbl = na, var label hi_max_lbl = na, var label lo_max_lbl = na
if barstate.islast and not showtotal and not showvol
line.delete(hi_avg_lin), line.delete(lo_avg_lin), line.delete(hi_max_lin), line.delete(lo_max_lin)
label.delete(hi_avg_lbl), label.delete(lo_avg_lbl), label.delete(hi_max_lbl), label.delete(lo_max_lbl)
hi_max_lin := line.new(bar_index + 1, op + max_hi, bar_index + 20, op + max_hi, color = color.lime, width =2)
hi_avg_lbl := label.new(bar_index + 10, op + hi_avg, text = str.tostring(math.round(avg_hi_z, 2)) + " SDs \n " + str.tostring(avg_hi_perc) + "% of Accumulation", color = transp, textcolor = color.lime)
hi_max_lbl := label.new(bar_index + 10, op + max_hi, text = str.tostring(math.round(max_hi_z, 2)) + " SDs \n " + str.tostring(max_hi_perc) + "% of Accumulation", color = transp, textcolor = color.lime)
hi_avg_lin := line.new(bar_index + 1, op + hi_avg, bar_index + 20, op + hi_avg, color = color.lime, width =2)
lo_avg_lbl := label.new(bar_index + 10, op - lo_avg, text = str.tostring(math.round(avg_lo_z, 2)) + " SDs \n " + str.tostring(avg_lo_perc) + "% of Accumulation", color = transp, textcolor = color.red)
lo_max_lin := line.new(bar_index + 1, op - lo_max, bar_index + 20, op - lo_max, color = color.red, width =2)
lo_max_lbl := label.new(bar_index + 10, op - lo_max, text = str.tostring(math.round(max_lo_z, 2)) + " SDs \n " + str.tostring(max_lo_perc) + "% of Accumulation", color = transp, textcolor = color.red)
lo_avg_lin := line.new(bar_index + 1, op - lo_avg, bar_index + 20, op - lo_avg, color = color.red, width =2)
if showby == "Volume"
above_max_vol = far()
above_avg_vol = far()
below_max_vol = far()
below_avg_vol = far()
bool above_hi_z = z >= avg_hi_z
bool above_max_hi = z >= max_hi_z
bool below_lo_z = z <= avg_lo_z
bool below_max_lo = z <= max_lo_z
for i = 0 to len
if above_hi_z[i]
array.push(above_avg_vol, vol[i])
else if above_max_hi[i]
array.push(above_max_vol, vol[i])
else if below_lo_z[i]
array.push(below_avg_vol, vol[i])
else if below_max_lo[i]
array.push(below_max_vol, vol[i])
above_max_sum = array.size(above_max_vol) - 1 > 0 ? array.sum(above_max_vol) : 0
above_avg_sum = array.size(above_avg_vol) - 1 > 0 ? array.sum(above_avg_vol) : 0
below_max_sum = array.size(below_max_vol) - 1 > 0 ? array.sum(below_max_vol) : 0
below_avg_sum = array.size(below_avg_vol) - 1 > 0 ? array.sum(below_avg_vol) : 0
total_vol = (above_max_sum + above_avg_sum + below_max_sum + below_avg_sum)
vol1_perc = math.round((above_max_sum / total_vol) * 100, 2)
vol2_perc = math.round((above_avg_sum / total_vol) * 100, 2)
vol3_perc = math.round((below_max_sum / total_vol) * 100, 2)
vol4_perc = math.round((below_avg_sum / total_vol) * 100, 2)
var line hi_avg_lin = na, var line hi_max_lin = na, var line lo_avg_lin = na, var line lo_max_lin = na
var label hi_avg_lbl = na, var label lo_avg_lbl = na, var label hi_max_lbl = na, var label lo_max_lbl = na
if barstate.islast and not showtotal and not showvol
line.delete(hi_avg_lin), line.delete(lo_avg_lin), line.delete(hi_max_lin), line.delete(lo_max_lin)
label.delete(hi_avg_lbl), label.delete(lo_avg_lbl), label.delete(hi_max_lbl), label.delete(lo_max_lbl)
hi_max_lin := line.new(bar_index + 1, op + max_hi, bar_index + 20, op + max_hi, color = color.lime, width =2)
hi_avg_lbl := label.new(bar_index + 10, op + hi_avg, text = str.tostring(math.round(avg_hi_z, 2)) + " SDs \n " + str.tostring(vol2_perc) + "% of Volume", color = transp, textcolor = color.lime)
hi_max_lbl := label.new(bar_index + 10, op + max_hi, text = str.tostring(math.round(max_hi_z, 2)) + " SDs \n " + str.tostring(vol1_perc) + "% of Volume", color = transp, textcolor = color.lime)
hi_avg_lin := line.new(bar_index + 1, op + hi_avg, bar_index + 20, op + hi_avg, color = color.lime, width =2)
lo_avg_lbl := label.new(bar_index + 10, op - lo_avg, text = str.tostring(math.round(avg_lo_z, 2)) + " SDs \n " + str.tostring(vol4_perc) + "% of Volume", color = transp, textcolor = color.red)
lo_max_lin := line.new(bar_index + 1, op - lo_max, bar_index + 20, op - lo_max, color = color.red, width =2)
lo_max_lbl := label.new(bar_index + 10, op - lo_max, text = str.tostring(math.round(max_lo_z, 2)) + " SDs \n " + str.tostring(vol3_perc) + "% of Volume", color = transp, textcolor = color.red)
lo_avg_lin := line.new(bar_index + 1, op - lo_avg, bar_index + 20, op - lo_avg, color = color.red, width =2)
one_sd = avg + (1 * sd)
two_sd = avg + (2 * sd)
three_sd = avg + (3 * sd)
neut = avg
neg_one_sd = avg + (-1 * sd)
neg_two_sd = avg + (-2 * sd)
neg_three_sd = avg + (-3 * sd)
bool above_1 = z >= 1
bool above_2 = z >= 2
bool above_3 = z >= 3
bool neutral = z < 1 and z > -1
bool below_neg1 = z <= -1
bool below_neg2 = z <= - 2
bool below_neg3 = z <= -3
perc(trues) =>
math.round((trues / len) * 100,2)
if showtotal
int one_sdc = 0
int two_sdc = 0
int three_sdc = 0
int neut_c = 0
int neg_one_c = 0
int neg_two_c = 0
int neg_three_c = 0
for i = 0 to len
if above_1[i]
one_sdc += 1
else if above_2[i]
two_sdc += 1
else if above_3[i]
three_sdc += 1
else if neutral[i]
neut_c += 1
else if below_neg1[i]
neg_one_c += 1
else if below_neg2[i]
neg_two_c += 1
else if below_neg3[i]
neg_three_c += 1
else
na
above_1_perc = perc(one_sdc)
above_2_perc = perc(two_sdc)
above_3_perc = perc(three_sdc)
neut_perc = perc(neut_c)
below_1_perc = perc(neg_one_c)
below_2_perc = perc(neg_two_c)
below_3_perc = perc(neg_three_c)
var line line1 = na, var line line2 = na, var line line3 = na, var line line4 = na, var line line5 = na, var line line6 = na, var line line7 = na
var label label1 = na, var label label2 = na, var label label3 = na, var label label4 = na, var label label5 = na, var label label6 = na, var label label7 = na
if barstate.isconfirmed
line.delete(line1), line.delete(line2), line.delete(line3), line.delete(line4), line.delete(line5), line.delete(line6), line.delete(line7)
label.delete(label1), label.delete(label2), label.delete(label3), label.delete(label4), label.delete(label5), label.delete(label6), label.delete(label7)
line1 := line.new(bar_index[len], three_sd, bar_index, three_sd, color = color.lime, width = 3)
line2 := line.new(bar_index[len], two_sd, bar_index, two_sd, color = color.lime, width = 3)
line3 := line.new(bar_index[len], one_sd, bar_index, one_sd, color = color.lime, width = 3)
line4 := line.new(bar_index[len], neut, bar_index, neut, color = color.aqua, width = 3)
line5 := line.new(bar_index[len], neg_one_sd, bar_index, neg_one_sd, color = color.red, width = 3)
line6 := line.new(bar_index[len], neg_two_sd, bar_index, neg_two_sd, color = color.red, width = 3)
line7 := line.new(bar_index[len], neg_three_sd, bar_index, neg_three_sd, color = color.red, width = 3)
label1 := label.new(bar_index - 200, three_sd, text = str.tostring(math.round(three_sd, 2)) + " \n " + str.tostring(above_3_perc) + "% of Accumulation", color = transp, textcolor = color.lime)
label2 := label.new(bar_index - 200, two_sd, text = str.tostring(math.round(two_sd, 2)) + "\n " + str.tostring(above_2_perc) + "% of Accumulation", color = transp, textcolor = color.lime)
label3 := label.new(bar_index - 200, one_sd, text = str.tostring(math.round(one_sd, 2)) + "\n " + str.tostring(above_1_perc) + "% of Accumulation", color = transp, textcolor = color.lime)
label4 := label.new(bar_index - 200, neut, text = str.tostring(math.round(neut, 2)) + " \n " + str.tostring(neut_perc) + "% of Accumulation", color = transp, textcolor = color.aqua)
label5 := label.new(bar_index - 200, neg_one_sd, text = str.tostring(math.round(neg_one_sd, 2)) + " \n " + str.tostring(below_1_perc) + "% of Accumulation", color = transp, textcolor = color.red)
label6 := label.new(bar_index - 200, neg_two_sd, text = str.tostring(math.round(neg_two_sd, 2)) + "\n " + str.tostring(below_2_perc) + "% of Accumulation", color = transp, textcolor = color.red)
label7 := label.new(bar_index - 200, neg_three_sd, text = str.tostring(math.round(neg_three_sd, 2)) + "\n " + str.tostring(below_3_perc) + "% of Accumulation", color = transp, textcolor = color.red)
volperc(vols, total) =>
if vols != 0
math.round((vols / total) * 100, 2)
else
0
// Box Colours
color greenfill = color.new(color.lime, 85)
color redfill = color.new(color.red, 85)
color aquafill = color.new(color.aqua, 85)
if showvol
bool neut_v = z > -1 and z < 1 // Vol1
bool btw_1 = z >= 1 and z <2 // Vol2
bool btw_2 = z >= 2 and z < 3 // Vol3
bool abv_3 = z >= 3 // Vol4
bool blw_1 = z <= -1 and z > -2 // Vol5
bool blw_2 = z <= -2 and z > -3 // Vol6
bool blw_3 = z <= -3 // Vol7
vol1 = far(), vol2 = far(), vol3 = far(), vol4 = far(), vol5 = far(), vol6 = far(), vol7 = far()
for i = 0 to len
if neut_v[i]
array.push(vol1, vol[i])
else if btw_1[i]
array.push(vol2, vol[i])
else if btw_2[i]
array.push(vol3, vol[i])
else if abv_3[i]
array.push(vol4, vol[i])
else if blw_1[i]
array.push(vol5, vol[i])
else if blw_2[i]
array.push(vol6, vol[i])
else if blw_3[i]
array.push(vol7, vol[i])
else
na
vol1_sum = array.size(vol1) - 1 > 0 ? array.sum(vol1) : 0
vol2_sum = array.size(vol2) - 1 > 0 ? array.sum(vol2) : 0
vol3_sum = array.size(vol3) - 1 > 0 ? array.sum(vol3) : 0
vol4_sum = array.size(vol4) - 1 > 0 ? array.sum(vol4) : 0
vol5_sum = array.size(vol5) - 1 > 0 ? array.sum(vol5) : 0
vol6_sum = array.size(vol6) - 1 > 0 ? array.sum(vol6) : 0
vol7_sum = array.size(vol7) - 1 > 0 ? array.sum(vol7) : 0
total_volume = (vol1_sum + vol2_sum + vol3_sum + vol4_sum + vol5_sum + vol6_sum + vol7_sum)
vol1_perc = math.round((vol1_sum / total_volume) * 100,2) , vol2_perc = volperc(vol2_sum, total_volume), vol3_perc = volperc(vol3_sum, total_volume), vol4_perc = volperc(vol4_sum, total_volume)
vol5_perc = volperc(vol5_sum, total_volume), vol6_perc = volperc(vol6_sum, total_volume), vol7_perc = volperc(vol7_sum, total_volume)
var box box1 = na, var box box2 = na, var box box3 = na, var box box4 = na, var box box5 = na
if barstate.isconfirmed
box.delete(box1), box.delete(box2), box.delete(box3), box.delete(box4), box.delete(box5)
box1 := box.new(bar_index[len], three_sd, bar_index, two_sd, border_color = color.white, bgcolor = greenfill, text_color = white, text = str.tostring(vol3_perc) + "%")
box2 := box.new(bar_index[len], two_sd, bar_index, one_sd, border_color = color.white, bgcolor = greenfill, text_color = white, text = str.tostring(vol2_perc) + "%")
box3 := box.new(bar_index[len], one_sd, bar_index, neg_one_sd, border_color = color.white, bgcolor = aquafill, text_color = white, text = str.tostring(vol1_perc) + "%")
box4 := box.new(bar_index[len], neg_one_sd, bar_index, neg_two_sd, border_color = color.white, bgcolor = redfill, text_color = white, text = str.tostring(vol5_perc) + "%")
box5 := box.new(bar_index[len], neg_two_sd, bar_index, neg_three_sd, border_color = color.white, bgcolor = redfill, text_color = white, text = str.tostring(vol6_perc) + "%")
https://www.tradingview.com/script/qCQyIppQ-ATR-Range-Accumulation-by-Standard-Deviation-and-Volume-SS/
Related