1. EMA Calculation:
- The script calculates three Exponential Moving Averages (EMAs): EMA 1, EMA 2, and EMA 50.
- The lengths of EMA 1 and EMA 2 are customizable by the user inputs `ema1Length` and `ema2Length`, respectively.
- EMA 50 is fixed with a length of 50.
2. EMA Crossover Detection:
- The script detects crossovers between EMA 1 and EMA 2 using the `ta.crossover()` and `ta.crossunder()` functions, storing the crossover events in the `cross` variable.
3. Crossover Symbol:
- A triangle-up shape is plotted below the bars when there is a crossover between EMA 1 and EMA 2. This symbol visually indicates the crossover points.
4. Trade Signals:
- Long and short signals are generated based on the crossover events and the relationship between the closing price and EMA 1.
- For a long signal, EMA 1 must cross above EMA 2, and both the current and previous closing prices must be above EMA 1.
- For a short signal, EMA 1 must cross below EMA 2, and both the current and previous closing prices must be below EMA 1.
5. Stop Conditions:
- Stop conditions are used to exit long or short trades.
- If in a long trade, the script checks if the low of the previous candle crossed below EMA 1 and the high of the current candle is below EMA 1. If true, it triggers the "Stop Long" condition.
- If in a short trade, the script checks if the high of the previous candle crossed above EMA 1 and the low of the current candle is above EMA 1. If true, it triggers the "Stop Short" condition.
6. Plotting:
- The script plots EMA 1, EMA 2, and EMA 50 on the chart to visualize their movements.
7. Alerts:
- The script generates alerts for EMA crossovers, long and short signals, as well as stop long and stop short conditions, allowing traders to receive notifications when these events occur.
Overall, the script provides a comprehensive EMA crossover strategy with customizable parameters and clear trade signals and exit conditions.