Pine Script 未 运行 通过所有点,只有一个入口,没有出口
Pine Script not running through all points , holds one entry and no exit
在下面找到 10 SMA 到 20 SMA 交叉的代码,但不知何故不起作用
//@version=5
strategy(' MA Crossover ', overlay=true)
start = timestamp(2007, 1, 1, 0, 0)
end = timestamp(2022, 03, 21, 0, 0)
ema1 = ta.sma(close, 10)
ema2 = ta.sma(close, 20)
plot(ema1, title='EMA 11', color=color.new(color.green, 0))
plot(ema2, title='EMA 20', color=color.new(color.blue, 0))
LongEntry = ta.crossover(ema1, ema2)
LongExit = ta.crossover(ema2, ema1)
strategy.entry('Long Entry', strategy.long, when=LongEntry)
strategy.close('Long Exit', when=LongExit)
strategy.close()
的第一个参数是id
。
id (series string) A required parameter. The order identifier. It is
possible to close an order by referencing its identifier.
您需要传递您要平仓的交易ID。在你的情况下应该是:
strategy.close('Long Entry', when=LongExit)
在下面找到 10 SMA 到 20 SMA 交叉的代码,但不知何故不起作用
//@version=5
strategy(' MA Crossover ', overlay=true)
start = timestamp(2007, 1, 1, 0, 0)
end = timestamp(2022, 03, 21, 0, 0)
ema1 = ta.sma(close, 10)
ema2 = ta.sma(close, 20)
plot(ema1, title='EMA 11', color=color.new(color.green, 0))
plot(ema2, title='EMA 20', color=color.new(color.blue, 0))
LongEntry = ta.crossover(ema1, ema2)
LongExit = ta.crossover(ema2, ema1)
strategy.entry('Long Entry', strategy.long, when=LongEntry)
strategy.close('Long Exit', when=LongExit)
strategy.close()
的第一个参数是id
。
id (series string) A required parameter. The order identifier. It is possible to close an order by referencing its identifier.
您需要传递您要平仓的交易ID。在你的情况下应该是:
strategy.close('Long Entry', when=LongExit)