本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Keanu_ritz
//@version=5
indicator("Intraday Buy/Sell using Gann Angles - RiTz", overlay=true)
ShowTable = input(title="Show Buy/Sell Levels in a Table", defval=true)
ShowBlvl = input(title="Show Buy Levels on Chart", defval=true)
ShowSlvl = input(title="Show Sell Levels on Chart", defval=true)
Cal = input.string(title="Calculate Buy/Sell Levels based on :", defval='Todays Open', options=['Todays Open', 'Previous Days High','Previous Days Low','Previous Days Close'])
TDO = request.security(syminfo.tickerid, 'D', open)
PDH = request.security(syminfo.tickerid, 'D', high[1])
PDL = request.security(syminfo.tickerid, 'D', low[1])
PDC = request.security(syminfo.tickerid, 'D', close[1])
Do = request.security(syminfo.tickerid, "D", time)
Dc = request.security(syminfo.tickerid, "D", time_close)
float sqCal = 0.00
if Cal == 'Todays Open'
sqCal := math.sqrt(TDO)
else if Cal == 'Previous Days High'
sqCal := math.sqrt(PDH)
else if Cal == 'Previous Days Low'
sqCal := math.sqrt(PDL)
else if Cal == 'Previous Days Close'
sqCal := math.sqrt(PDC)
d0f=0.0625
d1f=0.125
d2f=0.25
d3f=0.5
d4f=0.75
d5f=1
d6f=1.25
d7f=1.5
d8f=1.75
d9f=2
Bsl=(sqCal-d0f)*(sqCal-d0f)
Bat=(sqCal+d1f)*(sqCal+d1f)
Bt1=(sqCal+d2f)*(sqCal+d2f)
Bt2=(sqCal+d3f)*(sqCal+d3f)
Bt3=(sqCal+d4f)*(sqCal+d4f)
Bt4=(sqCal+d5f)*(sqCal+d5f)
Bt5=(sqCal+d6f)*(sqCal+d6f)
Bt6=(sqCal+d7f)*(sqCal+d7f)
Bt7=(sqCal+d8f)*(sqCal+d8f)
Bt8=(sqCal+d9f)*(sqCal+d9f)
Ssl=(sqCal+d0f)*(sqCal+d0f)
Sat=(sqCal-d1f)*(sqCal-d0f)
St1=(sqCal-d2f)*(sqCal-d0f)
St2=(sqCal-d3f)*(sqCal-d0f)
St3=(sqCal-d4f)*(sqCal-d0f)
St4=(sqCal-d5f)*(sqCal-d0f)
St5=(sqCal-d6f)*(sqCal-d0f)
St6=(sqCal-d7f)*(sqCal-d0f)
St7=(sqCal-d8f)*(sqCal-d0f)
St8=(sqCal-d9f)*(sqCal-d0f)
if ShowBlvl and timeframe.isintraday
pBsl = line.new(Do, Bsl, Dc, Bsl, xloc.bar_time, color=color.new(#fa2f04,45), style=line.style_dotted, width=2)
line.delete(pBsl[1])
lpBsl = label.new(Do, Bsl, text="SL for Buy Side : " + str.tostring(math.round(Bsl,2)), xloc=xloc.bar_time, textcolor=color.new(#fa2f04,35), style=label.style_none)
label.delete(lpBsl[1])
pBat = line.new(Do, Bat, Dc, Bat, xloc.bar_time, color=color.new(#78fa04,25), style=line.style_dotted, width=2)
line.delete(pBat[1])
lpBat = label.new(Do, Bat, text="Buy At or Above : " + str.tostring(math.round(Bat,2)), xloc=xloc.bar_time, textcolor=color.new(#78fa04,25), style=label.style_none)
label.delete(lpBat[1])
pBt1 = line.new(Do, Bt1, Dc, Bt1, xloc.bar_time, color=color.new(#78fa04,65), style=line.style_dotted, width=2)
line.delete(pBt1[1])
lpBt1 = label.new(Do, Bt1, text="Target 1 : " + str.tostring(math.round(Bt1,2)), xloc=xloc.bar_time, textcolor=color.new(#78fa04,45), style=label.style_none)
label.delete(lpBt1[1])
pBt2 = line.new(Do, Bt2, Dc, Bt2, xloc.bar_time, color=color.new(#78fa04,65), style=line.style_dotted, width=2)
line.delete(pBt2[1])
lpBt2 = label.new(Do, Bt2, text="Target 2 : " + str.tostring(math.round(Bt2,2)), xloc=xloc.bar_time, textcolor=color.new(#78fa04,45), style=label.style_none)
label.delete(lpBt2[1])
pBt3 = line.new(Do, Bt3, Dc, Bt3, xloc.bar_time, color=color.new(#78fa04,65), style=line.style_dotted, width=2)
line.delete(pBt3[1])
lpBt3 = label.new(Do, Bt3, text="Target 3 : " + str.tostring(math.round(Bt3,2)), xloc=xloc.bar_time, textcolor=color.new(#78fa04,45), style=label.style_none)
label.delete(lpBt3[1])
pBt4 = line.new(Do, Bt4, Dc, Bt4, xloc.bar_time, color=color.new(#78fa04,65), style=line.style_dotted, width=2)
line.delete(pBt4[1])
lpBt4 = label.new(Do, Bt4, text="Target 4 : " + str.tostring(math.round(Bt4,2)), xloc=xloc.bar_time, textcolor=color.new(#78fa04,45), style=label.style_none)
label.delete(lpBt4[1])
pBt5 = line.new(Do, Bt5, Dc, Bt5, xloc.bar_time, color=color.new(#78fa04,65), style=line.style_dotted, width=2)
line.delete(pBt5[1])
lpBt5 = label.new(Do, Bt5, text="Target 5 : " + str.tostring(math.round(Bt5,2)), xloc=xloc.bar_time, textcolor=color.new(#78fa04,45), style=label.style_none)
label.delete(lpBt5[1])
pBt6 = line.new(Do, Bt6, Dc, Bt6, xloc.bar_time, color=color.new(#78fa04,65), style=line.style_dotted, width=2)
line.delete(pBt6[1])
lpBt6 = label.new(Do, Bt6, text="Target 6 : " + str.tostring(math.round(Bt6,2)), xloc=xloc.bar_time, textcolor=color.new(#78fa04,45), style=label.style_none)
label.delete(lpBt6[1])
pBt7 = line.new(Do, Bt7, Dc, Bt7, xloc.bar_time, color=color.new(#78fa04,65), style=line.style_dotted, width=2)
line.delete(pBt7[1])
lpBt7 = label.new(Do, Bt7, text="Target 7 : " + str.tostring(math.round(Bt7,2)), xloc=xloc.bar_time, textcolor=color.new(#78fa04,45), style=label.style_none)
label.delete(lpBt7[1])
pBt8 = line.new(Do, Bt8, Dc, Bt8, xloc.bar_time, color=color.new(#78fa04,65), style=line.style_dotted, width=2)
line.delete(pBt8[1])
lpBt8 = label.new(Do, Bt8, text="Target 8 : " + str.tostring(math.round(Bt8,2)), xloc=xloc.bar_time, textcolor=color.new(#78fa04,45), style=label.style_none)
label.delete(lpBt8[1])
if ShowSlvl and timeframe.isintraday
pSsl = line.new(Do, Ssl, Dc, Ssl, xloc.bar_time, color=color.new(#78fa04,45), style=line.style_dotted, width=2)
line.delete(pSsl[1])
lpSsl = label.new(Do, Ssl, text="SL for Sell Side : " + str.tostring(math.round(Ssl,2)), xloc=xloc.bar_time, textcolor=color.new(#78fa04,35), style=label.style_none)
label.delete(lpSsl[1])
pSat = line.new(Do, Sat, Dc, Sat, xloc.bar_time, color=color.new(#fa2f04,25), style=line.style_dotted, width=2)
line.delete(pSat[1])
lpSat = label.new(Do, Sat, text="Sell At or Below : " + str.tostring(math.round(Sat,2)), xloc=xloc.bar_time, textcolor=color.new(#fa2f04,25), style=label.style_none)
label.delete(lpSat[1])
pSt1 = line.new(Do, St1, Dc, St1, xloc.bar_time, color=color.new(#fa2f04,65), style=line.style_dotted, width=2)
line.delete(pSt1[1])
lpSt1 = label.new(Do, St1, text="Target 1 : " + str.tostring(math.round(St1,2)), xloc=xloc.bar_time, textcolor=color.new(#fa2f04,45), style=label.style_none)
label.delete(lpSt1[1])
pSt2 = line.new(Do, St2, Dc, St2, xloc.bar_time, color=color.new(#fa2f04,65), style=line.style_dotted, width=2)
line.delete(pSt2[1])
lpSt2 = label.new(Do, St2, text="Target 2 : " + str.tostring(math.round(St2,2)), xloc=xloc.bar_time, textcolor=color.new(#fa2f04,45), style=label.style_none)
label.delete(lpSt2[1])
pSt3 = line.new(Do, St3, Dc, St3, xloc.bar_time, color=color.new(#fa2f04,65), style=line.style_dotted, width=2)
line.delete(pSt3[1])
lpSt3 = label.new(Do, St3, text="Target 3 : " + str.tostring(math.round(St3,2)), xloc=xloc.bar_time, textcolor=color.new(#fa2f04,45), style=label.style_none)
label.delete(lpSt3[1])
pSt4 = line.new(Do, St4, Dc, St4, xloc.bar_time, color=color.new(#fa2f04,65), style=line.style_dotted, width=2)
line.delete(pSt4[1])
lpSt4 = label.new(Do, St4, text="Target 4 : " + str.tostring(math.round(St4,2)), xloc=xloc.bar_time, textcolor=color.new(#fa2f04,45), style=label.style_none)
label.delete(lpSt4[1])
pSt5 = line.new(Do, St5, Dc, St5, xloc.bar_time, color=color.new(#fa2f04,65), style=line.style_dotted, width=2)
line.delete(pSt5[1])
lpSt5 = label.new(Do, St5, text="Target 5 : " + str.tostring(math.round(St5,2)), xloc=xloc.bar_time, textcolor=color.new(#fa2f04,45), style=label.style_none)
label.delete(lpSt5[1])
pSt6 = line.new(Do, St6, Dc, St6, xloc.bar_time, color=color.new(#fa2f04,65), style=line.style_dotted, width=2)
line.delete(pSt6[1])
lpSt6 = label.new(Do, St6, text="Target 6 : " + str.tostring(math.round(St6,2)), xloc=xloc.bar_time, textcolor=color.new(#fa2f04,45), style=label.style_none)
label.delete(lpSt6[1])
pSt7 = line.new(Do, St7, Dc, St7, xloc.bar_time, color=color.new(#fa2f04,65), style=line.style_dotted, width=2)
line.delete(pSt7[1])
lpSt7 = label.new(Do, St7, text="Target 7 : " + str.tostring(math.round(St7,2)), xloc=xloc.bar_time, textcolor=color.new(#fa2f04,45), style=label.style_none)
label.delete(lpSt7[1])
pSt8 = line.new(Do, St8, Dc, St8, xloc.bar_time, color=color.new(#fa2f04,65), style=line.style_dotted, width=2)
line.delete(pSt8[1])
lpSt8 = label.new(Do, St8, text="Target 8 : " + str.tostring(math.round(St8,2)), xloc=xloc.bar_time, textcolor=color.new(#fa2f04,45), style=label.style_none)
label.delete(lpSt8[1])
// ---- Table Settings Start {----//
max = 120 //Maximum Length
min = 10 //Minimum Length
dash_loc = input.session("Top Right","Dashboard Location" ,options=["Top Right","Bottom Right","Top Left","Bottom Left", "Middle Right","Bottom Center"] ,group='Style Settings')
text_size = input.session('Normal',"Dashboard Size" ,options=["Tiny","Small","Normal","Large"] ,group='Style Settings')
row_col = color.blue
col_col = color.blue
txt_col = color.white
// ---- Table Settings End ----}//
//-------------- Table code Start {-------------------//
//---- Table Position & Size code start {----//
var table_position = dash_loc == 'Top Left' ? position.top_left :
dash_loc == 'Bottom Left' ? position.bottom_left :
dash_loc == 'Middle Right' ? position.middle_right :
dash_loc == 'Bottom Center' ? position.bottom_center :
dash_loc == 'Top Right' ? position.top_right : position.bottom_right
var table_text_size = text_size == 'Tiny' ? size.tiny :
text_size == 'Small' ? size.small :
text_size == 'Normal' ? size.normal : size.large
var t = table.new(table_position,14,math.abs(max-min)+2,
frame_color=color.new(#000000,0),
frame_width=1,
border_color=color.new(#000000,0),
border_width=1)
//---- Table Position & Size code end ----}//
//---- Table Column & Rows code start {----//
if ShowTable and (barstate.islast) and timeframe.isintraday
//---- Table Main Column Headers code start {----//
table.cell(t,1,0,'Intraday',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
table.cell(t,2,0,'Buy/Sell',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
table.cell(t,3,0,'Levels',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
table.cell(t,4,0,'using',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
table.cell(t,5,0,'Gann Angles',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
table.cell(t,6,0,'based on',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
table.cell(t,7,0,str.tostring(Cal),text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
table.cell(t,1,1,str.replace_all(syminfo.tickerid, 'NSE:', ''),text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,2,1,'Entry level',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,3,1,'Stop Loss',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,4,1,'Target 1',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,5,1,'Target 2',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,6,1,'Target 3',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,7,1,'Target 4',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,8,1,'Target 5',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,9,1,'Target 6',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,10,1,'Target 7',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,11,1,'Target 8',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
//---- Table Main Column Headers code end ----}//
//---- Display Buying data code start {----//
table.cell(t,1,2, 'Buying',text_color=color.new(#78fa04,25),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,2,2, str.tostring(Bat, '#.##'),text_color=color.new(#78fa04,25),text_size=table_text_size, bgcolor=color.new(#78fa04,85))
table.cell(t,3,2, str.tostring(Bsl, '#.##'),text_color=color.new(#fa2f04,35),text_size=table_text_size, bgcolor=color.new(#fa2f04,85))
table.cell(t,4,2, str.tostring(Bt1, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(#78fa04,85))
table.cell(t,5,2, str.tostring(Bt2, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(#78fa04,85))
table.cell(t,6,2, str.tostring(Bt3, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(#78fa04,85))
table.cell(t,7,2, str.tostring(Bt4, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(#78fa04,85))
table.cell(t,8,2, str.tostring(Bt5, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(#78fa04,85))
table.cell(t,9,2, str.tostring(Bt6, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(#78fa04,85))
table.cell(t,10,2, str.tostring(Bt7, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(#78fa04,85))
table.cell(t,11,2, str.tostring(Bt8, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(#78fa04,85))
//---- Display Buying data code end ----}//
//---- Display Buying data code start {----//
table.cell(t,1,3, 'Selling',text_color=color.new(#fa2f04,25),text_size=table_text_size,bgcolor=color.new(color.blue,80))
table.cell(t,2,3, str.tostring(Sat, '#.##'),text_color=color.new(#fa2f04,25),text_size=table_text_size, bgcolor=color.new(#fa2f04,85))
table.cell(t,3,3, str.tostring(Ssl, '#.##'),text_color=color.new(#78fa04,35),text_size=table_text_size, bgcolor=color.new(#78fa04,85))
table.cell(t,4,3, str.tostring(St1, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(#fa2f04,85))
table.cell(t,5,3, str.tostring(St2, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(#fa2f04,85))
table.cell(t,6,3, str.tostring(St3, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(#fa2f04,85))
table.cell(t,7,3, str.tostring(St4, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(#fa2f04,85))
table.cell(t,8,3, str.tostring(St5, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(#fa2f04,85))
table.cell(t,9,3, str.tostring(St6, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(#fa2f04,85))
table.cell(t,10,3, str.tostring(St7, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(#fa2f04,85))
table.cell(t,11,3, str.tostring(St8, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(#fa2f04,85))
//---- Display Buying data code end ----}//
//---- Table Column & Rows code end ----}//
//-------------- Table code end -------------------}//