Position Tool & Price Targets For ThinkOrSwim

MCreek

New member
In the art of giving back for all I have gained on this site I've been working on a position monitoring and pice target tool that shows trade information, cost, profit/loss, number of shares, long, short, etc. and price targets. I began testing this before the TDA and Schwab merger. There was some bugs in it after the merger but I think I have them worked out. It was ogrinally coded to only display whenyou opened a position on a stock, but following the merger it became problematic and wouldn't always display. I fixed it to remain on your chart as a label. It's a pretty straightforward tool to keep track of your positions and price targets. You can set your price target in the label settings, as well as change the background color of the main label. I added a few default tagerts by percent. {default "5%", "7%", "10%", "12%", "20%", "25%"}; just as a starting point bt you can easily change the hard code as you like.

You open a position and the secondary target label automatically calculates the sale price based on your entry price. The seconday label remains yellow until you reach your target and them turns green and also sends an audible alert.

I've purposely used in on winning and loosing trades and put it through the paces. I think it's a great tool. At least for me it is. I can see at a glance how my trade is doing.

Code:
 (don't include in the code stamsp script)

def qty = GetQuantity();
def avePrice = if qty != 0 then GetAveragePrice() else 0;
def openCost = qty * avePrice;
def netliq = qty * close;
def PL = netliq - openCost;
def price = close(priceType = PriceType.LAST);
#
input Label_Color_Choice = {"magneta", "cyan", default
"pink", "light.grey", "orange", "red", "light.green", "grey", "limelight", "white"};
#

#Add the label with position and P/L information
AddLabel(yes, (if qty > 0 then "Long " else if qty < 0 then "Short " else "No Position ") + AbsValue(qty) +
              " Shares  Cost $" + openCost + "  AvgPrice " + avePrice +
              "  P/L $" + PL + " = " + (if openCost != 0 then AsPercent(PL / openCost) else "0%"),
          GetColor(Label_Color_Choice));

#Input to select the target percentage
input targetPercentage = {default "5%", "7%", "10%", "12%", "20%", "25%"};

#Calculate the target price based on the selected percentage
def targetPrice = avePrice * (1 + (if targetPercentage == targetPercentage."5%" then 0.05 else
                                   if targetPercentage == targetPercentage."7%" then 0.07 else
                                   if targetPercentage == targetPercentage."10%" then 0.10 else
                                   if targetPercentage == targetPercentage."12%" then 0.12 else
                                   if targetPercentage == targetPercentage."20%" then 0.20 else
                                   if targetPercentage == targetPercentage."25%" then 0.25 else 0));

# Define the condition for reaching the target price
def targetReached = close >= targetPrice;

# Add the label with conditional color
AddLabel(yes, "TargetPrice $" + targetPrice, if targetReached then Color.GREEN else Color.YELLOW);

# Add audible alert when target price is reached
Alert(targetReached, "Target Price Reached!", Alert.BAR, Sound.Chimes);
(don't include in the code stamsp script)

Happy Trading!! GLTA!!

Screenshot 2024-08-14 182059.png
Screenshot 2024-08-14 182020.png
Screenshot 2024-08-14 182222.png
 

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