Previous hour, hours high low close

Mikeydo2

New member
VIP
Thanks to all of you very much for the great studies and education. I am looking for the previous hour, hours, high, low, close. I have searched and haven’t had any luck. Could someone point me in the right direction? Or, perhaps create a script that would plot previous hour, or 2 hour, or 4 hour, high, low, close? That would stay printed on the chart. Thank you in advance for the help.

Just like the study below but hourly instead of daily

#Shows previous days High, Low, Open, Close, and High/Low of defined timeframe.

#Code by Svanoy



input Show_High = No;

input Show_Low = No;

input Show_Open = No;

input Show_Close = No;

input Show_Time_Frame_High_and_Low = Yes;

input periodstart = 1400;

input periodend = 1500;

input sPeriod = {default DAY, WEEK, MONTH, YEAR};

def offset = 1;



def DAY = if GetDay()==GetLastDAY() then 1 else 0;

def varhigh = high(period = sPeriod)[offset];

def varlow = low(period = sPeriod)[offset];

def varopen = open(period = sPeriod)[offset];

def varclose = close(period = sPeriod)[offset];



def activeperiod = If secondsFromTime(periodstart)>=0 and secondsTillTime(periodend)>0 then yes else Double.NaN;

def acriveperiodstartbar = if secondsFromTime(periodstart)==0 then barnumber() else acriveperiodstartbar[1];

def activeperiodendbar = fold i=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod,-i)) do GetValue(BarNumber(),-i);

def activeperiodlength = 1+(activeperiodendbar-acriveperiodstartbar);



def activeperiodhigh;

if secondsFromTime(periodstart)==0 {

activeperiodhigh = high;

}else if !IsNaN(activeperiod) and high>=activeperiodhigh[1]{

activeperiodhigh = high;

}else{

activeperiodhigh = activeperiodhigh[1];}



def activeperiodlow;

if secondsFromTime(periodstart)==0 {

activeperiodlow = low;

}else if !IsNaN(activeperiod) and low<=activeperiodlow[1]{

activeperiodlow = low;

}else{

activeperiodlow = activeperiodlow[1];}



def activephigh = fold iah=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh,-iah);

def activeplow = fold ial=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow,-ial);

def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;

def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;

def h = fold ih = 0 to 1 while !IsNaN(close[10]) do varhigh;

def l = fold il = 0 to 1 while !IsNaN(close[10]) do varlow;

def o = fold io = 0 to 1 while !IsNaN(close[10]) do varopen;

def c = fold ic = 0 to 1 while !IsNaN(close[10]) do varclose;



plot PreHigh = if !IsNaN(activeperiod) and activephigh>0 then activephigh else Double.NaN;

PreHigh.SetPaintingStrategy(PaintingStrategy.LINE);

PreHigh.SetDefaultColor(Color.LIME);

PreHigh.SetHiding(!Show_Time_Frame_High_and_Low);



plot PreLow = if !IsNaN(activeperiod) and activeplow>0 then activeplow else Double.NaN;

PreLow.SetPaintingStrategy(PaintingStrategy.LINE);

PreLow.SetDefaultColor(Color.PINK);

PreLow.SetHiding(!Show_Time_Frame_High_and_Low);



plot PMHigh = if IsNaN(activeperiod) and aph>0 then aph else Double.NaN;

PMHigh.SetPaintingStrategy(PaintingStrategy.DASHES);

PMHigh.SetDefaultColor(Color.LIME);

PMHigh.SetHiding(!Show_Time_Frame_High_and_Low);



plot PMLow = if IsNaN(activeperiod) and apl>0 then apl else Double.NaN;

PMLow.SetPaintingStrategy(PaintingStrategy.DASHES);

PMLow.SetDefaultColor(Color.PINK);

PMLow.SetHiding(!Show_Time_Frame_High_and_Low);



plot DayHigh = if h > 1 then h else Double.NaN;

DayHigh.SetPaintingStrategy(PaintingStrategy.DASHES);

DayHigh.SetDefaultColor(Color.LIGHT_GREEN);

DayHigh.SetHiding(!Show_High);



plot DayLow = if l > 1 then l else Double.NaN;

DayLow.SetPaintingStrategy(PaintingStrategy.DASHES);

DayLow.SetDefaultColor(Color.LIGHT_RED);

DayLow.SetHiding(!Show_Low);



plot DayOpen = if o > 1 then o else Double.NaN;

DayOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DayOpen.AssignValueColor(if varopen >= varclose then Color.GREEN else Color.RED);

DayOpen.SetHiding(!Show_Open);



plot DayClose = if c > 1 then c else Double.NaN;

DayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DayClose.AssignValueColor(if varopen >= varclose then CreateColor(128,123,0) else CreateColor(128,123,0));

DayClose.SetHiding(!Show_Close);
 
Thanks to all of you very much for the great studies and education. I am looking for the previous hour, hours, high, low, close. I have searched and haven’t had any luck. Could someone point me in the right direction? Or, perhaps create a script that would plot previous hour, or 2 hour, or 4 hour, high, low, close? That would stay printed on the chart. Thank you in advance for the help.

Just like the study below but hourly instead of daily

#Shows previous days High, Low, Open, Close, and High/Low of defined timeframe.

#Code by Svanoy



input Show_High = No;

input Show_Low = No;

input Show_Open = No;

input Show_Close = No;

input Show_Time_Frame_High_and_Low = Yes;

input periodstart = 1400;

input periodend = 1500;

input sPeriod = {default DAY, WEEK, MONTH, YEAR};

def offset = 1;



def DAY = if GetDay()==GetLastDAY() then 1 else 0;

def varhigh = high(period = sPeriod)[offset];

def varlow = low(period = sPeriod)[offset];

def varopen = open(period = sPeriod)[offset];

def varclose = close(period = sPeriod)[offset];



def activeperiod = If secondsFromTime(periodstart)>=0 and secondsTillTime(periodend)>0 then yes else Double.NaN;

def acriveperiodstartbar = if secondsFromTime(periodstart)==0 then barnumber() else acriveperiodstartbar[1];

def activeperiodendbar = fold i=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod,-i)) do GetValue(BarNumber(),-i);

def activeperiodlength = 1+(activeperiodendbar-acriveperiodstartbar);



def activeperiodhigh;

if secondsFromTime(periodstart)==0 {

activeperiodhigh = high;

}else if !IsNaN(activeperiod) and high>=activeperiodhigh[1]{

activeperiodhigh = high;

}else{

activeperiodhigh = activeperiodhigh[1];}



def activeperiodlow;

if secondsFromTime(periodstart)==0 {

activeperiodlow = low;

}else if !IsNaN(activeperiod) and low<=activeperiodlow[1]{

activeperiodlow = low;

}else{

activeperiodlow = activeperiodlow[1];}



def activephigh = fold iah=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh,-iah);

def activeplow = fold ial=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow,-ial);

def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;

def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;

def h = fold ih = 0 to 1 while !IsNaN(close[10]) do varhigh;

def l = fold il = 0 to 1 while !IsNaN(close[10]) do varlow;

def o = fold io = 0 to 1 while !IsNaN(close[10]) do varopen;

def c = fold ic = 0 to 1 while !IsNaN(close[10]) do varclose;



plot PreHigh = if !IsNaN(activeperiod) and activephigh>0 then activephigh else Double.NaN;

PreHigh.SetPaintingStrategy(PaintingStrategy.LINE);

PreHigh.SetDefaultColor(Color.LIME);

PreHigh.SetHiding(!Show_Time_Frame_High_and_Low);



plot PreLow = if !IsNaN(activeperiod) and activeplow>0 then activeplow else Double.NaN;

PreLow.SetPaintingStrategy(PaintingStrategy.LINE);

PreLow.SetDefaultColor(Color.PINK);

PreLow.SetHiding(!Show_Time_Frame_High_and_Low);



plot PMHigh = if IsNaN(activeperiod) and aph>0 then aph else Double.NaN;

PMHigh.SetPaintingStrategy(PaintingStrategy.DASHES);

PMHigh.SetDefaultColor(Color.LIME);

PMHigh.SetHiding(!Show_Time_Frame_High_and_Low);



plot PMLow = if IsNaN(activeperiod) and apl>0 then apl else Double.NaN;

PMLow.SetPaintingStrategy(PaintingStrategy.DASHES);

PMLow.SetDefaultColor(Color.PINK);

PMLow.SetHiding(!Show_Time_Frame_High_and_Low);



plot DayHigh = if h > 1 then h else Double.NaN;

DayHigh.SetPaintingStrategy(PaintingStrategy.DASHES);

DayHigh.SetDefaultColor(Color.LIGHT_GREEN);

DayHigh.SetHiding(!Show_High);



plot DayLow = if l > 1 then l else Double.NaN;

DayLow.SetPaintingStrategy(PaintingStrategy.DASHES);

DayLow.SetDefaultColor(Color.LIGHT_RED);

DayLow.SetHiding(!Show_Low);



plot DayOpen = if o > 1 then o else Double.NaN;

DayOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DayOpen.AssignValueColor(if varopen >= varclose then Color.GREEN else Color.RED);

DayOpen.SetHiding(!Show_Open);



plot DayClose = if c > 1 then c else Double.NaN;

DayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DayClose.AssignValueColor(if varopen >= varclose then CreateColor(128,123,0) else CreateColor(128,123,0));

DayClose.SetHiding(!Show_Close);

not sure what all your code does,
here is a basic version

Code:
def na = Double.NaN;

input Show_High = yes;
input Show_Low = yes;
input Show_Open = yes;
input Show_Close = yes;

input agg_period = AggregationPeriod.HOUR;
input offset = 1;
plot zo = if Show_Open then open(period = agg_period)[offset] else na;
plot zh = if Show_High then high(period = agg_period)[offset] else na;
plot zl = if Show_Low then low(period = agg_period)[offset] else na;
plot zc = if Show_Close then close(period = agg_period)[offset] else na;

zo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

zo.SetDefaultColor(Color.cyan);
zh.SetDefaultColor(Color.gray);
zl.SetDefaultColor(Color.gray);
zc.SetDefaultColor(Color.yellow);
#
 
not sure what all your code does,
here is a basic version

Code:
def na = Double.NaN;

input Show_High = yes;
input Show_Low = yes;
input Show_Open = yes;
input Show_Close = yes;

input agg_period = AggregationPeriod.HOUR;
input offset = 1;
plot zo = if Show_Open then open(period = agg_period)[offset] else na;
plot zh = if Show_High then high(period = agg_period)[offset] else na;
plot zl = if Show_Low then low(period = agg_period)[offset] else na;
plot zc = if Show_Close then close(period = agg_period)[offset] else na;

zo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

zo.SetDefaultColor(Color.cyan);
zh.SetDefaultColor(Color.gray);
zl.SetDefaultColor(Color.gray);
zc.SetDefaultColor(Color.yellow);
#
Thank you very much
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
316 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