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

Active 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

Active 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

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

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
 

Similar threads

Top