Pine script 策略和学习中价值观图的差异

Pine script 策略和学习中价值观图的差异,pine-script,Pine Script,我正在把这个策略变成一项研究 我当前的脚本 //@version=4 //strategy(title = "Noro's RiskDonchian Indicator", shorttitle = "RiskDonchian indi", overlay = true, default_qty_type = strategy.percent_of_equity, initial_capital = 100, default_qty_value = 100

我正在把这个策略变成一项研究

我当前的脚本

//@version=4
//strategy(title = "Noro's RiskDonchian Indicator", shorttitle = "RiskDonchian indi", overlay = true, default_qty_type = strategy.percent_of_equity, initial_capital = 100, default_qty_value = 100, commission_value = 0.1)
study(title = "Noro's RiskDonchian Indicator", shorttitle = "RiskDonchian indi", overlay = true)

//Settings
needlong = input(true, title = "Long")
needshort = input(true, title = "Short")
tp = input(3.0, minval = 1, title = "Take-profit, %")
tptype = input(defval = "2. Fix", options = ["1. None", "2. Fix", "3. Trailing"], title = "Take-profit type")
sltype = input(defval = "2. Center", options = ["1. None", "2. Center"], title = "Take-profit type")
risklong  = input(1.0, minval = 0.0, maxval = 99.9, title = "Risk size for long, %")
riskshort = input(1.0, minval = 0.0, maxval = 99.9, title = "Risk size for short, %")
pclen = input(20, minval = 1, title = "Price Channel Length")
showll = input(true, title = "Show lines")
showbg = input(false, title = "Show Background")
showof = input(false, title = "Show Offset")
showlabel = input(true, title = "Show label")
fromyear = input(1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, minval = 01, maxval = 31, title = "From day")
today = input(31, minval = 01, maxval = 31, title = "To day")

var  position = 0 // analogue strategy.position_size

//Price Channel
h = highest(high, pclen)
l = lowest(low, pclen)
center = (h + l) / 2

//Take-profit
tpl = 0.0
tpl := tptype == "2. Fix" and position > 0 ? tpl[1] : h * (100 + tp) / 100

//Stop-loss
tps = 0.0
tps := tptype == "2. Fix" and position < 0 ? tps[1] : l * (100 - tp) / 100

//Lines
tplcol = showll and needlong and tptype != "1. None" ? color.lime : na
pclcol = showll and needlong ? color.blue : na
sllcol = showll and needlong and sltype != "1. None" ? color.red : na
tpscol = showll and needshort and tptype != "1. None" ? color.lime : na
pcscol = showll and needshort ? color.blue : na
slscol = showll and needshort and sltype != "1. None" ? color.red : na
offset = showof ? 1 : 0
plot(tpl, offset = offset, color = tplcol, title = "TP Long")
plot(h, offset = offset, color = pclcol, title = "Channel High")
plot(center, offset = offset, color = sllcol, title = "SL Long")
plot(center, offset = offset, color = slscol, title = "SL Short")
plot(l, offset = offset, color = pcscol, title = "Channel Low")
plot(tps, offset = offset, color = tpscol, title = "TP Short")

//Background
size = position
bgcol = showbg == false ? na : size > 0 ? color.lime : size < 0 ? color.red : na
bgcolor(bgcol, transp = 70)

//Lot size
// risksizelong = -1 * risklong
// risklonga = ((center / h) - 1) * 100
// coeflong = abs(risksizelong / risklonga)
// lotlong = (strategy.equity / close) * coeflong
// risksizeshort = -1 * riskshort
// riskshorta = ((center / l) - 1) * 100
// coefshort = abs(risksizeshort / riskshorta)
// lotshort = (strategy.equity / close) * coefshort

//Trading
truetime = time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)
mo = 0
mo := position != 0 ? 0 : high >= center[1] and low <= center[1] ? 1 : mo[1]

if h > 0 and position[1] == 0 and needlong and truetime and high >= h[1]
    position := 1

if position[1] == 1 and needlong and truetime and (high >= tpl[1] or low <= center[1])
    position := 0

if h > 0 and position[1] == 0 and needshort and truetime and low <= l[1]
    position := -1

if position[1] == -1 and needshort and truetime and (low <= tps[1] or high >= center[1])
    position := 0

plotshape(position[1] == 0 and position[0] == 1, style=shape.triangleup, color=color.green, location=location.belowbar, text="Long", size=size.tiny)
plotshape(position[1] == 1 and position[0] == 0, style=shape.xcross, color=color.green, text="Exit Long", size=size.tiny)

plotshape(position[1] == 0 and position[0] == -1, style=shape.triangledown, color=color.red, text="Short", size=size.tiny)
plotshape(position[1] == -1 and position[0] == 0, style=shape.xcross, color=color.red, location=location.belowbar, text="Exit Short", size=size.tiny)
/@version=4
//策略(title=“Noro's RiskDonchian Indicator”,shorttitle=“RiskDonchian indi”,overlay=true,默认数量类型=策略。股权百分比,初始资本=100,默认数量价值=100,佣金价值=0.1)
研究(title=“诺罗风险指数”,shorttitle=“风险指数”,叠加=true)
//背景
needlong=输入(true,title=“Long”)
needshort=输入(true,title=“Short”)
tp=输入(3.0,最小值=1,title=“获取利润,%”)
tptype=input(defval=“2.Fix”,options=[“1.None”,“2.Fix”,“3.Trailing”],title=“获取利润类型”)
sltype=input(defval=“2.Center”,选项=[“1.None”,“2.Center”],title=“获取利润类型”)
risklong=输入(1.0,最小值=0.0,最大值=99.9,title=“长期风险大小,%”)
riskshort=输入(1.0,最小值=0.0,最大值=99.9,title=“短期风险大小,%”)
pclen=输入(20,最小值=1,title=“价格通道长度”)
showll=输入(true,title=“显示行”)
showbg=输入(假,title=“显示背景”)
showof=输入(假,title=“显示偏移”)
showlabel=输入(true,title=“Show label”)
fromyear=输入(1900,最小值=1900,最大值=2100,title=“起始年”)
toyear=输入(2100,最小值=1900,最大值=2100,title=“To Year”)
frommonth=input(01,minval=01,maxval=12,title=“From Month”)
tomonth=输入(12,最小值=01,最大值=12,title=“到月份”)
fromday=输入(01,minval=01,maxval=31,title=“From day”)
今天=输入(31,最小值=01,最大值=31,title=“今天”)
var位置=0//模拟策略。位置\u大小
//价格渠道
h=最高(高,pclen)
l=最低(低,pclen)
中心=(h+l)/2
//获利
tpl=0.0
tpl:=tptype==“2.修复”和位置>0?tpl[1]:h*(100+tp)/100
//止损
tps=0.0
tps:=tptype==“2.Fix”和位置<0?tps[1]:l*(100-tp)/100
//线条
tplcol=showll和needlong和tptype!=“1.没有”?颜色。酸橙:na
pclcol=showl和needlong?蓝色:na
sllcol=showll和needlong和sltype!=“1.没有”?颜色:红色:na
tpscol=showl和needshort和tptype!=“1.没有”?颜色。酸橙:na
pcscol=showl和needshort?蓝色:na
slscol=showl和needshort和sltype!=“1.没有”?颜色:红色:na
偏移量=showof?1 : 0
绘图(tpl,offset=offset,color=tplcol,title=“TP Long”)
绘图(h,偏移=偏移,颜色=pclcol,title=“通道高”)
绘图(中心,偏移=偏移,颜色=sllcol,title=“SL Long”)
绘图(中心,偏移=偏移,颜色=slscol,title=“SL Short”)
绘图(l,偏移=偏移,颜色=pcscol,title=“通道低”)
绘图(tps,偏移=偏移,颜色=tpscol,title=“TP Short”)
//背景
大小=位置
bgcol=showbg==false?na:大小>0?颜色。石灰:尺寸<0?颜色:红色:na
bgcolor(bgcol,传输=70)
//批量
//risksizelong=-1*risklong
//risklonga=((中心/h)-1)*100
//coeflong=abs(risksizelong/risklonga)
//lotlong=(strategy.equity/close)*coeflong
//risksizeshort=-1*riskshort
//riskshorta=((中心/l)-1)*100
//coefshort=abs(risksizeshort/riskshorta)
//lotshort=(strategy.equity/close)*coefshort
//交易
truetime=时间>时间戳(从年、从月、从日、00、00)和时间<时间戳(从年、明天、今天、23、59)
mo=0
mo:=位置!=0 ? 0:高>=中心[1],低0和位置[1]==0,需要长时间和真实时间,高>=h[1]
位置:=1
如果位置[1]==1,需要长时间、真实时间和(高>=tpl[1]或低0,位置[1]==0,需要短时间、真实时间和低可能是以下原因:

  • 策略仅在栏关闭时执行
  • 只有在
    策略执行后,才在下一个栏上打开一个位置(订单填充)。进入/退出
    (满足条件)

  • pine文档中对此有任何描述吗?这里:
    …默认情况下,在历史和实时计算过程中,代码是在条形图结束时计算的。
    Broker Emulator
    部分也有有用的信息