• LIMITED TIME ONLY: Take $40 off VIP with code: BTD40.

Hi, need help with 1) finding volume traded for the first 5minutes after open for today and 2)the average of this volume for the past 20 days.

dash

New member
Hi, need help with 1) finding volume traded for the first 5minutes after open for today and 2)the average of this volume for the past 20 days.

I was able to find 1) briefly through
def start = SecondsFromTime(0930);
def end = SecondsTillTime(0935);
def first5min = if start >=0 and end >0 then 1 else 0;
def vol = if first5min and !first5min[1] then volume else if first5min then vol[1]+volume else vol[1];

Now I am stuck on 2) and not sure how to go about finding the volume of first 5min traded for yesterday and that of the day before yesterday..etc to take the average of this 5min volume traded for the past 20 days. Please help.
 
Solution
Hi, need help with 1) finding volume traded for the first 5minutes after open for today and 2)the average of this volume for the past 20 days.

I was able to find 1) briefly through
def start = SecondsFromTime(0930);
def end = SecondsTillTime(0935);
def first5min = if start >=0 and end >0 then 1 else 0;
def vol = if first5min and !first5min[1] then volume else if first5min then vol[1]+volume else vol[1];

Now I am stuck on 2) and not sure how to go about finding the volume of first 5min traded for yesterday and that of the day before yesterday..etc to take the average of this 5min volume traded for the past 20 days. Please help.
This seems to work. Just make sure you have 20 days of bars on your chart you are viewing.
Ruby:
...

SleepyZ

Well-known member
VIP
Lifetime
Hi, need help with 1) finding volume traded for the first 5minutes after open for today and 2)the average of this volume for the past 20 days.

I was able to find 1) briefly through
def start = SecondsFromTime(0930);
def end = SecondsTillTime(0935);
def first5min = if start >=0 and end >0 then 1 else 0;
def vol = if first5min and !first5min[1] then volume else if first5min then vol[1]+volume else vol[1];

Now I am stuck on 2) and not sure how to go about finding the volume of first 5min traded for yesterday and that of the day before yesterday..etc to take the average of this 5min volume traded for the past 20 days. Please help.
This seems to work. Just make sure you have 20 days of bars on your chart you are viewing.
Ruby:
def start = SecondsFromTime(0930);
def end   = SecondsTillTime(0935);
def first5min = if start >= 0 and end > 0 then 1 else 0;
def vol       = if first5min and !first5min[1] then volume else if first5min then vol[1] + volume else vol[1];

def ymd = GetYYYYMMDD();
def x   = if Between(ymd, ymd[20], ymd) and first5min then x[1] + volume else x[1];

AddLabel(1, "Today Vol: " + vol, if vol > (x - vol) / 20 then Color.GREEN else Color.RED);
AddLabel(1, "20D Avg Vol: " + (x - vol) / 20, if vol > (x - vol) / 20 then Color.GREEN else Color.RED);
 
Solution

dash

New member
This seems to work. Just make sure you have 20 days of bars on your chart you are viewing.
I get different average numbers for different time frames (1min vs 5min vs 60min). Which timeframe do you recommend to use this one? The average volume number increases as I increase timeframe.
 

dash

New member
I get different average numbers for different time frames (1min vs 5min vs 60min). Which timeframe do you recommend to use this one? The average volume number increases as I increase timeframe.
Never mind. I was able to get the same average number by increasing "Time Interval" from 5D5Min to 30D5Min which shares the same Time Interval count as my 60min timeframe chart. Thank you.
 

Similar threads

Top