# High_Low_range_carter_00e
#https://usethinkscript.com/threads/looking-to-setup-a-high-low-range.13750/
#Looking to Setup A High-Low Range
#OGOptionSlayer 12/19
##1
#So I use a very specific setup. It's kind of a mashup between what John Carter teaches with one of his in Mastering the Trade and TradingWarz Golden Indicator. I've used it for about 2 years now and it's extremely profitable. Honestly, I haven't backtested it but I would love to but I'm just not as technical as most in here. I know it brings me immense profit and on Friday, my port grew 11% using it. It's not a small port either. It's a reversal setup and it's solid with tight stop losses. I use it with a Darvas Box but TOS has a great Darvas Box study.
#I'm looking to see if someone can create an indicator for it. To keep this post as short as possible, here is the setup:
#1) Only using the last 20 candles on any timeframe.
#2) Find the high and low of last 20 candles. As a new candle is created, it disregards anything not in the 20 candles.
#3) On the high candle, place a "Priceline" that is the low of that candle (wicks included).
#4) Once a candle closes a LL below that "Priceline", place a bubble called "Buy Puts" 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.
#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.
#6) On the low candle, place a "Priceline" that is the high of that candle (wicks included).
#7) Once a candle closes a HH above that "Priceline", place a bubble called "Buy Calls" 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.
#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.
# 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,
# for puts, put a stop loss at the HH of the last two candles
# for calls, put a stop loss at the LL of the last two candles
# to lock in profits
#=======================================
def bn = BarNumber();
def na = Double.NaN;
input buy_bubbles_on = yes;
input buy_type = { default completed_bar , active_bar };
def buyoff;
switch (buy_type) {
case completed_bar:
buyoff = 1;
case active_bar:
buyoff = 0;
}
# used in #4 buy puts , #7 calls
#---------------------------
# choose_wick_body01
#input plot_type = {default SMA, "Red EMA", "Green EMA", WMA};
input candle_levels = {default "wick" , "body" };
def highx;
def lowx;
switch (candle_levels) {
case "wick":
highx = high;
lowx = low;
case "body":
highx = Max( open, close);
lowx = Min( open, close);
}
#addlabel(yes, "choose=" + candle_levels + "..high=" + highx + "..low=" + lowx);
#-----------------------------
#1) Only using the last 20 candles on any timeframe.
input bars = 20;
def period = (!IsNaN(close) and IsNaN(close[-bars]));
#addverticalline(x,"-");
#2) Find the high and low of last 20 candles. As a new candle is created, it disregards anything not in the 20 candles.
# define group of x bars
def first = (!IsNaN(close[-(bars - 1)]) and IsNaN(close[-bars]));
AddVerticalLine(first, "-", Color.WHITE);
#----------------------------
# price level of the highest high
def hihi = if bn == 1 or isnan(close) then 0
# else if first then Highest(high[-(bars - 1)], (bars - 1))
else if first then Highest(high[-(bars - 1)], (bars - 0))
else hihi[1];
# find bn of just the first occurance of hihi
def hihifirstbn =
if hihi == 0 then 0
else if hihifirstbn[1] > 0 then hihifirstbn[1]
else if (hihi == high) then bn
else hihifirstbn[1];
# bars after the hihi
def hi_bars = (hihifirstbn > 0 and bn >= hihifirstbn);
# hihi price level from 1st highest bar
def hihi_level = if bn == 1 or isnan(close) then na
# else if hihifirstbn > 0 and bn >= hihifirstbn then hihi
else if hi_bars then hihi
else na;
# true on the hihi bar
def ishi = if bn == 1 then 0
else if hihifirstbn == bn then 1
else 0;
addchartbubble(0, low,
bn + "\n" +
hihifirstbn
, color.yellow, no);
#-------------------------------------
#def lolo = 0;
# find lowest low
#def lo = if bn == 1 then 0
# else if first then Lowest(low[-(bars - 1)], (bars - 1))
# else lo[1];
##def lo2 = (lo == low);
#def islo = (lo == low);
# price level of the lowest low
def lolo = if bn == 1 or isnan(close) then 0
# else if first then lowest(low[-(bars - 1)], (bars - 1))
else if first then lowest(low[-(bars - 1)], (bars - 0))
else lolo[1];
# find bn of the first occurance of lolo
def lolofirstbn =
if lolo == 0 then 0
else if lolofirstbn[1] > 0 then lolofirstbn[1]
else if (lolo == low) then bn
else lolofirstbn[1];
# bars on and after the lolo
def lo_bars = (lolofirstbn > 0 and bn >= lolofirstbn);
# lolo price level from 1st lowest bar
def lolo_level = if bn == 1 or isnan(close) then na
# else if lolofirstbn > 0 and bn >= lolofirstbn then lolo
else if lo_bars then lolo
else na;
# true on the lolo bar
def islo = if bn == 1 then 0
else if lolofirstbn == bn then 1
else 0;
input test1 = no;
AddChartBubble(test1, 38,
hihi + "\n" +
#hi2 + "\n" +
ishi + "\n" +
lolo + "\n" +
#lo2
islo
, Color.YELLOW, yes);
input hilo_arrows = yes;
plot z1 = if hilo_arrows and ishi then high else na;
z1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
z1.SetDefaultColor(Color.CYAN);
z1.SetLineWeight(3);
z1.HideBubble();
plot z2 = if hilo_arrows and islo 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 put_buy_hilo = if bn == 1 or isnan(close) then 0 else if ishi then low else put_buy_hilo[1];
plot z3 = if put_buy_hilo > 0 then put_buy_hilo else na;
z3.SetDefaultColor(Color.RED);
#4) Once a candle closes a LL below that "Priceline", place a bubble called "Buy Puts" 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.
# replace , draws many bubbles
#def buyput = if close[1] crosses below hilo then 1 else 0;
#def buyput = if close[buyoff] crosses below put_buy_hilo then 1 else 0;
#AddChartBubble(buy_bubbles_on and buyput, high * 1.0005, "Buy Put", Color.RED, yes);
# chg signal, remove dup signals
# when triggered on first time, keep signal at 1.
# then check for transition 0 to 1
# chg words ? option ., stock oriented , or options
# long-open , short-open
# buy call , buy put
# bp = buyput
def bp1 = if period and !first then (close[buyoff] crosses below put_buy_hilo) else 0;
def bp2 =
if bn == 1 then 0
else if bp2[1] then bp2[1]
else if bp1 then 1
else bp2[1];
def bp3 = if !bp2[1] and bp2 then 1 else 0;
AddChartBubble(buy_bubbles_on and bp3, high * 1.0005, "Buy Put", Color.RED, yes);
addchartbubble(0,low*.997,
close[buyoff] + "\n" +
put_buy_hilo + "\n" +
bp1 + "\n" +
bp2 + "\n" +
bp3
, color.yellow, no);
# buy only on first signal
#def buyput = if !period then 0
# else if buyput[1] then buyput[1]
# else if close[buyoff] crosses below hilo then 1
# else buyput[1];
#def bp = !buyput[1] and buyput;
#addchartbubble(bubbles_on and bp, high*1.001, "Buy Put", color.red, yes);
AddChartBubble(0, low * 0.997,
period + " p\n" +
#buyput + " bp\n" +
close[buyoff] + " cls\n" +
put_buy_hilo + " hl"
, Color.YELLOW, no);
#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.
# hihi_level
#def hilo = if bn == 1 then 0 else if hi2 then low else hilo[1];
#plot z3 = if hilo > 0 then hilo else na;
# put stop , short stop
#def put_sell_hihi = if bn == 1 then 0 else if ishi then high else put_sell_hihi[1];
#plot z4 = if put_sell_hihi > 0 then put_buy_hilo else na;
plot z4 = hihi_level;
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
#def call_buy_lohi = if bn == 1 or isnan(close) then na else if islo then high else call_buy_lohi[1];
# chg to 0 , simpler
def call_buy_lohi = if bn == 1 or isnan(close) then 0 else if islo then high else call_buy_lohi[1];
plot z5 = if call_buy_lohi > 0 then call_buy_lohi else na;
z5.SetDefaultColor(Color.GREEN);
#7) Once a candle closes a HH above that "Priceline", place a bubble called "Buy Calls" 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.
# may bubbles
#def buycall = if close[1] crosses above lohi then 1 else 0;
#def buycall = if close[buyoff] crosses above call_buy_lohi then 1 else 0;
#AddChartBubble(buy_bubbles_on and buycall, low * 0.9995, "Buy Call", Color.GREEN, no);
# just first bubble
# bc = buycall
#def bc1 = if period and !first then (close[buyoff] crosses above call_buy_lohi) else 0;
# use offset so first bar of call_buy_lohi checked is after the buy signal. so its not trying to cross above a na
#def bc1 = if period and !isnan(call_buy_lohi[1]) then (close[buyoff] crosses above call_buy_lohi) else 0;
def bc1 = if period and !first then (close[buyoff] crosses above call_buy_lohi) else 0;
def bc2 =
if bn == 1 then 0
else if bc2[1] then bc2[1]
else if bc1 then 1
else bc2[1];
def bc3 = if !bc2[1] and bc2 then 1 else 0;
AddChartBubble(buy_bubbles_on and bc3, low * 0.9995, "Buy Call", Color.GREEN, no);
addchartbubble(0,low*.997,
close[buyoff] + "\n" +
call_buy_lohi + "\n" +
bc1 + "\n" +
bc2 + "\n" +
bc3
, color.yellow, no);
#, (if bc3 then color.yellow else color.gray), 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 call_sell_lolo = if bn == 1 then na else if islo then low else call_sell_lolo[1];
#plot z6 = call_sell_lolo;
plot z6 = lolo_level;
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,
# for puts, put a stop loss at the HH of the last two candles
# for calls, put a stop loss at the LL of the last two candles
#input gain_stop_percent = 50;
input gain_stop_percent = 20;
def offx = 2;
def ref_bubble_x = (!IsNaN(close[offx]) and IsNaN(close[(offx-1)]));
# puts
# draw stop ref line at (buy put $$) - 50%
# putreflevel = hilo - ( hilo * x%)
# puts
def putreflevel = put_buy_hilo - (put_buy_hilo * (gain_stop_percent/100));
# dashed line for stop , gray/red. draw dash line first
plot z23 = if put_buy_hilo > 0 then putreflevel else na;
# this color will appear as longer dashes than next color
z23.SetDefaultColor(Color.light_red);
#z23.SetDefaultColor(Color.light_gray);
z23.SetStyle(Curve.medium_DASH);
plot z24 = z23;
z24.SetDefaultColor(Color.light_gray);
#z24.SetDefaultColor(Color.light_red);
addchartbubble(ref_bubble_x, z23[offx],
gain_stop_percent + "% put stop ref"
, color.yellow, yes);
addchartbubble(0, low,
put_buy_hilo + "\n" +
putreflevel + "\n" +
z23
, color.yellow, no);
# calls
def callreflevel = call_buy_lohi + (call_buy_lohi * (gain_stop_percent/100));
# dashed line for stop , gray/red. draw dash line first
plot z25 = if call_buy_lohi > 0 then callreflevel else na;
# this color will appear as longer dashes than next color
z25.SetDefaultColor(Color.green);
#z25.SetDefaultColor(Color.light_gray);
z25.SetStyle(Curve.medium_DASH);
plot z26 = z25;
z26.SetDefaultColor(Color.blue);
#z26.SetDefaultColor(Color.gray);
#z26.SetDefaultColor(Color.light_red);
addchartbubble(ref_bubble_x, z25[offx],
gain_stop_percent + "% call stop ref"
, color.yellow, no);
#