繁体   English   中英

我如何将这两个脚本代码合并到一个指标中?

[英]How can i combine these two script codes into one indicator?

我无法将这两个脚本代码合二为一。 我尝试了所有我知道的方法,但我无法将这两个代码结合起来。 第一个代码标识通道,而第二个代码确定通道的中线。 我真正想要做的是绘制第三条线,穿过通道线并将通道分成两部分。 有什么帮助吗?

第一个脚本是:

indicator("Nadaraya-Watson Envelope", 'NWEn', overlay=true,max_bars_back=1000,max_lines_count=500,max_labels_count=500)
length = input.float(500,'Window Size',maxval=500,minval=0)
h      = input.float(8.,'Bandwidth')
mult   = input.float(3.) 
src    = input.source(close,'Source')
showLabels = input.bool(false, 'Show ▲ ▼ Labels (repaint issue)')
lw = input.int(1, 'Line Width', [1,2,3,4])
dn_col = input.color(#39ff14,'Colors',inline='col')
up_col = input.color(#ff1100,'',inline='col')
//----
n = bar_index
var k = 2
var upper = array.new_line(0) 
var lower = array.new_line(0) 

ls = line.style_solid

lset(l,x1,y1,x2,y2,col,lineStyle)=>
    line.set_xy1(l,x1,y1)
    line.set_xy2(l,x2,y2)
    line.set_color(l, col)
    line.set_width(l,lw)
    line.set_style(l, lineStyle)


//----

if barstate.isfirst
    for i = 0 to length/k-1
        array.push(upper,line.new(na,na,na,na))
        array.push(lower,line.new(na,na,na,na))

//----
line up = na
line dn = na

//----
cross_up = 0.
cross_dn = 0.


if barstate.islast
    y = array.new_float(0)
    
    sum_e = 0.
    for i = 0 to length-1
        sum = 0.
        sumw = 0.
        
        for j = 0 to length-1
            w = math.exp(-(math.pow(i-j,2)/(h*h*2)))
            sum += src[j]*w
            sumw += w
        
        y2 = sum/sumw
        sum_e += math.abs(src[i] - y2)
        array.push(y,y2)

    mae = sum_e/length*mult
    
    for i = 1 to length-1
        y2 = array.get(y,i)
        y1 = array.get(y,i-1)
        up := array.get(upper,i/k)
        dn := array.get(lower,i/k)

        
        lset(up,n-i+1,y1 + mae,n-i,y2 + mae, y2 > y1 ? #ff1100 : #39ff14, ls)
        lset(dn,n-i+1,y1 - mae,n-i,y2 - mae, y2 > y1 ? #ff1100 : #39ff14, ls)

第一个代码看起来像在此处输入图像描述第二个代码看起来像在此处输入图像描述

第二个脚本是:

indicator('Nadaraya-Watson Estimator', 'NWEs', overlay=true, max_lines_count=500, max_bars_back=500)
h = input(8., 'Bandwidth')
src = input(close, 'Source')
showLabels = input(false, 'Show ▲ ▼ Labels (repaint issue)')
lw = input.int(1, 'Line Width', [1,2,3,4])
col = input.color(color.new(color.white, 60), 'Line Color')
//----
n = bar_index
var ln = array.new_line(0)
if barstate.isfirst
    for i = 0 to 499 by 1
        array.push(ln, line.new(na, na, na, na))
//----
float y2 = na
float y1 = na
float y1_d = na
//----
line l = na
label lb = na
if barstate.islast
    for i = 0 to math.min(499, n - 1) by 1
        sum = 0.
        sumw = 0.
        for j = 0 to math.min(499, n - 1) by 1
            w = math.exp(-(math.pow(i - j, 2) / (h * h * 2)))
            sum += src[j] * w
            sumw += w
            sumw
        y2 := sum / sumw
        d = y2 - y1

        l := array.get(ln, i)
        line.set_xy1(l, n - i + 1, y1)
        line.set_xy2(l, n - i, y2)
        line.set_color(l, y2 > y1 ? col : col)
        line.set_width(l, lw)
        line.set_style(l, line.style_solid)

        if d > 0 and y1_d < 0 and showLabels
            label.new(n - i + 1, src[i], '▲', color=#00000000, style=label.style_label_up, textcolor=#39ff14, textalign=text.align_center)
        if d < 0 and y1_d > 0 and showLabels
            label.new(n - i + 1, src[i], '▼', color=#00000000, style=label.style_label_down, textcolor=#ff1100, textalign=text.align_center)

        y1 := y2
        y1_d := d
        y1_d

我尝试了类似下面的方法,但没有解决:(

indicator("Nadaraya-Watson Envelope", 'NWEn', overlay=true,max_bars_back=1000,max_lines_count=500,max_labels_count=500)
length = input.float(500,'Window Size',maxval=500,minval=0)
h      = input.float(8.,'Bandwidth')
mult   = input.float(3.) 
src    = input.source(close,'Source')
showLabels = input.bool(false, 'Show ▲ ▼ Labels (repaint issue)')
lw = input.int(1, 'Line Width', [1,2,3,4])
dn_col = input.color(#39ff14,'Colors',inline='col')
up_col = input.color(#ff1100,'',inline='col')
col = input.color(color.new(color.white, 60), 'Line Color')

//----
n = bar_index
var ln = array.new_line(0)
var k = 2
var upper = array.new_line(0) 
var lower = array.new_line(0) 

ls = line.style_solid

lset(l,x1,y1,x2,y2,col,lineStyle)=>
    line.set_xy1(l,x1,y1)
    line.set_xy2(l,x2,y2)
    line.set_color(l, col)
    line.set_width(l,lw)
    line.set_style(l, lineStyle)


//----

if barstate.isfirst
    for i = 0 to length/k-1

        array.push(upper,line.new(na,na,na,na))
        array.push(lower,line.new(na,na,na,na))
    for i = 0 to 499 by 1
        array.push(ln, line.new(na, na, na, na))


//----
float y2 = na
float y1 = na
float y1_d = na

//----
line up = na
line dn = na
line l = na

//----
cross_up = 0.
cross_dn = 0.

if barstate.islast
    y = array.new_float(0)
    
    sum_e = 0.
    for i = 0 to length-1
        sum = 0.
        sumw = 0.
        
        for j = 0 to length-1
            w = math.exp(-(math.pow(i-j,2)/(h*h*2)))
            sum += src[j]*w
            sumw += w
            sumw
            
        y2 := sum/sumw
        d = y2 - y1
        l := array.get(ln, i)
        line.set_xy1(l, n - i + 1, y1)
        line.set_xy2(l, n - i, y2)
        line.set_color(l, y2 > y1 ? col : col)
        line.set_width(l, lw)
        line.set_style(l, line.style_solid)
        
        sum_e += math.abs(src[i] - y2)
        array.push(y,y2)

    mae = sum_e/length*mult
    
    for i = 1 to length-1
        y2 := array.get(y,i)
        y1 := array.get(y,i-1)
        up := array.get(upper,i/k)
        dn := array.get(lower,i/k)

        
        lset(up,n-i+1,y1 + mae,n-i,y2 + mae, y2 > y1 ? #ff1100 : #39ff14, ls)
        lset(dn,n-i+1,y1 - mae,n-i,y2 - mae, y2 > y1 ? #ff1100 : #39ff14, ls)
        lset(l,n-i+1,y1,n-i,y2, y2 > y1 ? #ff1100 : #39ff14, ls)

这里是 go。

 //@version=5 //credits to LuxAlgo for making both indicators. indicator("(2022)Nadaraya-Watson Guesstimator [LUX] by LuxAlgo (dh remix)","(2022)Market Crusher",overlay=true,max_bars_back=3000,max_lines_count=500,max_labels_count=500) //float length = 252 length = input.float(252,"length") h = input.float(8.,'Bandwidth') mult = input.float(2.8) src = input.source(close,'Source') up_col = input.color(#39ff14,'Colors',inline='col') dn_col = input.color(#ff1100,'',inline='col') updn_sty = line.style_solid, inline='sty' mid_sty = line.style_solid//, inline='sty' //---- n = bar_index var k = 2 var upper = array.new_line() var lower = array.new_line() var middel = array.new_line() //Line Plot Function... lset(l,x1,y1,x2,y2,col,sty)=> line.set_xy1(l,x1,y1) line.set_xy2(l,x2,y2) line.set_color(l,col) line.set_style(l,sty) line.set_width(l,2) ///// if barstate.isfirst for i = 0 to length/k-1 array.push(upper,line.new(na,na,na,na)) array.push(lower,line.new(na,na,na,na)) for i = 0 to length array.push(middel,line.new(na,na,na,na)) //---- //Set Vars.. line up = na line dn = na line mi = na cross_up = 0. cross_dn = 0. if barstate.islast y = array.new_float(0) sum_e = 0. for i = 0 to length-1 sum = 0. sumw = 0. for j = 0 to length-1 w = math.exp(-(math.pow(ij,2)/(h*h*2))) sum += src[j]*w sumw += w y2 = sum/sumw sum_e += math.abs(src[i] - y2) array.push(y,y2) mae = sum_e/length*mult for i = 1 to length-1 y2 = array.get(y,i) y1 = array.get(y,i-1) up:= array.get(upper,i/k) dn:= array.get(lower,i/k) mi:= array.get(middel,i) lset(up,n-i+1,y1 + mae,ni,y2 + mae,up_col,updn_sty) lset(dn,n-i+1,y1 - mae,ni,y2 - mae,dn_col,updn_sty) lset(mi,n-i+1,y1,ni,y2, y2 > y1? dn_col: up_col,mid_sty) if src[i] > y1 + mae and src[i+1] < y1 + mae label.new(ni,src[i],'▼',color=#00000000,style=label.style_label_down,textcolor=dn_col,textalign=text.align_center) if src[i] < y1 - mae and src[i+1] > y1 - mae label.new(ni,src[i],'▲',color=#00000000,style=label.style_label_up,textcolor=up_col,textalign=text.align_center)//,size=size.huge) cross_up:= array.get(y,0) + mae cross_dn:= array.get(y,0) - mae alertcondition(ta.crossover(src,cross_up),'Down','Down') alertcondition(ta.crossunder(src,cross_dn),'Up','Up')

长度变量限制为 252。因为 tradingview 限制为绘制 500 条线。

2 的组合很棒,如果只在估计器为绿色和红色的简称时打印长的话会更好......如果那可能吗? 我希望结合 2x NWE,但我不编码 pffft。 好一个丹

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM