UT Bot For ThinkOrSwim

ttsdmagic

Member
Interesting. It would be great if one of the developers here could compare the original TradingView to the conversion to validate the quality of the conversion. Any takers?
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
mod note:
The indicator that is the subject of this thread is NOT A REPAINTING INDICATOR.
This is an ATR Trailing Stop script written for use with Heiken Ashi candles


@ttsdmagic, @Nomak, @rip78, This script uses close to define the price. In the ToS, "close" means "last", the most current tick price.
So, as @Tradervic pointed out, on the most current candle the "close" will fluctuate with the "last" price until the bar completes. No idea, if Tradingview uses the same concept.

To read more about ATR Trailing Stops and how to use them:
https://www.incrediblecharts.com/indicators/atr_average_true_range_trailing_stops.php

PS: There was a chart setup posted to this thread that used a ZigZag study. Yes, ZigZags re-paint. So to not hijack this thread, discussions of using this indicator combined with repainting indicators have been moved to: https://usethinkscript.com/threads/atr-trailing-stop-zig-zag-chart-setup.14264/
 
Last edited:

calvin8tor

New member
VIP
Thank you @ttsdmagic for posting this indicator. It works great. Since I use 2 min and 5 min timeframe to trade, but the watchlist doesn't get updated within that timeframe when using the scan search posted in #7 . I hope it is alright that I took the liberty to modify the indicator so that would work in the watchlist column. I'm still new to code in thinkscript. All I did was really simple. I added the three lines of code below right after the statement (def sell = src < xATRTrailingStop and below) and then delete the rest of the code. The 1 and -1 is just random numbers for me to sort the column and also can be displayed on my mobile app. I hope this help!
Code:
plot UT_Bot = if buy then 1 else if sell then -1 else 0;
AssignBackgroundColor(if buy then color.dark_green else if sell then color.red else color.gray);
UT_Bot.assignValueColor(color.black);

Here is what the column looks like.
cnM1icn.png
 

ttsdmagic

Member
Hello calvin8tor . I'm glad you're able to use the study. Looks like a great enhancement to the code for shorter time frame use on your watchlist. If anyone else is using this study and can suggest improvements, bring em on. When I first saw this one on TradingView it looked like it had potential to offer good Buy and Sell signals. I'll keep checking back here to see what others are experiencing.
 

indiciatorhead

New member
https://usethinkscript.com/threads/ut-bot-for-thinkorswim.12640/#post-116615

Code:
# ATR Trailing Stop
# https://usethinkscript.com/threads/ut-bot-for-thinkorswim.12640/#post-116615

input Key_Vaule = 1.0;
def a = key_vaule;# input(1, title = "Key Vaule. 'This changes the sensitivity'")
input atr_period = 10;
def c = atr_period; # input(10, title = "ATR Period")
input Signals_from_Heikin_Ashi_Candles = no;
def h = signals_from_Heikin_Ashi_Candles; # input(false, title = "Signals from Heikin Ashi Candles")
input show_labels = yes;

def xATR = atr(c);
def nLoss = a * xATR;


def src = if h then (open + high + low + close) / 4 else close;

script nz{
input x = close;
input y = 0;
plot result = if isnan(x) then y else x;
}

#xATRTrailingStop = 0.0
def xATRTrailingStop =compoundValue(1, if(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src - nLoss),
if(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss),
if(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss))),0);

#pos = 0
def pos = compoundValue(1, if(src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0), 1,
if(src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) , 0);

def ema = expaverage(src,1);
def above = crosses(ema, xATRTrailingStop, crossingDirection.ABOVE);
def below = crosses(xATRTrailingStop, ema, crossingDirection.ABOVE);

def buy = src > xATRTrailingStop and above ;
def sell = src < xATRTrailingStop and below;

def barbuy = src > xATRTrailingStop ;
def barsell = src < xATRTrailingStop ;

defineglobalColor("Green", color.Green);
defineglobalcolor("Red", color.Red);
addchartbubble(show_labels and buy, low, "B", globalColor("Green"), no);
addchartbubble(show_labels and sell, high, "S", globalColor("Red"), yes);

input price_color_on = yes;
assignPriceColor(if !price_color_on then color.current else if barbuy then globalColor("Green") else color.CURRENT);
assignpriceColor(if !price_color_on then color.current else if barsell then globalColor("Red") else color.currENT);

input alert_sound_on = no;
alert(buy, "UT Long", alert.bar,if alert_sound_on then sound.ring else sound.NoSound);
alert(sell, "UT Short", alert.bar,if alert_sound_on then sound.bell else sound.NoSound);

arrow pointing up under candle for buy and arrow pointing down on top of candle indicating sell.

@halcyonguy any ideas?
 
Last edited by a moderator:

indiciatorhead

New member
Hello calvin8tor . I'm glad you're able to use the study. Looks like a great enhancement to the code for shorter time frame use on your watchlist. If anyone else is using this study and can suggest improvements, bring em on. When I first saw this one on TradingView it looked like it had potential to offer good Buy and Sell signals. I'll keep checking back here to see what others are experiencing.
hey man I am enjoying this script. If there's anything I could suggest would it be possible to add custom arrows instead of buy sell labels? I would love to be able to have an arrow pointing under the candle signaling buy and an another arrow pointing down on top of the candle signaling sell. Anyway there can be an updated script for that? other than that this script is awesome!
 

HODL-Lay-HE-hoo!

Well-known member
There you go.


Code:
# ATR Trailing Stop
# https://usethinkscript.com/threads/ut-bot-for-thinkorswim.12640/#post-116615

input Key_Vaule = 1.0;
def a = key_vaule;# input(1, title = "Key Vaule. 'This changes the sensitivity'")
input atr_period = 10;
def c = atr_period; # input(10, title = "ATR Period")
input Signals_from_Heikin_Ashi_Candles = no;
def h = signals_from_Heikin_Ashi_Candles; # input(false, title = "Signals from Heikin Ashi Candles")
input show_labels = yes;

def xATR = atr(c);
def nLoss = a * xATR;


def src = if h then (open + high + low + close) / 4 else close;

script nz{
input x = close;
input y = 0;
plot result = if isnan(x) then y else x;
}

#xATRTrailingStop = 0.0
def xATRTrailingStop =compoundValue(1, if(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src - nLoss),
if(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss),
if(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss))),0);

#pos = 0
def pos = compoundValue(1, if(src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0), 1,
if(src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) , 0);

def ema = expaverage(src,1);
def above = crosses(ema, xATRTrailingStop, crossingDirection.ABOVE);
def below = crosses(xATRTrailingStop, ema, crossingDirection.ABOVE);

def buy = src > xATRTrailingStop and above ;
def sell = src < xATRTrailingStop and below;

def barbuy = src > xATRTrailingStop ;
def barsell = src < xATRTrailingStop ;

defineglobalColor("Green", color.Green);
defineglobalcolor("Red", color.Red);
addchartbubble(show_labels and buy, low, "B", globalColor("Green"), no);
addchartbubble(show_labels and sell, high, "S", globalColor("Red"), yes);

Def buy1 = src > xATRTrailingStop and above ;
Def sell1 = src < xATRTrailingStop and below;

Def buy2= buy1;
buy2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Buy2.SetDefaultColor(Color.GREEN);
Buy2.SetLineWeight(1);

Def sell2 = sell1;
sell2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Sell2.SetDefaultColor(Color.Red);
Sell2.SetLineWeight(1);

input price_color_on = yes;
assignPriceColor(if !price_color_on then color.current else if barbuy then globalColor("Green") else color.CURRENT);
assignpriceColor(if !price_color_on then color.current else if barsell then globalColor("Red") else color.currENT);

input alert_sound_on = no;
alert(buy, "UT Long", alert.bar,if alert_sound_on then sound.ring else sound.NoSound);
alert(sell, "UT Short", alert.bar,if alert_sound_on then sound.bell else sound.NoSound);
 
Last edited:

indiciatorhead

New member
hey @HODL-Lay-HE-hoo! sorry to bother you but this is the error I see in both scripts. it automatically says "plot colors are dynamically set" not sure if that's something you're able to change. The option to select a color would ideally be open to select right under width for the Buy1 and Sell1. section. Not a big issue if it can't be changed. Thank you!
K5w0Wnr.png
YlvJT52.png
 

HODL-Lay-HE-hoo!

Well-known member
hey @HODL-Lay-HE-hoo! sorry to bother you but this is the error I see in both scripts. it automatically says "plot colors are dynamically set" not sure if that's something you're able to change. The option to select a color would ideally be open to select right under width for the Buy1 and Sell1. section. Not a big issue if it can't be changed. Thank you!
K5w0Wnr.png
YlvJT52.png
Edited the code you SHOULD be able to edit the colors in settings now.. I’ll verify when I get to my computer. 10th time is a charm.
 

samer800

Well-known member
@samer800 can you please help? I just need one line in the script to be able to add color to the arrows. :(
not sure if this what you want.

CSS:
# ATR Trailing Stop
# https://usethinkscript.com/threads/ut-bot-for-thinkorswim.12640/#post-116615

input Key_Vaule = 1.0;
def a = key_vaule;# input(1, title = "Key Vaule. 'This changes the sensitivity'")
input atr_period = 10;
def c = atr_period; # input(10, title = "ATR Period")
input Signals_from_Heikin_Ashi_Candles = no;
def h = signals_from_Heikin_Ashi_Candles; # input(false, title = "Signals from Heikin Ashi Candles")
input SignalStyle = {Default "Arrow", "Label", "None"};

def na = Double.NaN;
defineglobalColor("Green", color.Green);
defineglobalcolor("Red", color.Red);


def arrow = SignalStyle==SignalStyle."Arrow";
def Label = SignalStyle==SignalStyle."Label";
def SigStyle = if arrow then 1 else if Label then -1 else 0;
def xATR = atr(c);
def nLoss = a * xATR;


def src = if h then (open + high + low + close) / 4 else close;

script nz{
input x = close;
input y = 0;
plot result = if isnan(x) then y else x;
}

#xATRTrailingStop = 0.0
def xATRTrailingStop =compoundValue(1, if(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src - nLoss),
if(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss),
if(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss))),0);

#pos = 0
def pos = compoundValue(1, if(src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0), 1,
if(src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) , 0);

def ema = expaverage(src,1);
def above = crosses(ema, xATRTrailingStop, crossingDirection.ABOVE);
def below = crosses(xATRTrailingStop, ema, crossingDirection.ABOVE);

def buy = src > xATRTrailingStop and above ;
def sell = src < xATRTrailingStop and below;

def barbuy = src > xATRTrailingStop ;
def barsell = src < xATRTrailingStop ;

plot ArrowUp = if Arrow and buy then low - ATR(5)/10 else na;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetDefaultColor(globalColor("Green"));
ArrowUp.SetLineWeight(2);
plot ArrowDn = if Arrow and sell then high + ATR(5)/10 else na;
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.SetDefaultColor(globalColor("Red"));
ArrowDn.SetLineWeight(2);



addchartbubble(Label and buy, low, "B", globalColor("Green"), no);
addchartbubble(Label and sell, high, "S", globalColor("Red"), yes);

input price_color_on = yes;
assignPriceColor(if !price_color_on then color.current else if barbuy then globalColor("Green") else color.CURRENT);
assignpriceColor(if !price_color_on then color.current else if barsell then globalColor("Red") else color.currENT);

input alert_sound_on = no;
alert(buy, "UT Long", alert.bar,if alert_sound_on then sound.ring else sound.NoSound);
alert(sell, "UT Short", alert.bar,if alert_sound_on then sound.bell else sound.NoSound);
 

swaroop472

New member
I am searching for a functional script of UT Bot Alerts, a trading indicator that signals buying and selling, on Thinkorswim platform. Although I used Chat GPT to convert the script, it didn't provide me with a working version. Is there anyone who can assist me by sharing a functional script?
 

Chaomane

New member
Any way to port this to work on the mobile ToS app?? Maybe it doesn't work simply because it's a strategy and not a study but im not sure!
 

captbob123

New member
VIP
I am searching for a functional script of UT Bot Alerts, a trading indicator that signals buying and selling, on Thinkorswim platform. Although I used Chat GPT to convert the script, it didn't provide me with a working version. Is there anyone who can assist me by sharing a functional script?
Did you ever get the Ut bot to work in tos??
 

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
234 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.
Top