首页 > 解决方案 > 如何将此代码从 Pinescript 1.0 版迁移到 3.0 版

问题描述

我需要将此代码从 pinescript 1.0 迁移到 3.0

尝试使用它时它给我这些错误“错误:UNDLECARED IDENTIFIER”

想知道如何将代码转换为 pinescript 3.0

//@version=3
study("MTF candles", shorttitle="MTF candles", overlay=true)

res = input("60", type=resolution)

intv=security(tickerid, res, isintraday?interval:interval*1440)
o = security(tickerid, res, open, barmerge.gaps_off, barmerge.lookahead_on)
c = security(tickerid, res, close, barmerge.gaps_off, barmerge.lookahead_on)
h = security(tickerid, res, high, barmerge.gaps_off, barmerge.lookahead_on)
l = security(tickerid, res, low, barmerge.gaps_off, barmerge.lookahead_on)

min_of_day = (hour*60)+minute
midpoint=floor(intv/2)
wickwidth=input(1.0, title="Wick width in bars")*interval/2
step= input(true, title="Gray Borders with square edges of candles")
topsbots= input(true, title="Color top/bottom edge of candles")
pointyline= input(false, title="Colored Borders with non-square edges of candles")

wicktime= ((min_of_day % intv > midpoint-wickwidth) and (min_of_day % intv  <= midpoint+wickwidth)) ?true:false

col = c >= o ? lime : red

// why so many options... see below
plot(not pointyline?na:wicktime?o>c?h:l:o, color=col, title="Open", style=line, transp=40, title="pointyline open")
plot(not pointyline?na:wicktime?o<=c?h:l:c, color=col, title="Close", style=line, transp=40, title="pointyline close")
plot(not step?na:wicktime?o>c?h:l:o, color=gray, title="Open", style=stepline, transp=20, title="stepline open")
plot(not step?na:wicktime?o<=c?h:l:c, color=gray, title="Close", style=stepline, transp=20, title="stepline close")
plot(not topsbots?na:wicktime?o>c?h:l:o, color=col, title="Open", style=circles, transp=80)
plot(not topsbots?na:wicktime?o<=c?h:l:c, color=col, title="Close", style=circles, transp=80)

// These are the lines that should work, but...
// plot(foo,style=stepline, color=col) is not properly implemented by pinescript -- The color does not update
// and fill() does not properly fill steplines -- It fill them line regular lines.
// Both bugs have been reported.
// That is why the transparency is set to 100
po = plot(wicktime?o>c?h:l:o, color=col, title="Open", style=stepline, transp=100, title="hidden open", editable=false)
pc = plot(wicktime?o<=c?h:l:c, color=col, title="Close", style=stepline, transp=100, title="hidden close", editable=false)
// wick tips
plot(wicktime and h>c?h:na, color=col, title="High", style=circles, transp=60)
plot(wicktime and l<c?l:na, color=col, title="Low", style=circles, transp=60)

fill(po, pc, col)

标签: pine-scripttrading

解决方案


推荐阅读