This code represents a TradingView strategy that uses Fibonacci levels in conjunction with high/low price criteria over specified lookback periods to determine buy (long) and sell (short) conditions. Below is an explanation of each main part of the code:
Explanation of Key Sections User Inputs for Higher Time Frame and Candle Settings
Users can select a higher time frame (timeframe) for analysis and specify whether to use the "Current" or "Last" higher time frame (HTF) candle for calculating Fibonacci levels. The currentlast setting allows flexibility between using real-time or the most recent closed higher time frame candle. Lookback Periods for High/Low Criteria
Two lookback periods, lowestLookback and highestLookback, allow users to set the number of bars to consider when finding the lowest and highest prices, respectively. This determines the criteria for entering trades based on how recent highs or lows compare to current prices. Fibonacci Levels Configuration
Fibonacci levels (0%, 23.6%, 38.2%, 50%, 61.8%, 78.6%, and 100%) are configurable. These are used to calculate price levels between the high and low of the higher time frame candle. Each level represents a retracement or extension relative to the high/low range of the HTF candle, providing important price levels for decision-making. HTF Candle Calculation
HTF candle data is calculated based on the higher time frame selected by the user, using the newbar check to reset htfhigh, htflow, and htfopen values. The values are updated with each new HTF bar or as prices move within the same HTF bar to track the highest high and lowest low accurately. Set Fibonacci Levels Array
Using the calculated HTF candle's high, low, and open, the Fibonacci levels are computed by interpolating these values according to the user-defined Fibonacci levels. A fibLevels array stores these computed values. Plotting Fibonacci Levels
Each Fibonacci level is plotted on the chart with a different color, providing visual indicators for potential support/resistance levels. High/Low Price Criteria Calculation
The lowest and highest prices over the specified lookback periods (lowestLookback and highestLookback) are calculated and plotted on the chart. These serve as dynamic levels to trigger long or short entries. Trade Signal Conditions
longCondition: A long (buy) signal is generated when the price crosses above both the lowest price criteria and the 50% Fibonacci level. shortCondition: A short (sell) signal is generated when the price crosses below both the highest price criteria and the 50% Fibonacci level. Executing Trades
Based on the longCondition and shortCondition, trades are entered with the strategy.entry() function, using the labels "Long" and "Short" for tracking on the chart. Strategy Use This strategy allows traders to utilize Fibonacci retracement levels and recent highs/lows to identify trend continuation or reversal points, potentially providing entry points aligned with larger market structure. Adjusting the lowestLookback and highestLookback along with Fibonacci levels enables a customizable approach to suit different trading styles and market conditions.
진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.