tradingview 腳本 v2
tradingview 腳本 v2
tradingview 腳本 v2
// |---------------|
// | MACD 面積計算 |
// |---------------|
// |{---------------
// |--macd inputs--|
fang_da = input(title="enlargeh", type=input.integer, defval=1,
group="MACD Setting")
// |--macd colors--|
// col_macd = input(#2962FF, "MACD Line\uc0\u8195 \u8196 ",
input.color, group="Color Settings", inline="MACD")
// col_signal = input(#FF6D00, "Signal Line\uc0\u8195 \u8198 ",
input.color, group="Color Settings", inline="Signal")
// col_grow_above = input(#FF5252, "Above\uc0\u8196 \u8196 \u8197
Grow", input.color, group="Histogram", inline="Above")
// col_fall_above = input(#FFCDD2, "Fall", input.color,
group="Histogram", inline="Above")
// col_grow_below = input(#B2DFDB, "Below\uc0\u8195 Grow",
input.color, group="Histogram", inline="Below")
// col_fall_below = input(#26A69A, "Fall", input.color,
group="Histogram", inline="Below")
// Calculating macd
fast_ma = sma_source == "SMA" ? sma(src, fast_length) : ema(src,
fast_length)
slow_ma = sma_source == "SMA" ? sma(src, slow_length) : ema(src,
slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? sma(macd, signal_length) :
ema(macd, signal_length)
hist = macd - signal
ba = - hist
// 面積取小數點第二位
p = ceil(100*my_sumup(hist,1))/100
p_2 = ceil(100*my_sumup(ba,1))/100
// label 面積
label.delete(area_2[1])
// -------------------------------------------------------------}
// |--------------|
// | SMA 均線 |
// |--------------|
// |--SMA inputs--|
// |---plot MA---|
// ma1 = sma_source_1 == "SMA" ? sma(ma_src, ma_len_1) :
ema(ma_src, ma_len_1)
// ma2 = sma_source_2 == "SMA" ? sma(ma_src, ma_len_2) :
ema(ma_src, ma_len_2)
// ma3 = sma_source_3 == "SMA" ? sma(ma_src, ma_len_3) :
ema(ma_src, ma_len_3)
// ma4 = sma_source_4 == "SMA" ? sma(ma_src, ma_len_4) :
ema(ma_src, ma_len_4)
// ma5 = sma_source_5 == "SMA" ? sma(ma_src, ma_len_5) :
ema(ma_src, ma_len_5)
// ma6 = sma_source_6 == "SMA" ? sma(ma_src, ma_len_6) :
ema(ma_src, ma_len_6)
// ma7 = sma_source_7 == "SMA" ? sma(ma_src, ma_len_7) :
ema(ma_src, ma_len_7)
// ma8 = sma_source_8 == "SMA" ? sma(ma_src, ma_len_8) :
ema(ma_src, ma_len_8)
ma1 = sma(ma_src,ma_len_1)
ma2 = sma(ma_src,ma_len_2)
ma3 = sma(ma_src,ma_len_3)
ma4 = sma(ma_src,ma_len_4)
ma5 = sma(ma_src,ma_len_5)
ma6 = sma(ma_src,ma_len_6)
ma7 = sma(ma_src,ma_len_7)
ma8 = sma(ma_src,ma_len_8)
// -------------------------------------------------------------------------------}
// |--------------------------------------------|
// | Bollinger Band |
// |--------------------------------------------|
// |{--------------------------------------------
// |--------------------------------------------}
// |--------------------------------------------|
// | 纏論 K 線 |
// |--------------------------------------------|
// |{-------------------------------------------
// 分型
// 分型 inputs
// K_legal = input(title = "K legal", type = input.bool, defval=true,
group="頂底分型")
// K_situ = input(title = "K situation", type = input.bool, defval=true,
group="頂底分型")
// K_pre = input(title = "previous K", type = input.bool, defval=true,
group="頂底分型")
// K_Z = input(title= "KZ", type = input.bool, defval=true, group="頂底
分型")
// K_frac = input(title="K fractal", type=input.bool, defval=true,
group="頂底分型")
newHigh = high
newLow = low
// 包含關係
include_1 = high > newHigh[1] and low < newLow[1]
include_2 = high < newHigh[1] and low > newLow[1]
include_3 = high > newHigh[1] and low == newLow[1]
include_4 = high < newHigh[1] and low == newLow[1]
include_5 = high == newHigh[1] and low < newLow[1]
include_6 = high == newHigh[1] and low > newLow[1]
include_7 = high == newHigh[1] and low == newLow[1]
//var plotshape la = na
dir_up = false
dir_down = false
not_include = false
// 頂底分型判斷:
// 頂分型判斷
topfractal = ((newHigh[1] > newHigh and newHigh[1] > newHigh[2]
and newLow[1] > newLow and newLow[1] > newLow[2])
or (newHigh[1] >= newHigh and newHigh[1] > newHigh[2] and
newLow[1] > newLow and newLow[1] > newLow[2])
or (newHigh[1] > newHigh and newHigh[1] >= newHigh[2] and
newLow[1] > newLow and newLow[1] > newLow[2])
or (newHigh[1] > newHigh and newHigh[1] > newHigh[2] and
newLow[1] >= newLow and newLow[1] > newLow[2])
or (newHigh[1] > newHigh and newHigh[1] > newHigh[2] and
newLow[1] > newLow and newLow[1] >= newLow[2])
or (newHigh[1] >= newHigh and newHigh[1] >= newHigh[2] and
newLow[1] > newLow and newLow[1] > newLow[2])
// or (newHigh[1] >= newHigh and newHigh[1] > newHigh[2] and
newLow[1] >= newLow and newLow[1] > newLow[2])
or (newHigh[1] >= newHigh and newHigh[1] > newHigh[2] and
newLow[1] > newLow and newLow[1] >= newLow[2])
or (newHigh[1] > newHigh and newHigh[1] >= newHigh[2] and
newLow[1] >= newLow and newLow[1] > newLow[2])
or (newHigh[1] > newHigh and newHigh[1] >= newHigh[2] and
newLow[1] > newLow and newLow[1] >= newLow[2])
or (newHigh[1] > newHigh and newHigh[1] > newHigh[2] and
newLow[1] >= newLow and newLow[1] >= newLow[2])
// or (newHigh[1] >= newHigh and newHigh[1] >= newHigh[2] and
newLow[1] >= newLow and newLow[1] > newLow[2])
or (newHigh[1] >= newHigh and newHigh[1] >= newHigh[2] and
newLow[1] > newLow and newLow[1] >= newLow[2])
// or (newHigh[1] >= newHigh and newHigh[1] > newHigh[2] and
newLow[1] >= newLow and newLow[1] >= newLow[2])
or (newHigh[1] > newHigh and newHigh[1] >= newHigh[2] and
newLow[1] >= newLow and newLow[1] >= newLow[2])) and dir_up[1]
// 底分型判斷
buttomfractal = ((newHigh[1] < newHigh and newHigh[1] <
newHigh[2] and newLow[1] < newLow and newLow[1] < newLow[2])
or (newHigh[1] <= newHigh[2] and newHigh[1] < newHigh and
newLow[1] <= newLow[2] and newLow[1] <= newLow)
// or (newHigh[1] < newHigh[2] and newHigh[1] <= newHigh and
newLow[1] <= newLow[2] and newLow[1] <= newLow)
// or (newHigh[1] <= newHigh[2] and newHigh[1] <= newHigh and
newLow[1] < newLow[2] and newLow[1] <= newLow)
or (newHigh[1] <= newHigh[2] and newHigh[1] <= newHigh and
newLow[1] <= newLow[2] and newLow[1] < newLow)
or (newHigh[1] < newHigh[2] and newHigh[1] < newHigh and
newLow[1] <= newLow[2] and newLow[1] <= newLow)
// or (newHigh[1] < newHigh and newHigh[1] <= newHigh[2] and
newLow[1] < newLow and newLow[1] <= newLow[2])
or (newHigh[1] <= newHigh and newHigh[1] < newHigh[2] and
newLow[1] < newLow and newLow[1] <= newLow[2])
or (newHigh[1] < newHigh and newHigh[1] <= newHigh[2] and
newLow[1] <= newLow and newLow[1] < newLow[2])
// or (newHigh[1] <= newHigh and newHigh[1] < newHigh[2] and
newLow[1] <= newLow and newLow[1] < newLow[2])
or (newHigh[1] <= newHigh and newHigh[1] <= newHigh[2] and
newLow[1] < newLow and newLow[1] < newLow[2])
or (newHigh[1] < newHigh and newHigh[1] < newHigh[2] and
newLow[1] < newLow and newLow[1] <= newLow[2])
or (newHigh[1] < newHigh and newHigh[1] < newHigh[2] and
newLow[1] <= newLow and newLow[1] < newLow[2])
or (newHigh[1] < newHigh and newHigh[1] <= newHigh[2] and
newLow[1] < newLow and newLow[1] < newLow[2])
or (newHigh[1] <= newHigh and newHigh[1] < newHigh[2] and
newLow[1] < newLow and newLow[1] < newLow[2])) and dir_down[1]
// 標記頂底分型
if topfractal
labeltop = label.new(bar_index[1], na,
yloc=yloc.abovebar, color=color.red,
size=size.auto, style=label.style_triangledown)
if buttomfractal
labelbottom = label.new(bar_index[1], na,
yloc=yloc.belowbar, color=color.green,
size=size.auto, style=label.style_triangleup)