# Percent Points Based On Open For ThinkOrSwim
# @Svanoy UPDATED 6/5/2022
input periodstart = 0930;
input periodend = 1630;
input Target_Percentage = 1.0;
input Price_Point_1_Percentage = 1.5;
input Price_Point_2_Percentage = 1.0;
input Price_Point_3_Percentage = 0.5;
input Price_Point_4_Percentage = -0.5;
input Price_Point_5_Percentage = -1;
input Price_Point_6_Percentage = -1.5;
def daystart = SecondsFromTime(periodstart) == 0;
def activeperiod = if SecondsFromTime(periodstart) >= 0 and SecondsTillTime(periodend) > 0 then yes else Double.NaN;
def dayopen = if daystart then open else DayOpen[1];
def o = fold io = 0 to 1 while !IsNaN(close[10]) do dayopen;
plot DayOpenPlot = if o > 0 and activeperiod then o else Double.NaN;
DayOpenPlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DayOpenPlot.AssignValueColor(color.white);
def pricepoint1 = (dayopen * (Price_Point_1_Percentage/100)) + dayopen;
def pricepoint2 = (dayopen * (Price_Point_2_Percentage/100)) + dayopen;
def pricepoint3 = (dayopen * (Price_Point_3_Percentage/100)) + dayopen;
def pricepoint4 = (dayopen * (Price_Point_4_Percentage/100)) + dayopen;
def pricepoint5 = (dayopen * (Price_Point_5_Percentage/100)) + dayopen;
def pricepoint6 = (dayopen * (Price_Point_6_Percentage/100)) + dayopen;
def a = fold ia = 0 to 1 while !IsNaN(close[10]) do pricepoint1;
def b = fold ib = 0 to 1 while !IsNaN(close[10]) do pricepoint2;
def c = fold ic = 0 to 1 while !IsNaN(close[10]) do pricepoint3;
def d = fold id = 0 to 1 while !IsNaN(close[10]) do pricepoint4;
def e = fold ie = 0 to 1 while !IsNaN(close[10]) do pricepoint5;
def f = fold if = 0 to 1 while !IsNaN(close[10]) do pricepoint6;
plot PP1 = if a > 0 and activeperiod then a else Double.NaN;
PP1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP1.AssignValueColor(color.white);
plot PP2 = if b > 0 and activeperiod then b else Double.NaN;
PP2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP2.AssignValueColor(color.white);
plot PP3 = if c > 0 and activeperiod then c else Double.NaN;
PP3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP3.AssignValueColor(color.white);
plot PP4 = if d > 0 and activeperiod then d else Double.NaN;
PP4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP4.AssignValueColor(color.white);
plot PP5 = if e > 0 and activeperiod then e else Double.NaN;
PP5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP5.AssignValueColor(color.white);
plot PP6 = if f > 0 and activeperiod then f else Double.NaN;
PP6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP6.AssignValueColor(color.white);
AddChartBubble(!IsNaN(DayOpenPlot) and IsNaN(DayOpenPlot[-1]) and activeperiod,dayopen,"Day Open",Color.WHITE,if Price_Point_1_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP1) and IsNaN(PP1[-1]),a,"Price Point 1: "+Price_Point_1_Percentage+"%",Color.WHITE,if Price_Point_1_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP2) and IsNaN(PP2[-1]),b,"Price Point 2: "+Price_Point_2_Percentage+"%",Color.WHITE,if Price_Point_2_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP3) and IsNaN(PP3[-1]),c,"Price Point 3: "+Price_Point_3_Percentage+"%",Color.WHITE,if Price_Point_3_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP4) and IsNaN(PP4[-1]),d,"Price Point 4: "+Price_Point_4_Percentage+"%",Color.WHITE,if Price_Point_4_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP5) and IsNaN(PP5[-1]),e,"Price Point 5: "+Price_Point_5_Percentage+"%",Color.WHITE,if Price_Point_5_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP6) and IsNaN(PP6[-1]),f,"Price Point 6: "+Price_Point_6_Percentage+"%",Color.WHITE,if Price_Point_6_Percentage >= 0 then yes else no);
Alert(activeperiod and ((close[1] > Target_Percentage and close <= Target_Percentage) or (close[1] < Target_Percentage and close >= Target_Percentage)), "Target Hit", Alert.BAR, Sound.Ding);
AddLabel(yes,if activeperiod and ((close[1] > Target_Percentage and close <= Target_Percentage) or (close[1] < Target_Percentage and close >= Target_Percentage)) then "Target Hit" else " ",if activeperiod and ((close[1] > Target_Percentage and close <= Target_Percentage) or (close[1] < Target_Percentage and close >= Target_Percentage)) then color.green else color.gray);