# Retrofitted 01-29-2023 Farooq Khan from then day high low range specifications
# ... 01-31-2023 - Farooq Khan - remove duplicate Sell Put / Call Signals. Only show the very 1st signal for each set
# ...
#declare hide_on_daily;
declare once_per_bar;
input Bars_To_Skip = 0;
input ShowStartEnd = no;
#
# logic
#
# Establish 1st and last bar of today
def nan = Double.NaN;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def lastBarOfDay = if
(afterEnd[-1] == 1 and afterEnd == 0) or
(isRollover[-1] and firstBarOfDay[-1])
then 1
else 0;
#
# Identify first bar of any day and last bar of any day on chart
#
AddChartBubble(
firstBarOfDay and ShowStartEnd,
close,
"First Bar of Day" +BarNumber(),
Color.GREEN,
yes);
AddChartBubble(
lastBarOfDay and ShowStartEnd,
close,
"Last Bar of Day" +BarNumber(),
Color.GREEN,
no);
# High_Low_range_of today
#Looking to Setup A High-Low Range of Today
#=======================================
def bn = BarNumber();
def na = Double.NaN;
#1) Only using the First and last bar of today candles on any timeframe.
#def barsfromopen = (RegularTradingstart(GetYYYYMMDD())- GetTime() )/ GetAggregationPeriod();
#input bars = 118;
#2) Find the high and low starting from 1st bat of today + MoveBarsForward candles.
# find 1st and last bar of today
def barNumber = if firstBarOfDay then BarNumber() else 0 ;
def firstBarOfToday = HighestAll( barNumber) + Bars_To_Skip;
AddVerticalLine(firstBarOfToday == bn , "-", Color.WHITE);
def zlastbarnum = if lastBarOfDay then BarNumber() else 0 ;
def LastBarofTOday = HighestAll( zlastbarnum);
#get HIGH of today starting the firstBarOfToday + Bars_To_Skip
def zhigh = if bn > firstBarOfToday then high else nan;
def zhigh2 = HighestAll( zhigh);
def zhighest = if bn > firstBarOfToday then zhigh2 else nan;
def hi = zhighest;
def hi2 = (hi == high);
# Get Low of today starting the firstBarOfToday + Bars_To_Skip
def zlow = if bn > firstBarOfToday then low else nan;;
def zlow2 = LowestAll( zlow);
def zlowest = if bn > firstBarOfToday then zlow2 else nan;
def lo = zlowest;
def lo2 = (lo == low);
#addlabel(yes, " zlow2: " + zlow2 , Color.WHITE);
#addlabel(yes, " zhigh2: " + zhigh2 , Color.WHITE);
input hilo_arrows = yes;
plot z1 = if hilo_arrows and hi2 then high * 1.0005 else na;
z1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
z1.SetDefaultColor(Color.CYAN);
z1.SetLineWeight(3);
z1.HideBubble();
plot z2 = if hilo_arrows and lo2 then low else na;
z2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z2.SetDefaultColor(Color.CYAN);
z2.SetLineWeight(3);
z2.HideBubble();
#3) On the high candle, place a "Priceline" that is the low of that candle (wicks included).
# buy put
def hilo = if bn == 1 or bn > LastBarofTOday then na else if hi2 then low else hilo[1];
plot z3 = hilo;
z3.SetDefaultColor(Color.RED);
#4) Once a candle closes a LL below that "Priceline", place a bubble called "Sell Call" on that candle. It has to close below the low of the highest candle. It would be great if the candle could be painted a custom color. I use black in keeping with John Carter's concept.
#buy put or sell call
def buyput = if close[1] crosses below hilo then bn else 99999;
def sellCall = LowestAll( buyput);
def sellcall2 = if bn equals sellCall then 1 else 0;
#addlabel(yes, " sellCall: " + sellCall , Color.WHITE);
AddChartBubble(sellcall2, high * 1.0001, "Sell Call: " , Color.YELLOW, yes);
#5) A stop loss "Priceline" is drawn on the "High" of the highest candle. This is a great stop loss and keeps risk at a low with confirmation that the trend is not reversing but also keeps you from getting shaken out by MM's.
# put stop , short stop
def hihi = if bn == 1 or bn > LastBarofTOday then na else if hi2 then high else hihi[1];
plot z4 = hihi;
z4.SetDefaultColor(Color.RED);
z4.SetStyle(Curve.MEDIUM_DASH);
#6) On the low candle, place a "Priceline" that is the high of that candle (wicks included).
# buy call or sell put
def lohi = if bn == 1 or bn > LastBarofTOday then na else if lo2 then high else lohi[1];
plot z5 = lohi;
z5.SetDefaultColor(Color.GREEN);
#7) Once a candle closes a HH above that "Priceline", place a bubble called "Sell Put" on that candle. It has to close above the high of the lowest candle. It would be great to have this candle also painted a customer color. Again, default should be black.
# buy call is sell put
def buycall = if close[1] crosses above lohi then bn else 99999;
def sellPut = LowestAll( buycall);
def sellput2 = if bn equals sellPut then 1 else 0;
#addlabel(yes, " sellPut: " + sellPut , Color.WHITE);
AddChartBubble(sellPut2, low * 0.9999, "Sell Put", Color.YELLOW, no);
#8) A stop loss "Priceline" is drawn on the "Low" of the lowest candle. Again, another great stop loss to keep your risk at a minimum but also confirms that the trend reversal is not manifesting.
# call stop , long stop
def lolo = if bn == 1 or bn > LastBarofTOday then na else if lo2 then low else lolo[1];
plot z6 = lolo;
z6.SetDefaultColor(Color.GREEN);
z6.SetStyle(Curve.MEDIUM_DASH);
#9) Also, I would like the indicator to have a trailing stop loss. I forgot to include this important point.
#10) Once it has moved 50% from current entry, I would like it to put a stop loss at the HH of the last two candles for puts and the LL of the last two candles for calls. This locks in profits to ensure you don't get greedy and lose your gains when the market starts to shift.
# I do take profits on important pivots like PMH and PML
#EOF