Auto draw ATR Lines after placing trade?

Learnbot

Active member
I am not sure if this is possible but what I am trying to see if there is a way in which TOS automatically draws two lines when I place a buy order. so here are the details:

Let's say I placed and filled a market buy order for 1 stock of TSLA at $1000 at which point the ATR is 1.0. What I am trying to see (if possible) two lines get drawn at this time one stop loss line valued at 1000 - (2*ATR) and profit line valued at 1000+(4*ATR).

i dont think it's possible but maybe some of you smarter individuals than I, know more about me and maybe there is a way...

thank you for your help and time as always.
J
 
Last edited by a moderator:
@Miket Don't know if this is correct but give it a try.

Code:
input aggregationPeriod = AggregationPeriod.DAY;
def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def close = close(period = aggregationPeriod);

input length = 10;
input averageType = AverageType.WILDERS;

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

plot line = open + (ATR / 2);

The blue line represent the 50% of the 10 days ATR.
 
@Learnbot I have thought about doing what you want with an ATR band for stops, but what I do is I have a 1 min chart with the ATR(5) running. I make the ATR indicator area as small as possible, so that all I can really see is the ATR level bubble. I only want to see that number all day. When I go to put on a position based on indicators, price pattern, S/R levels, etc. (you guys know the drill, :) ) I will look at the ATR # and then set my initial stop as a multiple of that, usually X2. (As an aside, I am somewhat of a disciple of Chuck LeBeau). So if it says 6, for example, I will set the Trail stop at 15 (2 X 6 rounded up).After the trade is going, I will flatten the positions prior to the trail getting hit if price runs into resistance or some other indicator that tells me that the position is running into trouble. I also use the ATR # to keep me out of trades. i.e. if it is 30+, that tells me that the action is too rich for my blood, meaning 2 X 30 would be a 60 point stop. No thank you. Even with one NQ contract, that would be a $1200 stop at one level. So that is my deux centimes about ATRs. To each his/her own. Whatever works. Hope it gives you all something to think about. Talking about stops could take several books full, as you all know....
 
Good evening,

I was wondering if there is a function in thinkscipt that will determine weather you have a position in XYZ ticker, and if so draw a line that represents your stop-loss target price automatically. so if i buy 5 contracts of XYZ, it will find the high/low of the last 5 min period (arbitrary time frame) and will put a price level line at the high/low of that time frame, representing your stop.

Thanks in advance.
 
This will plot your average cost. You can add more plots with some math/logic to draw your stops and/or targets. You can look back at previous trades on your charts while testing this and it should plot where you had positions.
Ruby:
plot AveragePrice = if GetQuantity() != 0 then GetAveragePrice() else Double.NaN;
 
Good evening,

I was wondering if there is a function in thinkscipt that will determine weather you have a position in XYZ ticker, and if so draw a line that represents your stop-loss target price automatically. so if i buy 5 contracts of XYZ, it will find the high/low of the last 5 min period (arbitrary time frame) and will put a price level line at the high/low of that time frame, representing your stop.

Thanks in advance.
yes it can be done, look at this
https://usethinkscript.com/threads/...ot-being-displayed-correctly.5116/#post-48442
 
you can try this, i didnt test it but you just have to combine the codes similar to something like this:

Code:
def plBuy = if GetQuantity() != 0 then GetAveragePrice() else Double.NaN;
def plStraightLine = highestall(plBuy);

plot x=plStraightLine;
x.SetDefaultColor(Color.RED);
x.SetLineWeight(3);

# pl1 is Price Level 10%
plot pl1 = x * 1.10;
pl1.SetDefaultColor(Color.GREEN);
pl1.SetLineWeight(3);

addLabel(YES,plBuy,color.yellow);
 
Thanks for the responses everyone, much appreciated!

Does the GetQuanitity() function work only for commons or for option positions as well? i guess that would return greater than 1 regardless of if its commons or options?

@XeoNoX thank you so much for getting back to me. I'm a computer science student (Senior) I know java, I know thinkscript is derived from java, what do you recommend the best way to become familiar with thinkscript is? any youtube channels you'd recommend?
 
Thanks for the responses everyone, much appreciated!

Does the GetQuanitity() function work only for commons or for option positions as well? i guess that would return greater than 1 regardless of if its commons or options?

@XeoNoX thank you so much for getting back to me. I'm a computer science student (Senior) I know java, I know thinkscript is derived from java, what do you recommend the best way to become familiar with thinkscript is? any youtube channels you'd recommend?
just playing/attempting to write the scripts, using the thinkscript website and other peoples works for examples and then piecing it together. the longer you take trying to figure things out and then figuring it out, the more you learn. I accidently learned it over time and asking few questions and examples here and there, on the slow market days i just would tend to mess with it out of boredom to make my day go by faster and next thing i knew i just happened to learn it.
 
you can try this, i didnt test it but you just have to combine the codes similar to something like this:

Code:
def plBuy = if GetQuantity() != 0 then GetAveragePrice() else Double.NaN;
def plStraightLine = highestall(plBuy);

plot x=plStraightLine;
x.SetDefaultColor(Color.RED);
x.SetLineWeight(3);

# pl1 is Price Level 10%
plot pl1 = x * 1.10;
pl1.SetDefaultColor(Color.GREEN);
pl1.SetLineWeight(3);

addLabel(YES,plBuy,color.yellow);
Thank you!
 
Hello everyone, I found these ATR Lines by Mobius. They work very well depending on the length you choose and time frame. You will have to adjust the ATR multiplier for the underlying in question.

Here is an ask for the coders of the forum: can you have the study below calculate the ATR for the underlying automatically and that way the ATR multiplier adjusts itself.

I think that by automating the step above, you will only have to worry about the time frame and length.

Here is the code below

Code:
# 08:47 Mobius: bennet -



# ATR Lines

# Mobius

# Chat Room Request 11.05.2018



input n = 20;

input ATRmultiplier = 1.5;

def avg = Average(close, n);

def TR = TrueRange(high, close, low);

def ATR = Average(TR, n);

plot upper = HighestAll(if isNaN(close[-1])

                        then avg + (ATRmultiplier * ATR)

                        else double.nan);

plot lower = HighestAll(if isNaN(close[-1])

                        then avg - (ATRmultiplier * ATR)

                        else double.nan);
 
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
503 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