繁体   English   中英

PineScript / 转换为 V4

[英]PineScript / converting to V4

我很难将此脚本转换为最新版本 4。如果可能的话,有人可以帮我解决这个问题。 我所做的是,我采用了我最喜欢的一项研究,并在某种程度上将其转化为可操作的策略。 我试图添加新功能就像一个可选择的时间范围,我可以在其中限制我的回测运行,但由于 pine-script 版本,这是不可能的。

strategy(shorttitle = "SQZMOM_LB", title="Squeeze Momentum Indicator [LazyBear]", overlay=true)

length = input(20, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")

useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)

// Calculate BB
source = close
basis = sma(source, length)
dev = multKC * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev

// Calculate KC
ma = sma(source, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC

sqzOn  = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz  = (sqzOn == false) and (sqzOff == false)

val = linreg(source  -  avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), 
            lengthKC,0)

bcolor = iff( val > 0, 
            iff( val > nz(val[1]), lime, green),
            iff( val < nz(val[1]), red, maroon))
scolor = noSqz ? blue : sqzOn ? black : gray 
//plot(val, color=bcolor, style=histogram, linewidth=4)
//plot(0, color=scolor, style=cross, linewidth=2)



// Signal


buyEntry = crossover((bcolor == lime)? 1 : 0, 0)
sellEntry = crossover((bcolor == red)? 1 : 0, 0)

//plotarrow((buyEntry ? 1 : 0))
//plotarrow((sellEntry ? -1 : 0))

/////////////////////////////////////////////////////////////////////
//This controls the time when the backtest runs
//start = timestamp(2020,1,1)
//end = timestamp(2021,4,29)
//t = time(timeframe.period)



////////////////////////////////////////////////////////////////////////

//if time >= start and time <= end 
strategy.entry("Entry", strategy.long, 10000, when=buyEntry)
strategy.close("Entry", when = sellEntry)
   
//@version=4
strategy(shorttitle = "SQZMOM_LB", title="Squeeze Momentum Indicator [LazyBear]", overlay=true)

length = input(20, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")

useTrueRange = input(true, title="Use TrueRange (KC)", type=input.bool)

// Calculate BB
source = close
basis = sma(source, length)
dev = multKC * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev

// Calculate KC
ma = sma(source, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC

sqzOn  = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz  = (sqzOn == false) and (sqzOff == false)

val = linreg(source  -  avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), lengthKC,0)

bcolor = iff( val > 0, iff( val > nz(val[1]), color.lime, color.green), iff( val < nz(val[1]), color.red, color.maroon))
scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray 
//plot(val, color=bcolor, style=histogram, linewidth=4)
//plot(0, color=scolor, style=cross, linewidth=2)



// Signal


buyEntry = crossover((bcolor == color.lime)? 1 : 0, 0)
sellEntry = crossover((bcolor == color.red)? 1 : 0, 0)

//plotarrow((buyEntry ? 1 : 0))
//plotarrow((sellEntry ? -1 : 0))

/////////////////////////////////////////////////////////////////////
//This controls the time when the backtest runs
//start = timestamp(2020,1,1)
//end = timestamp(2021,4,29)
//t = time(timeframe.period)



////////////////////////////////////////////////////////////////////////

//if time >= start and time <= end 
strategy.entry("Entry", strategy.long, 10000, when=buyEntry)
strategy.close("Entry", when = sellEntry)

暂无
暂无

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

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