Hi all, sorry for the wait -- here is my latest attempt at the high-low indicator, with MTF options and no repainting once the signal is fully confirmed.
Above is the study using the 15min timeframe to form zones on the 5min chart -- I've also added the 13 and 48.5 emas in this picture.
As you can see, the zones no longer repaint, but I did add logic to suppress them after "length" amount of bars -- I may add this as an input later so that the length is separate from the zone extension. Also, given that this IS still a swinghigh/low study, you may see candles forming but if a new high/low is formed quickly, then it will reform the zone; that's just the nature of these studies, it can't detect the absolute high/low in real time lol. Also, you can obviously see that I still haven't gotten the duplicate signals to stop firing yet -- any help on that would be great.
Things I still want done here:
1. Making the signals only show once per zone
2. Adding the options for labels instead of arrows (probably doing this tonight)
3. Suppressing the signal creation if the chart or market internals are extremely against the countertrend signal (this can also likely be toggled)
4. There is still an option to add the vertical line but on MTF charts, it will show multiple times so I don't like it -- if there's a way to pretty that up it would be great
5. Adding the "buy types" back in, as I think that's a great option
Here is the link and code, I'll continue to improve on this but I wanted to at least get others' opinions and criticisms on this first:
http://tos.mx/gGbzkIZ
Code:
# +------------------------------------------------------------+
# New logic based on -- Example: How to extend levels to the right of the chart,
# by Robert Payne @ https://funwiththinkscript.com
# Logic provided by OGOptionsSlayer at usethinkscript.com
# define swing low points
input length = 20;
input add_cloud = yes;
#input buy_type = {default "Confirmation", "Active"};
#input bars_to_skip = 1;
input color_bars = yes;
input UseChartTime = no;
input agg = aggregationPeriod.FIFTEEN_MIN;
#input show_n =2;
def bn = BarNumber();
def na = double.nan;
# Scripts
script barssince {
input Condition = 0;
def barssince = if Condition then 1 else barssince[1] + 1;
plot return = barssince;
}
#//MTF
def l;
def h;
def c;
def o;
if UseChartTime
then {
o = open;
l = low;
h = high;
c = close;
} else {
o = open(period = agg);
l = low(period = agg);
h = high(period = agg);
c = close(period = agg);
}
def first = (!IsNaN(c[-(length - 1)]) and IsNaN(c[-length]));
def firstbar = bn - length;
#AddVerticalLine(first, "-", Color.WHITE);
def lastBar = HighestAll(if IsNaN(c) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
def swingLow = l < Lowest(l[1], length - 1) and l == GetValue(Lowest(l, length), -offset);
def swingHigh = h > Highest(h[1], length - 1) and h == GetValue(Highest(h, length), -offset);
# change candle colors just to make it easier to see what we are working with
AssignPriceColor(if color_bars then (if swingLow then Color.LIME else if swingHigh then Color.magenta else Color.current) else color.current);
# identify the very last swing low point
#def lowPointOneBarNumber = swingLow then bn else 0);
def swinglowbar = if swinglow then bn else swinglowbar[1];
def lowPointOnehigh = if swingLow then h else lowPointOnehigh[1];
def lowPointOneValue = if swinglowbar>=firstbar then (if swingLow then l else lowPointOneValue[1]) else na;
plot low1 = if swingLow then l else lowPointOneValue;
low1.SetDefaultColor(Color.LIME);
def lowPointOneup = if swinglowbar>=firstbar then (if swingLow then h else lowPointOnehigh[1]) else na;
plot low1high = if swingLow then h else lowPointOneup;
low1high.SetDefaultColor(Color.LIME);
AddCloud(if add_cloud then low1high else Double.NaN, low1, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
low1.setpaintingstrategy(paintingstrategy.horizontal);
low1high.setpaintingstrategy(paintingstrategy.horizontal);
def uppies = if barssince(swingLow) <= length then l else Double.NaN;
def sincelo = barssince(swingLow);
def crossup = if close[1] crosses above low1high then bn else 99999;
#def crossupbar = lowestall(crossup);
def crossupsig = if bn == crossup then 1 else 0;
def upsince = barssince(crossup);
# and upsince[1]<length;
plot lowup = crossupsig ;
# and barssince(swinglow)<20;
#and upsince[1]>5 ;
lowup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#AddLabel(yes , "Since Low " + barssince(swinglow), Color.GREEN);
def highbar = if swinghigh then bn else highbar[1];
# identify the very last swing low point
def highPointOneBarNumber = if swingHigh then bn else 0;
def highPointOnelo = if swingHigh then l else highPointOnelo[1];
def highPointOneValue = if highbar>=firstbar then (if swingHigh then h else highPointOneValue[1]) else na;
plot high1 = if swingHigh then h else highPointOneValue;
high1.SetDefaultColor(Color.RED);
#addchartbubble(swinghigh, low, "low" + low, color.yellow);
def highPointOnelow = if highbar>=firstbar then (if swingHigh then l else highPointOnelo[1]) else na;
plot high1low = if swingHigh then l else highPointOnelow;
high1low.SetDefaultColor(Color.RED);
AddCloud(if add_cloud then high1low else Double.NaN, high1, Color.LIGHT_RED, Color.LIGHT_RED);
def sincehigh = barssince(swingHigh);
#AddLabel(yes , if sincehigh < length then "True" else "False", Color.RED);
#AddLabel(yes , "Since High " + barssince(swinghigh), color.red);
#def crossdn = !first and close[1] crosses below high1low and close < high1low;
#def crossdn = (!first and close[1] crosses below high1low and close <high1low) or
# (sum(swinghigh, 3)>=1 and close[1] < high1low and close < high1low);
def crossdn = if close crosses below high1low then bn else 99999;
#def crossdnbar = between(highbar, crossdn, bn);
def crossdnsig = if bn equals crossdn then 1 else 0;
def dnsince = barssince(crossdn);
plot highdn = crossdnsig;
# and dnsince[1]<length;
highdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
high1.setpaintingstrategy(paintingstrategy.horizontal);
high1low.setpaintingstrategy(paintingstrategy.horizontal);
# End