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
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));