Repaints AGAIG ZigZag Arrows For ThinkOrSwim

Repaints

csricksdds

Trader Educator
VIP
I thought I had posted this before but can't find it on my posts. This is a change in direction indicator.
AsGoodAsItGets Trend Arrows:
HaxmGAP.png

Here is the code:
Ruby:
#CSR Buy/Sell Arrows with Short/LongHaulFilter Bubbles
#Developed 4-9-22 First Edition
#Modified by C. Ricks to show direction arrows only (Large Yellow Arroews Up/Down

declare upper;

input atrreversal = 2.0;#Hint atrreversal: Turn down for more entries, up for less entries. Purple signal indicates low point reversal and close approaching Kijun. Orange signal indicates the price is crossing the Kijun. Green signal indicates the low of the candle holds over the Kijun. Red signal means reversal at a high point.
def priceh = MovingAverage(AverageType.EXPONENTIAL, high, 5);
def pricel = MovingAverage(AverageType.EXPONENTIAL, low, 5);

def EIL = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = .01, "absolute reversal" = .05, "atr length" = 5, "atr reversal" = atrreversal).lastL;
def EIH = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = .01, "absolute reversal" = .05, "atr length" = 5, "atr reversal" = atrreversal).lastH;

plot signaldown = !isNAN(EIH);
signaldown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
signaldown.setdefaultcolor (CreateColor (255, 255, 0));



plot signalrevBot = !isNaN(EIL);
signalrevBot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_up);
signalrevBot.setdefaultcolor (CreateColor (255, 255, 0));

#End Code
 
Last edited by a moderator:
Here is the code with vertical lines instead of arrows:
Ruby:
# AsGoodAsItGets Lower Indicator
#CSR Buy/Sell Arrows with Short/Long Bubbles
#Developed 4-23-23 First Edition 8-23-22 Revised
#Updated 3/16/24 by C. Ricks

declare upper;

input atrreversal = 2.5;

def priceh = MovingAverage(AverageType.EXPONENTIAL, high, 5);
def pricel = MovingAverage(AverageType.EXPONENTIAL, low, 5);

def EIL = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = .01, "absolute reversal" = .05, "atr length" = 5, "atr reversal" = atrreversal).lastL;
def EIH = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = .01, "absolute reversal" = .05, "atr length" = 5, "atr reversal" = atrreversal).lastH;

def signaldown = !isNAN(EIH);

AddVerticalLine(signaldown, "EXT UP  +2.5 SD", Color.Red);


def signalrevBot = !isNaN(EIL);

AddVerticalLine(signalrevBot, "EXT DOWN  -2.5 SD", Color.Green);


#End Code
 
Last edited by a moderator:
Here is the code with bubbles instead of arrows:
Ruby:
#CSR Buy/Sell Arrows with Short/LongHaulFilter Bubbles
#Developed 4-9-22 First Edition

declare upper;

input atrreversal = 2.0;#Hint atrreversal: Turn down for more entries, up for less entries. Purple signal indicates low point reversal and close approaching Kijun. Orange signal indicates the price is crossing the Kijun. Green signal indicates the low of the candle holds over the Kijun. Red signal means reversal at a high point.   
def priceh = MovingAverage(AverageType.EXPONENTIAL, high, 5); 
def pricel = MovingAverage(AverageType.EXPONENTIAL, low, 5); 

def EIL = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = .01, "absolute reversal" = .05, "atr length" = 5, "atr reversal" = atrreversal).lastL; 
def EIH = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = .01, "absolute reversal" = .05, "atr length" = 5, "atr reversal" = atrreversal).lastH; 

def signaldown = !isNAN(EIH);
 
AddChartBubble(SignalDown, high, "Short", Color.white, no);

def signalrevBot = !isNaN(EIL);

AddChartBubble(Signalrevbot, low, "Long", Color.White, no);

input usealerts = yes;
alert(usealerts and signaldown[1] == 1, "Short", alert.bar, sound.ring);
alert(usealerts and signalrevbot[1] == 1, "Long", alert.bar, sound.ring);



#End Code
 
Last edited by a moderator:
As a trader (AsGoodAsItGets) I am always looking for Trend Continuation. This ZigZag modification I have made carries the trend out to eight places (since bars usually move 6-10 bars I have added 8-Bar average placement for this). Under studies and strategies you can click on the wheel and undo show plots for mah and mal if you choose. I also select high_low for my setting. I am using CYAN for down arrows (easy for me to see) and GREEN for up arrows. I also can't find who wrote the original code and hope you will let me know in order to credit. Image attached:


Code:
Ruby:
# used to switch between "zigzag based on high/low of price" and "zigzag based on then high/low of moving averages"
#Not sure who to credit for original code but modified by C. Ricks to show continuing arrows (up to 12) under AGAIG_ZigZag_ContinuationArrows 4/7/24

input method = {default average, high_low};

# data for the built-in zigzag indicator which is referenced in the study. To see the ZigZagHighLow() code, look for it in the built-in TOS studies
def bubbleoffset = .0005;
def percentamount = .01;
def revAmount = .05;
def atrreversal = 2.0;
def atrlength = 5;

# data for the moving averages
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.EXPONENTIAL;

# here are the moving averages used for the signals - changed to plots and given colors
plot mah = MovingAverage(averagetype, pricehigh, averagelength);
plot mal = MovingAverage(averagetype, pricelow, averagelength);
mah.setdefaultcolor(color.cyan);
mal.setdefaultcolor(color.cyan);

# continues the switch between the two different zigzag data points
def priceh = if method == method.high_low then pricehigh else mah;
def pricel = if method == method.high_low then pricelow else mal;

# references the built-in zigzag indicator
def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);

# not very clear on how this exactly works - but the end result is to plot the zigzag lines
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;


# calculates and plots the arrows
def EIL = if !IsNaN(EI) and !isUp then pricel else GetValue(EIL, 1);
def EIH = if !IsNaN(EI) and isUp then priceh else GetValue(EIH, 1);
def dir = CompoundValue(1, if EIL != EIL[1] or pricel == EIL[1] and pricel == EISave then 1 else if EIH != EIH[1] or priceh == EIH[1] and priceh == EISave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and pricel > EIL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and priceh < EIH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);
def showarrows = yes;
plot U1 = showarrows and signal > 0 and signal[1] <= 0;
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);
plot D1 = showarrows and signal < 0 and signal[1] >= 0;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.Cyan);
D1.SetLineWeight(4);

plot D2 = showarrows and signal < 0 and signal[2] >= 0;
D2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D2.SetDefaultColor(Color.Cyan);
D2.SetLineWeight(4);

plot D3 = showarrows and signal < 0 and signal[3] >= 0;
D3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D3.SetDefaultColor(Color.Cyan);
D3.SetLineWeight(4);

plot D4 = showarrows and signal < 0 and signal[4] >= 0;
D4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D4.SetDefaultColor(Color.Cyan);
D4.SetLineWeight(4);

plot D5 = showarrows and signal < 0 and signal[5] >= 0;
D5.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D5.SetDefaultColor(Color.Cyan);
D5.SetLineWeight(4);

plot D6 = showarrows and signal < 0 and signal[6] >= 0;
D6.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D6.SetDefaultColor(Color.Cyan);
D6.SetLineWeight(4);

plot D7 = showarrows and signal < 0 and signal[7] >= 0;
D7.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D7.SetDefaultColor(Color.Cyan);
D7.SetLineWeight(4);

plot D8 = showarrows and signal < 0 and signal[8] >= 0;
D8.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D8.SetDefaultColor(Color.Cyan);
D8.SetLineWeight(4);



plot U2 = showarrows and signal > 0 and signal[2] <= 0;
U2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U2.SetDefaultColor(Color.GREEN);
U2.SetLineWeight(4);

plot U3 = showarrows and signal > 0 and signal[3] <= 0;
U3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U3.SetDefaultColor(Color.GREEN);
U3.SetLineWeight(4);

plot U4 = showarrows and signal > 0 and signal[4] <= 0;
U4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U4.SetDefaultColor(Color.GREEN);
U4.SetLineWeight(4);

plot U5 = showarrows and signal > 0 and signal[5] <= 0;
U5.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U5.SetDefaultColor(Color.GREEN);
U5.SetLineWeight(4);

plot U6 = showarrows and signal > 0 and signal[6] <= 0;
U6.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U6.SetDefaultColor(Color.GREEN);
U6.SetLineWeight(4);

plot U7 = showarrows and signal > 0 and signal[7] <= 0;
U7.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U7.SetDefaultColor(Color.GREEN);
U7.SetLineWeight(4);

plot U8 = showarrows and signal > 0 and signal[8] <= 0;
U8.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U8.SetDefaultColor(Color.GREEN);
U8.SetLineWeight(4);



##End Code
 
Last edited by a moderator:
This is an interesting indicator. Since the indicator repaints, I would be curious to see what the chart would look like if the first arrow plot of the trend change was kept while continuing to let the indicator repaint its signals. Being able to see intermediate arrows would be nice as well but it is not as significant to view as the original arrow plot. Could someone on this forum please let me know if this is possible. I am still deciding whether to use this to guide me in my manual trading process and a visual would be great in helping me make that decision.
 
This is an interesting indicator. Since the indicator repaints, I would be curious to see what the chart would look like if the first arrow plot of the trend change was kept while continuing to let the indicator repaint its signals. Being able to see intermediate arrows would be nice as well but it is not as significant to view as the original arrow plot. Could someone on this forum please let me know if this is possible. I am still deciding whether to use this to guide me in my manual trading process and a visual would be great in helping me make that decision.
You might want to add an oscillator to you chart as the oscillator leaves a footprint behind showing where it has been non-repainting). Also hi/lo pivot lines will show the highest/lowest points achieved thus far.
 

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
255 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