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

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.

You can't display past trades, only active trades using EntryPrice()... Past trades are only viewable on the Monitor tab... Thinkscript cannot access historical trade data...
 

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

@kalyan Try this code by Mobius -

Code:
# Plotting Average Actual Entry
# Mobius
# 01.01.2018

input HardStop = 3.00;
input Dir = {default long, short};

plot hide = double.nan;
     hide.setDefaultColor(Color.Black);
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.Long_Dash);
     Entry_.SetLineWeight(3);
     Entry_.SetDefaultColor(CreateColor(255,215,0));
     Entry_.HideBubble();
     Entry_.HideTitle();
def PL = if Entry > 0 then Entry - c else 0;
AddChartBubble(barNumber() == HighestAll(barNumber()), Entry_, "AVG " +AsDollars(Entry), Entry_.TakeValueColor());
#Alert(c crosses below Entry, "", Alert.Bar, Sound.Chimes);
#Alert(c crosses above Entry, "", Alert.Bar, Sound.Ring);
plot stop;
switch (Dir)
{
case long:
    stop = Entry_ - HardStop;
case short:
    stop = Entry_ + HardStop;
}
#Alert(close crosses stop, "STOP", Alert.Bar, Sound.Bell);
# End Code

Also, try creating a watchlist and select "current account positions". Then, choose your desired columns, such as "Avg Price", "P/L %", "P/L Open", etc.
You can't display past trades, only active trades using EntryPrice()... Past trades are only viewable on the Monitor tab... Thinkscript cannot access historical trade data...
I didn't word it correctly I guess, these are trades I'm currently in but the script only seems to recognize trades I've entered since adding the script, if that makes sense?
 
Hi,

Is there anyway we could have a chart study that shows the P/L for the placed limit Sell orders to close an existing position? The P/L is shown in the Active Trader ladder with customization to add the P/L to the table but it is not easy to get the right amount unless you zoom out the values.

appreciate all the support
 
Hi,

Is there anyway we could have a chart study that shows the P/L for the placed limit Sell orders to close an existing position? The P/L is shown in the Active Trader ladder with customization to add the P/L to the table but it is not easy to get the right amount unless you zoom out the values.

appreciate all the support

I have no problem with the Open P/L in the Active Trader Ladder or my customized Current Account Positions watchlist but I do have a Chart Label that updates along with the rest... Here you go...

Ruby:
def PLOpen =  GetOpenPL();

AddLabel (yes, "P/L: " + AsText(PLOpen, NumberFormat.DOLLAR), if PLOpen > 0 then Color.GREEN else if PLOpen < 0 then Color.RED else Color.LIGHT_GRAY);
 
The watchlist P/L and P/L% that are available are averaging all of my positions in each stock. I would like to see the values reflect only my current open positions so that I can sort by them.

The trouble I am running into is that the functions for GetAveragePrice and GetOpenPL are not available to use in the editor for the watchlist.
I have no trouble using them on the chart.

Is there a workaround to get this info into a watchlist?
 
@KPasciak Beyond the currently available columns that @Pensar mentioned, you can calculate the rest based on those columns and functions like GetQuantity() to create Custom Watchlist Columns...
 
Last edited by a moderator:
Hi- Below is what I did to display my Trades on TOS chart. I hope this helps.

Check to see if advanced Features are enabled
  1. Log into TD Ameritrade
  2. Select My profile
  3. Under the general tab, make sure "Advanced Features" is set to "Enabled".
Display on Chart
  1. Click on the Gear
  2. General Tab -> Content ->Display -- Make sure "Show Trades" is checked
  3. Click "Setup" typically in the top right
  4. Save workspace as (enter your name)
  5. Close then restart TOS. I right clicked, run as ADMIN. Idk if it matters.
Brownbear311, Would you mind to recheck
"3. Under the general tab, make sure "Advanced Features" is set to "Enabled". I went to TD Ameritrade but didn't see it. I was trying to tick "show trades" in TOS but no luck.
Thank you.
 
Found a simple code that displays a label in the upper left corner of a chart that shows the P/L of the stock symbol from date of purchase.

Create a study and call it what ever you like and add this code:

AddLabel(yes, GetOpenPL(), Color.WHITE);

I have it on my 1yr 1 day chart.
 
@3AMBH I use the same basic label on my Option Trading panel as a compliment to the P/L Open column in my Active Trader ladder... Mine displays Green for increase and Red for Decrease in price movement, and Gray otherwise...

Ruby:
def PLOpen =  GetOpenPL();

AddLabel (yes, "P/L: " + AsText(PLOpen, NumberFormat.DOLLAR), if PLOpen > 0 then Color.GREEN else if PLOpen < 0 then Color.RED else Color.LIGHT_GRAY);
 
Hello. I am new on this, by looking on yours post I ended up combining the next script. Some one know if is posible to plto the line from the last bar/candle to the rigth. the main avrerage cost line is fine to keep it at it is. but the others ones Target/Stop loss lines are the one that I would like to keep short on the rigth chart.



# 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

input use_line_limits = yes;#Yes, plots line from/to; No, plot line across entire chart
input linefrom = 100;#Hint linefrom: limits how far line plots in candle area
input lineto = 12;#Hint lineto: limits how far into expansion the line will plot

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," P/L: " + AsDollars(PL) +" ",
if PL == 0 then color.cyan
else if PL > 0 then color.green
else color.red);

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

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

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

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

plot "20% Target" = if Entry_ then Entry_ + .20*Entry else double.nan;
"20% Target".SetDefaultColor(color.red);
# end code
 
@wcsharron Maybe look at this post, or you could try the modified code below that I have lately been using.
Note: Please ensure that the below study plots correctly before using.

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
Hello- where do you copy this program code?
 
I am attempting to show the current position profit/loss using the following code:
Code:
AddLabel(qty<>0, "P/L: " + AsText(GetOpenPL(), NumberFormat.DOLLAR),
if GetOpenPL()==0 then Color.LIGHT_GRAY else if GetOpenPL()>0 then Color.GREEN else Color.RED);

But, it occasionally shows a huge profit or loss as shown below. Is there a better way to calculate and show this?
YENikXu.png
 
Drop the AsText() and use AsDollars(GetOpenPL()) instead... It prepends a $ but, hey, it works... I run it on every trading panel in addition to having the standard column added into my Active Trader panels...
 
I have been using this study for Profit/Loss Label:

Code:
def averagePrice = GetAveragePrice();
def quantity = GetQuantity();

AddLabel(quantity != 0, " Pos: " + quantity
    + "@" + averagePrice
       + " = " + AsDollars(averagePrice * quantity)
       , CreateColor(89, 179, 0));


def openPL = GetOpenPL();
def pgain = if averagePrice != 0 then close - averagePrice else 0;

AddLabel(quantity != 0, " Net: " + AsDollars(close * quantity)
    + " | " + AsDollars(openPL)
    + " | "  + AsPercent(pgain/averagePrice)
    , if openPL >= 0 then Color.UPTICK else Color.DOWNTICK);

and this study for Entry Price Plot:

Code:
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 entryline = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0
              then highestAll(if isNaN(close[-1]) then Entry else double.nan)
              else double.nan;

entryline.SetStyle(Curve.MEDIUM_DASH);
entryline.SetLineWeight(2);
entryline.SetDefaultColor(CreateColor(89, 179, 0));
entryline.HideBubble();
entryline.HideTitle();

def PL = if Entry > 0 then Entry - c else 0;
AddChartBubble(barNumber() == HighestAll(barNumber()), entryline, "entry " + AsDollars(Entry), entryline.TakeValueColor());
 
Last edited by a moderator:
@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);
Now as an addition, is there a way of adding AddChartBubble to it to be able to see the target percentages? Or is that not doable? Thanks.
 
Now as an addition, is there a way of adding AddChartBubble to it to be able to see the target percentages? Or is that not doable? Thanks.
@AnakManis Its certainly possible. Here is a bubble example for you using the "5% Stop" plot -

Code:
input move_bubble_forward_how_many_bars = 10;
def bm = move_bubble_forward_how_many_bars;

AddChartBubble(!IsNaN(close[bm]) && IsNaN(close[bm-1]),"5% Stop", Round("5% Stop"), "5% Stop".TakeValueColor(), no);

See if you are able to code the remaining bubbles. If not, post the exact code that you are currently using and I will add them for you.
 
I want to be able to track the entry price on my watch list. I know I can chart it (and track separately in my log) but it would nice to have it right there.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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