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

Hi Gang,

This is just what I was looking to add to my charts... Why TOS doesn't have this feature is beyond me....

To take this feature 1-step further, is there any way to add the "P/L Percentage" in parenthesis to the right of the P/L dollar figure? 🤔
 
@evanevans You mentioned creating an P/L cloud in another thread based on the average cost. Here is a snippet for adding a P/L cloud to this code, may want to test it before using. I ran it today in PaperMoney to test the cloud plots.

Code:
input show_cloud = yes;
def up = if PL > 0 then Entry_ else double.nan;
def dn = if PL < 0 then Entry_ else double.nan;
AddCloud(if show_cloud then up else double.nan,hl2,color.green, color.green);
AddCloud(if show_cloud then dn else double.nan,hl2,color.red,color.red);

hLV2kFQ.png
 
I want to display a simple P/L open label on an upper chart and have the following code:

Code:
def PLOpen =  GetOpenPL();

AddLabel (yes, "P/L: " + if ( PLOpen >= 0 ) then PLOpen else PLOpen, if PLOpen > 0 then Color.Black else Color.Red);
# if PL > 0 then CreateColor(0,0,0) else CreateColor(255,0,0);

Instead of displaying "0" if there is no open position, the chart label doesn't show up at all and in its place there is a small error icon (an exclamation point in a circle) on the chart. This is going to be visually distracting to have the label pop in and out of existence based on the existence of a temporarily open position. Is there a simple way to structure an if/then/else or other type of conditional to cause "0" or "No Position" to display when GetOpenPL is returning a null value (ideally, in this case I'd also like the color of the label to be gray instead of red or black - I haven't figured out a way to have three potential label colors either, only two based on if/then/else)?
 
Last edited:
@lmk99 Is this more what you are looking for...??? The label should only display if there is an open trade...

Code:
def PLOpen =  GetOpenPL();

AddLabel (GetQuantity() > 0, "P/L: " + AsText(PLOpen, NumberFormat.DOLLAR), if PLOpen > 0 then Color.GREEN else if PLOpen < 0 then Color.RED else Color.GRAY);
 
Last edited:
@rad14733 The label wasn't displaying before because the 8 minute aggregation period wasn't supported for Portfolio functions. It works on the 5min chart. I want the label to indicate no position instead of disappearing when there's no open position, so it's OK for my purposes that it currently shows "P/L Open: 0" in that case. However I really appreciate your improvement of using "NumberFormat.DOLLAR" - thanks for that, I have made that update to my code!
 
I also use a snippet of code in another script I have on my charts that draws a line at my entry point. I plot it as dots rather than a line. Once I am out of the trade on a specific bar, I can easily tell which bar I exited on. See jpg below and code beneath.

What I was hoping to find was how to change the color of the line based on whether I entered short or long. Anyone have suggestions?

WWhJOnD.jpg


Code:
#Entry Line
declare upper;
def EP = Round(GetAveragePrice(),2);
Plot EntryLine = EP;
 
I could really use that feature, could you advise on how to enter the code? I use a mac so would I just open a monitor and cut ans paste the code?
Thanks for the help

I am curious what I am doing wrong, I go to setup - application settings - my profile, but there are no "advanced features" to enable or disable?
 
Last edited by a moderator:
@desertskies

The code below will place a label on your chart with your entry point plus gives you a label for your pesent Profit or Loss on the trade. You would simply paste this code into a new indicator and you are set to go.
I have found this to be the easiest/most relaibel way to track the entry.

On a chart you would click the Studies icon at the top of the chart, then "edit sudies", then "create".....give your new study a name you will remember, and paste the code below into it. Add it to you chart and you should be good to go.

Code:
def EP = Round(GetAveragePrice(), 2);
def PrLs = GetOpenPL();
def UPDN = EP + GetOpenPL();
AddLabel (yes, "Entry: " + EP, Color.CYAN);
AddLabel (if UPDN <> EP then yes else no, "PrLs: $" + PrLs , if UPDN > EP then Color.GREEN else Color.RED);
 
@Pensar I'm wondering if there's a way to plot lines indicator to let you get out at 5% Stop loss and/or at 10% gain. Idk if @BenTen knows the code to add that? Unless there's already a post on here that I missed.
 
I'm wondering if there's a way to plot lines indicator to let you get out at 5% Stop loss and/or at 10% gain. Idk if @BenTen knows the code to add that? Unless there's already a post on here that I missed.
@AnakManis Try adding this code snippet to the code you quoted above. It will only display when you are in a trade.

Code:
plot "5% Stop" = if Entry_ then Entry_ - .05*Entry else double.nan;
     "5% Stop".SetDefaultColor(color.red);

plot "10% Target" = if Entry_ then Entry_ + .10*Entry else double.nan;
     "10% Target".SetDefaultColor(color.green);
 
@wcsharron Glad you liked it! No payment needed, but if you want, you could pick up a VIP membership here at usethinkscript. :)
@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?
 
@Kylep19 - The lines will only show on the chart when you enter a trade, but there should be a cyan colored label showing in the upper left corner of your chart.
 
Yes, I have tried on charts with positions held. If it helps to indicate something, the cyan label on my chart is black. I can barely read the font in the negative space.
 
@Kylep19 If you are testing it in PaperMoney, it may have problems showing. Someone else I know of had that problem, but after a while the indicator worked again. I have no idea why, maybe the portfolio functions used are not supported in PaperMoney, but I'm just guessing here.
 
@Kylep19 Maybe try this code, although I think it's the same as in post #19. I'm running it now, and its working fine -

Code:
# Average Actual Entry
# Mobius
# 01.01.2018

# Pensar @ usethinkscript.com
# Removed portions of Mobius' code, added quantity and replaced Mobius' P/L
# calcuation with GetOpenPL() to show P/L more accurately.
# 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.FIRM);
     Entry_.SetLineWeight(1);
     Entry_.SetDefaultColor(color.BLUE);
     Entry_.HideBubble();
     Entry_.HideTitle();

plot "5% Stop" = if Entry_ then Entry_ - .05*Entry else double.nan;
     "5% Stop".SetDefaultColor(color.red);

plot "10% Target" = if Entry_ then Entry_ + .10*Entry else double.nan;
     "10% Target".SetDefaultColor(color.green);

AddLabel(1, "Qty: " + GetQuantity() +
         "   Avg $" + Entry +
         "   P/L: " + AsDollars(PL) + "   Max L: " + AsDollars(Entry*GetQuantity()),
         if PL == 0 then color.gray
         else if PL > 0 then color.green
         else color.red);

# end code
 
@Pensar, thanks for the info. It is still acting the same, and no paper account usage here. The odd thing is the cyan box you mentioned being blacked out on my screen, yet still there. Oh, and I tried the most recent script, same thing.
odd.
Here is a what the indicator tile looks like. Note, all the NaN values. This is on a live account chart I have been holding a position in since Yesterday.
https://www.screencast.com/t/DAFf4GQlwdk
 
Last edited:
@Pensar, thanks for the info. It is still acting the same, and no paper account usage here. The odd thing is the cyan box you mentioned being blacked out on my screen, yet still there. Oh, and I tried the most recent script, same thing.
odd.
Sounds like it could possibly be a platform problem . . . did you try contacting TOS support?
 

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