Greetings! I'm requesting help with the creation of a channel indicator to be used on a 5 minute chart. The script would plot horizontal lines based on a high/low price from the previous day BUT with the flexibility to input the number of bars back from the previous day's close from which to start. For example, the "look-back" from the previous day's close might be 40 bars or 20 bars. Hopefully the screen shot helps clarify how the indicator would look.
FYI, I had received a solution from SleepyZ for a 30 minute channel for the start of the current day, which works great for the first 2 hours of trading. That script is shown below, but try as I might I cannot get this modified to meet the current request.
Thanks in advance for the assistance. Sure appreciate this community . . . =A=
#30 minute high/low channel
#Modified to work on charts whether extended hours are displayed or not
#Credit to SleepyZ at useThinkScript
input bars = 7;
input ORBegin = 0930;
#Thisday snippet
def ymd = GetYYYYMMDD();
def candles = !IsNaN(close);
def capture = candles and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
#Identifies each day with visible bars starting with #1
def thisDay = (HighestAll(dayCount) - dayCount) + 1 ;
def endbn = if SecondsFromTime(ORBegin) == 0 then BarNumber() + bars - 1 else endbn[1];
def endh = if Between(BarNumber(), endbn - bars , endbn) then Highest(high, bars ) else endh[1];
def endl = if Between(BarNumber(), endbn - bars , endbn ) then Lowest(low, bars ) else endl[1];
#Plot of highs/lows (endh/endl) based upon the first x bars input, projected after those first x bars
plot hafter_endbn = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() > endbn then endh else Double.NaN;
plot lafter_endbn = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() > endbn then endl else Double.NaN;
hafter_endbn.SetDefaultColor(Color.CYAN);
lafter_endbn.SetDefaultColor(Color.CYAN);
#Offset ([-bars]) of endh/endl to backfill those plots over the first x bars
plot h_after_offset = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() <= endbn then endh[-bars] else Double.NaN;
plot l_after_offset = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() <= endbn then endl[-bars] else Double.NaN;
h_after_offset.SetPaintingStrategy(PaintingStrategy.DASHES);
h_after_offset.SetDefaultColor(Color.WHITE);
l_after_offset.SetPaintingStrategy(PaintingStrategy.DASHES);
l_after_offset.SetDefaultColor(Color.WHITE);
input test = yes;
AddChartBubble(test and BarNumber() <= endbn, endl[-bars], thisDay + " \n" + endh + " \n" + endl, if low == endl[-bars] then Color.WHITE else if high == endh[-bars] then Color.YELLOW else if BarNumber() == endbn[-bars] then Color.MAGENTA else Color.GRAY, no);
input cloud = yes;
AddCloud(h_after_offset, l_after_offset, Color.WHITE);
FYI, I had received a solution from SleepyZ for a 30 minute channel for the start of the current day, which works great for the first 2 hours of trading. That script is shown below, but try as I might I cannot get this modified to meet the current request.
Thanks in advance for the assistance. Sure appreciate this community . . . =A=
#30 minute high/low channel
#Modified to work on charts whether extended hours are displayed or not
#Credit to SleepyZ at useThinkScript
input bars = 7;
input ORBegin = 0930;
#Thisday snippet
def ymd = GetYYYYMMDD();
def candles = !IsNaN(close);
def capture = candles and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
#Identifies each day with visible bars starting with #1
def thisDay = (HighestAll(dayCount) - dayCount) + 1 ;
def endbn = if SecondsFromTime(ORBegin) == 0 then BarNumber() + bars - 1 else endbn[1];
def endh = if Between(BarNumber(), endbn - bars , endbn) then Highest(high, bars ) else endh[1];
def endl = if Between(BarNumber(), endbn - bars , endbn ) then Lowest(low, bars ) else endl[1];
#Plot of highs/lows (endh/endl) based upon the first x bars input, projected after those first x bars
plot hafter_endbn = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() > endbn then endh else Double.NaN;
plot lafter_endbn = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() > endbn then endl else Double.NaN;
hafter_endbn.SetDefaultColor(Color.CYAN);
lafter_endbn.SetDefaultColor(Color.CYAN);
#Offset ([-bars]) of endh/endl to backfill those plots over the first x bars
plot h_after_offset = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() <= endbn then endh[-bars] else Double.NaN;
plot l_after_offset = if thisDay == 1 and SecondsFromTime(ORBegin) >= 0 and BarNumber() <= endbn then endl[-bars] else Double.NaN;
h_after_offset.SetPaintingStrategy(PaintingStrategy.DASHES);
h_after_offset.SetDefaultColor(Color.WHITE);
l_after_offset.SetPaintingStrategy(PaintingStrategy.DASHES);
l_after_offset.SetDefaultColor(Color.WHITE);
input test = yes;
AddChartBubble(test and BarNumber() <= endbn, endl[-bars], thisDay + " \n" + endh + " \n" + endl, if low == endl[-bars] then Color.WHITE else if high == endh[-bars] then Color.YELLOW else if BarNumber() == endbn[-bars] then Color.MAGENTA else Color.GRAY, no);
input cloud = yes;
AddCloud(h_after_offset, l_after_offset, Color.WHITE);