I am trying to calculate the volume rate (volume per minute) (BTW, is the volume number for ES U6 a tick volume or real volume?) for each bar on a tick chart.
I started with my own code:
var lastTime = ((getHour(0) - getHour(-1))*60) + (getMinute(0) - getMinute(-1)) + ((getSecond(0) - getSecond(-1))/60);
var volumeDiff = volume(0);
return volumeDiff / lastTime;
But realized I might be off by a bar so I redid it thus:
var lastTime = ((getHour(+1) - getHour(0))*60) + (getMinute(+1) - getMinute(0)) + ((getSecond(+1) - getSecond(0))/60);
var volumeDiff = volume(0);
return volumeDiff / lastTime;
First, is that correct? I believe I am getting the time elapsed for the current bar and dividing that in minutes into the current bar volume.
Now if that is correct. There is still the problem of the last bar since there is no future bar. So in KB I found this, which I believe may give me the time elapsed for the last bar:
if (getCurrentBarIndex() < -1) return;
var nState = getBarState();
var vClockTime = new Date()*1;
if (nState == BARSTATE_NEWBAR) {
vTimeStamp = getValue("Time")*1 ;
}
var vTimeElapse = (vClockTime-vTimeStamp);
if (vTimeElapse < 0) return;
If I combine these two pieces together, will I be able to get what I want? Or better yet has someone already done this (I couldn't find anything)?
Thanks.
I started with my own code:
var lastTime = ((getHour(0) - getHour(-1))*60) + (getMinute(0) - getMinute(-1)) + ((getSecond(0) - getSecond(-1))/60);
var volumeDiff = volume(0);
return volumeDiff / lastTime;
But realized I might be off by a bar so I redid it thus:
var lastTime = ((getHour(+1) - getHour(0))*60) + (getMinute(+1) - getMinute(0)) + ((getSecond(+1) - getSecond(0))/60);
var volumeDiff = volume(0);
return volumeDiff / lastTime;
First, is that correct? I believe I am getting the time elapsed for the current bar and dividing that in minutes into the current bar volume.
Now if that is correct. There is still the problem of the last bar since there is no future bar. So in KB I found this, which I believe may give me the time elapsed for the last bar:
if (getCurrentBarIndex() < -1) return;
var nState = getBarState();
var vClockTime = new Date()*1;
if (nState == BARSTATE_NEWBAR) {
vTimeStamp = getValue("Time")*1 ;
}
var vTimeElapse = (vClockTime-vTimeStamp);
if (vTimeElapse < 0) return;
If I combine these two pieces together, will I be able to get what I want? Or better yet has someone already done this (I couldn't find anything)?
Thanks.
Comment