Tops and Bottoms [MisinkoMaster]

MisinkoMaster · study · 54 行 · 点赞 96 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MisinkoMaster
 
//@version=6
indicator("Tops and Bottoms [MisinkoMaster]", overlay = true, behind_chart = false)
/////////////////////////////////////////////////////////////////////////////
//Import Libraries
import TradingView/ta/14
/////////////////////////////////////////////////////////////////////////////
//Get User Defined Inputs
len = input.int(100, "Lookback")
ev = input.float(1.00, "Error Variance", step = 0.01)
speed = input.float(0.1, "Speed", step = 0.005)
/////////////////////////////////////////////////////////////////////////////
//Calculations
lowerinc = ta.hma(hl2, len) - (ta.hma(hl2, len) - ta.lowest(low, len)) * speed
higherinc = ta.hma(hl2, len) + (ta.highest(high, len) - ta.hma(hl2, len)) * speed
 
mid = ta.hma(hl2, len) > close ? lowerinc : higherinc
 
highvol = 0.0
highcount = 0
lowvol = 0.0
lowcount = 0
for i = 0 to len -1
    highvol += high[i] > mid ? math.pow(high[i] - mid, 2) * i: 0
    highcount += high[i] > mid ? i : 0
    lowvol += low[i] < mid ? math.pow(low[i] - mid, 2) * i : 0
    lowcount += low[i] < mid ? i : 0
 
highvol := highcount == 0 ? highvol[1] : math.sqrt(highvol / highcount)
lowvol := lowcount == 0 ? lowvol[1] : math.sqrt(lowvol / lowcount)
 
sqrt = math.round(math.sqrt(len))
HigherTop = ta.wma(mid + highvol + ta.atr(len) * ev, sqrt)
LowerTop = ta.wma(mid + highvol, sqrt)
 
HigherBottom = ta.wma(mid - lowvol, sqrt)
LowerBottom = ta.wma(mid - lowvol - ta.wma(ta.atr(len) * ev, sqrt), sqrt)
/////////////////////////////////////////////////////////////////////////////
//Plotting
colh = color.rgb(196, 22, 22, 40)
coll = color.rgb(29, 179, 24, 40)
coln = color.rgb(89, 100, 85, 85)
 
a = plot(HigherTop, color = colh)
b = plot(LowerTop, color = colh)
c = plot(HigherBottom, color = coll)
d = plot(LowerBottom, color = coll)
 
fill(a, b, colh)
fill(c, d, coll)
 
fill(b, d, coln)

← 返回列表