[STOCK] [策略][TRADINGVIEW][教學] 使用PINE SCRIPT來顯示最近幾天K棒平均的百分比

 

目的

本篇文章的交易策略範例是顯示最近幾天內的K棒平均百分比跟最大跟最小K棒百分比

如果文章對你有幫助在幫我按一下廣告來讓我有額外收入這也是對我來說是一種鼓勵

策略腳本

如何將腳本加入至圖表中請參考[STOCK][TRADINGVIEW][教學] TRADINGVIEW圖表上加入自己寫好的指標&策略 

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © CarterTsai

//@version=5
indicator("計算k棒最近百分比", overlay=true)

days = input.int(title="計算的時間區間", defval=30, minval = 1, maxval = 4999)

var dashboardTable = table.new(position = position.top_right,columns = 3, rows = 10, bgcolor = color.yellow, border_width = 5, border_color = color.blue)

a = array.new_float(0)
// 算出平均三十天的交易量
for i = 0 to (days -1)
    p = math.abs(((high[i] - low[i])/ low[i]) * 100 )
    array.push(a, p)

avg = array.avg(a)
max_val = array.max(a)
min_val = array.min(a)

if barstate.islast
    table.cell(table_id = dashboardTable, column = 0, row = 0, width = 15, text = str.format("平均{0,number,#.##}時間區間\n每個K棒百分比",days),text_color=color.white,  bgcolor=color.blue)
    table.cell(table_id = dashboardTable, column = 0, row = 4, width = 15, text = str.format("平均{0,number,#.##}時間區間\n最大/最小K棒百分比",days),text_color=color.white,  bgcolor=color.blue)

    table.cell(table_id = dashboardTable, column = 0, row = 3, text =  str.format("{0,number,#.##}%",avg), bgcolor=color.white)
    table.cell(table_id = dashboardTable, column = 0, row = 5, text =  str.format("{0,number,#.##}%/{1,number,#.##}%",max_val,min_val), bgcolor=color.white)

結果



留言

熱門文章