OPEN-SOURCE SCRIPT

Consecutive Bars Above/Below EMA Buy the Dip Strategy

█ STRATEGY DESCRIPTION
The "Consecutive Bars Above/Below EMA Buy the Dip Strategy" is a mean-reversion strategy designed to identify potential buying opportunities when the price dips below a moving average for a specified number of consecutive bars. It enters a long position when the dip condition is met and exits when the price shows strength by exceeding the previous bar's high. This strategy is suitable for use on various timeframes.

█ WHAT IS THE MOVING AVERAGE?
The strategy uses either a Simple Moving Average (SMA) or an Exponential Moving Average (EMA) as a reference for identifying dips. The type and length of the moving average can be customized in the settings.

█ SIGNAL GENERATION
1. LONG ENTRY
A Buy Signal is triggered when:
  • The close price is below the selected moving average for a specified number of consecutive bars (`consecutiveBarsTreshold`).
  • The signal occurs within the specified time window (between `Start Time` and `End Time`).


2. EXIT CONDITION
  • A Sell Signal is generated when the current closing price exceeds the high of the previous bar (`close > high[1]`). This indicates that the price has shown strength, potentially confirming the reversal and prompting the strategy to exit the position.


█ ADDITIONAL SETTINGS
  • Consecutive Bars Threshold: The number of consecutive bars the price must remain below the moving average to trigger a Buy Signal. Default is 3.
  • MA Type: The type of moving average used (SMA or EMA). Default is SMA.
  • MA Length: The length of the moving average. Default is 5.
  • Start Time and End Time: The time window during which the strategy is allowed to execute trades.


█ PERFORMANCE OVERVIEW
  • This strategy is designed for mean-reverting markets and performs best when the price frequently oscillates around the moving average.
  • It is sensitive to the number of consecutive bars below the moving average, which helps to identify potential dips.
  • Backtesting results should be analysed to optimize the Consecutive Bars Threshold, MA Type, and MA Length for specific instruments.
Breadth IndicatorsChart patternsCyclesdaytradingIndicesmeanreversionmovingavarageQQQreversalSPDR S&P 500 ETF (SPY) swingtrading

Script open-source

In pieno spirito TradingView, l'autore di questo script lo ha pubblicato open-source, in modo che i trader possano comprenderlo e verificarlo. Un saluto all'autore! È possibile utilizzarlo gratuitamente, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?

Declinazione di responsabilità