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.
Theo tinh thần TradingView thực sự, tác giả của tập lệnh này đã xuất bản dưới dạng nguồn mở để các nhà giao dịch có thể hiểu và xác minh. Chúc mừng tác giả! Bạn có thể sử dụng miễn phí. Tuy nhiên, bạn cần sử dụng lại mã này theo Quy tắc nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.