Skip to content

Update TradingView Pine Script version 4 to version 6 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions #15-扣抵3.pine
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//@version=4
//@version=6
// 本程式來自 https://www.leafbodhi.com/tradingview-deduct-group/

study("Deduct扣抵",overlay=true)
x = input(20, title="小均")
y = input(60, title="中均")
z = input(120, title="大均")
indicator('Deduct扣抵', overlay = true)
x = input(20, title = '小均')
y = input(60, title = '中均')
z = input(120, title = '大均')

close1 = close[x]
close2 = close[y]
Expand All @@ -16,26 +16,11 @@ close3 = close[z]
//tostring(x) 可以把本來是「數字」的x轉換成「字串」


l1 = label.new(bar_index-x, na, tostring(x)+'MA '+tostring(close[x]),
color=color.orange,
textcolor=color.white,
style=close[x] > open[x] ? label.style_labeldown : label.style_labelup,
yloc=close[x] > open[x] ? yloc.abovebar : yloc.belowbar
)
l1 = label.new(bar_index - x, na, str.tostring(x) + 'MA ' + str.tostring(close[x]), color = color.orange, textcolor = color.white, style = close[x] > open[x] ? label.style_label_down : label.style_label_up, yloc = close[x] > open[x] ? yloc.abovebar : yloc.belowbar)
label.delete(l1[1])

l2 = label.new(bar_index-y, na, tostring(y)+'MA '+tostring(close[y]),
color=color.blue,
textcolor=color.white,
style=close[y] > open[y] ? label.style_labeldown : label.style_labelup,
yloc=close[y] > open[y] ? yloc.abovebar : yloc.belowbar
)
l2 = label.new(bar_index - y, na, str.tostring(y) + 'MA ' + str.tostring(close[y]), color = color.blue, textcolor = color.white, style = close[y] > open[y] ? label.style_label_down : label.style_label_up, yloc = close[y] > open[y] ? yloc.abovebar : yloc.belowbar)
label.delete(l2[1])

l3 = label.new(bar_index-z, na, tostring(z) +'MA '+tostring(close[z]),
color=color.navy,
textcolor=color.white,
style=close[z] > open[z] ? label.style_labeldown : label.style_labelup,
yloc=close[z] > open[z] ? yloc.abovebar : yloc.belowbar
)
l3 = label.new(bar_index - z, na, str.tostring(z) + 'MA ' + str.tostring(close[z]), color = color.navy, textcolor = color.white, style = close[z] > open[z] ? label.style_label_down : label.style_label_up, yloc = close[z] > open[z] ? yloc.abovebar : yloc.belowbar)
label.delete(l3[1])
51 changes: 23 additions & 28 deletions #21-尋找高低點5.pine
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
//@version=4
study("教學:尋找高低點5", overlay=true)
//@version=6
indicator('教學:尋找高低點5', overlay = true)

// 尋找高低點5:移除多餘的高低點
// **持續變數的使用** 本堂課非常重要
// 藉由記錄上一次出現高點與低點的地方,判斷目前的高低點是不是有重複
barnum = input(title="左右K棒數", defval=4, type=input.integer, minval=2)

barnum = input.int(title = '左右K棒數', defval = 4, minval = 2)

// 此處的變數將持續使用
var timeHigh=bar_index // 最近一次高點的K棒號碼
var timeLow=bar_index // 最近一次低點的K棒號碼
var lastHigh=0.0 // 最近一次高點的高點
var lastLow=high*100 // 最近一次低點的低點
var timeHigh = bar_index // 最近一次高點的K棒號碼
var timeLow = bar_index // 最近一次低點的K棒號碼
var lastHigh = 0.0 // 最近一次高點的高點
var lastLow = high * 100 // 最近一次低點的低點


cond = high[barnum] == ta.highest(high, barnum * 2 + 1)
cond2 = low[barnum] == ta.lowest(low, barnum * 2 + 1)

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)
labelh


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
)
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)
lablel