ATR From the Lows help

zciwtrades

New member
Hello traders! I was looking if anyone could modify this code that plots 1.5 ATR from the lows so that it is like a trailing stop style, as in it flattens out until a higher low is made. Ideally if i could also set it to start at a certain date (like an anchored VWAP) that would be amazing!

Thanks!!!


Code:
input length = 20;
input factor = 1.5;

input averageType = AverageType.SIMPLE;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);

plot ATRTrail = low - (ATR *factor);
 
Solution
Hello traders! I was looking if anyone could modify this code that plots 1.5 ATR from the lows so that it is like a trailing stop style, as in it flattens out until a higher low is made. Ideally if i could also set it to start at a certain date (like an anchored VWAP) that would be amazing!

Thanks!!!


Code:
input length = 20;
input factor = 1.5;

input averageType = AverageType.SIMPLE;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);

plot ATRTrail = low - (ATR *factor);


this plots a trail line.
it uses max() to create a line that doesn't drop.
the if-then checks if close crosses the line. if it does then it stops drawing.
this starts a trail line at bar #1 and a bar after each time the previous...
Hello traders! I was looking if anyone could modify this code that plots 1.5 ATR from the lows so that it is like a trailing stop style, as in it flattens out until a higher low is made. Ideally if i could also set it to start at a certain date (like an anchored VWAP) that would be amazing!

Thanks!!!


Code:
input length = 20;
input factor = 1.5;

input averageType = AverageType.SIMPLE;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);

plot ATRTrail = low - (ATR *factor);


this plots a trail line.
it uses max() to create a line that doesn't drop.
the if-then checks if close crosses the line. if it does then it stops drawing.
this starts a trail line at bar #1 and a bar after each time the previous one ends.


Code:
#trail_atr_from_low

#https://usethinkscript.com/threads/atr-from-the-lows-help.19720/
#ATR From the Lows help
#zciwtrades  10/7

# I was looking if anyone could modify this code that plots 1.5 ATR from the lows so that it is like a trailing stop style, as in it flattens out until a higher low is made. Ideally if i could also set it to start at a certain date (like an anchored VWAP) that would be amazing!


def na = double.nan;
def bn = barnumber();

input length = 20;
input factor = 1.5;
input averageType = AverageType.SIMPLE;
def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);

def ATRTrail = low - (ATR *factor);

def trail_line = if bn == 1 then ATRTrail
 else if close < trail_line[1] then 0
 else max(trail_line[1] , ATRTrail );

plot z = if trail_line > 0 then trail_line else na;


addchartbubble((trail_line[1] > 0 and trail_line == 0), low,
"sell"
, color.yellow, no);
#


other posts about trailing
https://usethinkscript.com/threads/trailing-stop-loss-help-needed.16492/#post-133724
https://usethinkscript.com/threads/having-trouble-with-stop-loss-code.16083/#post-129176
 
Last edited:
Solution

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