TVC:GOLD   CFDs on Gold (US$ / OZ)
```
//@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)
```

Related Ideas

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.