Request for Real-Time Daily P/L Data or FPL() to trigger colored label on daily profit threshold input

immortalwon

New member
I am writing to inquire if there is any way to obtain the actual daily P/L that Active Trader shows via script in real time. I have been able to pull the FPL() from a strategy, but it is not the same. I am looking to show a colored label when the actual daily P/L or FPL() crosses an input threshold and then only after it drops like 10% from its peak the first time it occurs. This will be used to shut another program down that automates trading. I am new to thinkscript and have mashed a bunch of code together after several weeks of research. The problem is the label will not stay on once my conditions are met the first time. Thank you for your time and consideration. If you want to learn more about the inspiration, please see this thread which uses another program to monitor label colors:

Moving Average Master Strategy for ThinkOrSwim - by dap711

Code:
###############################################################
##########            TRADING HOURS                   #########
###############################################################
input zoneStartAM = 945;
input zoneEndAM = 1200;
input zoneStartPM = 1330;
input zoneEndPM = 1600;
input zoneLastEntry = 1554;

#Set active trading timeFrame for strategy
def Active = if (SecondsFromTime(zoneStartAM) > 0 and
    SecondsTillTime(zoneEndAM) > 0) or
    (SecondsFromTime(zoneStartPM) > 0 and
    SecondsTillTime(zoneLastEntry) > 0) then 1 else 0;

################################################################
##########            TAKE PROFIT                      #########
################################################################

input Profit_Target = 50;  # when the FPL or Daily P/L crossess this threshold
input Take_Daily_Profit_Drop = 0.10; # once threshold cross then show unique label color if drops by 10% from peak
input Take_Daily_Profit_Bars = 9; # number of bars to look back for a peak
input fplEnableDebugging = yes;

#Globals
def nan = Double.NaN;
def bn = if !IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close[-1]) then BarNumber() else bn[1];

#Daily profit
def FPL = FPL();
def highFPL = HighestAll(FPL);
def Midnight = if Active then FPL else Midnight[1];
def DaysProfit = FPL - Midnight;
def highBarNumber = CompoundValue(1, if FPL == highFPL
                                    then bn
                                    else highBarNumber[1], 0);

def enableDebugging = fplEnableDebugging;
def limitFPL = (highFPL - FPL) / highFPL;
def TakeProfitThreshold = if DaysProfit > Profit_Target then 1 else 0; # is the current daily profit higher then the profit target threshold
def CrossesProfitThreshold = if Crosses(DaysProfit, Profit_Target, CrossingDirection.ABOVE) then 1 else 0; # does the current daily profit higher then the profit target threshold
def ProfitDrop = (Highest(DaysProfit, Take_Daily_Profit_Bars) - DaysProfit) / Highest(DaysProfit, Take_Daily_Profit_Bars); # measure daily profit drop from rolling bar high
def OktoTrade = if ProfitDrop >= Take_Daily_Profit_Drop then 1 else 0;  # does the current daily exceed a percent threshold than the highest profit

def up = if Crosses(DaysProfit, Profit_Target, CrossingDirection.ABOVE) then 1 else 0;
#AssignPriceColor(if DaysProfit >= Profit_Target then Color.White else Color.Current);
#AssignPriceColor(if Crosses(DaysProfit, Profit_Target, CrossingDirection.ABOVE) then Color.WHITE else Color.CURRENT);

def down = if Crosses(ProfitDrop, Take_Daily_Profit_Drop, CrossingDirection.ABOVE) then 1 else 0;
#AssignPriceColor(if TakeProfitThreshold == 1 and ProfitDrop >= Take_Daily_Profit_Drop then Color.Yellow else Color.Current);
#AssignPriceColor(if Crosses(ProfitDrop, Take_Daily_Profit_Drop, crossingDirection.ABOVE) then Color.Yellow else Color.Current);

def Hold_Up_Value = if up then 1 else if !down then Hold_Up_Value[1] else 0;
#def Hold_Dn_Value = if down then 1 else if !up then Hold_Dn_Value[1] else 0;

#plot Signal_Up = if up and Hold_Dn_Value[1] == 1 then low else Double.NaN;
#Signal_Up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#Signal_Up.setDefaultColor(color.White);
#Signal_Up.setlineweight(3);

#plot Signal_Dn = if down and Hold_Up_Value[1] == 1 then high else Double.NaN;
#Signal_Dn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#Signal_Dn.SetDefaultColor(Color.YELLOW);
#Signal_Dn.SetLineWeight(3);

def risk = CompoundValue(1, if TakeProfitThreshold == 1 and ProfitDrop >= Take_Daily_Profit_Drop then bn else risk[1], 0); # trying to just mark first timeProfile it peaks and drops
#AssignPriceColor(if risk then Color.Blue else Color.Current);  #using to test hold on first indication

#AddLabel(yes, text = "P&L Percent Drop" + ":  " + AsPercent(round(limitFPL,3)), color = if limitFPL < Fplstoploss then Color.GREEN else Color.LIGHT_RED);

AddLabel(yes, text = "P&L High" + (if enableDebugging then " at bar " + highBarNumber else "") + ":  " + AsDollars(highFPL),
    color = if highFPL > 0 then
    Color.GREEN else
    Color.LIGHT_RED);

#AddLabel(TakeProfitThreshold > 0 and Crosses(ProfitDrop, Take_Daily_Profit_Drop, crossingDirection.ABOVE), "     STOP     ", CreateColor(102, 0, 102));
AddLabel(risk, "     STOP     ", CreateColor(102, 0, 102));
 

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.
Top