> For the complete documentation index, see [llms.txt](https://docs.pinescriptstrategy.com/tools/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pinescriptstrategy.com/tools/setup-instructions/generate-trading-signals/presets/2-ma-cross.md).

# 2 MA Cross

<figure><img src="/files/cGqvkvjYVQ9Kx4ntrdj3" alt=""><figcaption></figcaption></figure>

```pine_v5
//@version=5
indicator(title="[preset] 2 MA Cross", overlay=true, timeframe="", timeframe_gaps=true)
shortlen = input.int(9, "Short MA Length", minval=1)
longlen = input.int(21, "Long MA Length", minval=1)
short = ta.sma(close, shortlen)
long = ta.sma(close, longlen)
plot(short, color = #FF6D00, display = display.pane)
plot(long, color = #43A047, display = display.pane)
buy = ta.crossover(short, long)
sell = ta.crossunder(short, long)
signal = buy ? 1 : sell ? -1 : na
plotshape(buy, '', shape.labelup, location.belowbar, color.green, 0, 'BUY', color.black, display = display.pane)
plotshape(sell, '', shape.labeldown, location.abovebar, color.red, 0, 'SELL', color.black, display = display.pane)
plot(signal, 'Signal', display = display.data_window)
```
