Position Tool For ThinkOrSwim

Phil

New member
I love the TradingView position tool and have always wanted something similar built into Thinkorswim. I finally decided to attempt to create my own tool based on ATR. All you have to do is enter your position and choose short or long. You can set the ATR period, multiplier for stop loss, and multiplier for take profit. I looked for something on this forum but I had no real luck.

Don't know if anyone will find it useful but I use it for every trade so I thought I would share it. Let me know if it's as useful to you as it is to me.

Rich (BB code):
# Position Tool Proxy with ATR Multipliers for Thinkorswim
input PositionType = {default Long, Short};
input EntryPrice = 0.0;                     # Base entry price
input ATRPeriod = 14;                       # ATR period (default 14)
input averageType = AverageType.WILDERS;
input StopLossATRMultiplier = 1.5;          # Stop loss as multiple of ATR (e.g., 1.5x)
input TakeProfitATRMultiplier = 2.0;        # Take profit as multiple of ATR (e.g., 2.0x)
input ShowLabels = yes;



# Calculate ATR
def ATR = MovingAverage(averageType, TrueRange(high, close, low), ATRPeriod);

# Calculate Stop and Profit Prices based on ATR and Position Type
def StopLossPrice = if PositionType == PositionType.Long
                    then EntryPrice - (ATR * StopLossATRMultiplier)
                    else EntryPrice + (ATR * StopLossATRMultiplier);
def TakeProfitPrice = if PositionType == PositionType.Long
                      then EntryPrice + (ATR * TakeProfitATRMultiplier)
                      else EntryPrice - (ATR * TakeProfitATRMultiplier);

# Plot the lines
plot EntryLine = if EntryPrice > 0 then EntryPrice else Double.NaN;
plot StopLine = if StopLossPrice > 0 then StopLossPrice else Double.NaN;
plot ProfitLine = if TakeProfitPrice > 0 then TakeProfitPrice else Double.NaN;

AddCloud(EntryLine, StopLine, Color.light_red, Color.light_red);
AddCloud(EntryLine, ProfitLine, Color.light_green, Color.light_green);

# Styling
EntryLine.SetDefaultColor(Color.YELLOW);
EntryLine.SetLineWeight(2);
EntryLine.SetStyle(Curve.FIRM);

StopLine.SetDefaultColor(Color.RED);
StopLine.SetLineWeight(2);
StopLine.SetStyle(Curve.FIRM);

ProfitLine.SetDefaultColor(Color.GREEN);
ProfitLine.SetLineWeight(2);
ProfitLine.SetStyle(Curve.FIRM);

# Labels
AddLabel(ShowLabels and EntryPrice > 0, "Entry: " + EntryPrice, Color.YELLOW);
AddLabel(ShowLabels and StopLossPrice > 0, "Stop: " + Round(StopLossPrice, 2), Color.RED);
AddLabel(ShowLabels and TakeProfitPrice > 0, "Profit: " + Round(TakeProfitPrice, 2), Color.GREEN);
AddLabel(ShowLabels, "ATR: " + Round(ATR, 2), Color.GRAY);

# Risk-Reward
def Risk = if PositionType == PositionType.Long then EntryPrice - StopLossPrice else StopLossPrice - EntryPrice;
def Reward = if PositionType == PositionType.Long then TakeProfitPrice - EntryPrice else EntryPrice - TakeProfitPrice;
def RRRatio = if Risk != 0 then Round(Reward / Risk, 2) else Double.NaN;
AddLabel(ShowLabels and Risk > 0 and Reward > 0, "R:R = " + RRRatio, Color.WHITE);
 
Last edited by a moderator:
@Phil:

I have envied TradingView users for a long time, as they have enjoyed the availability of the TV Position tool for quite some time now...I have lamented the fact that the TOS developers have not addressed this by now...

The wait is over! Imagine my surprise and glee as I stumbled across your Position tool recently...I really like the incorporation of ATR...As a result, I have deployed your Position Tool on all of my charts...

Thanks for sharing...
 
@Phil:

I have envied TradingView users for a long time, as they have enjoyed the availability of the TV Position tool for quite some time now...I have lamented the fact that the TOS developers have not addressed this by now...

The wait is over! Imagine my surprise and glee as I stumbled across your Position tool recently...I really like the incorporation of ATR...As a result, I have deployed your Position Tool on all of my charts...

Thanks for sharing...
Thanks for responding and I'm glad you think it's useful. I'm happy to have it and use it for almost every trade. Here's one that doesn't use ATR but autocalcs your take profit based on your stop loss and preferred ratio. Thanks again.


Rich (BB code):
# Position Tool Proxy with Manual Stop and Ratio-Based Profit for Thinkorswim
input PositionType = {default Long, Short};
input EntryPrice = 0.0;                     # Manual entry price
input StopLossPrice = 0.0;                  # Manual stop loss price
input TakeProfitRatio = 2.0;                # Risk:Reward ratio (e.g., 2.0 = 2:1)
input ShowLabels = yes;

# Calculate Risk (absolute distance from entry to stop)
def Risk = if PositionType == PositionType.Long
           then EntryPrice - StopLossPrice
           else StopLossPrice - EntryPrice;

# Calculate Take Profit Price based on Risk and Ratio
def TakeProfitPrice = if PositionType == PositionType.Long
                      then EntryPrice + (Risk * TakeProfitRatio)
                      else EntryPrice - (Risk * TakeProfitRatio);

# Plot the lines
plot EntryLine = if EntryPrice > 0 then EntryPrice else Double.NaN;
plot StopLine = if StopLossPrice > 0 then StopLossPrice else Double.NaN;
plot ProfitLine = if TakeProfitPrice > 0 then TakeProfitPrice else Double.NaN;

AddCloud(EntryLine, StopLine, Color.light_red, Color.light_red);
AddCloud(EntryLine, ProfitLine, Color.light_green, Color.light_green);

# Styling
EntryLine.SetDefaultColor(Color.YELLOW);
EntryLine.SetLineWeight(2);
EntryLine.SetStyle(Curve.FIRM);

StopLine.SetDefaultColor(Color.RED);
StopLine.SetLineWeight(2);
StopLine.SetStyle(Curve.FIRM);

ProfitLine.SetDefaultColor(Color.GREEN);
ProfitLine.SetLineWeight(2);
ProfitLine.SetStyle(Curve.FIRM);

# Labels
AddLabel(ShowLabels and EntryPrice > 0, "Entry: " + EntryPrice, Color.YELLOW);
AddLabel(ShowLabels and StopLossPrice > 0, "Stop: " + Round(StopLossPrice, 2), Color.RED);
AddLabel(ShowLabels and TakeProfitPrice > 0, "Profit: " + Round(TakeProfitPrice, 2), Color.GREEN);

# Risk-Reward (for verification)
def Reward = if PositionType == PositionType.Long then TakeProfitPrice - EntryPrice else EntryPrice - TakeProfitPrice;
def RRRatio = if Risk != 0 then Round(Reward / Risk, 2) else Double.NaN;
AddLabel(ShowLabels and Risk > 0 and Reward > 0, "R:R = " + RRRatio, Color.WHITE);
 
I have been meaning to research this exact tool!
How do I use it in TOS? as a study or a strategy? I'm not sure where to add the code.
 
@PennnysPapi:

It is a Study...

With ATR: https://usethinkscript.com/threads/position-tool-for-thinkorswim.20717/post-151500

Without ATR: https://usethinkscript.com/threads/position-tool-for-thinkorswim.20717/post-151552

How to import a Study:

1. Click on "Studies"...from the Chart menu... (top right side)
2. Click on "Edit Studies"...
3. In the Edit Studies and Strategies window...below the listed Studies...click on "Import"
4. In the "Load STUDY" window...Browse to the folder where you saved your study
5. Make sure to save your study with a .ts extension... (ex. my_position_tool_study.ts)
6. Click and select the study to import...
7. Click "Open"...

How to backup your Studies:

1. Click on "Studies"...from the Chart menu...
2. Click on "Edit Studies"...
3. In Edit Studies and Strategies window...under the Studies tab...in the Search box...click the Down Arrow...
4. Click and select "User Defined"...
5. Click and select all the studies you want to transfer...
6. Right-click on those studies and select "Export"...
7. Specify/Create the destination folder for the exported studies...
8. Click "Save"...

Hope this helps...

Good Luck and Good Trading :cool:
 
Last edited:
Thanks for responding and I'm glad you think it's useful. I'm happy to have it and use it for almost every trade. Here's one that doesn't use ATR but autocalcs your take profit based on your stop loss and preferred ratio. Thanks again.


Rich (BB code):
# Position Tool Proxy with Manual Stop and Ratio-Based Profit for Thinkorswim
input PositionType = {default Long, Short};
input EntryPrice = 0.0;                     # Manual entry price
input StopLossPrice = 0.0;                  # Manual stop loss price
input TakeProfitRatio = 2.0;                # Risk:Reward ratio (e.g., 2.0 = 2:1)
input ShowLabels = yes;

# Calculate Risk (absolute distance from entry to stop)
def Risk = if PositionType == PositionType.Long
           then EntryPrice - StopLossPrice
           else StopLossPrice - EntryPrice;

# Calculate Take Profit Price based on Risk and Ratio
def TakeProfitPrice = if PositionType == PositionType.Long
                      then EntryPrice + (Risk * TakeProfitRatio)
                      else EntryPrice - (Risk * TakeProfitRatio);

# Plot the lines
plot EntryLine = if EntryPrice > 0 then EntryPrice else Double.NaN;
plot StopLine = if StopLossPrice > 0 then StopLossPrice else Double.NaN;
plot ProfitLine = if TakeProfitPrice > 0 then TakeProfitPrice else Double.NaN;

AddCloud(EntryLine, StopLine, Color.light_red, Color.light_red);
AddCloud(EntryLine, ProfitLine, Color.light_green, Color.light_green);

# Styling
EntryLine.SetDefaultColor(Color.YELLOW);
EntryLine.SetLineWeight(2);
EntryLine.SetStyle(Curve.FIRM);

StopLine.SetDefaultColor(Color.RED);
StopLine.SetLineWeight(2);
StopLine.SetStyle(Curve.FIRM);

ProfitLine.SetDefaultColor(Color.GREEN);
ProfitLine.SetLineWeight(2);
ProfitLine.SetStyle(Curve.FIRM);

# Labels
AddLabel(ShowLabels and EntryPrice > 0, "Entry: " + EntryPrice, Color.YELLOW);
AddLabel(ShowLabels and StopLossPrice > 0, "Stop: " + Round(StopLossPrice, 2), Color.RED);
AddLabel(ShowLabels and TakeProfitPrice > 0, "Profit: " + Round(TakeProfitPrice, 2), Color.GREEN);

# Risk-Reward (for verification)
def Reward = if PositionType == PositionType.Long then TakeProfitPrice - EntryPrice else EntryPrice - TakeProfitPrice;
def RRRatio = if Risk != 0 then Round(Reward / Risk, 2) else Double.NaN;
AddLabel(ShowLabels and Risk > 0 and Reward > 0, "R:R = " + RRRatio, Color.WHITE);

@Phil:

I like this variation, but I like the ATR version more :) With that said, is there a chance that you might be interested in developing these position tools further to incorporate position sizing as well?

I've been working for some time on trying to come up with a Position Risk Manager to no avail...I'm thinking now it might just be possible...

Here is a thread showing what I've been working on for some time...

https://usethinkscript.com/threads/working-on-a-trade-calculator-for-thinkorswim.917/post-5592

I'm hoping you might take a look when you have a chance to do so...

Given how important it is to assess and define your risk with each trade, I'm thinking that a Position Risk Management tool / Trade Calculator would be a big hit in the uTS community...I'm going to extend this invitation to @Ajordan930 and @snoopydoopy with the hope that the more people get involved (crowdsourcing), the better the chances are for eventual success...

Thank you for your time and potential consideration...Much appreciated!

Good Luck and Good Trading :cool:
 

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