TradingView
jacobnie2008
16 Kas 2016 06:00

Hilbert Sine Wave Support and Resistance 

S&P 500 IndexTVC

Açıklama

Support and Resistance plotted to match John Ehler's Hilbert Sine Wave
Yorumlar
sal157011
Can you explain the Drawing Lines? why (DCPeriod/8) and not straight DCPeriod ?
Dan_Micsa
@sal157011, I am looking for an explanation too
SKYNETAITR2
//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org/MPL/2.0/
// © SKYNETAITR2
indicator('Hilbert Sine Wave Support and Resistance', 'Sine Wave SR', overlay=true)
Price = close
alpha = 0.07
Smooth = (Price + 2 * Price[1] + 2 * Price[2] + Price[3]) / 6
Cycle = 0.
InstPeriod = 0.
Value1 = 0.
DCPeriod = 0.
drawingsupport = 0.
currdotvalue = 0.
Cycle := (1 - .5 * alpha) * (1 - .5 * alpha) * (Smooth - 2 * Smooth[1] + Smooth[2]) + 2 * (1 - alpha) * nz(Cycle[1]) - (1 - alpha) * (1 - alpha) * nz(Cycle[2])
Q1 = (.0962 * Cycle + .5769 * Cycle[2] - .5769 * Cycle[4] - .0962 * Cycle[6]) * (.5 + .08 * nz(InstPeriod[1]))
I1 = Cycle[3]
DeltaPhase = Q1 != 0 and Q1[1] != 0 ? (I1 / Q1 - I1[1] / Q1[1]) / (1 + I1 * I1[1] / (Q1 * Q1[1])) : na
DeltaPhase := DeltaPhase < 0.1 ? 0.1 : DeltaPhase
DeltaPhase := DeltaPhase > 1.1 ? 1.1 : DeltaPhase
MedianDelta = ta.percentile_nearest_rank(DeltaPhase, 5, 50)
DC = MedianDelta == 0 ? 15 : 6.28318 / MedianDelta + 0.5
InstPeriod := .33 * DC + .67 * nz(InstPeriod[1])
Value1 := .15 * InstPeriod + .85 * nz(Value1[1])
DCPeriod := math.floor(Value1)
RealPart = 0.
ImagPart = 0.
for count = 0 to DCPeriod - 1 by 1
RealPart += math.sin(6.28318 * count / DCPeriod) * Cycle[count]
ImagPart += math.cos(6.28318 * count / DCPeriod) * Cycle[count]
ImagPart
DCPhase = math.abs(ImagPart) > 0.001 ? math.atan(RealPart / ImagPart) : na
DCPhase := math.abs(ImagPart) <= 0.001 ? 1.572963 * math.sign(RealPart) : DCPhase
DCPhase += 1.572963
DCPhase := ImagPart < 0 ? DCPhase + 3.1415926 : DCPhase
DCPhase := DCPhase > 5.49778705 ? DCPhase - 6.28318 : DCPhase
Sine = math.sin(DCPhase)
LeadSine = math.sin(DCPhase + 0.78539815)

// Drawing Lines:
drawingsupport := nz(drawingsupport[1])
currdotvalue := nz(currdotvalue[1])
if LeadSine[math.floor(DCPeriod / 8)] <= Sine[math.floor(DCPeriod / 8)] and drawingsupport == 1
currdotvalue := high * 1.01
drawingsupport := 0
drawingsupport
if LeadSine[math.floor(DCPeriod / 8)] > Sine[math.floor(DCPeriod / 8)] and drawingsupport == 0
currdotvalue := low * 0.99
drawingsupport := 1
drawingsupport
currdotcolor = drawingsupport == 0 ? color.green : color.red
plot(currdotvalue, style=plot.style_circles, linewidth=2, color=currdotcolor)

Version 5 converted and fixed some issues.
pacifiedLlama80887
@SKYNETAITR2,
Hi is it possible if you can publish this as version 5, i tried using this script but it only shows value as 0. Reason i want it is so that i can export it as a lib and find out the values for many different symbols.
SKYNETAITR2
@pacifiedLlama80887, All source code of script is yours. Use it as you wish
cixcic4
prashu1
some error is coming while compliaton Script could not be translated from: |B|DeltaPhase := iff(DeltaPhase <
sal157011
@prashu1,
The indicator works fine with me, but I will not use it for it's a bad try of the Better Sine Wave. See emini-watch.com/
Did you put //@version=2 on the first line? It's a must, see below an excerpt of the tutorial manual. We should avoid the use of the operator ":=" whenever possible. This was translated from another language and it's easier to do it this way using just one mutable variable DeltaPhase but in the future there will be problems using mutable variables within functions.

Variable Assignment

Mutable variable is such a variable which can be given a new value.


The operator ‘:=’ must be used to give a value to a variable. To use this operator, a special attribute must be used in the first line of a code: //@version=2. This attribute identifies the version of Pine Script. Mutable variables were introduced in version 2.


A variable must be declared before you can set a value for it (declaration of variables has been described above).


Type of a variable is identified on the declaration step. A variable can be given a value of expression only if both the expression and the variable belong to the same type, otherwise it will give you a compilation error.


Variable assignment example:
//@version=2
study("My Script")
price = close
if hl2 > price
price := hl2
plot(price)
Dan_Micsa
For me it does not work, what I mean is that everything is OK until when it comes the last part, with currdotvalue and drawingsupport. Variable drawingsupport is always changing to 1.0 and stays like that all the time, so, from 400 closes, I get the answer for just one candle, like candle with number 365.
KJCheon
Hi, what does "Study Error: Index can't be a negative value(-1)" mean? Where or how do I have to modify in the code?
Daha Fazla