Fib Pivot Points Alerts

QuantNomad · study · 122 行 · 点赞 3,426 · TradingView 原页

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

Pine Script

//@version=4
study(title="Fib Pivot Points Alerts", shorttitle="Fib Pivot Points Alerts", overlay = true)
 
// 
// author: QuantNomad
// date: 2019-07-11
// Fibonacci Pivot Points Alerts
// https://www.tradingview.com/u/QuantNomad/
// https://t.me/quantnomad
//
 
// Function outputs 1 when it's the first bar of the D/W/M/Y
is_newbar(res) =>
    ch = 0
    if(res == 'Y')
        t  = year(time('D'))
        ch := change(t) != 0 ? 1 : 0
    else
        t = time(res)
        ch := change(t) != 0 ? 1 : 0
    ch
 
////////////
// INPUTS //
////////////
 
pp_period = input(title = "Period", type=input.string, defval="Day", options = ['Day', 'Week', 'Month', 'Year'])
 
pp_res = pp_period == 'Day' ? 'D' : pp_period == 'Week' ? 'W' : pp_period == 'Month' ? 'M' : 'Y' 
 
/////////////////////
// Get HLC from HT //
 
// Calc High
high_cur = 0.0
high_cur := is_newbar(pp_res) ? high : max(high_cur[1], high)
 
phigh = 0.0
phigh := is_newbar(pp_res) ? high_cur[1] : phigh[1]
 
// Calc Low
low_cur = 0.0
low_cur := is_newbar(pp_res) ? low : min(low_cur[1], low)
 
plow = 0.0
plow := is_newbar(pp_res) ? low_cur[1] : plow[1]
 
// Calc Close
pclose = 0.0
pclose := is_newbar(pp_res) ? close[1] : pclose[1]
 
////////////////////////////////
// CALCULATE fibonacci pivots //
 
vPP = (phigh + plow + pclose) / 3
vR1 = vPP + (phigh - plow) * 0.382
vS1 = vPP - (phigh - plow) * 0.382
vR2 = vPP + (phigh - plow) * 0.618
vS2 = vPP - (phigh - plow) * 0.618
vR3 = vPP + (phigh - plow) * 1.000
vS3 = vPP - (phigh - plow) * 1.000
  
//////////////
// PLOTTING //
 
bars_sinse = 0
bars_sinse := is_newbar(pp_res) ? 0 : bars_sinse[1] + 1
 
////////////////////////
// PLOT PIVOTS LEVELS //
 
vpp_p = line.new(bar_index[bars_sinse], vPP, bar_index, vPP, color=#f57f17, style =  line.style_solid, extend = extend.right)
vs1_p = line.new(bar_index[bars_sinse], vS1, bar_index, vS1, color=#f57f17, style =  line.style_solid, extend = extend.right)
vs2_p = line.new(bar_index[bars_sinse], vS2, bar_index, vS2, color=#f57f17, style =  line.style_solid, extend = extend.right)
vs3_p = line.new(bar_index[bars_sinse], vS3, bar_index, vS3, color=#f57f17, style =  line.style_solid, extend = extend.right)
vr1_p = line.new(bar_index[bars_sinse], vR1, bar_index, vR1, color=#f57f17, style =  line.style_solid, extend = extend.right)
vr2_p = line.new(bar_index[bars_sinse], vR2, bar_index, vR2, color=#f57f17, style =  line.style_solid, extend = extend.right)
vr3_p = line.new(bar_index[bars_sinse], vR3, bar_index, vR3, color=#f57f17, style =  line.style_solid, extend = extend.right)
 
// delete previous lines in the same period
if (not is_newbar(pp_res))
    line.delete(vpp_p[1])
    line.delete(vs1_p[1]) 
    line.delete(vs2_p[1])  
    line.delete(vs3_p[1])  
    line.delete(vr1_p[1]) 
    line.delete(vr2_p[1])  
    line.delete(vr3_p[1]) 
  
// delete entend for the old lines
if (is_newbar(pp_res))
    line.set_extend(vpp_p[1], extend.none)
    line.set_extend(vs1_p[1], extend.none) 
    line.set_extend(vs2_p[1], extend.none)  
    line.set_extend(vs3_p[1], extend.none)  
    line.set_extend(vr1_p[1], extend.none) 
    line.set_extend(vr2_p[1], extend.none)  
    line.set_extend(vr3_p[1], extend.none) 
 
// Add labels
if (is_newbar(pp_res))  
    label_vpp = label.new(bar_index, vPP, text="P",  style= label.style_none)
    label_vs1 = label.new(bar_index, vS1, text="S1", style= label.style_none)
    label_vs2 = label.new(bar_index, vS2, text="S2", style= label.style_none)
    label_vs3 = label.new(bar_index, vS3, text="S3", style= label.style_none)
    label_vr1 = label.new(bar_index, vR1, text="R1", style= label.style_none)
    label_vr2 = label.new(bar_index, vR2, text="R2", style= label.style_none)
    label_vr3 = label.new(bar_index, vR3, text="R3", style= label.style_none)
    
////////////
// ALERTS //
    
alertcondition(not is_newbar(pp_res) and cross(close, vPP), "Cross Fib P",  "Cross Fib P")
alertcondition(not is_newbar(pp_res) and cross(close, vS1), "Cross Fib S1", "Cross Fib S1")
alertcondition(not is_newbar(pp_res) and cross(close, vS2), "Cross Fib S2", "Cross Fib S2")
alertcondition(not is_newbar(pp_res) and cross(close, vS3), "Cross Fib S3", "Cross Fib S3")
alertcondition(not is_newbar(pp_res) and cross(close, vR1), "Cross Fib R1", "Cross Fib R1")
alertcondition(not is_newbar(pp_res) and cross(close, vR2), "Cross Fib R2", "Cross Fib R2")
alertcondition(not is_newbar(pp_res) and cross(close, vR3), "Cross Fib R3", "Cross Fib R3")
 
alertcondition(not is_newbar(pp_res) and (cross(close, vPP) or cross(close, vS1) or cross(close, vS2) or cross(close, vS3) or
   cross(close, vR1) or cross(close, vR2) or cross(close, vR3)), "Cross Fib Any", "Cross Fib Any")

← 返回列表