47 lines
1.9 KiB
Plaintext
47 lines
1.9 KiB
Plaintext
//@version=6
|
|
indicator("缠论超简版", shorttitle="缠论超简", overlay=true)
|
|
|
|
// 简单参数
|
|
min_gap = input.int(5, "分型间隔")
|
|
|
|
// 全局变量
|
|
var int last_fractal_bar = 0
|
|
var float last_fractal_price = 0.0
|
|
var string last_fractal_type = ""
|
|
|
|
// 简单分型检测
|
|
is_high = high[1] > high[0] and high[1] > high[2]
|
|
is_low = low[1] < low[0] and low[1] < low[2]
|
|
|
|
// 距离检查
|
|
gap_ok = bar_index[1] - last_fractal_bar >= min_gap
|
|
|
|
// 识别并显示顶分型
|
|
if is_high and gap_ok
|
|
label.new(bar_index[1], high[1], "顶", color=color.red, style=label.style_label_down, size=size.normal)
|
|
// 如果上一个是底分型,画笔
|
|
if last_fractal_type == "bottom" and last_fractal_bar > 0
|
|
line.new(last_fractal_bar, last_fractal_price, bar_index[1], high[1], color=color.blue, width=2)
|
|
last_fractal_bar := bar_index[1]
|
|
last_fractal_price := high[1]
|
|
last_fractal_type := "top"
|
|
|
|
// 识别并显示底分型
|
|
if is_low and gap_ok
|
|
label.new(bar_index[1], low[1], "底", color=color.green, style=label.style_label_up, size=size.normal)
|
|
// 如果上一个是顶分型,画笔
|
|
if last_fractal_type == "top" and last_fractal_bar > 0
|
|
line.new(last_fractal_bar, last_fractal_price, bar_index[1], low[1], color=color.blue, width=2)
|
|
last_fractal_bar := bar_index[1]
|
|
last_fractal_price := low[1]
|
|
last_fractal_type := "bottom"
|
|
|
|
// 信息显示
|
|
if barstate.islast
|
|
var table info = table.new(position.top_right, 2, 3, bgcolor=color.white)
|
|
table.cell(info, 0, 0, "缠论超简版", text_color=color.black)
|
|
table.cell(info, 1, 0, "", text_color=color.black)
|
|
table.cell(info, 0, 1, "最后分型", text_color=color.black)
|
|
table.cell(info, 1, 1, last_fractal_type, text_color=color.black)
|
|
table.cell(info, 0, 2, "分型间隔", text_color=color.black)
|
|
table.cell(info, 1, 2, str.tostring(min_gap), text_color=color.black) |