Pull data from same day

grapetux

Member
Hey there, I'm hoping to adjust the below study so it plots the high and low from midnight onward, starting fresh each day.
Today when I ran the study it pulled the high from yesterday's overnight session.
Thanks for the help, cheers.

input show_lines = yes;
input show_bubbles = yes;

input aggregationPeriod = AggregationPeriod.WEEK;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;


plot DailyHigh;
plot DailyLow;

def DH = if IsNaN(close(period = aggregationPeriod)[-1])
then DH[1]
else Highest(high(period = aggregationPeriod)[-displace], length);
def DL = if IsNaN(close(period = aggregationPeriod)[-1])
then DL[1]
else Lowest(low(period = aggregationPeriod)[-displace], length);

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
} else {
DailyHigh = DH ;
DailyLow = DL ;
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyHigh.SetHiding(!show_lines);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetHiding(!show_lines);

def bn = BarNumber();
input bubble_displace = 3;

def mid=DH-DL;
plot middy = DL+(mid/2);

#AddChartBubble(show_bubbles and bn == HighestAll(bn - bubble_displace), DailyHigh, DailyHigh, Color.GREEN);
#AddChartBubble(show_bubbles and bn == HighestAll(bn - bubble_displace), DailyLow, DailyLow, Color.RED);

#AddChartBubble(show_bubbles and bn == HighestAll(bn - bubble_displace), middy, middy, Createcolor(25,175,195));


#Zones
#def cone= 3752.75;
#def ctwo = 3739.75;
#addcloud(cone,ctwo,createcolor(25,155,185), createcolor(25,55,185));



g3shawP.png
 
Hey there, I'm hoping to adjust the below study so it plots the high and low from midnight onward, starting fresh each day.
Today when I ran the study it pulled the high from yesterday's overnight session.
Thanks for the help, cheers.

input show_lines = yes;
input show_bubbles = yes;

input aggregationPeriod = AggregationPeriod.WEEK;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;


plot DailyHigh;
plot DailyLow;

def DH = if IsNaN(close(period = aggregationPeriod)[-1])
then DH[1]
else Highest(high(period = aggregationPeriod)[-displace], length);
def DL = if IsNaN(close(period = aggregationPeriod)[-1])
then DL[1]
else Lowest(low(period = aggregationPeriod)[-displace], length);

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
} else {
DailyHigh = DH ;
DailyLow = DL ;
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyHigh.SetHiding(!show_lines);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetHiding(!show_lines);

def bn = BarNumber();
input bubble_displace = 3;

def mid=DH-DL;
plot middy = DL+(mid/2);

#AddChartBubble(show_bubbles and bn == HighestAll(bn - bubble_displace), DailyHigh, DailyHigh, Color.GREEN);
#AddChartBubble(show_bubbles and bn == HighestAll(bn - bubble_displace), DailyLow, DailyLow, Color.RED);

#AddChartBubble(show_bubbles and bn == HighestAll(bn - bubble_displace), middy, middy, Createcolor(25,175,195));


#Zones
#def cone= 3752.75;
#def ctwo = 3739.75;
#addcloud(cone,ctwo,createcolor(25,155,185), createcolor(25,55,185));



g3shawP.png

This is meant to project the plot from the bar of the @HH/LL from midnight

Ruby:
## Example_HHLL_starting_Midnight_
input openingTime = 0000;
def sec   = SecondsFromTime(openingTime);
def range = if sec == 0 then range[1] + 1 else range[1];
addverticalLine(sec==0,"Midnight",color.cyan, stroke = Curve.FIRM);

input n = 0;
def bn  = BarNumber();
def ymd = range;
def ok  = !IsNaN(close);
def capture  = ok and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay  = (HighestAll(dayCount) - dayCount) ;

def hh      = CompoundValue(1,
              if thisDay[1] == n + 1 and thisDay == n
              then high
              else if  high > hh[1]
              then high
              else hh[1] , high);
def hhigh   = if thisDay == n and high == hh
              then bn
              else Double.NaN;
def hhnan   = if IsNaN(hh)
              then hhnan[1]
              else if bn >= HighestAll(hhigh)
              then hh
              else hhnan[1];
plot hhplot =hhnan;
hhplot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def ll      = CompoundValue(1,
              if thisDay[1] == n + 1 and thisDay == n
              then low
              else if low < ll[1]
              then low
              else ll[1] , low);
def llow    = if thisDay == n and low == ll
              then bn
              else Double.NaN;
def llnan   = if IsNaN(ll)
              then llnan[1]
              else if bn >= HighestAll(llow)
              then ll
              else llnan[1];
plot llplot = if thisDay > n and bn <= HighestAll(llow)
              then  Double.NaN
              else llnan;
llplot.setpaintingStrategy(paintingStrategy.HORIZONTAL);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

This is meant to project the plot from the bar of the @HH/LL from midnight
Hey SleepyZ, thanks for putting this together. I'm not sure if I explained what I was hoping to achieve properly. .
I ran the code you gave me and it is still plotting a low from last Thursday..
All I want from this study is to show the High and Low each day , resetting after midnight.. I attached a pic showing your code


Gx8P79r.png



Hoping to have a visual of hi and lo while trading.. and putting in a midline of that range. (hi-lo)/2 + lo.. Thanks for your help
 
Hey SleepyZ, thanks for putting this together. I'm not sure if I explained what I was hoping to achieve properly. .
I ran the code you gave me and it is still plotting a low from last Thursday..
All I want from this study is to show the High and Low each day , resetting after midnight.. I attached a pic showing your code


Gx8P79r.png



Hoping to have a visual of hi and lo while trading.. and putting in a midline of that range. (hi-lo)/2 + lo.. Thanks for your help

I missed that you were using a tick chart, which causes problems with the above code.

The good news is that the volumeprofle script has built-in what you requested once I changed the def cond = getday()!=getday()[1];#count < count[1] + period - period[1]; The ProfileHigh and ProfileLow are defaulted to not show, but they are the high/low of the cond setting.

Screenshot-2022-11-10-143131.png
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2010-2022
#

input pricePerRowHeightMode = {AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {CHART, MINUTE, HOUR, default DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 70;
input opacity = 50;

def period;
def yyyymmdd = getYyyyMmDd();
def seconds = secondsFromTime(0);
def month = getYear() * 12 + getMonth();
def day_number = daysFromDate(first(yyyymmdd)) + getDayOfWeek(first(yyyymmdd));
def dom = getDayOfMonth(yyyymmdd);
def dow = getDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
switch (timePerProfile) {
case CHART:
    period = 0;
case MINUTE:
    period = floor(seconds / 60 + day_number * 24 * 60);
case HOUR:
    period = floor(seconds / 3600 + day_number * 24);
case DAY:
    period = countTradingDays(min(first(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case WEEK:
    period = floor(day_number / 7);
case MONTH:
    period = floor(month - first(month));
case "OPT EXP":
    period = exp_opt - first(exp_opt);
case BAR:
    period = barNumber() - 1;
}

def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % multiplier else count[1], 0);
def cond = getday()!=getday()[1];#count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
    height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    height = PricePerRow.TICKSIZE;
case CUSTOM:
    height = customRowHeight;
}

profile vol = volumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = compoundValue(1, onExpansion, no);
def pc = if IsNaN(vol.getPointOfControl()) and con then pc[1] else vol.getPointOfControl();
def hVA = if IsNaN(vol.getHighestValueArea()) and con then hVA[1] else vol.getHighestValueArea();
def lVA = if IsNaN(vol.getLowestValueArea()) and con then lVA[1] else vol.getLowestValueArea();

def hProfile = if IsNaN(vol.getHighest()) and con then hProfile[1] else vol.getHighest();
def lProfile = if IsNaN(vol.getLowest()) and con then lProfile[1] else vol.getLowest();
def plotsDomain = IsNaN(close) == onExpansion;

plot POC = if plotsDomain then pc else Double.NaN;
plot ProfileHigh = if plotsDomain then hProfile else Double.NaN;
plot ProfileLow = if plotsDomain then lProfile else Double.NaN;
plot VAHigh = if plotsDomain then hVA else Double.NaN;
plot VALow = if plotsDomain then lVA else Double.NaN;

DefineGlobalColor("Profile", GetColor(1));
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));

vol.show(globalColor("Profile"), if showPointOfControl then globalColor("Point Of Control") else color.current, if showValueArea then globalColor("Value Area") else color.current, opacity);
POC.SetDefaultColor(globalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetDefaultColor(globalColor("Value Area"));
VALow.SetDefaultColor(globalColor("Value Area"));
ProfileHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh.SetDefaultColor(GetColor(3));
ProfileLow.SetDefaultColor(GetColor(3));
ProfileHigh.setlineWeight(5);
ProfileLow.setlineWeight(5);
#ProfileHigh.hide();
#ProfileLow.hide();
 
I missed that you were using a tick chart, which causes problems with the above code.

The good news is that the volumeprofle script has built-in what you requested once I changed the def cond = getday()!=getday()[1];#count < count[1] + period - period[1]; The ProfileHigh and ProfileLow are defaulted to not show, but they are the high/low of the cond setting.
Ok awesome, I suppose this could kill two birds with one stone.. The only thing I would need help with is to have volume profile to start the plot at midnight each morning.. so each day has its own profile, plotting the high and low from midnight onward for the day's session. Thanks again for all your help
 
@john3 See if this helps

Capture.jpg
Code:
#VolumeProfile_MidNight_Anchor
input begin = 0000;

input pricePerRowHeightMode = {AUTOMATIC, default TICKSIZE};
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
    height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    height = PricePerRow.TICKSIZE;
}

def rth  = SecondsFromTime(begin) == 0 and secondsTillTime(begin)==0;

profile vol = VolumeProfile("startNewProfile" = rth, "onExpansion" = no, "numberOfProfiles" = 1000, pricePerRow = height);

def pca      = if IsNaN(vol.GetPointOfControl())   then pca[1] else vol.GetPointOfControl();
def hVA      = if IsNaN(vol.GetHighestValueArea()) then hVA[1] else vol.GetHighestValueArea();
def lVA      = if IsNaN(vol.GetLowestValueArea())  then lVA[1] else vol.GetLowestValueArea();

def poc = if !rth or IsNaN(close) then poc[1] else pca;
def ub  = if !rth or IsNaN(close) then ub[1]  else hVA;
def lb  = if !rth or IsNaN(close) then lb[1]  else lVA;

plot VPOC = poc;
plot VAH  = ub;
plot VAL  = lb;

VPOC.SetDefaultColor(Color.MAGENTA);
VAH.SetDefaultColor(Color.WHITE);
VAL.SetDefaultColor(Color.WHITE);
VPOC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input showpointofcontrol = yes;
input showvaluearea = yes;
input opacity = 50;

vol.Show(Color.CYAN, if showpointofcontrol then Color.CYAN else Color.CURRENT, if showvaluearea then Color.YELLOW else Color.CURRENT, opacity);

def hProfile = if IsNaN(vol.GetHighest()) then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest())  then lProfile[1] else vol.GetLowest();

plot ProfileHigh =  hprofile;
plot ProfileLow  =  lprofile;

ProfileHigh.SetDefaultColor(Color.GREEN);
ProfileLow.SetDefaultColor(Color.RED);
ProfileHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Hey SleepyZ, can we get the exact midnight volume profile code above for tick charts? thx
 
Ok awesome, I suppose this could kill two birds with one stone.. The only thing I would need help with is to have volume profile to start the plot at midnight each morning.. so each day has its own profile, plotting the high and low from midnight onward for the day's session. Thanks again for all your help
For whatever reason the GetDay function starts each profile a few hours before the start of each new day. Is there a way to get is right at midnight?

ehT0o8x.png
 
For whatever reason the GetDay function starts each profile a few hours before the start of each new day. Is there a way to get is right at midnight?

ehT0o8x.png

The getday starts at midnight. The best way to see that is to set your chart and workspace to Eastern Timezone, which is what TOS uses in Thinkscript. When you have either of the chart or workspace set to your local or non-Eastern timezones, then it will erroneously appear that this indicator does not start at midnight.

Here is workspace set at ET
Here is chart with code from above and chart settings at ET. You can see that the getday usage starts the volumeprofile and thus the highs/lows at midnight
 
Last edited:
Hi there, need some help adjusting the DailyOpen TOS study
for some reason its pulling the opening price from the previous day..
If I could get some help to add an input to this study so I can select start time , be it the US open, midnight etc..
Thanks for the help, cheers.


h0lGqWL.png
 
Hi there, need some help adjusting the DailyOpen TOS study
for some reason its pulling the opening price from the previous day..
If I could get some help to add an input to this study so I can select start time , be it the US open, midnight etc..
Thanks for the help, cheers.


h0lGqWL.png

That is the Globex Open, which the TOS Daily Open uses for Futures.

Here is something that might help you

The image is Midnight @Eastern Timezone Chart Settings.

{Edit to adjust midnight definition]

Screenshot-2022-11-17-130408.png


Ruby:
input opentime  = {default Manual, Globex, Midnight, RTHstart};
input time      = 0930;
def globextime  = GetYYYYMMDD() != GetYYYYMMDD()[1];
def midnighttime = secondsfromtime(0000) == 0;
def RTHstarttime = GetTime() crosses above RegularTradingStart(GetYYYYMMDD());

def op;

switch (opentime) {
case Manual:
    op = if secondsfromTime(time) == 0 then open else op[1];
case Globex:
    op = if globextime then open else op[1];
case Midnight:
    op = if midnighttime then open else op[1];
case RTHstart:
    op = if RTHstarttime then open else op[1];
}

plot open = op;
open.setpaintingStrategy(paintingStrategy.HORIZONTAL);
 
Last edited:
That is the Globex Open, which the TOS Daily Open uses for Futures.

Here is something that might help you

The image is Midnight @Eastern Timezone Chart Settings.
Hey SZ yo thank you for all your help my friend. Im hoping to integrate the code you provided into my ATR study.
Can you possibly help?

input aggregationPeriod = AggregationPeriod.day;
input showOnlyLastPeriod = yes;

def prevPrice = open(period = aggregationPeriod)[-1];
def price = open(period = aggregationPeriod);
plot monthlyOpen = if showOnlyLastPeriod and !IsNaN(prevPrice) then Double.NaN else price;
monthlyOpen.setDefaultColor(createcolor(145,120,0));
monthlyOpen.setLineWeight(3);


def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def dayrange = (high - low);

def r1 = dayrange[1];
def r2 = dayrange[2];
def r3 = dayrange[3];
def r4 = dayrange[4];
def r5 = dayrange[5];
def r6 = dayrange[6];
def r7 = dayrange[7];
def r8 = dayrange[8];
def r9 = dayrange[9];
def r10 = dayrange[10];

def adr_10 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10;
def adr_5 = (r1 + r2 + r3 + r4 + r5) / 5;

def hl1 = (open + (adr_10 / 2));
def ll1 = (open - (adr_10 / 2));

def gg= hl1-open;

##lines##

def h= adr_10/2;
def q= adr_10/4;
def e= adr_10/8;
def s= adr_10/16;
#Round( (s) / 0.25,0) * 0.25;


addlabel(1," " +roundup(s) + " : cube ", color.dark_green);

#addlabel(1," " + "1conSL: " +s*5+ " // " + "2conSL: " +roundup(s*10) + " // " + "5conSL: " +roundup(s*25)+ " // " + "10conSL: " +s*50 + " " , color.gray);


# s) / 0.25,0) * 0.25;
#Round( ( s) / 0.25,0) * 0.25

#Eighths ATR
plot e1= Round( (open+e) / 0.25,0) * 0.25; ;
e1.setDefaultColor(createcolor(95,95,95));
e1.setStyle(curve.short_dash);
plot e3= Round( (open+e*3) / 0.25,0) * 0.25;
e3.setDefaultColor(createcolor(95,95,95));
e3.setStyle(curve.short_dash);
plot e5= Round( (open+e*5) / 0.25,0) * 0.25; ;
e5.setDefaultColor(createcolor(95,95,95));
e5.setStyle(curve.short_dash);
plot e7= Round( (open+e*7) / 0.25,0) * 0.25; ;
e7.setDefaultColor(createcolor(95,95,95));
e7.setStyle(curve.short_dash);


plot ex1= Round( (open-e) / 0.25,0) * 0.25; ;
ex1.setDefaultColor(createcolor(95,95,95));
ex1.setStyle(curve.short_dash);
plot ex3= Round( (open-e*3) / 0.25,0) * 0.25; ;
ex3.setDefaultColor(createcolor(95,95,95));
ex3.setStyle(curve.short_dash);
plot ex5= Round( (open-e*5) / 0.25,0) * 0.25; ;
ex5.setDefaultColor(createcolor(95,95,95));
ex5.setStyle(curve.short_dash);
plot ex7= Round( (open-e*7) / 0.25,0) * 0.25; ;
ex7.setDefaultColor(createcolor(95,95,95));
ex7.setStyle(curve.short_dash);


#quarter ATR
plot q1= Round( (open+q) / 0.25,0) * 0.25; ;
q1.setDefaultColor(createcolor(115,115,115));
q1.setStyle(curve.firm);
q1.setLineWeight(1);
plot q2=Round( ( open+q*2) / 0.25,0) * 0.25; ;
q2.setDefaultColor(createcolor(115,115,115));
q2.setStyle(curve.firm);
q2.setLineWeight(1);
plot q3=Round( ( open+q*3) / 0.25,0) * 0.25; ;
q3.setDefaultColor(createcolor(115,115,115));
q3.setStyle(curve.firm);
q3.setLineWeight(1);

plot qx1=Round( ( open-q) / 0.25,0) * 0.25; ;
qx1.setDefaultColor(createcolor(115,115,115));
qx1.setStyle(curve.firm);
qx1.setLineWeight(1);
plot qx2=Round( ( open-q*2) / 0.25,0) * 0.25; ;
qx2.setDefaultColor(createcolor(115,115,115));
qx2.setStyle(curve.firm);
qx2.setLineWeight(1);

plot qx3= round( (open-q*3) / 0.25,0) * 0.25;
qx3.setDefaultColor(createcolor(115,115,115));
qx3.setStyle(curve.firm);
qx3.setLineWeight(1);


# ) / 0.25,0) * 0.25;
#Round( (

plot s1=Round( ( open+s) / 0.25,0) * 0.25; ;
s1.setDefaultColor(createcolor(85,85,85));
s1.setStyle(curve.short_dash);
plot s3= Round( (open+s*3) / 0.25,0) * 0.25; ;
s3.setDefaultColor(createcolor(85,85,85));
s3.setStyle(curve.short_dash);
plot s5=Round( ( open+s*5) / 0.25,0) * 0.25; ;
s5.setDefaultColor(createcolor(85,85,85));
s5.setStyle(curve.short_dash);
plot s7=Round( ( open+s*7) / 0.25,0) * 0.25; ;
s7.setDefaultColor(createcolor(85,85,85));
s7.setStyle(curve.short_dash);
plot s9=Round( ( open+s*9) / 0.25,0) * 0.25; ;
s9.setDefaultColor(createcolor(85,85,85));
s9.setStyle(curve.short_dash);
plot s11=Round( ( open+s*11) / 0.25,0) * 0.25; ;
s11.setDefaultColor(createcolor(85,85,85));
s11.setStyle(curve.short_dash);
plot s13=Round( ( open+s*13) / 0.25,0) * 0.25; ;
s13.setDefaultColor(createcolor(85,85,85));
s13.setStyle(curve.short_dash);
plot s15=Round( ( open+s*15) / 0.25,0) * 0.25; ;
s15.setDefaultColor(createcolor(85,85,85));
s15.setStyle(curve.short_dash);


plot sx1=Round( ( open-s) / 0.25,0) * 0.25; ;
sx1.setDefaultColor(createcolor(85,85,85));
sx1.setStyle(curve.short_dash);
plot sx3= Round( (open-s*3) / 0.25,0) * 0.25; ;
sx3.setDefaultColor(createcolor(85,85,85));
sx3.setStyle(curve.short_dash);
plot sx5=Round( ( open-s*5) / 0.25,0) * 0.25; ;
sx5.setDefaultColor(createcolor(85,85,85));
sx5.setStyle(curve.short_dash);
plot sx7=Round( ( open-s*7) / 0.25,0) * 0.25; ;
sx7.setDefaultColor(createcolor(85,85,85));
sx7.setStyle(curve.short_dash);
plot sx9=Round( ( open-s*9) / 0.25,0) * 0.25; ;
sx9.setDefaultColor(createcolor(85,85,85));
sx9.setStyle(curve.short_dash);
plot sx11=Round( ( open-s*11) / 0.25,0) * 0.25; ;
sx11.setDefaultColor(createcolor(85,85,85));
sx11.setStyle(curve.short_dash);
plot sx13=Round( ( open-s*13) / 0.25,0) * 0.25; ;
sx13.setDefaultColor(createcolor(85,85,85));
sx13.setStyle(curve.short_dash);
plot sx15=Round( ( open-s*15) / 0.25,0) * 0.25; ;
sx15.setDefaultColor(createcolor(85,85,85));
sx15.setStyle(curve.short_dash);
 
Hey SZ yo thank you for all your help my friend. Im hoping to integrate the code you provided into my ATR study.
Can you possibly help?

input aggregationPeriod = AggregationPeriod.day;
input showOnlyLastPeriod = yes;

def prevPrice = open(period = aggregationPeriod)[-1];
def price = open(period = aggregationPeriod);
plot monthlyOpen = if showOnlyLastPeriod and !IsNaN(prevPrice) then Double.NaN else price;
monthlyOpen.setDefaultColor(createcolor(145,120,0));
monthlyOpen.setLineWeight(3);


def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def dayrange = (high - low);

def r1 = dayrange[1];
def r2 = dayrange[2];
def r3 = dayrange[3];
def r4 = dayrange[4];
def r5 = dayrange[5];
def r6 = dayrange[6];
def r7 = dayrange[7];
def r8 = dayrange[8];
def r9 = dayrange[9];
def r10 = dayrange[10];

def adr_10 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10;
def adr_5 = (r1 + r2 + r3 + r4 + r5) / 5;

def hl1 = (open + (adr_10 / 2));
def ll1 = (open - (adr_10 / 2));

def gg= hl1-open;

##lines##

def h= adr_10/2;
def q= adr_10/4;
def e= adr_10/8;
def s= adr_10/16;
#Round( (s) / 0.25,0) * 0.25;


addlabel(1," " +roundup(s) + " : cube ", color.dark_green);

#addlabel(1," " + "1conSL: " +s*5+ " // " + "2conSL: " +roundup(s*10) + " // " + "5conSL: " +roundup(s*25)+ " // " + "10conSL: " +s*50 + " " , color.gray);


# s) / 0.25,0) * 0.25;
#Round( ( s) / 0.25,0) * 0.25

#Eighths ATR
plot e1= Round( (open+e) / 0.25,0) * 0.25; ;
e1.setDefaultColor(createcolor(95,95,95));
e1.setStyle(curve.short_dash);
plot e3= Round( (open+e*3) / 0.25,0) * 0.25;
e3.setDefaultColor(createcolor(95,95,95));
e3.setStyle(curve.short_dash);
plot e5= Round( (open+e*5) / 0.25,0) * 0.25; ;
e5.setDefaultColor(createcolor(95,95,95));
e5.setStyle(curve.short_dash);
plot e7= Round( (open+e*7) / 0.25,0) * 0.25; ;
e7.setDefaultColor(createcolor(95,95,95));
e7.setStyle(curve.short_dash);


plot ex1= Round( (open-e) / 0.25,0) * 0.25; ;
ex1.setDefaultColor(createcolor(95,95,95));
ex1.setStyle(curve.short_dash);
plot ex3= Round( (open-e*3) / 0.25,0) * 0.25; ;
ex3.setDefaultColor(createcolor(95,95,95));
ex3.setStyle(curve.short_dash);
plot ex5= Round( (open-e*5) / 0.25,0) * 0.25; ;
ex5.setDefaultColor(createcolor(95,95,95));
ex5.setStyle(curve.short_dash);
plot ex7= Round( (open-e*7) / 0.25,0) * 0.25; ;
ex7.setDefaultColor(createcolor(95,95,95));
ex7.setStyle(curve.short_dash);


#quarter ATR
plot q1= Round( (open+q) / 0.25,0) * 0.25; ;
q1.setDefaultColor(createcolor(115,115,115));
q1.setStyle(curve.firm);
q1.setLineWeight(1);
plot q2=Round( ( open+q*2) / 0.25,0) * 0.25; ;
q2.setDefaultColor(createcolor(115,115,115));
q2.setStyle(curve.firm);
q2.setLineWeight(1);
plot q3=Round( ( open+q*3) / 0.25,0) * 0.25; ;
q3.setDefaultColor(createcolor(115,115,115));
q3.setStyle(curve.firm);
q3.setLineWeight(1);

plot qx1=Round( ( open-q) / 0.25,0) * 0.25; ;
qx1.setDefaultColor(createcolor(115,115,115));
qx1.setStyle(curve.firm);
qx1.setLineWeight(1);
plot qx2=Round( ( open-q*2) / 0.25,0) * 0.25; ;
qx2.setDefaultColor(createcolor(115,115,115));
qx2.setStyle(curve.firm);
qx2.setLineWeight(1);

plot qx3= round( (open-q*3) / 0.25,0) * 0.25;
qx3.setDefaultColor(createcolor(115,115,115));
qx3.setStyle(curve.firm);
qx3.setLineWeight(1);


# ) / 0.25,0) * 0.25;
#Round( (

plot s1=Round( ( open+s) / 0.25,0) * 0.25; ;
s1.setDefaultColor(createcolor(85,85,85));
s1.setStyle(curve.short_dash);
plot s3= Round( (open+s*3) / 0.25,0) * 0.25; ;
s3.setDefaultColor(createcolor(85,85,85));
s3.setStyle(curve.short_dash);
plot s5=Round( ( open+s*5) / 0.25,0) * 0.25; ;
s5.setDefaultColor(createcolor(85,85,85));
s5.setStyle(curve.short_dash);
plot s7=Round( ( open+s*7) / 0.25,0) * 0.25; ;
s7.setDefaultColor(createcolor(85,85,85));
s7.setStyle(curve.short_dash);
plot s9=Round( ( open+s*9) / 0.25,0) * 0.25; ;
s9.setDefaultColor(createcolor(85,85,85));
s9.setStyle(curve.short_dash);
plot s11=Round( ( open+s*11) / 0.25,0) * 0.25; ;
s11.setDefaultColor(createcolor(85,85,85));
s11.setStyle(curve.short_dash);
plot s13=Round( ( open+s*13) / 0.25,0) * 0.25; ;
s13.setDefaultColor(createcolor(85,85,85));
s13.setStyle(curve.short_dash);
plot s15=Round( ( open+s*15) / 0.25,0) * 0.25; ;
s15.setDefaultColor(createcolor(85,85,85));
s15.setStyle(curve.short_dash);


plot sx1=Round( ( open-s) / 0.25,0) * 0.25; ;
sx1.setDefaultColor(createcolor(85,85,85));
sx1.setStyle(curve.short_dash);
plot sx3= Round( (open-s*3) / 0.25,0) * 0.25; ;
sx3.setDefaultColor(createcolor(85,85,85));
sx3.setStyle(curve.short_dash);
plot sx5=Round( ( open-s*5) / 0.25,0) * 0.25; ;
sx5.setDefaultColor(createcolor(85,85,85));
sx5.setStyle(curve.short_dash);
plot sx7=Round( ( open-s*7) / 0.25,0) * 0.25; ;
sx7.setDefaultColor(createcolor(85,85,85));
sx7.setStyle(curve.short_dash);
plot sx9=Round( ( open-s*9) / 0.25,0) * 0.25; ;
sx9.setDefaultColor(createcolor(85,85,85));
sx9.setStyle(curve.short_dash);
plot sx11=Round( ( open-s*11) / 0.25,0) * 0.25; ;
sx11.setDefaultColor(createcolor(85,85,85));
sx11.setStyle(curve.short_dash);
plot sx13=Round( ( open-s*13) / 0.25,0) * 0.25; ;
sx13.setDefaultColor(createcolor(85,85,85));
sx13.setStyle(curve.short_dash);
plot sx15=Round( ( open-s*15) / 0.25,0) * 0.25; ;
sx15.setDefaultColor(createcolor(85,85,85));
sx15.setStyle(curve.short_dash);

I have meshed it into your code. However, as is, I do not think it will work how you want.
You are using an aggregationperiod, which will not match most of the input opentime options.

Ruby:
input opentime  = {default Manual, Globex, Midnight, RTHstart};
input aggregationPeriod = AggregationPeriod.day;
input showOnlyLastPeriod = yes;


input time      = 0930;
def globextime  = GetYYYYMMDD() != GetYYYYMMDD()[1];
def midnighttime = secondsfromtime(0000) == 0;
def RTHstarttime = GetTime() crosses above RegularTradingStart(GetYYYYMMDD());

def op;

switch (opentime) {
case Manual:
    op = if secondsfromTime(time) == 0 then open(period = aggregationPeriod) else op[1];
case Globex:
    op = if globextime then open(period = aggregationPeriod) else op[1];
case Midnight:
    op = if midnighttime then open(period = aggregationPeriod) else op[1];
case RTHstart:
    op = if RTHstarttime then open(period = aggregationPeriod) else op[1];
}

#def open = op;
#open.setpaintingStrategy(paintingStrategy.HORIZONTAL);



def prevPrice = open(period = aggregationPeriod)[-1];
def price = open(period = aggregationPeriod);
plot monthlyOpen = if showOnlyLastPeriod and !IsNaN(prevPrice) then Double.NaN else price;
monthlyOpen.setDefaultColor(createcolor(145,120,0));
monthlyOpen.setLineWeight(3);


def open = op;
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def dayrange = (high - low);

def r1 = dayrange[1];
def r2 = dayrange[2];
def r3 = dayrange[3];
def r4 = dayrange[4];
def r5 = dayrange[5];
def r6 = dayrange[6];
def r7 = dayrange[7];
def r8 = dayrange[8];
def r9 = dayrange[9];
def r10 = dayrange[10];

def adr_10 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10;
def adr_5 = (r1 + r2 + r3 + r4 + r5) / 5;

def hl1 = (open + (adr_10 / 2));
def ll1 = (open - (adr_10 / 2));

def gg= hl1-open;

##lines##

def h= adr_10/2;
def q= adr_10/4;
def e= adr_10/8;
def s= adr_10/16;
#Round( (s) / 0.25,0) * 0.25;


addlabel(1," " +roundup(s) + " : cube ", color.dark_green);

#addlabel(1," " + "1conSL: " +s*5+ " // " + "2conSL: " +roundup(s*10) + " // " + "5conSL: " +roundup(s*25)+ " // " + "10conSL: " +s*50 + " " , color.gray);


# s) / 0.25,0) * 0.25;
#Round( ( s) / 0.25,0) * 0.25

#Eighths ATR
plot e1= Round( (open+e) / 0.25,0) * 0.25; ;
e1.setDefaultColor(createcolor(95,95,95));
e1.setStyle(curve.short_dash);
plot e3= Round( (open+e*3) / 0.25,0) * 0.25;
e3.setDefaultColor(createcolor(95,95,95));
e3.setStyle(curve.short_dash);
plot e5= Round( (open+e*5) / 0.25,0) * 0.25; ;
e5.setDefaultColor(createcolor(95,95,95));
e5.setStyle(curve.short_dash);
plot e7= Round( (open+e*7) / 0.25,0) * 0.25; ;
e7.setDefaultColor(createcolor(95,95,95));
e7.setStyle(curve.short_dash);


plot ex1= Round( (open-e) / 0.25,0) * 0.25; ;
ex1.setDefaultColor(createcolor(95,95,95));
ex1.setStyle(curve.short_dash);
plot ex3= Round( (open-e*3) / 0.25,0) * 0.25; ;
ex3.setDefaultColor(createcolor(95,95,95));
ex3.setStyle(curve.short_dash);
plot ex5= Round( (open-e*5) / 0.25,0) * 0.25; ;
ex5.setDefaultColor(createcolor(95,95,95));
ex5.setStyle(curve.short_dash);
plot ex7= Round( (open-e*7) / 0.25,0) * 0.25; ;
ex7.setDefaultColor(createcolor(95,95,95));
ex7.setStyle(curve.short_dash);


#quarter ATR
plot q1= Round( (open+q) / 0.25,0) * 0.25; ;
q1.setDefaultColor(createcolor(115,115,115));
q1.setStyle(curve.firm);
q1.setLineWeight(1);
plot q2=Round( ( open+q*2) / 0.25,0) * 0.25; ;
q2.setDefaultColor(createcolor(115,115,115));
q2.setStyle(curve.firm);
q2.setLineWeight(1);
plot q3=Round( ( open+q*3) / 0.25,0) * 0.25; ;
q3.setDefaultColor(createcolor(115,115,115));
q3.setStyle(curve.firm);
q3.setLineWeight(1);

plot qx1=Round( ( open-q) / 0.25,0) * 0.25; ;
qx1.setDefaultColor(createcolor(115,115,115));
qx1.setStyle(curve.firm);
qx1.setLineWeight(1);
plot qx2=Round( ( open-q*2) / 0.25,0) * 0.25; ;
qx2.setDefaultColor(createcolor(115,115,115));
qx2.setStyle(curve.firm);
qx2.setLineWeight(1);

plot qx3= round( (open-q*3) / 0.25,0) * 0.25;
qx3.setDefaultColor(createcolor(115,115,115));
qx3.setStyle(curve.firm);
qx3.setLineWeight(1);


# ) / 0.25,0) * 0.25;
#Round( (

plot s1=Round( ( open+s) / 0.25,0) * 0.25; ;
s1.setDefaultColor(createcolor(85,85,85));
s1.setStyle(curve.short_dash);
plot s3= Round( (open+s*3) / 0.25,0) * 0.25; ;
s3.setDefaultColor(createcolor(85,85,85));
s3.setStyle(curve.short_dash);
plot s5=Round( ( open+s*5) / 0.25,0) * 0.25; ;
s5.setDefaultColor(createcolor(85,85,85));
s5.setStyle(curve.short_dash);
plot s7=Round( ( open+s*7) / 0.25,0) * 0.25; ;
s7.setDefaultColor(createcolor(85,85,85));
s7.setStyle(curve.short_dash);
plot s9=Round( ( open+s*9) / 0.25,0) * 0.25; ;
s9.setDefaultColor(createcolor(85,85,85));
s9.setStyle(curve.short_dash);
plot s11=Round( ( open+s*11) / 0.25,0) * 0.25; ;
s11.setDefaultColor(createcolor(85,85,85));
s11.setStyle(curve.short_dash);
plot s13=Round( ( open+s*13) / 0.25,0) * 0.25; ;
s13.setDefaultColor(createcolor(85,85,85));
s13.setStyle(curve.short_dash);
plot s15=Round( ( open+s*15) / 0.25,0) * 0.25; ;
s15.setDefaultColor(createcolor(85,85,85));
s15.setStyle(curve.short_dash);


plot sx1=Round( ( open-s) / 0.25,0) * 0.25; ;
sx1.setDefaultColor(createcolor(85,85,85));
sx1.setStyle(curve.short_dash);
plot sx3= Round( (open-s*3) / 0.25,0) * 0.25; ;
sx3.setDefaultColor(createcolor(85,85,85));
sx3.setStyle(curve.short_dash);
plot sx5=Round( ( open-s*5) / 0.25,0) * 0.25; ;
sx5.setDefaultColor(createcolor(85,85,85));
sx5.setStyle(curve.short_dash);
plot sx7=Round( ( open-s*7) / 0.25,0) * 0.25; ;
sx7.setDefaultColor(createcolor(85,85,85));
sx7.setStyle(curve.short_dash);
plot sx9=Round( ( open-s*9) / 0.25,0) * 0.25; ;
sx9.setDefaultColor(createcolor(85,85,85));
sx9.setStyle(curve.short_dash);
plot sx11=Round( ( open-s*11) / 0.25,0) * 0.25; ;
sx11.setDefaultColor(createcolor(85,85,85));
sx11.setStyle(curve.short_dash);
plot sx13=Round( ( open-s*13) / 0.25,0) * 0.25; ;
sx13.setDefaultColor(createcolor(85,85,85));
sx13.setStyle(curve.short_dash);
plot sx15=Round( ( open-s*15) / 0.25,0) * 0.25; ;
sx15.setDefaultColor(createcolor(85,85,85));
sx15.setStyle(curve.short_dash);
 
I have meshed it into your code. However, as is, I do not think it will work how you want.
You are using an aggregationperiod, which will not match most of the input opentime options.
Thank you again sir! Can we possibly add a daily close function this this as well with the ability to choose different times? Cheers
 
Thank you again sir! Can we possibly add a daily close function this this as well with the ability to choose different times? Cheers

Try this

Ruby:
input closetime  = {default Manual, PreMarketend, RTHend, EXTend};
input time       = 1600;
def PreMarketend = gettime() crosses above regularTradingStart(getyyyYMMDD());
def RTHend       = secondsfromtime(1600) == 0;
def EXTend       = GetTime() crosses above RegularTradingEnd(GetYYYYMMDD());

def cl;

switch (closetime) {
case Manual:
    cl = if SecondsFromTime(time) == 0 then close else cl[1];
case PreMarketend:
    cl = if PreMarketend then close[1] else cl[1];
case RTHend:
    cl = if RTHend then close else cl[1];
case EXTend:
    cl = if EXTend then close else cl[1];
}

plot close = cl;
close.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
434 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top