The script uses two distinct timeframes: a higher (daily) timeframe for identifying the trend and a lower (hourly) timeframe for making trades. This combination allows the script to follow the larger trend while timing entries and exits with more precision on a shorter timeframe. Moving Averages Calculation:
higher_ma: The 20-period Simple Moving Average (SMA) calculated based on the daily timeframe. This average gives a sense of the larger trend direction. lower_ma: The 20-period SMA calculated on the hourly (current) timeframe, providing a dynamic level for detecting entry and exit points within the broader trend. Trend Identification:
Bullish Trend: The script determines that a bullish trend is present if the current price is above the daily moving average (higher_ma). Bearish Trend: Similarly, a bearish trend is identified when the current price is below this daily moving average. Trade Signals:
Buy Signal: A buy signal is generated when the price on the hourly chart crosses above the hourly 20-period MA, but only if the higher (daily) timeframe trend is bullish. This ensures that buy trades align with the larger upward trend. Sell Signal: A sell signal is generated when the price on the hourly chart crosses below the hourly 20-period MA, but only if the daily trend is bearish. This ensures that sell trades are consistent with the broader downtrend. Plotting and Visual Cues:
Higher Timeframe MA: The daily 20-period moving average is plotted in red to help visualize the long-term trend. Buy and Sell Signals: Buy signals appear as green labels below the price bars with the text "BUY," while sell signals appear as red labels above the bars with the text "SELL." Background Coloring: The background changes color based on the identified trend for easier trend recognition: Green (with transparency) when the daily trend is bullish. Red (with transparency) when the daily trend is bearish.
진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.