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

@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!
 

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

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!
 
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
 
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:
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
 
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.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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