P/L Day Label

perroveloz

New member
Hi, does any body know how to creat a label with a P/L Day? I already have one with a P/L Open

thanks in advance

this is what I got for open PL


def PL = GetOpenPL();

AddLabel (yes, "P/L: $" + Round(PL, 2), if PL > 0 then Color.UPTICK else if PL == 0 then Color.WHITE else Color.DOWNTICK);

and yes I am talking about a simple midnight to midnight
 
Last edited by a moderator:
Solution
this may work:
Code:
declare lower;

def t = secondsFromTime(0931);

def day_open_pl = if t >= 0 and t[1] < 0 then PositionOpenPL() else day_open_pl[1];

AddVerticalLine(t >= 0 and t[1] < 0, "market open", color.black);

plot day_pl = PositionOpenPL() - day_open_pl;
plot zero = 0;

addLabel(yes, "  Start of Day: " + asDollars(day_open_pl) + "  ", if day_pl > 0 then color.dark_green else if day_pl == 0 then color.gray else color.red);
addLabel(yes, "  Day P/L: " + asDollars(day_pl) + "  ", if day_pl > 0 then color.dark_green else if day_pl == 0 then color.gray else color.red);

I wrote the code initially to work with strategies and used FPL(). If you want your actuals, use the code above.

Also, I can't get it to work with midnight...
this may work:
Code:
declare lower;

def t = secondsFromTime(0931);

def day_open_pl = if t >= 0 and t[1] < 0 then PositionOpenPL() else day_open_pl[1];

AddVerticalLine(t >= 0 and t[1] < 0, "market open", color.black);

plot day_pl = PositionOpenPL() - day_open_pl;
plot zero = 0;

addLabel(yes, "  Start of Day: " + asDollars(day_open_pl) + "  ", if day_pl > 0 then color.dark_green else if day_pl == 0 then color.gray else color.red);
addLabel(yes, "  Day P/L: " + asDollars(day_pl) + "  ", if day_pl > 0 then color.dark_green else if day_pl == 0 then color.gray else color.red);

I wrote the code initially to work with strategies and used FPL(). If you want your actuals, use the code above.

Also, I can't get it to work with midnight. It's set to call the open at 930 eastern right now. I don't know why it doesn't work so well with midnight at the moment. perhaps I can fix it some day.

If you just want the labels, use this code:
Code:
declare upper;

def t = secondsFromTime(0931);

def day_open_pl = if t >= 0 and t[1] < 0 then PositionOpenPL() else day_open_pl[1];

AddVerticalLine(t >= 0 and t[1] < 0, "market open", color.black);

def day_pl = PositionOpenPL() - day_open_pl;

addLabel(yes, "  Start of Day: " + asDollars(day_open_pl) + "  ", if day_pl > 0 then color.dark_green else if day_pl == 0 then color.gray else color.red);
addLabel(yes, "  Day P/L: " + asDollars(day_pl) + "  ", if day_pl > 0 then color.dark_green else if day_pl == 0 then color.gray else color.red);

-mashume
 
Solution

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

it shows zero for both labels, can you please advise how to fix it?
The function PositionOpenPL() only shows a value if you have an open position for the instrument you're looking at. If you have a strategy running you can use FPL(). I'd have to look on the learning center for portfolio value functions. I don't know the off hand.

-mashume
 
Active Trader also has a position summary option that includes P&L Day and P&L Open. You might look into that since it's built into the platform. It does it based on the symbol of the Active Trader chart, so it's not portfolio-level... but neither is a label.
 
GetOpenPL() only records a bar historically if you had a position open for the entire bar into the next, or while the position is still actually open. Otherwise, it drops back down to zero once you've exited, and it ignores the profit or loss from the final bar of a trade.

In this case, I covered the short on the big red bar, whereas GetOpenPL() stops recording at the prior bar. It was showing a much larger profit during that final bar until I exited.

a2UGIQd.png


There are some tricks where you can rotate into a different calculation using differences in net liquidity upon exiting, but the net liquidity function is account-wide, so it only works if you're an exclusive single instrument trader. Otherwise your other holdings will interfere with it.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
179 Online
Create Post

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