TVC:GOLD   黄金差价合约(美元/盎司)
```
//@version=4
strategy("Moving Average Crossover")

// Define moving averages
fastMA = input(title="Fast MA Period", type=input.integer, defval=10)
slowMA = input(title="Slow MA Period", type=input.integer, defval=50)

// Calculate moving averages
fast = sma(close, fastMA)
slow = sma(close, slowMA)

// Set up Buy and Sell conditions
buySignal = crossover(fast, slow)
sellSignal = crossunder(fast, slow)

// Set up stop loss
stopLoss = strategy.position_avg_price * 0.5
takeProfit = strategy.position_avg_price * 2

// Enter Buy or Sell orders
if buySignal
strategy.entry("Buy", strategy.long)
strategy.exit("Stop Loss", "Buy", stop=stopLoss, limit=takeProfit)

if sellSignal
strategy.entry("Sell", strategy.short)
strategy.exit("Stop Loss", "Sell", stop=stopLoss, limit=takeProfit)

// Plot Buy and Sell signals
plotshape(buySignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, transp=0)
plotshape(sellSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, transp=0)
```

相关观点

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。