-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy path#21-尋找高低點5.pine
41 lines (30 loc) · 1.36 KB
/
#21-尋找高低點5.pine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//@version=4
study("教學:尋找高低點5", overlay=true)
// 尋找高低點5:移除多餘的高低點
// **持續變數的使用** 本堂課非常重要
// 藉由記錄上一次出現高點與低點的地方,判斷目前的高低點是不是有重複
barnum = input(title="左右K棒數", defval=4, type=input.integer, minval=2)
// 此處的變數將持續使用
var timeHigh=bar_index // 最近一次高點的K棒號碼
var timeLow=bar_index // 最近一次低點的K棒號碼
var lastHigh=0.0 // 最近一次高點的高點
var lastLow=high*100 // 最近一次低點的低點
cond = high[barnum] == highest(high, barnum*2+1)
cond2= low[barnum] == lowest(low, barnum*2+1)
if cond
timeHigh:=bar_index-barnum
lastHigh:=high[barnum]
lineh = line.new(x1=timeLow, y1=lastLow,
x2=timeHigh, y2=lastHigh,
color=color.orange, width=2)
labelh = label.new(x=bar_index-barnum, y=na, text="H",
size=size.normal, color=#EEEEEE, textcolor=color.red,
yloc=yloc.abovebar, style=label.style_label_down
)
if cond2
timeLow:=bar_index-barnum
lastLow:=low[barnum]
lablel = label.new(x=bar_index-barnum, y=na, text="L",
size=size.normal, color=#EEEEEE, textcolor=color.green,
yloc=yloc.belowbar, style=label.style_label_up
)