Tweak Below Code to Draw Horizontal Priceline (at center of candle) instead of up/down arrows

D

dvorakm

New member
2019 Donor
VIP
Code:
# Trading Analysis Swing Waves
# Version 1.0.1
# 4/20/2015
#
# Author: Brian Strong ([email protected])
# MicroQuant
#

input MajorLeftStr = 13;
input MajorRightStr = 13;
input MinorLeftStr = 5;
input MinorRightStr = 5;
input SwingTickOffset = 2;
input AlertsOn = yes;

# This indicator must be applied to a bar interval larger than 5 ticks.

def offset = TickSize() * (HighestAll(high) - LowestAll(low)) * SwingTickOffset;

#Calculate Major Swings
def pivotH = if high > Highest(high[1], MajorLeftStr) and high > Highest(high[-MajorRightStr], MajorRightStr) then 1 else 0;
def pValH = if pivotH then high + offset else Double.NaN;
def pivotL = if low < Lowest(low[1], MajorLeftStr) and low < Lowest(low[-MajorRightStr], MajorRightStr) then 1 else 0;
def pValL = if pivotL then low - offset else Double.NaN;

#Plot Major Swings
plot MajorSwHigh = pValH;
MajorSwHigh.setpaintingStrategy(paintingStrategy.POINTS);
MajorSwHigh.setLineWeight(5);
MajorSwHigh.setdefaultColor(Color.BLUE);
plot MajorSwLow = pValL;
MajorSwLow.setpaintingStrategy(paintingStrategy.POINTS);
MajorSwLow.setLineWeight(5);
MajorSwLow.setdefaultColor(Color.BLUE);
 
O

OBW

New member
Add this to the bottom of your code:

Ruby:
plot midLine = if pivotH or pivotL then hl2 else Double.NaN;
midLine.SetPaintingStrategy(12);
midLine.SetDefaultColor(Color.MAGENTA);
midLine.SetLineWeight(3);
 
O

OBW

New member
how does this work any details?

pivotH and pivotL are the variables that @dvorakm defined as his pivot points. He asked for a horizontal line {SetPaintingStrategy(12);} at the center of the candle.

The center of the candle would be: (High + Low) / 2. Rather than typing that out, though, I used HL2which is one of the built-in fundamentals.
 
D

dvorakm

New member
2019 Donor
VIP
thanks! it plots the line in center of candle as I hoped for. I will just manually select the ones to draw a price line.
 
Last edited:
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
Code:
# Trading Analysis Swing Waves
# Version 1.0.1
# 4/20/2015
#
# Author: Brian Strong ([email protected])
# MicroQuant
#

input MajorLeftStr = 13;
input MajorRightStr = 13;
input MinorLeftStr = 5;
input MinorRightStr = 5;
input SwingTickOffset = 2;
input AlertsOn = yes;

# This indicator must be applied to a bar interval larger than 5 ticks.

def offset = TickSize() * (HighestAll(high) - LowestAll(low)) * SwingTickOffset;

#Calculate Major Swings
def pivotH = if high > Highest(high[1], MajorLeftStr) and high > Highest(high[-MajorRightStr], MajorRightStr) then 1 else 0;
def pValH = if pivotH then high + offset else Double.NaN;
def pivotL = if low < Lowest(low[1], MajorLeftStr) and low < Lowest(low[-MajorRightStr], MajorRightStr) then 1 else 0;
def pValL = if pivotL then low - offset else Double.NaN;

#Plot Major Swings
plot MajorSwHigh = pValH;
MajorSwHigh.setpaintingStrategy(paintingStrategy.POINTS);
MajorSwHigh.setLineWeight(5);
MajorSwHigh.setdefaultColor(Color.BLUE);
plot MajorSwLow = pValL;
MajorSwLow.setpaintingStrategy(paintingStrategy.POINTS);
MajorSwLow.setLineWeight(5);
MajorSwLow.setdefaultColor(Color.BLUE);
How can I add alerts for the swing highs and lo's
 

Similar threads

Top