What line of code to use for recording the highs of each bar marked in the script?

jngy2k

Member
Code:
declare hide_on_daily;
declare once_per_bar;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
AddChartBubble(firstBarOfDay , close, "Fb", Color.white, yes);

The above script registers each bar at the start of each trading day on the chart as firstBarofDay
Whether the chart is in 5min, 15min, hourly, etc. the firstbar of each trading day will be captured.

Now, I'm trying to capture the value of each bar, specifically the High and the Low.

My feeble attempt below
Code:
def MOHigh = if firstbarofday[1] == 0 AND firstbarofday == 1 then high else MOHigh[1];
def MOLow = if firstbarofday[1] == 0 AND firstbarofday == 1 then low else MOLow[1];
This only captures the high and low of the firstbaroftheday for the latest bar.
Question: How would I capture the high and low of each firstbarofday bars in the chart?

The Goal: My purpose for doing so is to find the range (high-low) of each firstbarofday and compare it to today's firstbarofday.
What I will have to do after registering the High and Low values in the script is to find the Average Range of all the firstbarofday in the chart.
So thats Question 2: How do I find the Average Range of all the firstbarofday?
My feeble attempt below
Code:
def avgmo = average(mohigh,2)-average(molow,2);
AddLabel (yes, "AvgOR: " + round(avgmo,2), color.white);

Any help gladly appreciated.

nM8hEc6.png
 
Code:
declare hide_on_daily;
declare once_per_bar;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
AddChartBubble(firstBarOfDay , close, "Fb", Color.white, yes);

The above script registers each bar at the start of each trading day on the chart as firstBarofDay
Whether the chart is in 5min, 15min, hourly, etc. the firstbar of each trading day will be captured.

Now, I'm trying to capture the value of each bar, specifically the High and the Low.

My feeble attempt below
Code:
def MOHigh = if firstbarofday[1] == 0 AND firstbarofday == 1 then high else MOHigh[1];
def MOLow = if firstbarofday[1] == 0 AND firstbarofday == 1 then low else MOLow[1];
This only captures the high and low of the firstbaroftheday for the latest bar.
Question: How would I capture the high and low of each firstbarofday bars in the chart?

The Goal: My purpose for doing so is to find the range (high-low) of each firstbarofday and compare it to today's firstbarofday.
What I will have to do after registering the High and Low values in the script is to find the Average Range of all the firstbarofday in the chart.
So thats Question 2: How do I find the Average Range of all the firstbarofday?
My feeble attempt below
Code:
def avgmo = average(mohigh,2)-average(molow,2);
AddLabel (yes, "AvgOR: " + round(avgmo,2), color.white);

Any help gladly appreciated.

See if this helps

Code:
declare hide_on_daily;
declare once_per_bar;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else Double.NaN;
def firstbarcount = if !IsNaN(firstBarOfDay) then firstbarcount[1] + 1 else firstbarcount[1];
AddChartBubble(firstBarOfDay , close, "Fb: " + firstbarcount, Color.WHITE, yes);
def mohigh = if !IsNaN(firstBarOfDay) then mohigh[1] + high else mohigh[1];
AddLabel(1, "H: " + mohigh, color.green);
def molow = if !IsNaN(firstBarOfDay) then molow[1] + low else molow[1];
AddLabel(1, "L: " + molow, color.red);
def avgmo = (mohigh - molow) / firstbarcount;
AddLabel(1, "AvgOR: " + AsText(avgmo), Color.WHITE);
 

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

@SleepyZ I'll lok at it in the morning. Currently at work. Thanks for the help.
@SleepyZ Just reading thru it and imaging the code work
I can't believe I didn't think of registering the bar count.
That's great work.


edit: my revision and how i'll use it
https://books.mec.biz/tmp/books/KSPF578WWBQYG4VRFYV6.pdf
read the first few pages about opening range break outs
toby crabel is a billionaire hedge fund manager

Code:
#Average First Bar of Day range on chart
declare hide_on_daily;
declare once_per_bar;
input showMO = yes;
input showBubble = no;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());


def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else Double.NaN;


def firstbarcount = if !IsNaN(firstBarOfDay) then firstbarcount[1] + 1 else firstbarcount[1];


def mohightotal = if !IsNaN(firstBarOfDay) then mohightotal[1] + high else mohightotal[1];
def molowtotal = if !IsNaN(firstBarOfDay) then molowtotal[1] + low else molowtotal[1];


def avgmo = (mohightotal - molowtotal) / firstbarcount;
AddLabel(showmo, "MO: " + AsText(avgmo), Color.yellow);
AddChartBubble(if showbubble then firstBarOfDay else double.nan, low, firstbarcount, Color.yellow, no);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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