# Swing Waves - good indicator - needs documentation

V

#### vensonom

##### New member
I have this indicator which was provided as part of a training course i took , long time back. i cant find the documentation for it and haven't received response from its authors. any chance someone can help summarize what it might be doing ? it plots some good resistance/support lines, but don't understand how its being calculated.

Code:
``````# Trading Analysis Swing Waves - Trader
# Version 1.0
# 6/13/2016
#
# Authors: Brian Strong - Micro Quant ([email protected]) SwingWave detection
#          Daniel Sinnig - Biiuse Trading ([email protected]) Ideal entry detection
#

input MajorSwingPeriod = 13;
input MinorSwingPeriod = 5;
input ExpansionFactor = 1.0;
input LookBackPeriod = 200;
input ShowCounterTrendEntries = no;

def powerStopsOff = no;

def signalOffsetFactor = 0.20;
def offset = Average(TrueRange(high, close, low), 9) * signalOffsetFactor;

#Calculate Major Swings
def majorPivotH = if high > Highest(high[1], MajorSwingPeriod) and high >
Highest(high[-MajorSwingPeriod], MajorSwingPeriod) then 1 else 0;
def majorH = if majorPivotH then high+offset else Double.NaN;
def majorPivotL = if low < Lowest(low[1], MajorSwingPeriod) and low <
Lowest(low[-MajorSwingPeriod], MajorSwingPeriod) then 1 else 0;
def majorL = if majorPivotL then low-offset else Double.NaN;

#Calculate Minor Swings
def minorPivotH = if high > Highest(high[1], MinorSwingPeriod) and high >
Highest(high[-MinorSwingPeriod], MinorSwingPeriod) then 1 else 0;
def minorH = if minorPivotH then high+offset else Double.NaN;
def minorPivotL = if low < Lowest(low[1], MinorSwingPeriod) and low <
Lowest(low[-MinorSwingPeriod], MinorSwingPeriod) then 1 else 0;
def minorL = if minorPivotL then low-offset else Double.NaN;

#Ideal entry detection
#Find last minor and major High and Lows
def indexOfLastMinorHigh = fold minorHighIndex = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod  while IsNaN(GetValue(minorH, minorHighIndex)) do minorHighIndex + 1;
def indexOfLastMinorLow = fold minorLowIndex = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod while IsNaN(GetValue(minorL, minorLowIndex)) do minorLowIndex + 1;
def indexOfLastMajorHigh = fold majorHighIndex = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod while IsNaN(GetValue(majorH, majorHighIndex)) do majorHighIndex + 1;
def indexOfLastMajorLow = fold majorLowIndex = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod while IsNaN(GetValue(majorL, majorLowIndex)) do majorLowIndex + 1;

#Find High / Low between current bar and last minor low / high (check that it should only minor for major stops as well)/
def indexOfLastHigh_sinceMinorHigh = fold i20 = -MajorSwingPeriod to indexOfLastMinorHigh + 1 with _tempHigh = Double.NEGATIVE_INFINITY do if GetValue(high, i20) > _tempHigh then GetValue(high, i20) else _tempHigh;
def indexOfLastLow_sinceMinorLow = fold i21 = -MajorSwingPeriod to indexOfLastMinorLow + 1 with _tempLow = Double.POSITIVE_INFINITY do if GetValue(low, i21) < _tempLow then GetValue(low, i21) else _tempLow;

#Calculate and set individual differences

#---------------------------------------------
# (1) Major High to major Low
def differenceMajorH_to_MajorL = if IsNaN(majorL)
then 0 #if we are not at a major low then it's 0
else #otherwise find the corresponding major High and calculate the difference
fold i1 = 1 to lookBackPeriod
with diffMajorHighToMajorLow = 0
while (diffMajorHighToMajorLow == 0) do
if (!IsNaN(GetValue(majorL, i1))) then Double.NaN else #if another major low is found then cancel
if (!IsNaN(GetValue(majorH, i1)) and (GetValue(DiPlusDiMinusDiff, i1) < 0)) then Double.NaN #if DI+ is less than DI- then flag as NaN so that loop will stop and it'll be ignored later on
else if (!IsNaN(GetValue(majorH, i1))) then high[i1] - low
else 0;
def sum_AllDifferences_MajorH_to_MajorL = fold i5 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod
with _tempSum_MajorH_to_MajorL = 0 do
if !IsNaN(differenceMajorH_to_MajorL[i5]) then _tempSum_MajorH_to_MajorL + differenceMajorH_to_MajorL[i5] else _tempSum_MajorH_to_MajorL;

def count_AllDifferences_MajorH_to_MajorL = fold i9 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod with _tempCount_MajorH_to_MajorL = 0 do if
!IsNaN(differenceMajorH_to_MajorL[i9]) then
if (differenceMajorH_to_MajorL[i9] <> 0) then _tempCount_MajorH_to_MajorL + 1 else _tempCount_MajorH_to_MajorL
else _tempCount_MajorH_to_MajorL;

def average_MajorH_to_MajorL = if (count_AllDifferences_MajorH_to_MajorL <> 0) then sum_AllDifferences_MajorH_to_MajorL / count_AllDifferences_MajorH_to_MajorL else 0;

#FINAL
plot majorLongEntryLine = HighestAll(if IsNaN(close[-MajorSwingPeriod - 1]) and !IsNaN(close) then
if (!powerStopsOff and (ShowCounterTrendEntries or GetValue(DiPlusDiMinusDiff, -MajorSwingPeriod) >= 0)) then indexOfLastHigh_sinceMinorHigh - average_MajorH_to_MajorL * ExpansionFactor else Double.NaN
else Double.NaN);

majorLongEntryLine.SetLineWeight(2);
majorLongEntryLine.SetDefaultColor(Color.GREEN);

#------------------------------------------------
# (2) Major Low to major High

def differenceMajorL_to_MajorH = if IsNaN(majorH)
then 0 #if we are not at a minor high then it's 0
else #otherwise find the corresponding major Low and calculate the difference
fold i2 = 1 to lookBackPeriod
with diffMajorLowToMajorHigh = 0
while (diffMajorLowToMajorHigh == 0) do
if (!IsNaN(GetValue(majorH, i2))) then Double.NaN else #if another major high is found then cancel
if (!IsNaN(GetValue(majorL, i2)) and (GetValue(DiPlusDiMinusDiff, i2) > 0)) then Double.NaN #if DI+ is greater than DI- then flag as NaN so that loop will stop and it'll be ignored later on
else if (!IsNaN(GetValue(majorL, i2))) then high - low[i2]
else 0;
def sum_AllDifferences_MajorL_to_MajorH = fold i6 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod
with _tempSum_MajorL_to_MajorH = 0 do
if !IsNaN(differenceMajorL_to_MajorH[i6]) then _tempSum_MajorL_to_MajorH + differenceMajorL_to_MajorH[i6] else _tempSum_MajorL_to_MajorH;

def count_AllDifferences_MajorL_to_Major_H = fold i10 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod with _tempCount_MajorL_to_MajorH = 0 do if
!IsNaN(differenceMajorL_to_MajorH[i10]) then
if (differenceMajorL_to_MajorH[i10] <> 0) then _tempCount_MajorL_to_MajorH + 1 else _tempCount_MajorL_to_MajorH
else _tempCount_MajorL_to_MajorH;

def average_MajorL_to_MajorH = if (count_AllDifferences_MajorL_to_Major_H <> 0) then sum_AllDifferences_MajorL_to_MajorH / count_AllDifferences_MajorL_to_Major_H else 0;

#FINAL
plot majorShortEntryLine = HighestAll(if IsNaN(close[-MajorSwingPeriod - 1]) and !IsNaN(close) then
if (!powerStopsOff and (ShowCounterTrendEntries or GetValue(DiPlusDiMinusDiff, -MajorSwingPeriod) <= 0)) then indexOfLastLow_sinceMinorLow + average_MajorL_to_MajorH * ExpansionFactor else Double.NaN
else Double.NaN);

majorShortEntryLine.SetLineWeight(2);
majorShortEntryLine.SetDefaultColor(Color.RED);

#------------------------------------------------
# (3) Any high to any low (except major to major)

def differenceMinorH_to_MinorL = if IsNaN(minorL)
then 0 #if we are not at a minor low (that is not also a major low)  then it's 0
else #otherwise find the corresponding major High and calculate the difference
fold i3 = 1 to lookBackPeriod
with diffMinorHighToMinorLow = 0
while (diffMinorHighToMinorLow == 0) do
if (!IsNaN(GetValue(minorL, i3))) then Double.NaN else #if another low is found then cancel
if !IsNaN(majorL) and !IsNaN(GetValue(majorH, i3)) then Double.NaN else #exclude major to major
if (!IsNaN(GetValue(minorH, i3)) and (GetValue(DiPlusDiMinusDiff, i3) < 0)) then Double.NaN #if DI+ is less than DI- then flag as NaN so that loop will stop and it'll be ignored later on
else if (!IsNaN(GetValue(minorH, i3))) then high[i3] - low
else 0;

def sum_AllDifferences_MinorH_to_Minor_L = fold i7 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod
with _tempSum_MinorH_to_MinorL = 0 do
if !IsNaN(differenceMinorH_to_MinorL[i7]) then _tempSum_MinorH_to_MinorL + differenceMinorH_to_MinorL[i7] else _tempSum_MinorH_to_MinorL;

def count_AllDifferences_MinorH_to_MinorL = fold i11 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod with _tempCount_MinorH_to_MinorL = 0 do if
!IsNaN(differenceMinorH_to_MinorL[i11]) then
if (differenceMinorH_to_MinorL[i11] <> 0) then _tempCount_MinorH_to_MinorL + 1 else _tempCount_MinorH_to_MinorL
else _tempCount_MinorH_to_MinorL;

def average_MinorH_to_MinorL = if (count_AllDifferences_MinorH_to_MinorL <> 0) then sum_AllDifferences_MinorH_to_Minor_L / count_AllDifferences_MinorH_to_MinorL else 0;

#FINAL
plot minorLongEntryLine = HighestAll(if IsNaN(close[-MajorSwingPeriod - 1]) and !IsNaN(close) then
if (!powerStopsOff and (ShowCounterTrendEntries or GetValue(DiPlusDiMinusDiff, -MajorSwingPeriod) >= 0)) then indexOfLastHigh_sinceMinorHigh - average_MinorH_to_MinorL * ExpansionFactor else Double.NaN
else Double.NaN);

minorLongEntryLine.SetDefaultColor(Color.GREEN);

#------------------------------------------------
# (4) Minor Low (not major) to Minor High (not major)

def differenceMinorL_to_MinorH = if IsNaN(minorH)
then 0 #if we are not at a minor low (that is not also a major low)  then it's 0
else #otherwise find the corresponding major High and calculate the difference
fold i4 = 1 to lookBackPeriod
with diffMinorLowToMinorHigh = 0
while (diffMinorLowToMinorHigh == 0) do
if (!IsNaN(GetValue(minorH, i4))) then Double.NaN else #if another high is found then cancel
if !IsNaN(majorH) and !IsNaN(GetValue(majorL, i4)) then Double.NaN else #exclude major to major
if (!IsNaN(GetValue(minorL, i4)) and (GetValue(DiPlusDiMinusDiff, i4) > 0)) then Double.NaN #if DI+ is greater than DI- then flag as NaN so that loop will stop and it'll be ignored later on
else if (!IsNaN(GetValue(minorL, i4))) then high - low [i4]
else 0;

def sum_AllDifferences_MinorL_to_MinorH = fold i8 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod
with _tempSum_MinorL_to_MinorH = 0 do
if !IsNaN(differenceMinorL_to_MinorH[i8]) then _tempSum_MinorL_to_MinorH + differenceMinorL_to_MinorH[i8] else _tempSum_MinorL_to_MinorH;

def count_AllDifferences_MinorL_to_MinorH = fold i12 = -MajorSwingPeriod to lookBackPeriod - MajorSwingPeriod with _tempCount_MinorL_to_MinorH = 0 do if
!IsNaN(differenceMinorL_to_MinorH[i12]) then
if (differenceMinorL_to_MinorH[i12] <> 0) then _tempCount_MinorL_to_MinorH + 1 else _tempCount_MinorL_to_MinorH
else _tempCount_MinorL_to_MinorH;

def average_MinorL_to_MinorH = if (count_AllDifferences_MinorL_to_MinorH <> 0) then sum_AllDifferences_MinorL_to_MinorH / count_AllDifferences_MinorL_to_MinorH else 0;

#FINAL
plot minorShortEntryLine = HighestAll(if IsNaN(close[-MajorSwingPeriod - 1]) and !IsNaN(close) then
if  (!powerStopsOff and (ShowCounterTrendEntries or GetValue(DiPlusDiMinusDiff, -MajorSwingPeriod) <= 0)) then indexOfLastLow_sinceMinorLow + average_MinorL_to_MinorH * ExpansionFactor else Double.NaN
else Double.NaN);

minorShortEntryLine.SetDefaultColor(Color.RED);``````

D

#### dominos101

##### New member
VIP
Seems like the opening range breakout indicator.

#### J007RMC

##### Well-known member
2019 Donor
VIP
Wonder if it is possible to create a scan from the swing waves script?

Last edited by a moderator:

#### BenTen

Staff
VIP
@J007RMC I don't see how you shouldn't be able to. Here is an example:

#### J007RMC

##### Well-known member
2019 Donor
VIP
@J007RMC I don't see how you shouldn't be able to. Here is an example:

Thanks Ben

#### J007RMC

##### Well-known member
2019 Donor
VIP
Thanks Ben
I put the short wave scan together and it works Ben is an Allstar