需要帮助将指标从Pinescript V2转换为V4

时间:2020-10-23 00:50:36

标签: pine-script forex tradingview-api

我正在尝试将用Pinescript V2编写的指标转换为V3 / 4(我知道我可以先将其转换为V3,然后使用内置的“转换为V4”选项)。我还知道,必须先定义V2以外的变量,然后才能对其进行引用。

实际上,该指标在这些变量的定义内引用了一些变量。我已经成功地成功格式化了其中两个(“ greatstrange”和“ smoothedlocation”),但是我不知道如何重新格式化“ extmapbuffer”和“ extmapbuffer1”。另外,当我尝试在V3中运行脚本时,“ pricelocation”被认为是“未声明的变量”。它不是自指的,所以我不太确定为什么V3不喜欢它。

无论如何,在此先感谢您提供的所有帮助!

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

//@version=4
study("KusKus v4")
//parameters
range = input(9,title="Range Periods")
pricesmoothing = input(0.45,title="Price Smoothing")
indexsmoothing = input(0.47,title="Index Smoothing")
emaLength = input(2, "EMA Period")
highesthigh = highest(high,range)
lowestlow = lowest(low,range)
initial_greatestrange = (highesthigh-lowestlow) !=0
greatestrange = initial_greatestrange == true? (highesthigh-lowestlow): initial_greatestrange[1]
midprice = (high+low)/2

//pricelocation
pricelocation = 2*((midprice-lowestlow)/greatestrange)-1

//smoothing of pricelocation

extmapbuffer = pricesmoothing*nz(extmapbuffer[1]) + (1-pricesmoothing)*pricelocation
initial_smoothedlocation = (extmapbuffer>0.99?0.99:(extmapbuffer<-0.99?-0.99:extmapbuffer))!=1
smoothedlocation = initial_smoothedlocation ==true?(extmapbuffer>0.99?0.99:(extmapbuffer<-0.99?-0.99:extmapbuffer)):initial_smoothedlocation[1]

//fisherlocation
fishindex = log((1+smoothedlocation)/(1-smoothedlocation))

//smoothingoffishindex
extmapbuffer1 = indexsmoothing*nz(extmapbuffer1[1])+(1-indexsmoothing)*fishindex
smoothedfish = extmapbuffer1

ma = ema(smoothedfish,emaLength)
ma2len = input(2)
ma2 = ema(ma, ma2len)
plot(smoothedfish,color=smoothedfish>0?green:red,linewidth=3,style=histogram)
plot(ma, color=yellow, linewidth=2)
plot(ma2, color=red, linewidth=2)


0 个答案:

没有答案