Pine script 为什么我的pine脚本代码不起作用? /@version=4 策略(title=“daily crypto strategy”,shorttitle=“MyStrategy”,overlay=true,聚合=2,佣金类型=strategy.commissi

Pine script 为什么我的pine脚本代码不起作用? /@version=4 策略(title=“daily crypto strategy”,shorttitle=“MyStrategy”,overlay=true,聚合=2,佣金类型=strategy.commissi,pine-script,Pine Script,为什么我的pine脚本代码不起作用? /@version=4 策略(title=“daily crypto strategy”,shorttitle=“MyStrategy”,overlay=true,聚合=2,佣金类型=strategy.commission.percent,佣金值=0.07,默认数量类型=strategy.percent,默认数量值=100,币种=currency.USD) ///ADX和DI adxlen=输入(14,“adx平滑”,最小值=1,步长=1) dilen=输入

为什么我的pine脚本代码不起作用?
/@version=4
策略(title=“daily crypto strategy”,shorttitle=“MyStrategy”,overlay=true,聚合=2,佣金类型=strategy.commission.percent,佣金值=0.07,默认数量类型=strategy.percent,默认数量值=100,币种=currency.USD)
///ADX和DI
adxlen=输入(14,“adx平滑”,最小值=1,步长=1)
dilen=输入(14,“DI长度”,最小值=1,步长=1)
迪莫夫(len)=>
上升=变化(高)
向下=-变化(低)
truerange=rma(tr,len)
plus=fixnan(100*rma(向上>向下和向上>0?向上:0,len)/truerange)
减=fixnan(100*rma(向下>向上和向下>0?向下:0,len)/truerange)
[加,减]
adx(迪伦,阿德克斯伦)=>
[加,减]=迪尔莫夫(迪伦)
总和=正+负
adx=100*rma(绝对绝对值(加减)/(总和=0?1:总和),adxlen)
[adx,正,负]
//[adx,di+,d-]
[sig,up,down]=adx(迪伦,阿德克斯伦)
//计算DEMA的函数
dema(系列,长度)=>
如果(长度>0)
ema值=ema(系列,长度)
2*emaValue-ema(emaValue,长度)
其他的
na
///RSİ
rsilen=输入(14,“rsi长度”,最小值=1,步长=1)
上传=输入(70,“上限”,最小值=1,步长=1)
下行限制=输入(30,“下限”,最小值=1,步长=1)
//rsi
rsival=rsi(关闭,rsilen)
rsismooth1=dema(rsival,5)
rsismooth2=dema(rsival,10)
///柴金
快速=输入(3,“快速长度”,最小值=1,步长=1)
慢速=输入(14,“慢速长度”,最小值=1,步长=1)
//柴金osc
osc=ema(accdist,快速)-ema(accdist,慢速)
OSC1=dema(osc,5)
OSC2=dema(osc,10)
///TP&SL
//sl_类型=输入(“%”,选项=[“%”,“ATR”,“绝对”])
//sl_perc=input(1,title=“%sl”,type=input.float)
//atr_长度=输入(10,title=“atr长度”)
//atr_mult=input(1.2,title=“atr mult”,type=input.float)
//sl_absol=input(1,title=“Absolute sl”,type=input.float)
////SL值
//sl_val=sl_type==“ATR”?atr_mult*atr(atr_长度):
//sl_类型==“绝对”?绝对的:
//关闭*sl_perc/100
////使用输入选项配置跟踪停止级别(可选)
//longTrailPerc=输入(title=“Trail Long Loss(%)”,
//类型=浮动,最小值=0.0,步长=0.1,偏差=1)*0.01
//shortTrailPerc=输入(title=“Trail短期损失(%)”,
//类型=浮动,最小值=0.0,步长=0.1,偏差=1)*0.01
//长的
////确定跟踪止损价格
//价格=0.0
//longStopPrice:=if(strategy.position\u size>0)
//stopValue=close*(1-longTrailPerc)
//最大值(stopValue,longStopPrice[1])
//否则
//     0
long_tp1_inp=输入(2,标题为“long Take Profit 1%”,步长=0.1)/100
多头tp1数量=输入(25,title=“多头获利1数量”,步骤=1)
long_tp2_inp=输入(3,标题为“long Take Profit 2%”,步长=0.1)/100
多头tp2数量=输入(100,title=“多头获利2数量”,步骤=1)
long_sl_inp=输入(1,title='long Stop Loss%',步长=0.1)/100
多头交易水平=策略、头寸、平均价格*(1+多头交易价格)
long_take_level_2=策略、位置、平均价格*(1+long_tp2_inp)
长期止损水平=策略位置平均价格*(1-长期止损水平)
//短
////确定尾随空头价格
//shortStopPrice=0.0
//shortStopPrice:=如果(策略位置大小<0)
//stopValue=close*(1+shortTrailPerc)
//最小值(stopValue,ShortStopRice[1])
//否则
//     999999
空头交易1\u inp=输入(2,标题为“空头获利1%”,步骤=0.1)/100
空头数量=输入(25,title=“空头获利1数量”,步骤=1)
short_tp2_inp=输入(3,title='short Take Profit 2%',step=0.1)/100
空头数量=输入(100,title=“空头获利2数量”,步骤=1)
短脉冲输入=输入(1,title='short Stop Loss%',阶跃=0.1)/100
空头价格水平=策略位置平均价格*(1-空头价格)
空头价格水平=策略位置平均价格*(1-空头价格水平)
短线止损水平=策略位置平均价格*(1+短线止损水平)
///策略
//RSI超买、超卖
ifdownlimit=rsivaluplimit?正确:交叉(rsival,uplimit)?对:错
//长的,短的
ifosclong=交叉(osc,0)?真:oscsmooth1>oscsmooth1[1]?对:错
ifoscshort=crossunder(osc,0)?真:oscsmooth1rsismouth1[1])或(crossion(rsival,50)和ifosclong)
分录\价格\长=值何时(分录\长,结束,0)
退出\u长=关闭=短\u停止\u水平
/////回溯测试周期///////
testStartYear=输入(2018年,“回溯测试开始年份”)
testStartMonth=输入(1,“反向测试开始月份”)
testStartDay=输入(1,“回溯测试开始日”)
testPeriodStart=时间戳(testStartYear、testStartMonth、testStartDay、0、0)
testStopYear=输入(2020,“回溯测试停止年”)
testStopMonth=输入(12,“反向测试停止月”)
testStopDay=输入(31,“反向测试停止日”)
testPeriodStop=时间戳(testStopYear、testStopMonth、testStopDay、0、0)
testPeriod()=>
时间>=测试周期开始和时间0
strategy.entry(“long”,true,when=entry\u long,comment=“INSERT ENTER long comment”)
策略.退出(“TP1”、“长期”,数量百分比=长期TP1数量,限制=长期采取水平1)
策略.exit(“TP2”,“long”,数量百分比=long\u TP2\u数量,限制=long\u take\u level\u 2,注释='INSERT exit long comment')
策略.close(“long”,when=exit\u long,comment=“插入exit long comment”)
如果strategy.position\u size==0或strategy.position\u size<0
strategy.entry(“short”,false,when=entry\u short,comment=“INSERT ENTER short comment”)
策略.退出(“TP1”,“短”,数量百分比=短\U TP1\U数量,限制=短\U获取\U级别\U 1)
策略.退出(“TP2”,“短”,数量百分比=短,数量限制=短,级别2,co
    //@version=4
strategy(title="daily crypto strategy", shorttitle="MyStrategy", overlay=true, pyramiding=2, commission_type=strategy.commission.percent, commission_value=0.07, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, currency = currency.USD)


/// ADX and DI

adxlen = input(14, "adx smoothing", minval=1, step=1)
dilen  = input(14, "DI length", minval=1, step=1)

dirmov(len) =>

    up        = change(high)
    down      = -change(low)
    truerange = rma(tr, len)
    plus      = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange)
    minus     = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / truerange)

    [plus, minus]

adx(dilen, adxlen) => 

    [plus, minus] = dirmov(dilen)

    sum = plus + minus
    adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)

    [adx, plus, minus]


//[adx, di+, d-]
[sig, up, down] = adx(dilen, adxlen)


// Function that calculates the DEMA
dema(series, length) =>
    if (length > 0)
        emaValue = ema(series, length)
        2 * emaValue - ema(emaValue, length)
    else
        na

/// RSİ

rsilen = input(14, "rsi length", minval=1, step=1)
uplimit = input(70, "up limit", minval=1, step=1)
downlimit = input(30, "down limit", minval=1, step=1)

//rsi
rsival = rsi(close, rsilen)
rsismooth1 = dema(rsival, 5)
rsismooth2 = dema(rsival, 10)


/// CHAIKIN

fast = input(3, "fast length", minval=1, step=1)
slow = input(14, "slow length", minval=1, step=1)

//chaikin osc

osc   = ema(accdist, fast) - ema(accdist, slow)
oscsmooth1 = dema(osc, 5)
oscsmooth2 = dema(osc, 10)

/// TP & SL

// sl_type    = input("%", options = ["%", "ATR", "Absolute"])

// sl_perc    = input(1,     title = "% SL",        type = input.float)
// atr_length = input(10,    title = "ATR Length")
// atr_mult   = input(1.2,   title = "ATR Mult",    type = input.float)
// sl_absol   = input(1,     title = "Absolute SL", type = input.float)

// // SL values
// sl_val = sl_type == "ATR"      ? atr_mult * atr(atr_length) : 
//          sl_type == "Absolute" ? sl_absol : 
//          close * sl_perc / 100

// // Configure trail stop level with input options (optional)
// longTrailPerc = input(title="Trail Long Loss (%)",
//      type=float, minval=0.0, step=0.1, defval=1) * 0.01

// shortTrailPerc = input(title="Trail Short Loss (%)",
//      type=float, minval=0.0, step=0.1, defval=1) * 0.01

//LONG

// // Determine trail stop loss prices
// longStopPrice = 0.0

// longStopPrice := if (strategy.position_size > 0)
//     stopValue = close * (1 - longTrailPerc)
//     max(stopValue, longStopPrice[1])
// else
//     0

long_tp1_inp = input(2, title='Long Take Profit 1 %', step=0.1)/100
long_tp1_qty = input(25, title="Long Take Profit 1 Qty", step=1)

long_tp2_inp = input(3, title='Long Take Profit 2 %', step=0.1)/100
long_tp2_qty = input(100, title="Long Take Profit 2 Qty", step=1)

long_sl_inp  = input(1, title='Long Stop Loss %', step=0.1)/100

long_take_level_1 = strategy.position_avg_price * (1 + long_tp1_inp)
long_take_level_2 = strategy.position_avg_price * (1 + long_tp2_inp)
long_stop_level   = strategy.position_avg_price * (1 - long_sl_inp)

//SHORT

// // Determine trailing short price
// shortStopPrice = 0.0

// shortStopPrice := if (strategy.position_size < 0)
//     stopValue = close * (1 + shortTrailPerc)
//     min(stopValue, shortStopPrice[1])
// else
//     999999

short_tp1_inp = input(2, title='Short Take Profit 1 %', step=0.1)/100
short_tp1_qty = input(25, title="Short Take Profit 1 Qty", step=1)

short_tp2_inp = input(3, title='Short Take Profit 2 %', step=0.1)/100
short_tp2_qty = input(100, title="Short Take Profit 2 Qty", step=1)

short_sl_inp  = input(1, title='Short Stop Loss %', step=0.1)/100

short_take_level_1 = strategy.position_avg_price * (1 - short_tp1_inp)
short_take_level_2 = strategy.position_avg_price * (1 - short_tp2_inp)
short_stop_level   = strategy.position_avg_price * (1 + short_sl_inp)


/// Strategy

//RSI overbought,oversold
ifdownlimit = rsival < downlimit ? true : crossover(rsival, downlimit) ? true : false
ifuplimit   = rsival > uplimit ? true : crossunder(rsival, uplimit) ? true : false

//CHAININ long,short
ifosclong   = crossover(osc, 0) ? true : oscsmooth1 > oscsmooth1[1] ? true : false
ifoscshort  = crossunder(osc, 0) ? true : oscsmooth1 < oscsmooth1[1]? true : false

//LONG               //rsi - dmi - chaikin strategy long entry
entry_long         = (ifdownlimit and crossunder(down, sig) and ifosclong) or (ifdownlimit and rsismooth1 > rsismooth1[1]) or (crossover(rsival, 50) and ifosclong)
entry_price_long   = valuewhen(entry_long,close,0)

exit_long          = close <= long_stop_level

//SHORT              //rsi - dmi - chaikin strategy short entry
entry_short        = (ifuplimit and crossunder(up, sig) and ifoscshort) or (ifuplimit and rsismooth1 < rsismooth1[1]) or (crossunder(rsival, 50) and ifoscshort)
entry_price_short  = valuewhen(entry_short,close,0)

exit_short         = close >= short_stop_level


///// BACKTEST PERIOD ///////
testStartYear      = input(2018, "Backtest Start Year")
testStartMonth     = input(1, "Backtest Start Month")
testStartDay       = input(1, "Backtest Start Day")
testPeriodStart    = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)

testStopYear       = input(2020, "Backtest Stop Year")
testStopMonth      = input(12, "Backtest Stop Month")
testStopDay        = input(31, "Backtest Stop Day")
testPeriodStop     = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)

testPeriod() =>
    time >= testPeriodStart and time <= testPeriodStop ? true : false

if testPeriod()
    if strategy.position_size == 0 or strategy.position_size > 0
        strategy.entry("long", true, when = entry_long, comment="INSERT ENTER LONG COMMENT")
        strategy.exit("TP1", "long", qty_percent=long_tp1_qty, limit=long_take_level_1)
        strategy.exit("TP2", "long", qty_percent=long_tp2_qty, limit=long_take_level_2, comment = 'INSERT EXIT LONG COMMENT')
        strategy.close("long", when=exit_long, comment = "INSERT EXIT LONG COMMENT")
    
    if strategy.position_size == 0 or strategy.position_size < 0
        strategy.entry("short", false, when = entry_short, comment="INSERT ENTER SHORT COMMENT")
        strategy.exit("TP1","short", qty_percent=short_tp1_qty, limit=short_take_level_1)
        strategy.exit("TP2","short", qty_percent=short_tp2_qty, limit=short_take_level_2, comment = "INSERT EXIT SHORT COMMENT")
        strategy.close("short", when=exit_short, comment = "INSERT EXIT SHORT COMMENT")


// LONG POSITION
plot(strategy.position_size > 0 ? long_take_level_1 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="1st Long Take Profit")
plot(strategy.position_size > 0 ? long_take_level_2 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="2nd Long Take Profit")
plot(strategy.position_size > 0 ? long_stop_level : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Stop Loss")

// SHORT POSITION
plot(strategy.position_size < 0 ? short_take_level_1 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="1st Short Take Profit")
plot(strategy.position_size < 0 ? short_take_level_2 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="2nd Short Take Profit")
plot(strategy.position_size < 0 ? short_stop_level : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Stop Loss")
//@version=4
strategy(title="daily crypto strategy", shorttitle="MyStrategy", overlay=true, pyramiding=2, commission_type=strategy.commission.percent, commission_value=0.07, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, currency = currency.USD)


/// ADX and DI

adxlen = input(14, "adx smoothing", minval=1, step=1)
dilen  = input(14, "DI length", minval=1, step=1)

dirmov(len) =>

    up        = change(high)
    down      = -change(low)
    truerange = rma(tr, len)
    plus      = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange)
    minus     = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / truerange)

    [plus, minus]

adx(dilen, adxlen) => 

    [plus, minus] = dirmov(dilen)

    sum = plus + minus
    adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)

    [adx, plus, minus]


//[adx, di+, d-]
[sig, up, down] = adx(dilen, adxlen)


// Function that calculates the DEMA
dema(series, length) =>
    if (length > 0)
        emaValue = ema(series, length)
        2 * emaValue - ema(emaValue, length)
    else
        na

/// RSİ

rsilen = input(14, "rsi length", minval=1, step=1)
uplimit = input(70, "up limit", minval=1, step=1)
downlimit = input(30, "down limit", minval=1, step=1)

//rsi
rsival = rsi(close, rsilen)
rsismooth1 = dema(rsival, 5)
rsismooth2 = dema(rsival, 10)


/// CHAIKIN

fast = input(3, "fast length", minval=1, step=1)
slow = input(14, "slow length", minval=1, step=1)

//chaikin osc

osc   = ema(accdist, fast) - ema(accdist, slow)
oscsmooth1 = dema(osc, 5)
oscsmooth2 = dema(osc, 10)

/// TP & SL

// sl_type    = input("%", options = ["%", "ATR", "Absolute"])

// sl_perc    = input(1,     title = "% SL",        type = input.float)
// atr_length = input(10,    title = "ATR Length")
// atr_mult   = input(1.2,   title = "ATR Mult",    type = input.float)
// sl_absol   = input(1,     title = "Absolute SL", type = input.float)

// // SL values
// sl_val = sl_type == "ATR"      ? atr_mult * atr(atr_length) : 
//          sl_type == "Absolute" ? sl_absol : 
//          close * sl_perc / 100

// // Configure trail stop level with input options (optional)
// longTrailPerc = input(title="Trail Long Loss (%)",
//      type=float, minval=0.0, step=0.1, defval=1) * 0.01

// shortTrailPerc = input(title="Trail Short Loss (%)",
//      type=float, minval=0.0, step=0.1, defval=1) * 0.01

//LONG

// // Determine trail stop loss prices
// longStopPrice = 0.0

// longStopPrice := if (strategy.position_size > 0)
//     stopValue = close * (1 - longTrailPerc)
//     max(stopValue, longStopPrice[1])
// else
//     0

long_tp1_inp = input(2, title='Long Take Profit 1 %', step=0.1)/100
long_tp1_qty = input(25, title="Long Take Profit 1 Qty", step=1)

long_tp2_inp = input(3, title='Long Take Profit 2 %', step=0.1)/100
long_tp2_qty = input(100, title="Long Take Profit 2 Qty", step=1)

long_sl_inp  = input(1, title='Long Stop Loss %', step=0.1)/100

long_take_level_1 = strategy.position_avg_price * (1 + long_tp1_inp)
long_take_level_2 = strategy.position_avg_price * (1 + long_tp2_inp)
long_stop_level   = strategy.position_avg_price * (1 - long_sl_inp)

//SHORT

// // Determine trailing short price
// shortStopPrice = 0.0

// shortStopPrice := if (strategy.position_size < 0)
//     stopValue = close * (1 + shortTrailPerc)
//     min(stopValue, shortStopPrice[1])
// else
//     999999

short_tp1_inp = input(2, title='Short Take Profit 1 %', step=0.1)/100
short_tp1_qty = input(25, title="Short Take Profit 1 Qty", step=1)

short_tp2_inp = input(3, title='Short Take Profit 2 %', step=0.1)/100
short_tp2_qty = input(100, title="Short Take Profit 2 Qty", step=1)

short_sl_inp  = input(1, title='Short Stop Loss %', step=0.1)/100

short_take_level_1 = strategy.position_avg_price * (1 - short_tp1_inp)
short_take_level_2 = strategy.position_avg_price * (1 - short_tp2_inp)
short_stop_level   = strategy.position_avg_price * (1 + short_sl_inp)


/// Strategy

//RSI overbought,oversold
co = crossover(rsival, downlimit)
cu = crossover(rsival, uplimit)

ifdownlimit = rsival < downlimit ? true : co ? true : false
ifuplimit   = rsival > uplimit ? true : cu ? true : false

//CHAININ long,short
ifosclong   = crossover(osc, 0) ? true : oscsmooth1 > oscsmooth1[1] ? true : false
ifoscshort  = crossunder(osc, 0) ? true : oscsmooth1 < oscsmooth1[1]? true : false

//LONG               //rsi - dmi - chaikin strategy long entry
entry_long         = (ifdownlimit and crossunder(down, sig) and ifosclong) or (ifdownlimit and rsismooth1 > rsismooth1[1]) or (crossover(rsival, 50) and ifosclong)
entry_price_long   = valuewhen(entry_long,close,0)

exit_long          = close <= long_stop_level

//SHORT              //rsi - dmi - chaikin strategy short entry
entry_short        = (ifuplimit and crossunder(up, sig) and ifoscshort) or (ifuplimit and rsismooth1 < rsismooth1[1]) or (crossunder(rsival, 50) and ifoscshort)
entry_price_short  = valuewhen(entry_short,close,0)

exit_short         = close >= short_stop_level


///// BACKTEST PERIOD ///////
testStartYear      = input(2018, "Backtest Start Year")
testStartMonth     = input(1, "Backtest Start Month")
testStartDay       = input(1, "Backtest Start Day")
testPeriodStart    = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)

testStopYear       = input(2020, "Backtest Stop Year")
testStopMonth      = input(12, "Backtest Stop Month")
testStopDay        = input(31, "Backtest Stop Day")
testPeriodStop     = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)

testPeriod() =>
    time >= testPeriodStart and time <= testPeriodStop ? true : false

if testPeriod()
    if strategy.position_size == 0 or strategy.position_size > 0
        strategy.entry("long", true, when = entry_long, comment="L_in")
        strategy.exit("TP1", "long", qty_percent=long_tp1_qty, limit=long_take_level_1)
        strategy.exit("TP2", "long", qty_percent=long_tp2_qty, limit=long_take_level_2, comment = 'L_out')
        strategy.close("long", when=exit_long, comment = "L_out")
    
    if strategy.position_size == 0 or strategy.position_size < 0
        strategy.entry("short", false, when = entry_short, comment="S_in")
        strategy.exit("TP1","short", qty_percent=short_tp1_qty, limit=short_take_level_1)
        strategy.exit("TP2","short", qty_percent=short_tp2_qty, limit=short_take_level_2, comment = "S_out")
        strategy.close("short", when=exit_short, comment = "S_out")


// LONG POSITION
plot(strategy.position_size > 0 ? long_take_level_1 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="1st Long Take Profit")
plot(strategy.position_size > 0 ? long_take_level_2 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="2nd Long Take Profit")
plot(strategy.position_size > 0 ? long_stop_level : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Stop Loss")

// SHORT POSITION
plot(strategy.position_size < 0 ? short_take_level_1 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="1st Short Take Profit")
plot(strategy.position_size < 0 ? short_take_level_2 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="2nd Short Take Profit")
plot(strategy.position_size < 0 ? short_stop_level : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Stop Loss")