Compute the average high for current day


Category:
0
0

Hi Pete, I was wondering how can tell the study to star the calculation over at  the very first candle of the day  the same way vwap can you help please, I was reading the answer here I can seem to find any. Thanks in advance

def Data = if high then 1 else 0;
def x = TotalSum (data);
plot volh = TotalSum (high) / x;

Attachments:
Marked as spam
Posted by (Questions: 8, Answers: 23)
Asked on August 1, 2019 3:34 pm
96 views
2
Private answer

After getting a bit more details from the author of the post I have a new solution. The goal is to compute the average high for the current day on an intraday chart. The code must first identify the first bar of the new day. Then count the number of bars since that first bar. We'll also need to keep a running sum total for the high of each bar since the first bar of the new day. Then we simply plot the result of that running sum of highs divided by the number of bars. And we do this for every bar on the chart.

Here is the code. Screenshot below shows the result. Notice that the code resets on the first bar of each new day.

def newDay = GetDay() <> GetDay()[1];
rec runningSumOfHighs = if newDay then high else runningSumOfHighs[1] + high;
rec numberOfBarsToday = if newDay then 1 else numberOfBarsToday[1] + 1;
plot averageHighsForToday = runningSumOfHighs / numberOfBarsToday;

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 2, 2019 6:56 pm
0
Thanks Pete you are the man!! One Last request how can i plot only the last day?
( at August 2, 2019 7:25 pm)
0

Replace this line:
plot averageHighsForToday = runningSumOfHighs / numberOfBarsToday;
With this:
plot averageHighsForToday = if GetDay() == GetLastDay() then runningSumOfHighs / numberOfBarsToday else Double.NaN;

( at August 3, 2019 9:18 am)
0
Hi Pete, Im sorry to bother you but is not working the code plot averageHighsForToday = if GetDay() == GetLast Day() then runningSumOfHighs / numberOfBarsToday else Double.NaN; turns red!
( at August 3, 2019 12:46 pm)
0
There was a space in the word GetLastDay. I corrected that and it works.
( at August 3, 2019 5:04 pm)
0
Thank you!
( at August 4, 2019 7:03 pm)
-1
Private answer

Well the first thing we need to work out is that first line of code:

def Data = if high then 1 else 0;

You are testing if high is true or false and then assigning a value of 1 if true and a value of zero if false. The problem is that "high" is never a true/false variable. So the entire premise of your code is invalid. What exactly did you intend for that first line of code? Perhaps then we can begin to unravel the rest and provide a solution. I see you attached a screenshot of a chart with an arrow pointing to one of the candles. I have no clue what that screenshot was supposed to convey. So please explain that as well.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 2, 2019 11:10 am
0
Ok, lets see what I am doing is this.. def Data = if high then 1 else 0; this does count the number of bars in the chart \\\\\\\\” i do not code so this does it for me\\\\” def x = TotalSum (data); this line gives me the total amount of bars in the chart \\\\\\\\”say in intraday 390 candles \\\\\\\\” plot volh = TotalSum (high) / x; this line add all high prices and divide by numbers of candles therefore giving me and average high, i hope you understand me now the issue that i have is that when i have 5 day 1 minute it takes the candles of all 5 days and i don\\\\\\\\’t want that i wanted to start the count at the very first candle of the day, one day only, so screen shot is for you to have an idea where i want the study to start, similar to the vwap at the very first candle, if possible show only the last day. i hope its clear now . thanks in advance Pete.
( at August 2, 2019 12:29 pm)
0
Perhaps instead of giving this question the title of: "Start calculation at the first candle", it would have been simpler to just state: "Compute the average high for current day". This would have made your goal perfectly clear and I could them go straight to teaching you where your code was failing and how to adapt it to achieve that goal.
( at August 2, 2019 2:24 pm)
0
I'm sorry Pete, what do I do should I post a new question? I'm trying to edited it and its not going trough!!
( at August 2, 2019 2:45 pm)
0
Don't worry about a thing. I will update the title of the question. Then I will edit my answer to include some code to help you out. When I change the title of the question it will also break the current URL link. I will email you the new link after I update the title.
( at August 2, 2019 3:20 pm)
0
Thank you very much Pete.
( at August 2, 2019 4:01 pm)