0

以下代码属于 v2 版本。我需要更新到 v5 版本,但我知道的不多,我很困惑。你能帮助我吗?

//Settings

needlong = input(true, "long")

needshort = input(true, "short")

needstops = input(false, "stops")

stoppercent = input(5, defval = 5, minval = 1, maxval = 50, title = "Stop, %")

usefastsma = input(true, "Use fast MA Filter")

fastlen = input(5, defval = 5, minval = 1, maxval = 50, title = "fast MA Period")

slowlen = input(21, defval = 20, minval = 2, maxval = 200, title = "slow MA Period")

bars = input(2, defval = 2, minval = 0, maxval = 3, title = "Bars Q")

needbg = input(false, defval = false, title = "Need trend Background?")

needex = input(true, defval = true, title = "Need extreme? (crypto/fiat only!!!)")

fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")

toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")

frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")

tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")

fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")

today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

src = close

//PriceChannel 1

lasthigh = highest(src, slowlen)

lastlow = lowest(src, slowlen)

center = (lasthigh + lastlow) / 2

//PriceChannel 2

lasthigh2 = highest(src, fastlen)

lastlow2 = lowest(src, fastlen)

center2 = (lasthigh2 + lastlow2) / 2

//Trend

trend = low > center and low[1] > center[1] ? 1 : high < center and high[1] < center[1] ? -1 : trend[1]

//Bars

bar = close > open ? 1 : close < open ? -1 : 0

redbars = bars == 0 ? 1 : bars == 1 and bar == -1 ? 1 : bars == 2 and bar == -1 and 
bar[1] == -1 ? 1 : bars == 3 and bar == -1 and bar[1] == -1 and bar[2] == -1 ? 1 : 0

greenbars = bars == 0 ? 1 : bars == 1 and bar == 1 ? 1 : bars == 2 and bar == 1 and 
bar[1] == 1 ? 1 : bars == 3 and bar == 1 and bar[1] == 1 and bar[2] == 1 ? 1 : 0

//Fast RSI

fastup = rma(max(change(close), 0), 2)

fastdown = rma(-min(change(close), 0), 2)

fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))

//CryptoBottom

mac = sma(close, 10)

len = abs(close - mac)

sma = sma(len, 100)

max = max(open, close)

min = min(open, close)

//Signals

up1 = trend == 1 and (low < center2 or usefastsma == false) and redbars == 1

dn1 = trend == -1 and (high > center2 or usefastsma == false) and greenbars == 1

up2 = high < center and high < center2 and bar == -1 and needex

dn2 = low > center and low > center2 and bar == 1 and needex

up3 = close < open and len > sma * 3 and min < min[1] and fastrsi < 10 ? 1 : 0

//Lines

plot(center2, color = red, linewidth = 3, transp = 0, title = "Fast MA")

plot(center, color = blue, linewidth = 3, transp = 0, title = "Slow MA")

//Background

col = needbg == false ? na : trend == 1 ? lime : red

bgcolor(col, transp = 80)

//Trading


stoplong = up1 == 1 and needstops == true ? close - (close / 100 * stoppercent) : stoplong[1]

stopshort = dn1 == 1 and needstops == true ? close + (close / 100 * stoppercent) : stopshort[1]

if up1 or up2 or up3

    strategy.entry("Long", strategy.long, needlong == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))

    strategy.exit("Stop Long", "Long", stop = stoplong)

if dn1
    strategy.entry("Short", strategy.short, needshort == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))

    strategy.exit("Stop Short", "Short", stop = stopshort)
    
if time > timestamp(toyear, tomonth, today, 23, 59)
    strategy.close_all()
4

1 回答 1

0

主要变化是:

  • 将新input.int()功能用于用户输入integer类型
  • 使用新的命名空间tamath
  • 使用新color.new()功能创建具有透明度的颜色

这是v5:

//Settings

needlong = input(true, "long")

needshort = input(true, "short")

needstops = input(false, "stops")

stoppercent = input.int(5, minval = 1, maxval = 50, title = "Stop, %")

usefastsma = input(true, "Use fast MA Filter")

fastlen = input.int(5, minval = 1, maxval = 50, title = "fast MA Period")

slowlen = input.int(21, minval = 2, maxval = 200, title = "slow MA Period")

bars = input.int(2, minval = 0, maxval = 3, title = "Bars Q")

needbg = input(false, title = "Need trend Background?")

needex = input(true, title = "Need extreme? (crypto/fiat only!!!)")

fromyear = input.int(1900, minval = 1900, maxval = 2100, title = "From Year")

toyear = input.int(2100, minval = 1900, maxval = 2100, title = "To Year")

frommonth = input.int(01, minval = 01, maxval = 12, title = "From Month")

tomonth = input.int(12, minval = 01, maxval = 12, title = "To Month")

fromday = input.int(01, minval = 01, maxval = 31, title = "From day")

today = input.int(31, minval = 01, maxval = 31, title = "To day")

src = close

//PriceChannel 1

lasthigh = ta.highest(src, slowlen)

lastlow = ta.lowest(src, slowlen)

center = (lasthigh + lastlow) / 2

//PriceChannel 2

lasthigh2 = ta.highest(src, fastlen)

lastlow2 = ta.lowest(src, fastlen)

center2 = (lasthigh2 + lastlow2) / 2

//Trend
trend = false
trend := low > center and low[1] > center[1] ? 1 : high < center and high[1] < center[1] ? -1 : trend[1]

//Bars

bar = close > open ? 1 : close < open ? -1 : 0

redbars = bars == 0 ? 1 : bars == 1 and bar == -1 ? 1 : bars == 2 and bar == -1 and 
  bar[1] == -1 ? 1 : bars == 3 and bar == -1 and bar[1] == -1 and bar[2] == -1 ? 1 : 0

greenbars = bars == 0 ? 1 : bars == 1 and bar == 1 ? 1 : bars == 2 and bar == 1 and 
  bar[1] == 1 ? 1 : bars == 3 and bar == 1 and bar[1] == 1 and bar[2] == 1 ? 1 : 0

//Fast RSI

fastup = ta.rma(math.max(ta.change(close), 0), 2)

fastdown = ta.rma(-math.min(ta.change(close), 0), 2)

fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))

//CryptoBottom

mac = ta.sma(close, 10)

len = math.abs(close - mac)

sma = ta.sma(len, 100)

max = math.max(open, close)

min = math.min(open, close)

//Signals

up1 = trend == 1 and (low < center2 or usefastsma == false) and redbars == 1

dn1 = trend == -1 and (high > center2 or usefastsma == false) and greenbars == 1

up2 = high < center and high < center2 and bar == -1 and needex

dn2 = low > center and low > center2 and bar == 1 and needex

up3 = close < open and len > sma * 3 and min < min[1] and fastrsi < 10 ? 1 : 0

//Lines
c_red = color.new(color.red, 0)
c_blue = color.new(color.blue, 0)
c_lime = color.new(color.lime, 0)

plot(center2, color = c_red, linewidth = 3, title = "Fast MA")

plot(center, color = c_blue, linewidth = 3, title = "Slow MA")

//Background

col = needbg == false ? na : trend == 1 ? c_lime : c_red

bgcolor(col)

//Trading

stoplong = 0.0
stoplong := up1 == 1 and needstops == true ? close - (close / 100 * stoppercent) : stoplong[1]

stopshort = 0.0
stopshort := dn1 == 1 and needstops == true ? close + (close / 100 * stoppercent) : stopshort[1]

if up1 or up2 or up3

    strategy.entry("Long", strategy.long, needlong == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))

    strategy.exit("Stop Long", "Long", stop = stoplong)

if dn1
    strategy.entry("Short", strategy.short, needshort == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))

    strategy.exit("Stop Short", "Short", stop = stopshort)
    
if time > timestamp(toyear, tomonth, today, 23, 59)
    strategy.close_all()
于 2021-11-27T20:27:08.000 回答