PineCodersTASC

TASC 2022.11 Phasor Analysis

█ OVERVIEW

TASC's November 2022 edition Traders' Tips includes an article by John ​Ehlers titled "Recurring Phase Of Cycle Analysis". This is the code that implements the ​phasor analysis indicator presented in this publication.


█ CONCEPTS

The article explores the use of phasor analysis to identify market trends.

An ordinary rotating phasor diagram is a two-dimensional vector, anchored to the origin, whose rotation rate corresponds to the cycle period in the price data stream. Similarly, Ehlers' phasor is a representation of angular phase rotation along the course of time. Its angle reflects the current phase of the cycle. Angles -180, -90, +90 and +180 degrees correspond to the beginning, valley, peak and end of the cycle, respectively.

If the observed cycle is very long, the market can be considered trending. In his article, John ​Ehlers defined trending behavior to occur when the derived instantaneous cycle period value is greater that 60 bars. The author also introduced guidelines for long and short entries in a trending state. Depending on the tuning of the indicator period input, a long entry position may occur when the phasor angle is around the approximate vicinity of −90 degrees, while a short entry position may occur when the phasor angle will be around the approximate vicinity of +90 degrees. Applying these definitive guidelines, the author proposed a state variable that is indicated by +1 for a trending long position, 0 for cycling, and −1 for a trending short position (or out).

The phasor angle, the cycle period, and the state variable are made available with three selectable display modes provided for this TradingView indicator.

█ CALCULATIONS

The calculations are carried out as follows.

First, the price data stream is correlated with cosine and sine of a fixed cycle period. This produces two new data streams that correspond to the projections of the frequency domain phasor diagram to the horizontal (so-called real) and vertical (so-called imaginary) axis respectively. The wavelength of the cycle period input should be set for the midrange vicinities of the phasor to coincide with the peaks and valleys of the charted price data.

Secondly, the phase angle of the phasor is easily computed as the arctangent of the ratio of the imaginary component to the real component. The difference between the current phasor values and its last is then employed to calculate a derived instantaneous period and market state. This computation is then repeated successively for each individual bar over the entire duration of the data set.

Tools and ideas for all Pine coders: www.tradingview.com/u/PineCoders/
Pine news broadcasts: t.me/PineCodersSquawkBox or twitter.com/PineCoders
TASC: traders.com/
開源腳本

本著真正的TradingView精神,該腳本的作者將其開源發布,以便交易者可以理解和驗證它。為作者喝彩吧!您可以免費使用它,但在出版物中重複使用此代碼受網站規則的約束。 您可以收藏它以在圖表上使用。

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想在圖表上使用此腳本?