Guide
How does the EMA Cross Strategy strategy work ?
The EMA Cross Strategy employs two Exponential Moving Averages (EMAs), a fast EMA and a slow EMA, to define entry points based on their crossovers. This particular script offers customization through input fields where you can define the lengths of the EMA periods, select the trade direction as long, short, or both, and set a specific backtest date range using a date picker.
Calculations are performed to determine the value of the two EMAs at each bar, and the conditions for entering trades are checked within the specified date range. If the fast EMA crosses over the slow EMA, a long trade is initiated, and conversely, if the fast EMA crosses under, a short trade is entered. The script also facilitates exiting positions based on the opposite signal – exiting a long position if a short condition appears and vice versa, provided that the trade direction allowed for such an order.
- Plotting: Visual representation of the EMAs is displayed on the chart with different colors and linewidths.
- Conditions: Before executing trades, the script verifies that the bar’s close falls within the predefined date range and adheres to the selected trade direction.
- Orders: Strategic entry and exit points are set up depending on the long and short signals derived from whether the EMAs cross over or under each other.