繁体   English   中英

为什么这个 pinescript 策略确实显示“没有数据”

[英]why this pinescript strategy does show 'no data'

//我已按照上一个问题的建议更正了代码。 我还为正确显示的测试添加了一些价格//标签。 该策略虽然说没有数据,但它在最后一天有一个//条目(?。),我试图在箭头向上进入并在箭头//向下时退出。 没有金字塔。 建议是//赞赏。谢谢。

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

//@version=5
strategy("test1", overlay=true,initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=100,process_orders_on_close=true)
backTestStart=input.time(timestamp("1 Jan 2022 12:00"), title="Start backtest")

//==Nadaraya====
length = input.float(500,'Window Size',maxval=500,minval=0)
h      = input.float(8.,'Bandwidth')
mult   = input.float(3.) 
src    = input.source(close,'Source')

var condL=false
var condS=false
var longCondition=bool(false)
var shortCondition=bool(false)

up_col = input.color(#39ff14,'Colors',inline='col')
dn_col = input.color(#ff1100,'',inline='col')
//----
n = bar_index
var k = 2
var upper = array.new_line(0) 
var lower = array.new_line(0) 

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

if barstate.islastconfirmedhistory
    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.islastconfirmedhistory
    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,up_col)
        lset(dn,n-i+1,y1 - mae,n-i,y2 - mae,dn_col)
        
        if src[i] > y1 + mae and src[i+1] < y1 + mae
            label.new(n-i,src[i],'▼',color=#00000000,style=label.style_label_down,textcolor=dn_col,textalign=text.align_center)
            label.new(n-i,src[i]+30,str.tostring(close[i],".#"),color=#00000000,style=label.style_label_down,textcolor=dn_col,textalign=text.align_center)
            condL:=true
            longCondition :=condL and time>backTestStart
            if (longCondition)
                strategy.entry("Long", strategy.long)
            condL:=false
        if src[i] < y1 - mae and src[i+1] > y1 - mae
            label.new(n-i,src[i],'▲',color=#00000000,style=label.style_label_up,textcolor=up_col,textalign=text.align_center)
            label.new(n-i,src[i]-30,str.tostring(close[i],".#"),color=#00000000,style=label.style_label_up,textcolor=up_col,textalign=text.align_center)
            condS:=true
            shortCondition:=true
            if shortCondition
                strategy.close_all()
            condS:=false
        
 //======================       
    cross_up := array.get(y,0) + mae
    cross_dn := array.get(y,0) - mae

//=============test
//plotchar(condL,char="D",color=color.white)

alertcondition(ta.crossover(src,cross_up),'Down','Down')
alertcondition(ta.crossunder(src,cross_dn),'Up','Up')

//----
var tb = table.new(position.top_right, 1, 1 , bgcolor = #35202b)

由于您单开 position 且没有平仓交易,没有足够的数据来计算策略报告,所以no data

暂无
暂无

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

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