• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Chart Label to show Daily P/L Status (%) in real time

NJM

New member
I've been trying to script a study that would add a label up in the top left corner of a chart showing this info:
  • % up or down of today's current P/L compared with yesterday's P/L (or p/l as of 11:59p yesterday)
The goal here is to potentially better recognize when daily targets or max losses are hit.

I can get the current value from "GetNetLiq()", but struggling to calculate historic account value data.

Once this is calculated, a simple equation could be done (today's pl / yesterday's pl = value I'm looking for) and then the rest of the customization would be straightforward:
  • color based on how much up or down
  • alert based on how much up or down

Thanks!
NJM
 

Len20

Member
On a daily chart you could use GetNetLiq() [1] to get yesterdays value. However, it doesn't seem to allow using a daily aggregation on other timeframes. I thought it wasn't possible, but this great post HERE by RobertPayne shows how to still access yesterday's values. For example, this code should get you started with the values you need, and you can go from there:
Code:
def today = GetDay() == GetLastDay();
def todayNetLiq = GetNetLiq();
def yestNetLiq = if today then yestNetLiq[1] else GetNetLiq();
 

Chuck

Well-known member
Does anyone have an indicator that shows options profit and loss on the screen. I am buying puts from the active trader dome in TOS. The indicator I have now does not pick up options and the Active Trader does not plot out PL for options. I have to continually switch back and forth to the monitor tab to see PL. I know I can see it other ways but it sure would be nice to have it plotted on the screen.
 

rad14733

Well-known member
VIP
Does anyone have an indicator that shows options profit and loss on the screen. I am buying puts from the active trader dome in TOS. The indicator I have now does not pick up options and the Active Trader does not plot out PL for options. I have to continually switch back and forth to the monitor tab to see PL. I know I can see it other ways but it sure would be nice to have it plotted on the screen.
@Chuck Are you aware of the P/L Open column in Active Trader...??? That would be the best way to know where you're at... I have is displaying at the far right all the time, along with other customizations... I also have P/L Open displaying in my Active Positions Watchlist in my left sidebar... 💡
 

Chuck

Well-known member
@rad14733,

PL/Open is one of my favorite uses of active trader, but it does not work on options(or so I have been told by TOS Support)......I copy an option from the option chain and paste it into my active trader (separate window on flex grid), when I do this it does not show P/L. I have most of the scripts on this forum(that I can find) that display P/L on the chart. But none of them work so far.

rad, I just want to the a min to thank you for all your assistance. It is very much appreciated.

I forgot about the P/L in the Active Positions Watchlist, I will have to try that.

l set up the P/L Open on the left sidebar and it did not show in OnDemand, I will have to test it later, but I would still like to have it on my screen. Scenarioes change as I switch between grids, active trader, chats and my multitude of trading setups. Because of this I like to have everything on my charts/grids... just so I don't mess up and forget something.
 
Last edited by a moderator:

rad14733

Well-known member
VIP
I need to get the exact same number as is shown in the WatchList column. Thanks
Unfortunately, they may not display exactly the same due to latency issues... It was apparent to me today while watching an active trade... The option prices were anywhere from spot on to as much as 1.50 different between the Watchlist and Active Trader ladder... Remember, Watchlists can have lag but Active Trader should be more real-time... This is even true when using Current Account Positions for your Watchlist...
 

cabe1332

Active member
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:

epete

New member
VIP
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:"?
 

cabe1332

Active member
@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
 

NJM

New member
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
 

drdDavi

New member
Hey Guys,

How do I add P/L details on my chart for an individual ticker, it would need to be for all trades over time and factors in both Shares and Options.
 

rad14733

Well-known member
VIP
@drDavi Your request is somewhat beyond the scope of the Thinkorswim platforms capabilities... While it is possible to have a chart label that displays realtime P/L of an active trade we can't extrapolate historic trade data... I have an on-chart label that displays my option scalping P/L which mirrors the Open P/L column in the Active Trader panel below it... In additional, we can't display trade data from an option on the underlying instruments chart... It is worth mentioning that historic trade data is displayed at the bottom of your charts already... We also have the Monitor Panel at our disposal for tracking historical trades...

RLAqwYd.png
 

anasmatar

New member
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
 

rad14733

Well-known member
VIP
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);
 

Similar threads

Top