OPEN-SOURCE SCRIPT

skalping tool

Sure! To create a custom trading indicator based on the strategy you mentioned, where you buy when the EMA (Exponential Moving Average) 9 crosses above EMA 21 and sell when it crosses below, here's a simple script that can be used in Pine Script (for TradingView).

```pinescript
//version=5
indicator("EMA 9 and EMA 21 Crossover", overlay=true)

// Define the EMAs
ema9 = ta.ema(close, 9)
ema21 = ta.ema(close, 21)

// Plot the EMAs
plot(ema9, color=color.blue, linewidth=2, title="EMA 9")
plot(ema21, color=color.orange, linewidth=2, title="EMA 21")

// Buy condition: EMA 9 crosses above EMA 21
buyCondition = ta.crossover(ema9, ema21)

// Sell condition: EMA 9 crosses below EMA 21
sellCondition = ta.crossunder(ema9, ema21)

// Plot buy and sell signals
plotshape(series=buyCondition, color=color.green, style=shape.labelup, location=location.belowbar, text="BUY", textcolor=color.white, size=size.small)
plotshape(series=sellCondition, color=color.red, style=shape.labeldown, location=location.abovebar, text="SELL", textcolor=color.white, size=size.small)

// Generate alerts
alertcondition(buyCondition, title="Buy Alert", message="EMA 9 crossed above EMA 21")
alertcondition(sellCondition, title="Sell Alert", message="EMA 9 crossed below EMA 21")
```

### Explanation:
1. **EMA 9 and EMA 21**: This script calculates the Exponential Moving Averages for the periods 9 and 21.
2. **Buy Signal**: The script will detect when the EMA 9 crosses above the EMA 21 and mark it with a green "BUY" label below the price bar.
3. **Sell Signal**: The script will detect when the EMA 9 crosses below the EMA 21 and mark it with a red "SELL" label above the price bar.
4. **Alert Conditions**: Alerts are also set up for when these crossovers happen, so you can get notified.

You can copy this script into TradingView's Pine Script editor, and it will display the signals on your chart.

Let me know if you'd like any adjustments!

免責聲明