floating pl with reset for start of day

taipanaz

New member
hi, does anyone know how to set floating pl for the day. i would like the floating pl to be reset to 0 every day. is this possible?

#
# TD Ameritrade IP Company, Inc. (c) 2012
#
declare lower;

plot FPL = FPL();
plot ZeroLine = 0;

FPL.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
FPL.DefineColor("Positive and Up", Color.GREEN);
FPL.DefineColor("Positive and Down", Color.DARK_GREEN);
FPL.DefineColor("Negative and Down", Color.RED);
FPL.DefineColor("Negative and Up", Color.DARK_RED);
FPL.AssignValueColor(if FPL >= 0 then if FPL > FPL[1] then FPL.Color("Positive and Up") else FPL.Color("Positive and Down") else if FPL < FPL[1] then FPL.Color("Negative and Down") else FPL.Color("Negative and Up"));
ZeroLine.SetDefaultColor(Color.GRAY);

hi, i am trying to get a floating pl with a reset to 0 for start of every day. is this possible?

here is what i got so far:

declare lower;

# Define variables
def reset = secondsfromtime(0000) >= 86400; # 86400 seconds = 24 hours
def fplvalue = fpl();
def FPLValue2 = if reset then 0 else fplvalue[1] + close - close[1];
plot FPL = fplvalue2;
plot ZeroLine = 0;

# Set painting strategy and colors
FPL.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
FPL.DefineColor("Positive and Up", Color.GREEN);
FPL.DefineColor("Positive and Down", Color.DARK_GREEN);
FPL.DefineColor("Negative and Down", Color.RED);
FPL.DefineColor("Negative and Up", Color.DARK_RED);
FPL.AssignValueColor(if FPL >= 0 then if FPL > FPL[1] then FPL.Color("Positive and Up") else FPL.Color("Positive and Down") else if FPL < FPL[1] then FPL.Color("Negative and Down") else FPL.Color("Negative and Up"));

ZeroLine.SetDefaultColor(Color.GRAY);


the fpl is supposed to reset to 0, but it does not seem to be working. can anyone help?
 
Solution
hi, does anyone know how to set floating pl for the day. i would like the floating pl to be reset to 0 every day. is this possible?

#
# TD Ameritrade IP Company, Inc. (c) 2012
#
declare lower;

plot FPL = FPL();
plot ZeroLine = 0;

FPL.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
FPL.DefineColor("Positive and Up", Color.GREEN);
FPL.DefineColor("Positive and Down", Color.DARK_GREEN);
FPL.DefineColor("Negative and Down", Color.RED);
FPL.DefineColor("Negative and Up", Color.DARK_RED);
FPL.AssignValueColor(if FPL >= 0 then if FPL > FPL[1] then FPL.Color("Positive and Up") else FPL.Color("Positive and Down") else if FPL < FPL[1] then FPL.Color("Negative and Down") else FPL.Color("Negative and Up"))...
hi, does anyone know how to set floating pl for the day. i would like the floating pl to be reset to 0 every day. is this possible?

#
# TD Ameritrade IP Company, Inc. (c) 2012
#
declare lower;

plot FPL = FPL();
plot ZeroLine = 0;

FPL.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
FPL.DefineColor("Positive and Up", Color.GREEN);
FPL.DefineColor("Positive and Down", Color.DARK_GREEN);
FPL.DefineColor("Negative and Down", Color.RED);
FPL.DefineColor("Negative and Up", Color.DARK_RED);
FPL.AssignValueColor(if FPL >= 0 then if FPL > FPL[1] then FPL.Color("Positive and Up") else FPL.Color("Positive and Down") else if FPL < FPL[1] then FPL.Color("Negative and Down") else FPL.Color("Negative and Up"));
ZeroLine.SetDefaultColor(Color.GRAY);

hi, i am trying to get a floating pl with a reset to 0 for start of every day. is this possible?

here is what i got so far:

declare lower;

# Define variables
def reset = secondsfromtime(0000) >= 86400; # 86400 seconds = 24 hours
def fplvalue = fpl();
def FPLValue2 = if reset then 0 else fplvalue[1] + close - close[1];
plot FPL = fplvalue2;
plot ZeroLine = 0;

# Set painting strategy and colors
FPL.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
FPL.DefineColor("Positive and Up", Color.GREEN);
FPL.DefineColor("Positive and Down", Color.DARK_GREEN);
FPL.DefineColor("Negative and Down", Color.RED);
FPL.DefineColor("Negative and Up", Color.DARK_RED);
FPL.AssignValueColor(if FPL >= 0 then if FPL > FPL[1] then FPL.Color("Positive and Up") else FPL.Color("Positive and Down") else if FPL < FPL[1] then FPL.Color("Negative and Down") else FPL.Color("Negative and Up"));

ZeroLine.SetDefaultColor(Color.GRAY);


the fpl is supposed to reset to 0, but it does not seem to be working. can anyone help?
several things,

this will never be true,
def reset2 = SecondsFromTime(0000) >= 86400;
if you look at /ES and at 23:59pm (depending on time zone, 22:59 for me) the seconds are 86340.
at midnight, the time is 0 and seconds are 0.

you could do something like this,
def reset = SecondsFromTime(0000) == 0;
for stocks, there probably won't be a bar at midnight, so it won't trigger.

i used getday(), to determine when a new day starts, for the reset,
def d = getday();
def newday = d != d[1];



if there are no trades, then fpl is n/a
i added this to convert the errors to 0, then the def FPLValue2 = formula can process numbers and not error out.
def fplvalue = if isnan(FPL()) then 0 else FPL();



this code is a study.
to really test fpl, you will have to copy and paste this code in as a strategy, to generate profits and losses.
need to add code to generate buy and sell signals.
then add addorder() functions, to buy and sell, based on the buy and sell signals.

def buy = ....
def sell = ...
AddOrder(OrderType.BUY_TO_OPEN, buy, ticksize = 1, tickcolor = Color.green, arrowcolor = Color.green, name = "buy");
AddOrder(OrderType.SELL_TO_CLOSE, sell, ticksize = 1, tickcolor = Color.red, arrowcolor = Color.red, name = "sell");
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AddOrder

because there are no addorder()'s, there is no data for fpl() to read, so it is always 0.
fplvalue is always 0. so the difference in 2 closes is plotted in the histogram
def FPLValue2 = if reset then 0 else fplvalue[1] + close - close[1];


there is a test bubble that can be turned on to see some values


Code:
#PL_reset_daily

#https://usethinkscript.com/threads/floating-pl-with-reset-for-start-of-day.18106/
#floating pl with reset for start of day
#taipanaz  Mar 16, 2024  #1

# i am trying to get a floating pl with a reset to 0 for start of every day. is this possible?
#here is what i got so far:

declare lower;

def d = getday();
def newday = d != d[1];

# Define variables
def reset2 = SecondsFromTime(0000) >= 86400; # 86400 seconds = 24 hours
def reset = newday;

def fplvalue = if isnan(FPL()) then 0 else FPL();

def FPLValue2 = if reset then 0 else fplvalue[1] + close - close[1];
plot FPL = FPLValue2;
plot ZeroLine = 0;

# Set painting strategy and colors
FPL.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
FPL.DefineColor("Positive and Up", Color.GREEN);
FPL.DefineColor("Positive and Down", Color.DARK_GREEN);
FPL.DefineColor("Negative and Down", Color.RED);
FPL.DefineColor("Negative and Up", Color.DARK_RED);
FPL.AssignValueColor(if FPL >= 0 then if FPL > FPL[1] then FPL.Color("Positive and Up") else FPL.Color("Positive and Down") else if FPL < FPL[1] then FPL.Color("Negative and Down") else FPL.Color("Negative and Up"));

ZeroLine.SetDefaultColor(Color.GRAY);

#------------------------
input test1 = no;
addchartbubble(test1, 0,
reset2 + " rst2\n" +
SecondsFromTime(0000) + " sec\n" +
reset + " rst\n" +
fplvalue + " fpl \n" +
fplvalue2 + " fpl2"
, color.yellow, no);
#
 

Attachments

  • Capture.JPG
    Capture.JPG
    111.3 KB · Views: 27
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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