diff --git "a/#15-\346\211\243\346\212\2653.pine" "b/#15-\346\211\243\346\212\2653.pine" index 3b76417..abbfc70 100644 --- "a/#15-\346\211\243\346\212\2653.pine" +++ "b/#15-\346\211\243\346\212\2653.pine" @@ -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] @@ -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]) diff --git "a/#21-\345\260\213\346\211\276\351\253\230\344\275\216\351\273\2365.pine" "b/#21-\345\260\213\346\211\276\351\253\230\344\275\216\351\273\2365.pine" index d87ac0b..7bc5e1a 100644 --- "a/#21-\345\260\213\346\211\276\351\253\230\344\275\216\351\273\2365.pine" +++ "b/#21-\345\260\213\346\211\276\351\253\230\344\275\216\351\273\2365.pine" @@ -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 +