This Pine Script code builds an indicator called EMA Crossover with Historical Price Projection that combines two components:
EMA Crossover Strategy:
EMA 9 and EMA 21: The script calculates two exponential moving averages (EMAs) using the ta.ema() function. The crossover between these EMAs generates buy/sell signals. A bullish crossover (when EMA 9 crosses above EMA 21) signals a buy. A bearish crossover (when EMA 9 crosses below EMA 21) signals a sell. These buy/sell signals are visualized on the chart using the plotshape() function with green and red symbols. Historical Price Projection:
The code projects future prices based on historical price trends. It takes into account growth factors (user-defined drift percentages) to estimate future prices. Projection Line: It draws a projection line from the anchor point (set by the user) using historical data. The drift factor allows you to control the projection's slope. Forecasting Area: It shows an optional area around the projected price, adjusting the width with a user-defined growth factor for the forecast's uncertainty. Key Sections: Inputs:
User-defined inputs for controlling the growth factor, line styles, and forecasting area settings. An anchoring point is provided to determine from which bar the price projection should start. EMA Crossover:
The crossover conditions for EMA 9 and EMA 21 are defined, and the script generates buy and sell signals at those crossovers. Historical Price Projection:
It stores the percentage changes between bars in barDeltaPercents. It projects the future price based on these percentages and the user-defined drift factor. The projected price is visualized using polyline.new(), and a shaded area can be added to show the range of price possibilities. Execution Logic:
The script runs when the current time is greater than the anchor point. If the anchor point is too far back in history, it gives a warning via the showInfoPanel function. As new bars are confirmed, the drift is calculated, and the projection line and area are updated based on historical price changes. Overall Flow: It gathers price data up to 500 bars from the anchor point. Based on the historical price trend, it forecasts the future price with a projection line and an optional shaded area. The crossover logic for EMA 9 and 21 provides actionable signals on when to buy or sell.
Siguiendo fielmente el espíritu de TradingView, el autor de este script lo ha publicado en código abierto, permitiendo que otros traders puedan entenderlo y verificarlo. ¡Olé por el autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la reutilización de este código en la publicación se rige por las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.