Code:
# Wolf Waves
# Mobius
# V01.05.22.2018
# Nube added Bulkowski's 1-2-3 Trend Change
# To scan for reversal, look for reversal plots equal to 1
# 7.18.18
# v 0.2 shows bubbles labeling each point
# 7.27.18
# 4.4.2020
# Version 0.3 technomentor - Fixed the 3 lines of code that needed comment symbol so it doesn't throw error codes when loaded in TOS
# Modified 09/28/2021 for short time frame.
# User Inputs
input n = 10;
# Internal Script Reference
script LinePlot {
input BarID = 0;
input Value = 0;
input BarOrigin = 0;
def ThisBar = HighestAll(BarOrigin);
def ValueLine = if BarOrigin == ThisBar
then Value
else Double.NaN;
plot P = if ThisBar - BarID <= BarOrigin
then HighestAll(ValueLine)
else Double.NaN;
}
# Variables
def h = high;
def l = low;
def c = close;
def na = Double.NaN;
def bn = BarNumber();
# R1
def hh = fold i = 1 to n + 1
with p = 1
while p
do h > GetValue(h, -i);
def PivotH = if (bn > n and
h == Highest(h, n) and
hh)
then h
else na;
def PHValue = if !IsNaN(PivotH)
then PivotH
else PHValue[1];
def PHBarOrigin = if !IsNaN(PivotH)
then bn
else PHBarOrigin[1];
def PHBarID = bn - PHBarOrigin;
# R2
def R2PHValue = if PHBarOrigin != PHBarOrigin[1]
then PHValue[1]
else R2PHValue[1];
def R2PHBarOrigin = if PHBarOrigin != PHBarOrigin[1]
then PHBarOrigin[1]
else R2PHBarOrigin[1];
def R2PHBarID = bn - R2PHBarOrigin;
# S1
def ll = fold j = 1 to n + 1
with q = 1
while q
do l < GetValue(l, -j);
def PivotL = if (bn > n and
l == Lowest(l, n) and
ll)
then l
else na;
def PLValue = if !IsNaN(PivotL)
then PivotL
else PLValue[1];
def PLBarOrigin = if !IsNaN(PivotL)
then bn
else PLBarOrigin[1];
def PLBarID = bn - PLBarOrigin;
# S2
def S2PLValue = if PLBarOrigin != PLBarOrigin[1]
then PLValue[1]
else S2PLValue[1];
def S2PLBarOrigin = if PLBarOrigin != PLBarOrigin[1]
then PLBarOrigin[1]
else S2PLBarOrigin[1];
def S2PLBarID = bn - S2PLBarOrigin;
# Plots
def R1 = LinePlot(BarID = PHBarID,
Value = PHValue,
BarOrigin = PHBarOrigin);
#R1.SetDefaultColor(Color.GREEN);
AddChartBubble(bn == HighestAll(PHBarOrigin), PHValue, "R1", Color.GREEN, 1);
def R2 = LinePlot(BarID = R2PHBarID,
Value = R2PHValue,
BarOrigin = R2PHBarOrigin);
#R2.SetDefaultColor(Color.GREEN);
AddChartBubble(bn == HighestAll(R2PHBarOrigin), PHValue, "R2", Color.GREEN, 1);
def S1 = LinePlot(BarID = PLBarID,
Value = PLValue,
BarOrigin = PLBarOrigin);
#S1.SetDefaultColor(Color.RED);
AddChartBubble(bn == HighestAll(PLBarOrigin), PLValue, "S1", Color.RED, 0);
def S2 = LinePlot(BarID = S2PLBarID,
Value = S2PLValue,
BarOrigin = S2PLBarOrigin);
#S2.SetDefaultColor(Color.RED);
AddChartBubble(bn == HighestAll(S2PLBarOrigin), PLValue, "S2", Color.RED, 0);
plot ResistanceLineR2R1 = if bn == HighestAll(R2PHBarOrigin)
then R2
else if bn == HighestAll(PHBarOrigin)
then R1
else na;
ResistanceLineR2R1.EnableApproximation();
ResistanceLineR2R1.SetDefaultColor(Color.Gray);
ResistanceLineR2R1.SetLineWeight(1);
ResistanceLineR2R1.SetStyle(Curve.LONG_DASH);
def slopeR2R1 = (R2 - R1) /
(HighestAll(R2PHBarOrigin) - HighestAll(PHBarOrigin));
plot ExtLineR2R1 = if bn >= HighestAll(PHBarOrigin)
then (bn - HighestAll(PHBarOrigin)) * slopeR2R1 + R1
else na;
ExtLineR2R1.EnableApproximation();
ExtLineR2R1.SetDefaultColor(Color.Gray);
ExtLineR2R1.SetLineWeight(1);
ExtLineR2R1.SetStyle(Curve.LONG_DASH);
plot SupportLineS2S1 = if bn == HighestAll(S2PLBarOrigin)
then S2
else if bn == HighestAll(PLBarOrigin)
then S1 #Parentlow
else na;
SupportLineS2S1.EnableApproximation();
SupportLineS2S1.SetDefaultColor(Color.Gray);
SupportLineS2S1.SetLineWeight(1);
SupportLineS2S1.SetStyle(Curve.LONG_DASH);
def slopeS2S1 = (S2 - S1) /
(HighestAll(S2PLBarOrigin) - PLBarOrigin);
plot ExtLineS2S1 = if bn >= S2PLBarOrigin
then (bn - HighestAll(S2PLBarOrigin)) * slopeS2S1 + S2
else na;
ExtLineS2S1.EnableApproximation();
ExtLineS2S1.SetDefaultColor(Color.Gray);
ExtLineS2S1.SetLineWeight(1);
ExtLineS2S1.SetStyle(Curve.LONG_DASH);
Last edited by a moderator: