MA Cross Strategy
Pine Script strategy by Chart GT · Published
Long when the fast SMA crosses above the slow SMA; flat when it crosses back.
Tags: strategy, trend, moving-average, crossover
Source code
//@version=6
// @name MA Cross Strategy
// @description Long when the fast SMA crosses above the slow SMA; flat when it crosses back.
// @tags strategy,trend,moving-average,crossover
strategy("MA Cross Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.01)
fastLen = input.int(10, "Fast SMA", minval=1)
slowLen = input.int(30, "Slow SMA", minval=1)
fast = ta.sma(close, fastLen)
slow = ta.sma(close, slowLen)
plot(fast, "Fast SMA", color=color.teal)
plot(slow, "Slow SMA", color=color.orange)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("Long")
License: MPL-2.0
Open the chart to add it, or browse more community scripts.