Paste following codes here: https://cutt.
ly/9fikso
Custom Moving Average Indicator
//@version=5
indicator('Simple Moving Average', shorttitle='SMA', overlay=true)
length = input.int(14, minval=1)
src = close
sma = ta.sma(src, length)
plot(sma, color=color.new(color.blue, 0), linewidth=2)
Custom Moving Average Crossover Strategy
//@version=5
strategy("20 and 50 SMA Crossover Strategy", overlay=true)
// Define input parameters
fast_length = input.int(20, title="Fast MA Length")
slow_length = input.int(50, title="Slow MA Length")
// Calculate simple moving averages
fast_ma = ta.sma(close, fast_length)
slow_ma = ta.sma(close, slow_length)
// Plot moving averages on chart
plot(fast_ma, color=color.green, title="Fast MA")
plot(slow_ma, color=color.red, title="Slow MA")
// Define trading conditions
buy_signal = ta.crossover(fast_ma, slow_ma)
sell_signal = ta.crossunder(fast_ma, slow_ma)
// Execute trades based on trading conditions
if (buy_signal)
strategy.entry("Buy", strategy.long)
if (sell_signal)
strategy.entry("Sell", strategy.