Entry, Target, Profit Loss (PnL) Watchlists, Labels of Owned Equities In ThinkOrSwim

Sounds like it could possibly be a platform problem . . . did you try contacting TOS support?
I did not, yet. Figured they would shy away from 3rd party script issues. I have been searching my parameters for something I may have changed myself, but no luck so far.
When I go to Chart Settings>General>Show Trades, my entries don't show up in the native format either. This would normally indicate something I've changed in my custom chart settings but searching online, this native entry indicator has been having issues as well.
I am actually very surprised this isn't just a part of TOS out of the box, as it seems many folks are.
 

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

I am a new member and my first to share. I wrote two simple labels that would show on top of the chart as a label. I trade Equities.

Code:
#Code 1
# Portfolio Functions Label to display in the chart

def GetAveragePrice = GetAveragePrice();
def GetQuantity = GetQuantity();
def TargetPrice = Round((GetAveragePrice * .10) + GetAveragePrice); # Change Percent you wish as target price.
def pgain = if GetAveragePrice != 0 then close - GetAveragePrice else 0;

AddLabel(yes, " Pos: " + GetQuantity
       + " | Avg Price: $" + Round(GetAveragePrice)
        + " | Exit (10%) Price: $ " + TargetPrice
         + " | Price Gain: $ " + Round(pgain) + " "
            , if pgain > close then Color.green else Color.light_green);

#end of Code 1

#Code 2
# Profiting or Losing on Chart
# if Profiting background label to Green with $ amount
# if Losing background label to Light_Red with $ amount

def GetOpenPL = GetOpenPL();

AddLabel(yes, " P/L: $ " + Round(GetOpenPL) + " "
            , if GetOpenPL > 0 then Color.green else Color.light_red);

#end of Code 2

I hope that helps. Please let me know how if it works for you.

cabe1332
 
Last edited:
Thanks cabe1332 for the formula for "P/L:" That seems to get me the profit from Opening the position. Do you have a calculation to get the "P/L Day:"?
 
@epete I really did not need P/L Day since I really don't average into a position. When I enter I just let it ride. What I did though is add a percent to the P/L label. I feel that is more lucrative for me to take profits at a certain price range. Sorry about that.

Code:
# code
# Label if Profiting or Losing

def GetOpenPL = GetOpenPL();
def GetAveragePrice = GetAveragePrice();
def AvgPrice = if GetAveragePrice != 0 then close - GetAveragePrice else 0;

AddLabel(yes, " P/L: $ " + Round(GetOpenPL) + " | "  
        + (round((AvgPrice/GetAveragePrice)*100,2) + " %")
        , if GetOpenPL >= 0 then Color.green else Color.light_red);

# end code

Good luck!

cabe1332
 
@rlohmeyer TY for the great study..I use it everyday!! Is it possible to make for a watchlist...just so I don't have to cycle through trades all the time...Thank you again for this!!
 
@kmg526 There are Portfolio Watchlist functions that can be added to track Open P/L, Days P/L for each position, and others. Click settings to add a column and look under Portfolio. Here is a screen shot of the list. I am using the code previously shared on this discussion to show entry lines on your chart listed in post 19 by @wcsharron . I've posted it again below the screen shot. It was done by Mobius originally, a wizard coder.

oA70LkT.jpg


Code:
# Average Actual Entry
# Mobius
# 01.01.2018

# Removed portions of Mobius' code, added quantity and replaced Mobius' P/L
# calculation with GetOpenPL().
# Color-coded label, edited study look/colors for personal preference

def PL = GetOpenPL();
def c = if isNaN(close[-1]) then close else c[1];
def Entry = if isNaN(GetAveragePrice()) then Entry[1] else GetAveragePrice();
def LastEntryBar = if Entry != Entry[1] then barNumber() else LastEntryBar[1];

plot Entry_ = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0
              then highestAll(if isNaN(close[-1]) then Entry else double.nan) else double.nan;
     Entry_.SetStyle(Curve.SHORT_DASH);
     Entry_.SetLineWeight(3);
     Entry_.SetDefaultColor(color.BLUE);
     Entry_.HideBubble();
     Entry_.HideTitle();

AddLabel(1, "Qty: " + GetQuantity() + 
         "   Avg Cost $" + Entry +
         "   P/L: " + AsDollars(PL),
         if PL == 0 then color.cyan
         else if PL > 0 then color.green 
         else color.red);
# end code
 
Hi all, this is my finding when I tried to enable 'Show trade" on Thinkorswim".
I could not get the trades shown although I have the "show trade" checked on chart setting.
Solution used to be to go to TD Ameritrade site and enable "Advanced Features", now this option is not available and you won't be able to find "Advanced Features" on the website, so you need to request through Thinkorswim representative and it needs to go through an overnight update. The only down side is that your transaction history in ThinkorSwim will be wiped, however it's still available on the TD Ameritrade website(tdameritrade.com). My account > history & statements > transcations.
 
@Pensar, I must be the one unlucky soul who is having trouble with this. It does nit show up on my charts.
Are there any requirements, like restarting TOS, or having the study applied at the tune of the trade?
I had this issue too, and ended up having to apply for futures trading abilities to get advanced features, and now the script works!
 
Can someone please help me make a script that will automatically place a "Price Level" drawing connected to the candle\time when I buy into a position? When I buy into a stock, I like to draw a price line to the candle\exact price so I can visualize how my trades are doing versus looking at the watchlist or other windows.
 
Can someone please help me make a script that will automatically place a "Price Level" drawing connected to the candle\time when I buy into a position? When I buy into a stock, I like to draw a price line to the candle\exact price so I can visualize how my trades are doing versus looking at the watchlist or other windows.
The best you can do is use EntryPrice() similar to the code below... It should also account for multiple purchases...

Ruby:
plot tradePrice = if GetQuantity() > 0  then GetAveragePrice() else Double.NaN;
 
The best you can do is use EntryPrice() similar to the code below... It should also account for multiple purchases...

Ruby:
plot tradePrice = if GetQuantity() > 0  then GetAveragePrice() else Double.NaN;
Here's a link to the image of what that code did

Screenshot-2021-01-28-121603.png


I'm looking for something to do this with the "price level"

Screenshot-2021-01-28-121909.png
 
@Angry_Raven Correct... Because of the criteria you need to plot based on your trade, the code can only draw the line based on the duration of your trade... Other than that you would need to draw manually... The code I posted is working as expected... We have to live within the constraints of the TOS platform... Perhaps someone else has time or knows how to assist further... I don't even think the line will remain after the position is closed...
 
@Angry_Raven Correct... Because of the criteria you need to plot based on your trade, the code can only draw the line based on the duration of your trade... Other than that you would need to draw manually... The code I posted is working as expected... We have to live within the constraints of the TOS platform... Perhaps someone else has time or knows how to assist further... I don't even think the line will remain after the position is closed...
Either way. I still like what your code does. I'm happy with it for now so thank you a lot!
 
So I am looking to add a column that shows the market value of my positions in the position statement window under the activity and position tab. Is there a default one or I need to create a custom code for it.
 
I think there is a misunderstanding here...I would like to add a column for market value for each stock I hold. I can't find a default one so unless I missed it, I will have to create a custom code which is simply the avg price times the quantity of shares. I just don't know how to code on thinkorswim to create it myself.
Market-Value.jpg

Okay, problem solved. There is already a default column for it. Its called "net liquidity". Thanks
 
Here's a script that may help with Daily Profit/Loss goals and/or protect from big losses. I'd love to see if anyone has revisions or different variations to this.

Open position targets/losses may be a good one to add into the mix also.

Code:
input Daily = AggregationPeriod.DAY;


#plot YesterdayAccountNetLiq = if getlastday() == getday() then getnetliq() else double.nan;
declare lower;

#def previous = gettotalCash()[1];

#def today = gettotalCash();

#def nettoday = today-previous;

input DailyGoal = .04;
input DailyMaxLoss = .02;

def cash = gettotalCash();

def today = GetDay() == GetLastDay();
def todayNetLiq = GetNetLiq();
def yestNetLiq = if today then yestNetLiq[1] else GetNetLiq();
def TodayPL = todayNetLiq - yestNetLiq;

def DayDec = (todayNetLiq / yestNetLiq) - 1;

def DailyMaxLossNumber = round((highest(todaynetLiq)*dailyMaxLoss),0);

def DailyMaxLossFloor = (highest(todaynetLiq)-dailymaxLossnumber);

def TofaysPLhigh = highest(todaynetliq);

plot myvalue = (todayNetLiq / yestNetLiq);


AddLabel(yes, "   Today's Goal:  $" + Round((yestNetLiq * DailyGoal), 0) + "  (" + aspercent(dailyGoal) + ")   ", Color.WHITE);

AddLabel(yes, "   Today's P/L:  $" + TodayPL + "   ", if TodayPL > 0 then Color.GREEN else if TodayPL < 0 then Color.LIGHT_RED else Color.WHITE);

AddLabel(yes, "   % of Goal:  " + AsPercent((todayNetLiq - yestNetLiq)/(Round((yestNetLiq * DailyGoal), 0))) + "   ", if myvalue == 1 then Color.WHITE else if myvalue between 01 and 1.01 then color.light_green else if myvalue between 1.01 and 1.02 then getcolor(6) else if myvalue > 1.02 then Color.GREEN else if myvalue between -0.99 and -0.98 then color.red else if myvalue > -0.97 then Color.RED else Color.BLACK);

addlabel(yes, "   Daily Max Loss:  $" + highest(dailyMaxLossnumber) + "  (" + aspercent(dailymaxLoss) + ")   ", color.white);

AddLabel(yes, "***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***MAX LOSS***" + AsPercent((todayNetLiq / yestNetLiq) - 1), if (todayNetLiq < (DailyMaxLossFloor)) then Color.RED else Color.BLACK);

#This will change entire chart background:
#assignBackgroundColor(if myvalue == 0 then color.white else if myvalue > 0 then color.current else color.black);

#plot pct = (nettoday/previous);

#addlabel(yes, aspercent(pct));

#plot highestvalue = highest(myvalue);

NJM
 
I know this is an old thread but just found it.This works great for new trades but doesn't seem to recognize existing trades. the box shows up but it has no relevant content. Is there a waay to force it to find past trades? it worked great in new trades on paper trading.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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