Intraday Trading Zones

universalteacher · study · 181 行 · 点赞 1,300 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Vinay Chhabra
 
//@version=4
 
study("Intraday Trading Zones", shorttitle="ITZ", overlay = true)
 
disp_dp = input(true, title="Show PDH, PDL, PDC ?", tooltip="Previous Day High, Low and Close")
previousdaycolor = input(defval=color.red, title="Select Color", type=input.color)
previousdaylinestyle = input(defval= line.style_dashed, title="Select Line Style", type=input.string, options=["dsh", "sol", "dot"], tooltip="Dashed, Solid, Dotted")
 
disp_fib = input(true, title="Show Intraday Fibs ?", tooltip="Intraday Fibonacci, Current Day High and Low")
fibcolor = input(defval=color.black, title="Select FIB Color", type=input.color)
fiblinestyle=input(defval= line.style_solid, title="Select FIB Line Style", type=input.string, options=["dsh", "sol", "dot"])
fib1 = input(0.38)
fib2 = input(0.62)
fib3 = input(0.0, type=input.float, tooltip ="Show a third FIB level on chart")
 
disp_pivot = input(true, title="Show CPR ?", tooltip="Show Central Pivot Range")
cprcolor = input(defval=color.blue, title="Select CPR Color", type=input.color)
cprlinestyle=input(defval= line.style_dotted, title="Select CPR Line Style", type=input.string, options=["dsh", "sol", "dot"])
 
disp_s1r1 = input(true, title="Show S1, S2, S3, R1, R2, R3 ?", tooltip="Show Pivot Support and Resistance")
s1color = input(defval=color.green, title="Select S1, S2, S3 Color", type=input.color)
r1color = input(defval=color.orange, title="Select R1, R2, R3 Color", type=input.color)
s1r1linestyle=input(defval= line.style_dotted, title="Select Line Style", type=input.string, options=["dsh", "sol", "dot"])
 
disp_historicalpivot = input(title="Show Historical Pivots ?", type=input.bool, defval=false)
 
disp_brn = input(false, title="Show Round Number S/R ?", tooltip="Round Number Support and Resistance like 15500, 15600, etc.")
roundnumbercolor = input(defval=color.black, title="Select Color", type=input.color)
roundnumberlinestyle=input(defval= line.style_dotted, title="Select Line Style", type=input.string, options=["dsh", "sol", "dot"])
 
firstbar(resolution) =>
    ch = 0
    if(resolution == 'Y')
        t  = year(time('D'))
        ch := change(t) != 0 ? 1 : 0
    else
        t = time(resolution)
        ch := change(t) != 0 ? 1 : 0
    ch
 
pp_res = 'D'
bars_sinse = 0
bars_sinse := firstbar(pp_res) ? 0 : bars_sinse[1] + 1
 
// label location shift
chper = time - time[1]
chper := change(chper) > 0 ? chper[1] : chper
xlocation = time + chper * 30
// label location shift ends
 
 
phigh_d = security(syminfo.tickerid, "D", high[1], barmerge.gaps_off, barmerge.lookahead_on)
plow_d = security(syminfo.tickerid, "D", low[1], barmerge.gaps_off, barmerge.lookahead_on)
pclose_d = security(syminfo.tickerid, "D", close[1], barmerge.gaps_off, barmerge.lookahead_on)
 
y_th = line.new(bar_index[min(bars_sinse, 5)], disp_dp?phigh_d :na, bar_index, disp_dp?phigh_d :na, color=previousdaycolor,  style =  previousdaylinestyle, width=1, extend = extend.right)
y_to = line.new(bar_index[min(bars_sinse, 5)], disp_dp?pclose_d :na, bar_index, disp_dp?pclose_d :na, color=previousdaycolor,  style =  previousdaylinestyle,width=1, extend = extend.right)
y_tl = line.new(bar_index[min(bars_sinse, 5)], disp_dp?plow_d :na, bar_index, disp_dp?plow_d :na, color=previousdaycolor,  style = previousdaylinestyle,width=1, extend = extend.right)
 
line.delete(y_th[1])
line.delete(y_to[1])
line.delete(y_tl[1])
 
label_yh = label.new(x = xlocation, y=disp_dp?phigh_d : na, text="PDH",  style= label.style_none, xloc = xloc.bar_time, yloc=yloc.price)
label_yc = label.new(x = xlocation, y=disp_dp?pclose_d : na, text="PDC",  style= label.style_none, xloc = xloc.bar_time, yloc=yloc.price)
label_yl = label.new(x = xlocation, y=disp_dp?plow_d : na, text="PDL",  style= label.style_none, xloc = xloc.bar_time, yloc=yloc.price)
 
 
label.delete(label_yh[1])
label.delete(label_yc[1])
label.delete(label_yl[1]) 
 
 
brn_1 = ceil(close/100)
brn_1 := brn_1*100 
brn_2 = brn_1+100 
brn_3 = brn_1-100 
brn_4 = brn_1-200
 
line_brn_1 = line.new(bar_index[min(bars_sinse, 5)], disp_brn?brn_1 :na, bar_index, disp_brn?brn_1 :na, color=roundnumbercolor,  style =  roundnumberlinestyle,width=1, extend = extend.right)
line.delete(line_brn_1[1])
 
line_brn_2 = line.new(bar_index[min(bars_sinse, 5)], disp_brn?brn_2 :na, bar_index, disp_brn?brn_2 :na, color=roundnumbercolor,  style =  roundnumberlinestyle,width=1, extend = extend.right)
line.delete(line_brn_2[1])
 
line_brn_3 = line.new(bar_index[min(bars_sinse, 5)], disp_brn?brn_3 :na, bar_index, disp_brn?brn_3 :na, color=roundnumbercolor,  style =  roundnumberlinestyle,width=1, extend = extend.right)
line.delete(line_brn_3[1])
 
line_brn_4 = line.new(bar_index[min(bars_sinse, 5)], disp_brn?brn_4 :na, bar_index, disp_brn?brn_4 :na, color=roundnumbercolor,  style =  roundnumberlinestyle,width=1, extend = extend.right)
line.delete(line_brn_4[1])
 
 
th_d = security(syminfo.tickerid, "D", high, barmerge.gaps_off, barmerge.lookahead_on)
tl_d = security(syminfo.tickerid, "D", low, barmerge.gaps_off, barmerge.lookahead_on)
 
 
line_th_d = line.new(bar_index[max(bars_sinse, 1)], disp_fib?th_d :na, bar_index, disp_fib?th_d :na, color=fibcolor,  style =  fiblinestyle,width=1, extend = extend.right)
line.delete(line_th_d[1])
label_th_d = label.new(xlocation, y=disp_fib?th_d : na, text="DH",  color = color.lime, textcolor=color.black, style= label.style_label_down, xloc = xloc.bar_time, yloc=yloc.price)
label.delete(label_th_d[1])
 
line_tl_d = line.new(bar_index[max(bars_sinse, 1)], disp_fib?tl_d :na, bar_index, disp_fib?tl_d :na, color=fibcolor,  style =  fiblinestyle,width=1, extend = extend.right)
line.delete(line_tl_d[1])
label_tl_d = label.new(x = xlocation, y=disp_fib?tl_d : na, text="DL",  color = color.lime, textcolor=color.black, style= label.style_label_up, xloc = xloc.bar_time, yloc=yloc.price)
 
label.delete(label_tl_d[1])
 
 
 
//intraday fibs
 
range = (th_d-tl_d)
 
lowfib = (range*fib1)+tl_d
highfib= (range*fib2)+tl_d
fib05 = (range*fib3)+tl_d
 
lowfibline = line.new(bar_index[max(bars_sinse, 1)], disp_fib?lowfib :na, bar_index, disp_fib?lowfib :na, color=fibcolor,  style =  fiblinestyle ,width=1, extend = extend.right)
line.delete(lowfibline[1])
 
highfibline = line.new(bar_index[max(bars_sinse, 1)], disp_fib?highfib :na, bar_index, disp_fib?highfib :na, color=fibcolor,  style =  fiblinestyle,width=1, extend = extend.right)
line.delete(highfibline[1])
 
fib05line = line.new(bar_index[max(bars_sinse, 1)], disp_fib?fib05 :na, bar_index, disp_fib?fib05 :na, color=fibcolor,  style =  fiblinestyle,width=1, extend = extend.right)
line.delete(fib05line[1])
 
 
// Pivot Range
P = (phigh_d + plow_d + pclose_d) / 3 
TC = (phigh_d + plow_d)/2
BC = (P - TC) + P
 
line_p_d = line.new(bar_index[max(bars_sinse, 1)], disp_pivot?TC :na, bar_index, disp_pivot?TC :na, color=cprcolor,  style =  cprlinestyle,width=2, extend = extend.right)
line_TC_d = line.new(bar_index[max(bars_sinse, 1)], disp_pivot?P :na, bar_index, disp_pivot?P :na, color=cprcolor,  style =  cprlinestyle,width=2, extend = extend.right)
line_BC_d = line.new(bar_index[max(bars_sinse, 1)], disp_pivot?BC :na, bar_index, disp_pivot?BC :na, color=cprcolor,  style =  cprlinestyle,width=2, extend = extend.right)
line.delete(line_p_d[1])
line.delete(line_TC_d[1])
line.delete(line_BC_d[1])
 
// Resistance Levels
R3 = phigh_d + 2*(P - plow_d)
R2 = P + (phigh_d - plow_d)
R1 = (P * 2) - plow_d
 
// Support Levels
S1 = (P * 2) - phigh_d
S2 = P - (phigh_d - plow_d)
S3 = plow_d - 2*(phigh_d - P)
 
line_s1_d = line.new(bar_index[max(bars_sinse, 1)], disp_s1r1?S1 :na, bar_index, disp_s1r1?S1 :na, color=s1color,  style =  cprlinestyle,width=2, extend = extend.right)
line.delete(line_s1_d[1])
line_s2_d = line.new(bar_index[max(bars_sinse, 1)], disp_s1r1?S2 :na, bar_index, disp_s1r1?S2 :na, color=s1color,  style =  cprlinestyle,width=2, extend = extend.right)
line.delete(line_s2_d[1])
line_s3_d = line.new(bar_index[max(bars_sinse, 1)], disp_s1r1?S3 :na, bar_index, disp_s1r1?S3 :na, color=s1color,  style =  cprlinestyle,width=2, extend = extend.right)
line.delete(line_s3_d[1])
 
line_r1_d = line.new(bar_index[max(bars_sinse, 1)], disp_s1r1?R1 :na, bar_index, disp_s1r1?R1 :na, color=r1color,  style =  cprlinestyle,width=2, extend = extend.right)
line.delete(line_r1_d[1])
line_r2_d = line.new(bar_index[max(bars_sinse, 1)], disp_s1r1?R2 :na, bar_index, disp_s1r1?R2 :na, color=r1color,  style =  cprlinestyle,width=2, extend = extend.right)
line.delete(line_r2_d[1])
line_r3_d = line.new(bar_index[max(bars_sinse, 1)], disp_s1r1?R3 :na, bar_index, disp_s1r1?R3 :na, color=r1color,  style =  cprlinestyle,width=2, extend = extend.right)
line.delete(line_r3_d[1])
 
 
//show historical pivots
plot(disp_historicalpivot ? P : na, title="Historical Pivot", linewidth=1, color=cprcolor, style=plot.style_circles)
plot(disp_historicalpivot ? TC : na, title="Historical TC", linewidth=1, color=cprcolor, style=plot.style_circles)
plot(disp_historicalpivot ? BC : na, title="Historical BC", linewidth=1, color=cprcolor, style=plot.style_circles)
 
plot(disp_historicalpivot ? S1 : na, title="Historical S1", linewidth=1, color=s1color, style=plot.style_circles)
plot(disp_historicalpivot ? S2 : na, title="Historical S2", linewidth=1, color=s1color, style=plot.style_circles)
plot(disp_historicalpivot ? S3 : na, title="Historical S3", linewidth=1, color=s1color, style=plot.style_circles)
plot(disp_historicalpivot ? R1 : na, title="Historical R1", linewidth=1, color=r1color, style=plot.style_circles)
plot(disp_historicalpivot ? R2 : na, title="Historical R2", linewidth=1, color=r1color, style=plot.style_circles)
plot(disp_historicalpivot ? R3 : na, title="Historical R3", linewidth=1, color=r1color, style=plot.style_circles)
 
//plot vwap
plot( vwap, color = color.orange, title="VWAP", linewidth=1)

← 返回列表