plot a $1.00 trailing stop

tobywon

New member
Plus
I want to plot a $1.00 trailing stop in TOS. This is not a volatility-based stop. It is just the trailing stop TOS uses in Active Trader to exit a trade on a $1.00 pullback from the current high. I have tried a variety of codes, but I haven't gotten it right yet.

#Lookup 20_Trail 1.00
#20 period midprice long-short condition
def LO = Lowest(low, 20);
def HI = Highest(high, 20);
def MID = ((HI - LO) / 2 + LO);

def MidOver = high > mid;
def MidUnder = low < mid;

#$1.00 trailing stop off the high
def LOW1 = Lowest(low, 1);
def HIGH1 = Highest(high, 1);

plot HiTrail = HIGH1 - 1.00;# and midover;
plot LoTrail = LOW1 + 1.00 ;#and midunder;
 
Solution
I want to plot a $1.00 trailing stop in TOS. This is not a volatility-based stop. It is just the trailing stop TOS uses in Active Trader to exit a trade on a $1.00 pullback from the current high. I have tried a variety of codes, but I haven't gotten it right yet.

#Lookup 20_Trail 1.00
#20 period midprice long-short condition
def LO = Lowest(low, 20);
def HI = Highest(high, 20);
def MID = ((HI - LO) / 2 + LO);

def MidOver = high > mid;
def MidUnder = low < mid;

#$1.00 trailing stop off the high
def LOW1 = Lowest(low, 1);
def HIGH1 = Highest(high, 1);

plot HiTrail = HIGH1 - 1.00;# and midover;
plot LoTrail = LOW1 + 1.00 ;#and midunder; hal_stop


i think you are describing 2 things.
i think of a trailing stop as a line that...

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

I want to plot a $1.00 trailing stop in TOS. This is not a volatility-based stop. It is just the trailing stop TOS uses in Active Trader to exit a trade on a $1.00 pullback from the current high. I have tried a variety of codes, but I haven't gotten it right yet.

#Lookup 20_Trail 1.00
#20 period midprice long-short condition
def LO = Lowest(low, 20);
def HI = Highest(high, 20);
def MID = ((HI - LO) / 2 + LO);

def MidOver = high > mid;
def MidUnder = low < mid;

#$1.00 trailing stop off the high
def LOW1 = Lowest(low, 1);
def HIGH1 = Highest(high, 1);

plot HiTrail = HIGH1 - 1.00;# and midover;
plot LoTrail = LOW1 + 1.00 ;#and midunder; hal_stop


i think you are describing 2 things.
i think of a trailing stop as a line that starts from a buy signal, and is based on prices from several candles and can only rise or stay the same. it exists until it is crossed.
a stop based on just the current candle is something else. here is my interpretation.

it draws a,
..horizontal line, over the last 2 candles, and 1 candle space after them.
..a bubble with the stop level

if price crosses below the line, a down arrow appears.

can pick a number to subtract from the high,
..a number (like $1.00),
..or some multiple of the ATR (default is 90% of ATR)

i started with the original code and added an option to turn the lines off.


Code:
#stop_dollars_or_atr

#https://usethinkscript.com/threads/plot-a-1-00-trailing-stop.17019/#post-133368
#plot a $1.00 trailing stop

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

#def lastbn = HighestAll(If(IsNaN(close), 0, bn));
#def lastbar = if (bn == lastbn) then 1 else 0;
def lastbar = !isnan(close[0]) and isnan(close[-1]);

#Lookup 20_Trail 1.00
#20 period midprice long-short condition
def LO = Lowest(low, 20);
def HI = Highest(high, 20);
def MID = ((HI - LO) / 2 + LO);

def MidOver = high > MID;
def MidUnder = low < MID;


#$1.00 trailing stop off the high
def len1 = 1;
def LOW1 = Lowest(low, len1);
def HIGH1 = Highest(high, len1);

input show_original_lines = yes;
plot HiTrail = if show_original_lines then (HIGH1 - 1.00) else na;# and midover;
plot LoTrail = if show_original_lines then (LOW1 + 1.00) else na;#and midunder;

# choose atr or $$
input stop_type = { default amount, atr};
input stop_amount = 1.0;
input stop_atr_factor = 1.0;
def atr1 = atr();
def stop_atr = round(stop_atr_factor * atr1,2);

def stop_amt;
switch (stop_type) {
case amount:
    stop_amt = stop_amount;
case atr:
stop_amt = stop_atr;
}

def stop_lvl = round(high - stop_amt, 2);

addlabel(1, "stop amount " + stop_amt, color.yellow);
addlabel(1, "stop level " + stop_lvl, color.yellow);

def stop_line = if lastbar[-1] then stop_lvl[-1]
else if lastbar[0] then stop_lvl[0]
else if lastbar[1] then stop_lvl[1]
else na;

# plot a line on last 2 bars and next 1
input show_stop1_line = yes;
plot z1 = if show_stop1_line then stop_line else na;
z1.SetDefaultColor(Color.cyan);
z1.setlineweight(2);
z1.hidebubble();

def bub1 = 1;
addchartbubble(
 show_stop1_line and lastbar[bub1],
 stop_line[bub1-1],
 "H-\n" + stop_line[bub1]
, color.yellow, no);

# down arrow when price goes below stop level
plot z2 = if lastbar and close < stop_line then high*1.001 else na;
z2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
z2.SetDefaultColor(Color.cyan);
z2.setlineweight(3);
z2.hidebubble();

#

green candle
stop_amount = 1
EeHruLf.jpg


red candle
stop_amount = 0.3
JCJRyn9.jpg
 
Last edited:
Solution

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
379 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