ATR static line as stoploss and profit target. NOT trailing stop

3AMBH

Active member
2019 Donor
This code is very helpful. Thanks for coding it for us. How could I modify it so when a trade is placed the levels will show across the chart and NOT just over each bar?

I use the code today and the levels showed a small mark above the first candle, etc. I am using the code on an options chart. Thanks
 
Last edited:
Solution
assuming you have some sort of signal for long or short entry, you can assign a value to an array like this to be able to reference it later:

Code:
def signal = if condition then 1 else 0;
def one_atr = if signal == 1 then ATR() else one_atr[1];

plot sl = entryprice + ( one_atr * 1.5 );
plot pt = entryprice - ( one_atr * 3 );

I've had code like this running previously, so the idea should work.

-mashume
Hi,

I am looking to create a strategy were the value of the ATR on the bar of my entry price is my stoploss and profit target, but since the ATR value is changing from candle to candle, it becomes the classic ATR trailing stop.

Here is the code I have but havent figure how to only take the value the atr had on my entry price.

#ATR

def entryPrice = entryPrice();

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

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

plot SL= entryprice + (ATR * 1.5);
plot PT = entryprice - (ATR * 3) ;

If anyone could help I would really appreciate it!
 
assuming you have some sort of signal for long or short entry, you can assign a value to an array like this to be able to reference it later:

Code:
def signal = if condition then 1 else 0;
def one_atr = if signal == 1 then ATR() else one_atr[1];

plot sl = entryprice + ( one_atr * 1.5 );
plot pt = entryprice - ( one_atr * 3 );

I've had code like this running previously, so the idea should work.

-mashume
 
Solution
since I trade futures, tick size and tick value are important to me... but this should work on anything, I think:
Code:
addLabel(yes, " ATR: " + one_atr + ",   1 ATR Value: " + asDollars(one_atr / tickSize() * TickValue()) + "    ", color.blue);

-mashume
 
I tend to use a multiple of ATR as a stop loss. Does anyone have or know of an ATR stop loss % label that would calculate the percentage from the current price?
 
Hi guys,

Just looking for a something to script a horizontal line that would plot a stop loss at 1.5 ATR of the current candle close and a first Target price of 1 ATR of the same candle close.

I tried using the above, but I don't have a "condition". I tried plotting without, but I don't see anything. This may be super easy but I am relatively new to this and would appreciate any help.

Cheers!
 
Hi guys,

Just looking for a something to script a horizontal line that would plot a stop loss at 1.5 ATR of the current candle close and a first Target price of 1 ATR of the same candle close.

I tried using the above, but I don't have a "condition". I tried plotting without, but I don't see anything. This may be super easy but I am relatively new to this and would appreciate any help.

Cheers!
F1yw6eE.png

Ruby:
# #################################
# ATR Stop & Target based on current candle
# requested by Docbrown83
input ATRStopMultiple = 1.5;
input ATRTargetMultiple = 1.0;
input length = 14;
input averageType = AverageType.WILDERS;
def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
def Target = close + (ATR * ATRTargetMultiple);
def Stop =  close - (ATR * ATRStopMultiple) ;

# #################################
# Charting & Formatting
addlabel(yes, "TARGET: " + round(Target,2) +" | "+ " STOP: " + round(Stop,2) , color.dark_orange);
plot TargetLine = HighestAll(if IsNaN(Close[-1]) then Target else double.NaN);
plot StopLine = HighestAll(if IsNaN(Close[-1]) then Stop else double.NaN);
 
Is there a way to input your actual buy price and have it calculate the SL & Targets? And whether it is a long or short trade?
tz09bJN.png

Ruby:
# #################################
# ATR Stop & Target based on buy price
# requested by tigerWares
input ATRStopMultiple = 1.5;
input ATRTargetMultiple = 1.0;
input length = 14;
input averageType = AverageType.WILDERS;
def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
def BuyPrice = GetAveragePrice();
def PL = GetOpenPL();
def Target = BuyPrice + (ATR * ATRTargetMultiple);
def Stop =  BuyPrice - (ATR * ATRStopMultiple) ;

# #################################
# Charting & Formatting
addlabel(yes, "TARGET: " + round(Target,2) +" | "+ " STOP: " + round(Stop,2) , color.dark_orange);
plot TargetLine = HighestAll(if IsNaN(Close[-1]) then Target else double.NaN);
plot StopLine = HighestAll(if IsNaN(Close[-1]) then Stop else double.NaN);
#Sase
#Add bubble above the the current candle if there is an open position
#If PL is positive then green else yellow
AddChartBubble (GetQuantity () != 0 and isnan(close[-1]), high, "buy price" +"\n"+ round(BuyPrice,2),if PL > 0 Then Color.GREEN Else Color.YELLOW, Yes);
 
View attachment 17801
Ruby:
# #################################
# ATR Stop & Target based on buy price
# requested by tigerWares
input ATRStopMultiple = 1.5;
input ATRTargetMultiple = 1.0;
input length = 14;
input averageType = AverageType.WILDERS;
def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
def BuyPrice = GetAveragePrice();
def PL = GetOpenPL();
def Target = BuyPrice + (ATR * ATRTargetMultiple);
def Stop =  BuyPrice - (ATR * ATRStopMultiple) ;

# #################################
# Charting & Formatting
addlabel(yes, "TARGET: " + round(Target,2) +" | "+ " STOP: " + round(Stop,2) , color.dark_orange);
plot TargetLine = HighestAll(if IsNaN(Close[-1]) then Target else double.NaN);
plot StopLine = HighestAll(if IsNaN(Close[-1]) then Stop else double.NaN);
#Sase
#Add bubble above the the current candle if there is an open position
#If PL is positive then green else yellow
AddChartBubble (GetQuantity () != 0 and isnan(close[-1]), high, "buy price" +"\n"+ round(BuyPrice,2),if PL > 0 Then Color.GREEN Else Color.YELLOW, Yes);
This is awesome, Merry. This line right here is gold: (GetQuantity () != 0 and isnan(close[-1]), high, "buy price" +"\n"+ round(BuyPrice,2),if PL > 0 Then Color.GREEN Else Color.YELLOW, Yes);

So the plot lines will only show up if holding a position, looks like?
 

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