OPEN-SOURCE SCRIPT

Long/Short EMA Premium [NL]

Updated
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.
Release Notes
### Updated Features:

1. Adjustable EMA Parameters:
- Users can now customize the lengths of EMA 1 and EMA 2, while EMA 50 remains fixed.

2. EMA Crossover Detection:
- The script detects both crossovers (EMA 1 crossing above EMA 2) and crossunders (EMA 1 crossing below EMA 2) and marks these events on the chart with a single customizable symbol.

3. Long and Short Signals:
- Long Signal: Generated when EMA 1 crosses above EMA 2 and the closing prices of the next two consecutive candles are above EMA 1.
- Short Signal: Generated when EMA 1 crosses below EMA 2 and the closing prices of the next two consecutive candles are below EMA 1.

4. Stop Signals:
- Stop Long: Triggered after a Long Signal when the entire body of any subsequent candle (from high to low) is below or equal to EMA 1.
- Stop Short: Triggered after a Short Signal when the entire body of any subsequent candle (from high to low) is above or equal to EMA 1.

5. Visibility Toggle for Stop Signals:
- Users can toggle the visibility of "Stop Long" and "Stop Short" signals separately in the settings. This allows users to hide these stop signals without affecting the display of Long and Short signals.

6. Customizable Crossover Symbol:
- Users can select a custom symbol to represent EMA crossovers on the chart.

7. Alerts:
- Alerts have been set up for the following events: EMA 1 crossing EMA 2, Long Signal, Short Signal, Stop Long, and Stop Short. These alerts help users stay informed when these key events occur.

This updated script provides enhanced flexibility and clearer signal management for users, making it a more robust tool for trading strategies based on EMA crossovers.
Release Notes
Here are the additional features added in:

1. Display Price: The last closing price is displayed alongside the Long and Short signals.
2. Adjustable Distance: The distance between the labels and the candles is dynamically adjusted based on the current price.

These features enhance the readability and usability of the indicator by providing additional context and ensuring adequate spacing between the labels and the candlesticks.
Release Notes
The feature to select the color at the crossover symbol allows users to customize the appearance of the symbol based on their preferences. This functionality enables them to visually distinguish between upward and downward crossovers, enhancing clarity and usability.
Release Notes
Feature: Price Display on Stop Long and Stop Short Labels

Description:
This feature enhances the existing Long/Short EMA Premium indicator by adding the current price to the labels for "Stop Long" and "Stop Short" signals. This provides traders with immediate information about the price level at which their stop conditions were triggered, aiding in more precise trade management and analysis.

Functionality:
1. Stop Long Label:
- When a "Stop Long" condition is met, the label not only indicates the stop event but also displays the price at which the stop condition was triggered. This helps traders see exactly where their long position was exited.

2. Stop Short Label:
- Similarly, when a "Stop Short" condition is met, the label shows the stop event along with the price at which the stop condition was activated. This gives traders clear information about the price level at which their short position was exited.

Benefits:
- Enhanced Clarity: By displaying the exact price at which stop conditions are met, traders can more easily track and review their trades.
- Improved Decision Making: Immediate access to stop prices helps traders make faster and more informed decisions regarding their trading strategy.
- Better Trade Analysis: Historical analysis of stop prices can provide insights into market behavior and the effectiveness of the trading strategy.

Use Case:
- Example: If a trader has entered a long position based on the indicator's signal, and later the stop long condition is triggered, the label on the chart will show "Stop Long" along with the price at which this condition was met, providing a clear exit point for review.

By incorporating the current price into the stop labels, this feature aims to provide traders with crucial information directly on their charts, thereby enhancing the overall utility and user experience of the Long/Short EMA Premium indicator.
Release Notes
Updated Pine Script Description with EMA3 and EMA4 Customizable Inputs

This updated version of the Pine Script includes the ability to customize two additional EMAs (EMA3 and EMA4). Users can now specify the lengths for these EMAs, providing more flexibility for analysis.

Features:
1. Customizable EMAs:
- The script allows users to input the lengths for four EMAs: EMA1, EMA2, EMA3, and EMA4.
- Default lengths are set to 9 and 21 for EMA1 and EMA2, with user-defined defaults for EMA3 and EMA4.

2. Trading Signal Generation:
- Long Signal: Triggered when the close price is above EMA1 for two consecutive bars after a bullish crossover (EMA1 crossing above EMA2).
- Short Signal: Triggered when the close price is below EMA1 for two consecutive bars after a bearish crossover (EMA1 crossing below EMA2).

3. Stop Signal Generation:
- Stop Long: Triggered when a long trade is active and the low price of the previous bar is below EMA1 and the high price of the current bar is below EMA1.
- Stop Short: Triggered when a short trade is active and the high price of the previous bar is above EMA1 and the low price of the current bar is above EMA1.

4. Label Display with Price:
- Labels for "Stop Long" and "Stop Short" now include the price at which the stop condition was triggered.

5. User Inputs:
- Options to show or hide stop long and stop short labels.
- Input fields for customizing the lengths of EMA1, EMA2, EMA3, and EMA4.

6. Alerts:
- Configurable alerts for crossovers, long and short signals, and stop conditions.

Feature: Customizable EMA3 and EMA4 with Price Display on Stop Labels

Description:
This updated version of the Long/Short EMA Premium indicator includes two additional customizable EMAs (EMA3 and EMA4). It also enhances the stop labels for long and short positions by including the price at which the stop condition was triggered.

Functionality:
1. Customizable EMAs:
- Allows users to input custom lengths for four EMAs (EMA1, EMA2, EMA3, and EMA4).

2. Enhanced Stop Labels:
- "Stop Long" and "Stop Short" labels now display the price at which the stop condition was triggered, providing clearer information for trade management.

By incorporating these features, the script becomes more versatile and user-friendly, offering more detailed information and greater customization for traders.
Exponential Moving Average (EMA)

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer