首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么这个笔录策略确实显示“没有数据”

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

Stack Overflow用户
提问于 2022-09-24 05:47:03
回答 1查看 28关注 0票数 0

//我已经按照我上一个问题中的建议对代码进行了更正。我还为测试添加了一些正确显示的价格//标签。但是,策略中没有数据,它在最后一天有一个//条目(?!)。我正试着让箭头向上和退出箭头//向下,没有金字塔。谢谢你的建议。

代码语言:javascript
复制
// 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)
EN

回答 1

Stack Overflow用户

发布于 2022-09-24 07:44:22

由于您有单一的开盘头寸和没有关闭的交易,没有足够的数据来计算策略报告,所以显示no data

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73834990

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档