2 Hour line in script correct but Price in watchlist is wrong

Epavell

New member
Hello, I have a script that paint a 2 hour line on the chart and it works well. I also use the same script for a watchlist and trying to place the price but seems to use the top of the hour (meaning 9 am , 11 AM, 1PM and 3 PM). I was looking for the 9:30, 11:30, 1:30, and 3:30 prices.

Here is the script I hope it's an easy fix as I can't figure it out. Thank you in advance.


def agg = AggregationPeriod.two_HOURS;
def o = open(period = agg)[0];

plot open_horizontal = if Between(GetTime(), RegularTradingStart(GetYYYYMMDD()), RegularTradingEnd(GetYYYYMMDD())) and GetDay() == GetLastDay() then o else Double.NaN;
open_horizontal.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#------------------------------------
# LABEL SECTION
#------------------------------------


AddLabel(yes, "" + o, Color.black );


assignbackgroundColor(
if
o < close then color.green else if
o > close then color.red else color.white);
 
Hello, I have a script that paint a 2 hour line on the chart and it works well. I also use the same script for a watchlist and trying to place the price but seems to use the top of the hour (meaning 9 am , 11 AM, 1PM and 3 PM). I was looking for the 9:30, 11:30, 1:30, and 3:30 prices.

Here is the script I hope it's an easy fix as I can't figure it out. Thank you in advance.


def agg = AggregationPeriod.two_HOURS;
def o = open(period = agg)[0];

plot open_horizontal = if Between(GetTime(), RegularTradingStart(GetYYYYMMDD()), RegularTradingEnd(GetYYYYMMDD())) and GetDay() == GetLastDay() then o else Double.NaN;
open_horizontal.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#------------------------------------
# LABEL SECTION
#------------------------------------


AddLabel(yes, "" + o, Color.black );


assignbackgroundColor(
if
o < close then color.green else if
o > close then color.red else color.white);

read open price on every x bars
can pick a start time (default 9:30)
uses an agg time (default 2 hours) as a multiplier


watchlist study
zlines_2hr
http://tos.mx/!HQdheuGo
set to 5min
ext hours were turned on when i made the share (don't have to be)


Code:
# zlines_2hr
#lines_2hour_01

#https://usethinkscript.com/threads/2-hour-line-in-script-correct-but-price-in-watchlist-is-wrong.17501/
#2 Hour line in script correct but Price in watchlist is wrong
#Epavell  1/3

def bn = BarNumber();
def na = double.nan;

def agg = AggregationPeriod.TWO_HOURS;
#def o = open(period = agg)[0];
def aggmin = agg / 60000;

input start = 0930;
def daymin = (SecondsFromTime(start) / 60);
def multi = if daymin % aggmin == 0 then 1 else 0;
def agg_open = if bn == 1 then 0 else if multi then open else agg_open[1];

plot z = if agg_open == 0 then na else agg_open;
z.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

AddLabel(yes, agg_open, Color.black);

AssignBackgroundColor(
# if 1 then Color.CURRENT else 
 if agg_open < close then Color.GREEN else
 if agg_open > close then Color.RED
 else Color.WHITE);


#---------------------------
AddChartBubble(0, low,
aggmin + "\n" +
daymin + "\n" +
multi + "\n" +
agg_open
, ( if multi then Color.YELLOW else Color.GRAY), no);
#

Unr5L7U.jpg



---------------------------------


upper chart test study

Code:
#lines_2hour_01

#https://usethinkscript.com/threads/2-hour-line-in-script-correct-but-price-in-watchlist-is-wrong.17501/
#2 Hour line in script correct but Price in watchlist is wrong
#Epavell  1/3

def bn = BarNumber();
def na = double.nan;

def agg = AggregationPeriod.TWO_HOURS;
#def o = open(period = agg)[0];
def aggmin = agg / 60000;

input start = 0930;
def daymin = (SecondsFromTime(start) / 60);
def multi = if daymin % aggmin == 0 then 1 else 0;
def agg_open = if bn == 1 then 0 else if multi then open else agg_open[1];

plot z = if agg_open == 0 then na else agg_open;
z.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

AddLabel(yes, agg_open, Color.GRAY);

AssignBackgroundColor(
 if 1 then Color.CURRENT else 
 if agg_open < close then Color.GREEN else
 if agg_open > close then Color.RED
 else Color.WHITE);


#---------------------------
AddChartBubble(0, low,
aggmin + "\n" +
daymin + "\n" +
multi + "\n" +
agg_open
, ( if multi then Color.YELLOW else Color.GRAY), no);

#
 

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