Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pine script 测试策略中的未声明变量_Pine Script - Fatal编程技术网

Pine script 测试策略中的未声明变量

Pine script 测试策略中的未声明变量,pine-script,Pine Script,我试图将这个指示器添加到我的测试中,但我遇到了一个错误,我熟悉python,但在pinescript中,我不明白为什么e1变量用作e1和e1在同一行中,根据web,我甚至无法使用控制台来查看e1的值 // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © quechon //@version=4 strategy('Test

我试图将这个指示器添加到我的测试中,但我遇到了一个错误,我熟悉python,但在pinescript中,我不明白为什么e1变量用作e1和e1在同一行中,根据web,我甚至无法使用控制台来查看e1的值

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © quechon
//@version=4
strategy('Testing indicators', process_orders_on_close=true)

//time to backtest from
start = timestamp(2017, 01, 01, 0, 0, 0)
end = timestamp(2020, 11, 03, 0, 0, 0)

var float e1 = 0

//fxSniper
CCI_Period = 14
T3_Period = 3 //default is 5
b = 0.618
xPrice = close
b2 = b*b
b3 = b2*b
c1 = -b3
c2 = (3*(b2 + b3))
c3 = -3*(2*b2 + b + b3)
c4 = (1 + 3*b + b3 + 3*b2)
nn = iff(T3_Period < 1, 1, T3_Period)
nr = 1 + 0.5*(nn - 1)
w1 = 2 / (nr + 1)
w2 = 1 - w1    
xcci = cci(xPrice, CCI_Period)
e1 = w1*xcci + w2*nz(e1[1])
e2 = w1*e1 + w2*nz(e2[1])
e3 = w1*e2 + w2*nz(e3[1])
e4 = w1*e3 + w2*nz(e4[1])
e5 = w1*e4 + w2*nz(e5[1])
e6 = w1*e5 + w2*nz(e6[1])
xccir = c1*e6 + c2*e5 + c3*e4 + c4*e3  

//buy long when price crosses above dpo
long = xccir > 0
    
// short when price is below dpo
short = xccir < 0

if time >= start and time <= end
    
    
    //strategy to buy according to dpo
    if long
        strategy.close('Short')
        strategy.entry('Long', strategy.long, 10000)
        
    //strategy to go short
    if short
        strategy.close('Long')
        strategy.entry('Short', strategy.short, 10000)
我做了一些搜索,但找不出来

原稿

/////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 25/07/2014
// This simple indicator gives you a lot of useful information - when to enter, when to exit
// and how to reduce risks by entering a trade on a double confirmed signal.
// You can use in the xPrice any series: Open, High, Low, Close, HL2, HLC3, OHLC4 and ect...
////////////////////////////////////////////////////////////
study(title="FX Sniper:  T3-CCI", shorttitle="T3-CCI")
CCI_Period = input(14, minval=1)
T3_Period = input(5, minval=1)
b = input(0.618)
hline(0, color=purple, linestyle=line)
xPrice = close
plot(xPrice)
b2 = b*b
b3 = b2*b
c1 = -b3
c2 = (3*(b2 + b3))
c3 = -3*(2*b2 + b + b3)
c4 = (1 + 3*b + b3 + 3*b2)
nn = iff(T3_Period < 1, 1, T3_Period)
nr = 1 + 0.5*(nn - 1)
w1 = 2 / (nr + 1)
w2 = 1 - w1    
xcci = cci(xPrice, CCI_Period)
e1 = w1*xcci + w2*nz(e1[1])
e2 = w1*e1 + w2*nz(e2[1])
e3 = w1*e2 + w2*nz(e3[1])
e4 = w1*e3 + w2*nz(e4[1])
e5 = w1*e4 + w2*nz(e5[1])
e6 = w1*e5 + w2*nz(e6[1])
xccir = c1*e6 + c2*e5 + c3*e4 + c4*e3  
cciHcolor = iff(xccir >= 0 , green,
        iff(xccir < 0, red, black))
plot(xccir, color=blue, title="T3-CCI")
plot(xccir, color=cciHcolor, title="CCIH", style = histogram)
/////////////////////////////////////////////////////////////
//HPotter v1.0版权所有2014年7月25日
//这个简单的指示器为您提供了很多有用的信息-何时进入,何时退出
//以及如何通过在双重确认信号下进行交易来降低风险。
//您可以在xPrice中使用任何系列:打开、高、低、关闭、HL2、HLC3、OHLC4等。。。
////////////////////////////////////////////////////////////
研究(title=“FX狙击手:T3-CCI”,shorttitle=“T3-CCI”)
CCI_周期=输入(14,最小值=1)
T3_周期=输入(5,最小值=1)
b=输入(0.618)
hline(0,颜色=紫色,线条样式=线条)
xPrice=close
地块(xPrice)
b2=b*b
b3=b2*b
c1=-b3
c2=(3*(b2+b3))
c3=-3*(2*b2+b+b3)
c4=(1+3*b+b3+3*b2)
nn=iff(T3_周期<1,1,T3_周期)
nr=1+0.5*(nn-1)
w1=2/(nr+1)
w2=1-w1
xcci=cci(价格,周期)
e1=w1*xcci+w2*nz(e1[1])
e2=w1*e1+w2*nz(e2[1])
e3=w1*e2+w2*nz(e3[1])
e4=w1*e3+w2*nz(e4[1])
e5=w1*e4+w2*nz(e5[1])
e6=w1*e5+w2*nz(e6[1])
xccir=c1*e6+c2*e5+c3*e4+c4*e3
cciHcolor=iff(xccir>=0,绿色,
iff(xccir<0,红色,黑色))
绘图(xccir,颜色=蓝色,title=“T3-CCI”)
绘图(xccir,color=cciHcolor,title=“CCIH”,style=histogram)
请参见

您正在声明一个可变变量
e1
,因此必须使用
:=
为其赋值。 您还应该将变量
e2
声明为可变变量
e6
,因为您正在使用
e2[1]
引用它们以前的值
由于您没有显式声明
e2
,因此它是在首次使用时声明的。
同时,你试图引用它的历史,它当时还不存在

这就行了。
我还修改了一些代码以利用现有函数,并将一些变量转换为输入,这样您就可以在指示器的设置中更改它们,而无需更改源代码

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © quechon
//@version=4
strategy('Testing indicators', process_orders_on_close=true)

//time to backtest from
start = timestamp(2017, 01, 01, 0, 0, 0)
end = timestamp(2020, 11, 03, 0, 0, 0)

var float e1 = 0
var float e2 = 0
var float e3 = 0
var float e4 = 0
var float e5 = 0
var float e6 = 0

//fxSniper
var int CCI_Period = input(14, "CCI_Period", minval=0)
var int T3_Period = input(3, "T3_Period", minval=0) //default is 5
b = 0.618
xPrice = input(close, "xPrice", type=input.source)
b2 = pow(b,2)
b3 = pow(b,3)
c1 = -b3
c2 = (3*(b2 + b3))
c3 = -3*(2*b2 + b + b3)
c4 = (1 + 3*b + b3 + 3*b2)
nn = T3_Period < 1 ? 1 : T3_Period
nr = 1 + 0.5*(nn - 1)
w1 = 2 / (nr + 1)
w2 = 1 - w1    
xcci = cci(xPrice, CCI_Period)
e1 := w1*xcci + w2*nz(e1[1])
e2 := w1*e1 + w2*nz(e2[1])
e3 := w1*e2 + w2*nz(e3[1])
e4 := w1*e3 + w2*nz(e4[1])
e5 := w1*e4 + w2*nz(e5[1])
e6 := w1*e5 + w2*nz(e6[1])
xccir = c1*e6 + c2*e5 + c3*e4 + c4*e3  

//buy long when price crosses above dpo
long = crossover(xccir, 0) 
    
// short when price is below dpo
short = crossunder(xccir, 0)

if time >= start and time <= end
    //strategy to buy according to dpo
    if long
        strategy.close('Short')
        strategy.entry('Long', strategy.long, 10000)
        
    //strategy to go short
    if short
        strategy.close('Long')
        strategy.entry('Short', strategy.short, 10000)
//此源代码受Mozilla公共许可证2.0的条款约束,位于https://mozilla.org/MPL/2.0/
//©奎川
//@版本=4
策略(‘测试指标’、‘流程指令’、‘关闭’=true)
//从中进行回溯测试的时间
开始=时间戳(2017,01,01,0,0,0)
结束=时间戳(2020,11,03,0,0,0)
var浮点e1=0
var浮点e2=0
变量浮点e3=0
var浮点e4=0
var浮点e5=0
var浮点e6=0
//狙击手
变量int CCI_Period=输入(14,“CCI_Period”,minval=0)
var int T3_Period=input(3,“T3_Period”,minval=0)//默认值为5
b=0.618
xPrice=input(关闭“xPrice”,type=input.source)
b2=功率(b,2)
b3=功率(b,3)
c1=-b3
c2=(3*(b2+b3))
c3=-3*(2*b2+b+b3)
c4=(1+3*b+b3+3*b2)
nn=T3\u周期<1?1:T3_期
nr=1+0.5*(nn-1)
w1=2/(nr+1)
w2=1-w1
xcci=cci(价格,周期)
e1:=w1*xcci+w2*nz(e1[1])
e2:=w1*e1+w2*nz(e2[1])
e3:=w1*e2+w2*nz(e3[1])
e4:=w1*e3+w2*nz(e4[1])
e5:=w1*e4+w2*nz(e5[1])
e6:=w1*e5+w2*nz(e6[1])
xccir=c1*e6+c2*e5+c3*e4+c4*e3
//当价格超过dpo时买入多头
长=交叉(xccir,0)
//当价格低于dpo时做空
短=交叉下(xccir,0)

如果时间>=开始和时间嘿,非常感谢您的帮助,但由于某种原因,如果我绘制xccir变量,它将在一天内关闭原始脚本绘制一行,一直到最后一支蜡烛此脚本绘制一行直到知道原因的前一天,再次感谢您的帮助原始脚本甚至没有编译。正因为如此,我想知道你怎么能看到它一直画到最后一根蜡烛?你能提供一个脚本+屏幕截图来显示这一点吗?粘贴的原始脚本是最后一段代码,添加了一个屏幕截图,在玩了脚本之后,我发现策略功能是个问题,只要我用类似原始脚本的学习脚本替换它,就必须弄清楚那里发生了什么
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © quechon
//@version=4
strategy('Testing indicators', process_orders_on_close=true)

//time to backtest from
start = timestamp(2017, 01, 01, 0, 0, 0)
end = timestamp(2020, 11, 03, 0, 0, 0)

var float e1 = 0
var float e2 = 0
var float e3 = 0
var float e4 = 0
var float e5 = 0
var float e6 = 0

//fxSniper
var int CCI_Period = input(14, "CCI_Period", minval=0)
var int T3_Period = input(3, "T3_Period", minval=0) //default is 5
b = 0.618
xPrice = input(close, "xPrice", type=input.source)
b2 = pow(b,2)
b3 = pow(b,3)
c1 = -b3
c2 = (3*(b2 + b3))
c3 = -3*(2*b2 + b + b3)
c4 = (1 + 3*b + b3 + 3*b2)
nn = T3_Period < 1 ? 1 : T3_Period
nr = 1 + 0.5*(nn - 1)
w1 = 2 / (nr + 1)
w2 = 1 - w1    
xcci = cci(xPrice, CCI_Period)
e1 := w1*xcci + w2*nz(e1[1])
e2 := w1*e1 + w2*nz(e2[1])
e3 := w1*e2 + w2*nz(e3[1])
e4 := w1*e3 + w2*nz(e4[1])
e5 := w1*e4 + w2*nz(e5[1])
e6 := w1*e5 + w2*nz(e6[1])
xccir = c1*e6 + c2*e5 + c3*e4 + c4*e3  

//buy long when price crosses above dpo
long = crossover(xccir, 0) 
    
// short when price is below dpo
short = crossunder(xccir, 0)

if time >= start and time <= end
    //strategy to buy according to dpo
    if long
        strategy.close('Short')
        strategy.entry('Long', strategy.long, 10000)
        
    //strategy to go short
    if short
        strategy.close('Long')
        strategy.entry('Short', strategy.short, 10000)