繁体   English   中英

Pinescript - 简单的买卖策略未执行

[英]Pinescript - Simple Buy Sell Strategy not executing

嗨,我正在尝试为 TradingView 编写我的第一个 PineScript 代码。 它是一种 SMA 交叉买卖策略。 代码似乎运行没有问题,但没有找到交易。 任何反馈将不胜感激🙏

''''
//@version=5
strategy("My Strategy", overlay=true)

// Create Indicator's
shortSMA = ta.sma(close, 10)
longSMA = ta.sma(close, 30)


// Specify crossover conditions
longCondition = ta.crossover(shortSMA, longSMA)
sellCondition = ta.crossunder(shortSMA, longSMA)

// Execute trade if condition is True
if (longCondition)
    strategy.entry("long", strategy.long)
    strategy.close("long", when = sellCondition)


// Plot Moving Average's to chart
plot(shortSMA)
plot(longSMA, color=color.black)

'''

如果longConditionsellCondition都是true ,则您正在调用您的strategy.close()

使用另一个 if 检查来平仓。

if (longCondition)
    strategy.entry("long", strategy.long)

if (sellCondition)
    strategy.close("long")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM