% chg from random intraday periods

PriorMember

New member
Hello I am new here, please does anyone have a code for the percentage price change from one specific intraday time to another? for example: A %chg from random times like 9:52a up to 10:32a or any 2 min frame. Any help will be much appreciated!!
 
Hello I am new here, please does anyone have a code for the percentage price change from one specific intraday time to another? for example: A %chg from random times like 9:52a up to 10:32a or any 2 min frame. Any help will be much appreciated!!


find price and % difference between 2 bars during the same day.
pick 2 times, in HHMM format , in EST.
defaults
input start = 0945;
input end = 1115;

draw cyan dots on bars
prices from current day are displayed in labels

Code:
# chg_of2_bars

def bn = BarNumber();
def na = Double.NaN;

#def daytime3 = (gettime() >= RegularTradingStart(GetYYYYMMDD()) and gettime() < RegularTradingend(GetYYYYMMDD()));
#def difftime = daytime3 != daytime3[1];
#def timefirst = daytime3 and !daytime3[1];
#def timelast = daytime3 and !daytime3[-1];
def diffday = GetDay() != GetDay()[1];
#def lastday = GetDay() != GetlastDay();

# times , (EST)
input start = 0945;
input end = 1115;

def t1 = if secondsfromTime(start) >= 0 and secondstillTime(start) >= 0 then 1 else 0;
def t2 = if secondsfromTime(end) >= 0 and secondstillTime(end) >= 0 then 1 else 0;

def cls1 = if diffday then 1 else if t1 then close else cls1[1];
def cls2 = if diffday then 1 else if t2 then close else cls2[1];
def diff = if t2 then cls2 - cls1 else diff[1];
def per = 100 * diff / cls1;

addlabel(1, (cls2 + " - " + cls1 + " = " + diff), color.yellow);
addlabel(1, per + " % chg", color.yellow);

plot zcls1 = if t1 then close else double.nan;
zcls1.SetPaintingStrategy(PaintingStrategy.POINTS);
zcls1.SetDefaultColor(Color.cyan);
zcls1.setlineweight(5);
#zcls1.hidebubble();

plot zcls2 = if t2 then close else double.nan;
zcls2.SetPaintingStrategy(PaintingStrategy.POINTS);
zcls2.SetDefaultColor(Color.cyan);
zcls2.setlineweight(5);
#zcls2.hidebubble();
#

BwKstIi.jpg
 
find price and % difference between 2 bars during the same day.
pick 2 times, in HHMM format , in EST.
defaults
input start = 0945;
input end = 1115;

draw cyan dots on bars
prices from current day are displayed in labels

Code:
# chg_of2_bars

def bn = BarNumber();
def na = Double.NaN;

#def daytime3 = (gettime() >= RegularTradingStart(GetYYYYMMDD()) and gettime() < RegularTradingend(GetYYYYMMDD()));
#def difftime = daytime3 != daytime3[1];
#def timefirst = daytime3 and !daytime3[1];
#def timelast = daytime3 and !daytime3[-1];
def diffday = GetDay() != GetDay()[1];
#def lastday = GetDay() != GetlastDay();

# times , (EST)
input start = 0945;
input end = 1115;

def t1 = if secondsfromTime(start) >= 0 and secondstillTime(start) >= 0 then 1 else 0;
def t2 = if secondsfromTime(end) >= 0 and secondstillTime(end) >= 0 then 1 else 0;

def cls1 = if diffday then 1 else if t1 then close else cls1[1];
def cls2 = if diffday then 1 else if t2 then close else cls2[1];
def diff = if t2 then cls2 - cls1 else diff[1];
def per = 100 * diff / cls1;

addlabel(1, (cls2 + " - " + cls1 + " = " + diff), color.yellow);
addlabel(1, per + " % chg", color.yellow);

plot zcls1 = if t1 then close else double.nan;
zcls1.SetPaintingStrategy(PaintingStrategy.POINTS);
zcls1.SetDefaultColor(Color.cyan);
zcls1.setlineweight(5);
#zcls1.hidebubble();

plot zcls2 = if t2 then close else double.nan;
zcls2.SetPaintingStrategy(PaintingStrategy.POINTS);
zcls2.SetDefaultColor(Color.cyan);
zcls2.setlineweight(5);
#zcls2.hidebubble();
#

BwKstIi.jpg
Thank you! The labels are accurate, but can I ask for a tweak if it's possible, I should've ask originally for the percent distance from the high to low on only two specific times on a 2 minute bar. Not the range of the other bars that's in-between those two times, only the high and low of lets say 9:42a to 11:12a or 11:12a to 9:42 regardless which ever 2-minute bar is above the other by the time the 2nd time bar forms. if not, the script here you made for me will still be beneficial. Thanks again.
 

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
212 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