# Beznas Labels
# Dispalys: Position, Average Cost, Profit/Loss, RSI, ATR, Expected move, Put/Call ratio, PE, Options, Aggregation
# 06/2021 By Bezna$
# -------inputs-----------
input ShowRSI = YES;
input ShowPosition = YES;
input ShowATR = NO;
input ATRLength = 14;
input ShowVolatility = NO;
input ShowExpectedMove = YES;
input ShowPCR = YES;
input ShowPE = YES;
input Show_Agg = Yes;
def rnd = if close < .1 then 4 else if close < 1 then 3 else if close > 100 then 1 else 2; #rounding the price
#------ Display Position
def Position = Round(GetQuantity() * close, 0);
def AVP = Round(GetAveragePrice(), rnd);
def Profit = Round(Position - (AVP * GetQuantity()), rnd);
AddLabel(ShowPosition and !IsNaN(Position) and Position > 0, Concat("Postion: $", Position),
if Profit > 0 then Color.GREEN else Color.RED);
AddLabel(ShowPosition and !IsNaN(AVP) and AVP > 0, Concat(" Cost: ", AVP ) + " " ,
if AVP < close then Color.GREEN else Color.RED);
AddLabel(ShowPosition and Profit != 0 and !IsNaN(Profit), Concat("P/L: ", Profit),
if Profit > 0 then Color.GREEN else Color.RED);
#------ Display RSI
def priceRSI = Round(reference RSI("price" = close, "length" = 14), 0);
AddLabel (if (IsOptionable() and !IsNaN(priceRSI) and ShowRSI) then yes else no , Concat( " RSI: ", priceRSI) + " " ,
if priceRSI <= 30 then Color.GREEN
else if (priceRSI > 50 and priceRSI < 70) then Color.PINK
else if (priceRSI <= 50 and priceRSI > 30) then Color.LIGHT_GREEN
else Color.RED);
#------------------------------ Display ATR, Expcted move, Volatility ------------------------------
def ATR = Round(Average(TrueRange(high, close, low), ATRLength), 2);
def Volatility = Round(close() * (imp_volatility() / 15.87), 2);
def Expmove = Round ((Volatility / close) * 100 , 2);
#AddLabel(if (IsOptionable() and !IsNaN(ATR) and ShowATR) then yes else no, Concat( " ATR: ", ATR) , Color.WHITE);
AddLabel(if (IsOptionable() and !IsNaN(Expmove) and ShowExpectedMove) then yes else no, Concat( " ± ", Expmove) + " %" , Color.WHITE);
AddLabel(if (IsOptionable() and !IsNaN(Volatility) and ShowVolatility) then yes else no, Concat( " Volatility: ", Volatility) , Color.WHITE);
# ---------------- Call Puts Ratio ---------------------------
def series = 1;
def CurrentYear = GetYear();
def CurrentMonth = GetMonth();
def CurrentDOM = GetDayOfMonth(GetYYYYMMDD());
def Day1DOW1 = GetDayOfWeek(CurrentYear * 10000 + CurrentMonth * 100 + 1);
def FirstFridayDOM1 = if Day1DOW1 < 6
then 6 - Day1DOW1
else if Day1DOW1 == 6
then 7
else 6;
def RollDOM = FirstFridayDOM1 + 14;
def ExpMonth1 = if RollDOM > CurrentDOM
then CurrentMonth + series - 1
else CurrentMonth + series;
def ExpMonth2 = if ExpMonth1 > 12
then ExpMonth1 - 12
else ExpMonth1;
def ExpYear = if ExpMonth1 > 12
then CurrentYear + 1
else CurrentYear ;
def Day1DOW = GetDayOfWeek(ExpYear * 10000 + ExpMonth2 * 100 + 1);
def FirstFridayDOM = if Day1DOW < 6
then 6 - Day1DOW
else if Day1DOW == 6
then 7
else 6;
def ExpDOM = FirstFridayDOM + 14;
def date = ExpYear * 10000 + ExpMonth2 * 100 + ExpDOM + 1;
#def date = 20210618;
def PutVolume = if IsNaN(volume(symbol = GetATMOption(GetUnderlyingSymbol(), date, OptionClass.PUT)))
then PutVolume[1]
else volume(symbol = GetATMOption(GetUnderlyingSymbol(), date, OptionClass.PUT));
def CallVolume = if IsNaN(volume(symbol = GetATMOption(GetUnderlyingSymbol(), date, OptionClass.CALL)))
then CallVolume[1]
else volume(symbol = GetATMOption(GetUnderlyingSymbol(), date, OptionClass.CALL));
def SP = Round(close(symbol = GetUnderlyingSymbol()) / .5, 0) * .5;
def PV = if IsNaN(PutVolume)
then PV[1]
else PutVolume;
def CV = if IsNaN(CallVolume)
then CV[1]
else CallVolume;
#------ADD PCR ----------------
def PCR = Round ((PV / CV), 2);
AddLabel(if (IsOptionable() and !IsNaN(PCR) and PCR < 1000 and ShowPCR) then yes else no,
" P/C " + PCR + " (" + PV + "/" + CV + ") ",
if PCR <= 1 then Color.GREEN
else Color.RED);
# --------- ADD P/E ---------
def AE = if IsNaN(GetActualEarnings()) then 0 else GetActualEarnings();
def EPS_TTM = Sum(AE, 252);
def pe = Round(close / EPS_TTM, 0);
AddLabel (if (!IsNaN (pe) and pe < 300 and ShowPE ) then yes else no, Concat(” -- P/E: ”, pe + " -- "), if pe <= 25 then Color.GREEN else Color.WHITE) ;
# --------- ADD Dividend ---------
def DCont = if IsNaN(GetDividend()) then DCont[1] else GetDividend();
def DivA = if DCont <> 0 then DCont * 4 else Double.NaN;
def yield = Round(DivA / close * 100, 1);
AddLabel(if !IsNaN(yield) then yes else no, Concat(” --- Div: ”, yield + " % -- "), Color.CYAN) ;
#------------ Show aggregation
def Agg = GetAggregationPeriod();
AddLabel(yes, Concat("Agg: ", Agg), Color.CYAN); #debug