ZigZag Lines

rwfarrell

Member
Hello, I extracted this script from the reversal indicator. I am looking to add the Aggregation Period to this script to see the lines from a higher timeframe on a lower timeframe. Very much like the MA HTF script. Can anyone add to this to make that possible? Thank you!


####### ZigZag Lines

input Period = AggregationPeriod.DAY;
input method = {default average, high_low};
def bubbleoffset = .0005;
def percentamount = .01;
def revAmount = .05;
def atrreversal = 2.0;
def atrlength = 5;
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.EXPONENTIAL;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh = if method == method.high_low then pricehigh else mah;
def pricel = if method == method.high_low then pricelow else mal;
def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
def reversalAmount = if (close * percentamount / 100) > Max(revAmount < atrreversal * reference ATR(atrlength), revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * reference ATR(atrlength) then atrreversal * reference ATR(atrlength) else revAmount;
rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);
def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(EI, 1)) and GetValue(isConf, 1));
def EId = if isUp then 1 else 0;
plot EnhancedLines = if EId <= 1 then EI else Double.NaN;
EnhancedLines.AssignValueColor(if EId == 1 then Color.green else if EId == 0 then Color.RED else Color.DARK_ORANGE);
EnhancedLines.SetStyle(Curve.FIRM);
EnhancedLines.EnableApproximation();
EnhancedLines.HideBubble();
 
Hello, I extracted this script from the reversal indicator. I am looking to add the Aggregation Period to this script to see the lines from a higher timeframe on a lower timeframe. Very much like the MA HTF script. Can anyone add to this to make that possible? Thank you!


####### ZigZag Lines

input Period = AggregationPeriod.DAY;
input method = {default average, high_low};
def bubbleoffset = .0005;
def percentamount = .01;
def revAmount = .05;
def atrreversal = 2.0;
def atrlength = 5;
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.EXPONENTIAL;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh = if method == method.high_low then pricehigh else mah;
def pricel = if method == method.high_low then pricelow else mal;
def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
def reversalAmount = if (close * percentamount / 100) > Max(revAmount < atrreversal * reference ATR(atrlength), revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * reference ATR(atrlength) then atrreversal * reference ATR(atrlength) else revAmount;
rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);
def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(EI, 1)) and GetValue(isConf, 1));
def EId = if isUp then 1 else 0;
plot EnhancedLines = if EId <= 1 then EI else Double.NaN;
EnhancedLines.AssignValueColor(if EId == 1 then Color.green else if EId == 0 then Color.RED else Color.DARK_ORANGE);
EnhancedLines.SetStyle(Curve.FIRM);
EnhancedLines.EnableApproximation();
EnhancedLines.HideBubble();

Try changing these lines in bold. You can make most indicators multi-timeframe with these types of changes to the price fundamentals in the base code.

As to displaying the multiple timeframe zigzag on a lower timeframe chart, try to use a higher timeframe close to a multiple of chart timeframe. If you choose too high of a higher timeframe, it will often distort the plot of the higher timeframe zigzag.

In the image below, the dotted line is the 5m chart zigzag and the solid line is a 15m multiple timeframe zigzag, a close multiple of the 5m chart timeframe. The zigzags in the image may provide better information this way. If you switched the higher timeframe to 30m, you will see the higher timeframe zigzag will be distorted.

Always remember that both of these zigzags can repaint the zigzag lines,

Capture.jpg
Rich (BB code):
####### ZigZag Lines



input Period = AggregationPeriod.FIFTEEN_MIN;

input method = {default average, high_low};

def bubbleoffset = .0005;

def percentamount = .01;

def revAmount = .05;

def atrreversal = 2.0;

def atrlength = 5;

def pricehigh = high(period = Period);

def pricelow = low(period = Period);

def averagelength = 5;

def averagetype = AverageType.EXPONENTIAL;

def mah = MovingAverage(averagetype, pricehigh, averagelength);

def mal = MovingAverage(averagetype, pricelow, averagelength);

def priceh = if method == method.high_low then pricehigh else mah;

def pricel = if method == method.high_low then pricelow else mal;

def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);

def reversalAmount = if (close(period=period) * percentamount / 100) > Max(revAmount < atrreversal * reference ATR(atrlength), revAmount) then (close(period=period) * percentamount / 100) else if revAmount < atrreversal * reference ATR(atrlength) then atrreversal * reference ATR(atrlength) else revAmount;

rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);

def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);

def isUp = chg >= 0;

rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(EI, 1)) and GetValue(isConf, 1));

def EId = if isUp then 1 else 0;

plot EnhancedLines = if EId <= 1 then EI else Double.NaN;

EnhancedLines.AssignValueColor(if EId == 1 then Color.GREEN else if EId == 0 then Color.RED else Color.DARK_ORANGE);

EnhancedLines.SetStyle(Curve.FIRM);

EnhancedLines.EnableApproximation();

EnhancedLines.HideBubble();
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
386 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top