【问题标题】:Pincescript to get the average of high and low valuesPincescript 获取高值和低值的平均值
【发布时间】:2021-05-20 18:29:49
【问题描述】:

我从交易视图中获得了以下代码。如何从标记中添加另一条最高价和最低价的平均线。

示例:以下代码将图表标记为 5 分钟时间范围内 30 分钟蜡烛的最高点和最低点。所以,我想再添加一条高点和低点的平均线。

study(title="ORB-30Min", shorttitle="ORB30", overlay=true)
up30on = input(true, title="35 Minute Opening Range High")
down30on = input(true, title="35 Minute Opening Range Low")

is_newbar(res) => change(time(res)) != 0 

adopt(r, s) => security(tickerid, r, s) 

high_range = valuewhen(is_newbar('D'),high,0)
low_range = valuewhen(is_newbar('D'),low,0)

high_rangeL = valuewhen(is_newbar('D'),high,0) 
low_rangeL = valuewhen(is_newbar('D'),low,0) 

//averaged = (high_rangeL + low_rangeL)/2

up30 = plot(up30on ? adopt('30', high_rangeL): na, color = #333fff, style=line, linewidth=1) 
down30 = plot(down30on ? adopt('30', low_rangeL): na, color = #333fff, style=line, linewidth=1) 

//ave = plot(down30on ? adopt('30', low_rangeL): na, color = #e97d53, style=line, linewidth=1) 


trans30 = up30on ?  97 : 100
fill(up30, down30, color = white, transp=trans30)

【问题讨论】:

    标签: pine-script


    【解决方案1】:
    //@version=4
    study(title="ORB-30Min", shorttitle="ORB30", overlay=true)
    
    up30on = input(true, title="35 Minute Opening Range High")
    down30on = input(true, title="35 Minute Opening Range Low")
    avg30on = input(true, title="35 Minute Opening Range Average")
    
    is_newbar(res) => change(time(res)) != 0 
    
    adopt(r, s) => security(syminfo.tickerid, r, s) 
    
    high_range = valuewhen(is_newbar('D'),high,0)
    low_range = valuewhen(is_newbar('D'),low,0)
    
    high_rangeL = valuewhen(is_newbar('D'),high,0) 
    low_rangeL = valuewhen(is_newbar('D'),low,0) 
    
    
    up30 = plot(up30on ? adopt('30', high_rangeL): na, color = #333fff, style=plot.style_stepline, linewidth=1) 
    down30 = plot(down30on ? adopt('30', low_rangeL): na, color = #333fff, style=plot.style_stepline, linewidth=1) 
    
    avg30 = plot(avg30on ? adopt('30', avg(high_rangeL,low_rangeL)): na, color = #e97d53, style=plot.style_stepline, linewidth=1) 
    
    color30 = up30on ?  color.new(color.white,97) : color.new(color.white,100)
    fill(up30, down30, color = color30)
    

    【讨论】:

    • 非常感谢。我如何也可以为此添加策略?当价格超过avg30时,买入卖出,30点后退出。
    猜你喜欢
    • 2021-02-17
    • 1970-01-01
    • 2014-06-28
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-18
    相关资源
    最近更新 更多