[英]Can someone let me know how would I implement this into my code (Im very new to this)
[英]Can someone help me troubleshoot my trading startegy i wrote in pinescript very new to this
我正在使用以下代码
**
//@version=2
// Define variables
fastPeriod = 12
slowPeriod = 26
// Calculate the fast and slow moving averages
fastMa = sma(close, fastPeriod)
slowMa = sma(close, slowPeriod)
// Enter a long position when the fast MA crosses above the slow MA
if (fastMa > slowMa)
strategy.entry("Long", strategy.long)
plot(bar_index, high, "Buy", "arrowup", color=green, offset=-5)
// Enter a short position when the fast MA crosses below the slow MA
if (fastMa < slowMa)
strategy.entry("Short", strategy.short)
plot(bar_index, low, "Sell", "arrowdown", color=red, offset=-5)
// Close the position when the opposite condition is met
if (fastMa < slowMa)
strategy.close("Long")
plot(bar_index, low, "Sell", "arrowdown", color=red, offset=-5)
if (fastMa > slowMa)
strategy.close("Short")
plot(bar_index, high, "Buy", "arrowup", color=green, offset=-5)
**
并面临以下错误消息编译错误。 第 11 行:不匹配的输入“strategy.entry”期望“没有行继续的行结束”
我希望能够编译脚本并在我的图表上看到它。 谢谢!
//@version=2
// Define variables
fastPeriod = 12
slowPeriod = 26
// Calculate the fast and slow moving averages
fastMa = sma(close, fastPeriod)
slowMa = sma(close, slowPeriod)
// Enter a long position when the fast MA crosses above the slow MA
if (fastMa > slowMa)
strategy.entry("Long", strategy.long)
plot(bar_index, high, "Buy", "arrowup", color=green, offset=-5)
// Enter a short position when the fast MA crosses below the slow MA
if (fastMa < slowMa)
strategy.entry("Short", strategy.short)
plot(bar_index, low, "Sell", "arrowdown", color=red, offset=-5)
// Close the position when the opposite condition is met
if (fastMa < slowMa)
strategy.close("Long")
plot(bar_index, low, "Sell", "arrowdown", color=red, offset=-5)
if (fastMa > slowMa)
strategy.close("Short")
plot(bar_index, high, "Buy", "arrowup", color=green, offset=-5)
strategy.entry 和 plot 行之前的间距已关闭。 我删除并添加了 4 个空格键
它修复了以下与 bar_index 相关的新错误
Compilation error. Line 13: Undeclared identifier 'bar_index';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.