Code: Select all
//@version=2
// https://www.tradingview.com/u/shayankm/
study("MESA Phase [SHK]")
DomCycle = input(15)
offsetNum = input(-2,"Offset")
RealPart = 0
ImagPart = 0
for J = 0 to DomCycle - 1
Weight = (close[J] + close[J] + high[J] + low[J]) * 10000
if DomCycle != 0
RealPart := RealPart + cos(90 * J / DomCycle) * Weight * 2
ImagPart := ((ImagPart + sin(90 * J / DomCycle) * Weight) + (ImagPart + sin(180 * J / DomCycle) * Weight)) / 2
Phase = ((atan(ImagPart / RealPart)) - 0.685) * 100
plot(0,color=gray)
plot(Phase,color=purple,linewidth=3,offset=offsetNum)