# 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...
this kinda works
Code:
``````declare upper;

input length = 10;
input stop = 1.0;

plot mark = highest(high, length);
plot trail = mark - stop;``````

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

#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;
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

red candle
stop_amount = 0.3

Last edited:
Trailing Stop Loss Percent Plot Questions 2
Plot trailing stop Questions 1
Plot horizontal line at keltner channel Questions 2
Fluctuating Plot Line vs Static Questions 1
plot horizontal line specific time Questions 1

87k+ Posts
379 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?