TASC 2022.11 Phasor Analysis
"TASC 2022.11 Phasor Analysis" by PineCodersTASC, MPL-2.0. Ported to FloScript by FloSignals; modifications under MPL-2.0. Original: TASC 2022.11 Phasor Analysis (v1.0), read 2026-11-15T18:33:04.326Z; source language v5.
Licence: Mozilla Public License 2.0 (MPL-2.0) — full text. The source is published with it, modifications included, under the same licence.
TASC 2022.11 Phasor Analysis by PineCodersTASC, ported from Pine v5. Pane indicator with 3 plots, 3 levels and 6 inputs.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// (Notice added by FloSignals: the author's source carries none. It was published open-source on 2022-10-13; since 2019-07-26 the platform it was published on has released such a script under MPL-2.0 automatically.)
// TASC Issue: November 2022 - Vol. 40, Issue 12
// Article: Recurring Phase Of Cycle Analysis
// Using Phasor Analysis To Identify Market Trend
// Article By: John Ehlers
// Language: Pine-compatible v5
// Provided By: PineCoders, for tradingview.com
// As representatives of TradingView members, we sincerely
// congratulate John Ehlers on his "100th TASC article". The
// immense amount of contributed technical wisdom that Ehlers
// has graciously provided to so many TASC readers has, is,
// and will continue to be a treasured mathemagical blessing.
//
// WE HONOR & THANK YOU,
// "PineCoders"
// ------------------------------------------------------------------------------------------------
// Original author: PineCodersTASC
// Original title: TASC 2022.11 Phasor Analysis
// Licence: MPL-2.0 (the notice above was added by FloSignals; the original carries none)
// Pine version: 5
// Fetched: 2026-11-15
// Ported to FloScript by FloSignals; modifications under MPL-2.0.
// Converter: @flosignals/floscript 0.1.0, strict mode, score 100/100
// ------------------------------------------------------------------------------------------------
//@floscript=1
//@version=5
indicator(title='TASC 2022.11 Phasor Analysis', overlay=false)
Phasor(float Signal = close, int Period = 28) =>
var float angFreq = 2.0 * math.pi / Period
float Sx = 0.0
float Sxx = 0.0
float rSxy = 0.0
float iSxy = 0.0
float rSyy = 0.0
float iSyy = 0.0
float rSy = 0.0
float iSy = 0.0
for i = 0 to Period - 1
float tmp = angFreq * i
float X = Signal[i]
float Yr = math.cos(tmp)
float Yi = -math.sin(tmp)
Sx += X
Sxx += X * X
rSxy += X * Yr
iSxy += X * Yi
rSyy += Yr * Yr
iSyy += Yi * Yi
rSy += Yr
iSy += Yi
float varianceX = Period * Sxx - Sx * Sx
float varianceYr = Period * rSyy - rSy * rSy
float varianceYi = Period * iSyy - iSy * iSy
float covarianceXYr = Period * rSxy - Sx * rSy
float covarianceXYi = Period * iSxy - Sx * iSy
float rDenominator = varianceX * varianceYr
float iDenominator = varianceX * varianceYi
float real = nz(covarianceXYr / math.sqrt(rDenominator))
float imag = nz(covarianceXYi / math.sqrt(iDenominator))
float angle = 0.0
float prevAngle = nz(angle[1])
angle := if real == 0.0
prevAngle
else
90.0 - math.todegrees(math.atan(imag / real))
if real < 0.0
angle -= 180.0
float temp = math.abs(prevAngle) - math.abs(angle - 360.0)
if -90.0 > prevAngle and temp < angle - prevAngle and 90.0 < angle
angle -= 360.0
if angle < prevAngle and (angle > -135.0 and prevAngle < 135 or angle < -90.0 and prevAngle < -90.0)
angle := prevAngle
angle
Analysis(float Angle) =>
float deltaAngle = Angle - nz(Angle[1])
if deltaAngle <= 0.0
deltaAngle := nz(deltaAngle[1])
float derivedPeriod = if deltaAngle == 0.0
0.0
else
math.min(60.0, 360.0 / deltaAngle)
int state = 0
if deltaAngle <= 6.0
state := Angle > -90.0 and Angle < 90.0 ? -1 : 1
[derivedPeriod, state]
string grp1 = 'Angle Parameters'
string grp2 = 'Indicator Choices'
Signal = input.source(close, 'Source', group=grp1)
Period = input.int(28, 'Period', group=grp1, minval=5)
ThresholdUpper = input.int(90, 'Upper Threshold', 1, 179)
ThresholdLower = input.int(-90, 'Lower Threshold', -179, -1)
Indy = input.string('Angle', 'Indicator Mode', group=grp2, options=['Angle', 'Period', 'State'])
ChangeRate = input.int(6, 'Change Rate (degrees)', minval=2, tooltip='Intended for use with the State mode', group=grp2)
float phAngle = Phasor(Signal, Period)
[dPeriod, Trend] = Analysis(phAngle)
// Phasor Color Wizardry
var seventeenTwelfths = 17.0 / 12.0
var seventeenSixths = 17.0 / 6.0
colorValue = phAngle * seventeenSixths
colorAngle = color.rgb(phAngle > 90.0 ? 255 : phAngle < -90.0 ? 0.0 : seventeenTwelfths * phAngle + 127.5, phAngle < 0.0 ? (phAngle > -90.0 ? 255 : colorValue + 510) : phAngle > 90.0 ? 0.0 : 255 - colorValue, phAngle > 0.0 ? (phAngle < 90.0 ? 0.0 : colorValue - 255) : phAngle < -90.0 ? 255 : -colorValue)
plot(Indy == 'Angle' ? phAngle : na, 'Angle', colorAngle, 3)
plot(Indy == 'Period' ? dPeriod : na, 'DerivPeriod', #FFFF00)
plot(Indy == 'State' ? Trend : na, 'TrendState', linewidth=2, color=Trend > 0 ? #00FF00 : Trend < 0 ? #FF0000 : #888800)
hline(0, 'ZeroLine', #FFFFFF)
hline(Indy == 'Angle' ? ThresholdUpper : na, 'Upper Threshold', #FF00FF, hline.style_dotted, 2)
hline(Indy == 'Angle' ? ThresholdLower : na, 'Lower Threshold', #0055FF, hline.style_dotted, 2)
This file is under the Mozilla Public License 2.0; it is a port of the original by PineCodersTASC, with the original licence header kept and the changes made for FloScript noted in the file.
- v1
Library refresh 2026-11-15
Disclaimer. Scripts are written and published by members, or ported by FloSignals from open-source originals, and are their authors' own work and opinion. FloSignals does not review them for correctness and nothing in a script is financial advice or a recommendation to buy or sell anything — read the Risk Disclaimer. Posting here is under the Community Rules; a script that is not the poster's to post can be reported as the Copyright & Takedowns page says.

Comments (0)
No comments yet. Members can leave one.