View Full Version : Time of Day Average Volume
ClayB1
06-25-2007, 12:45 PM
I'm in the process of moving from eSignal/Tradestation to NinjaTrader and am new to C# programming. I've been able to convert most of my indicators without too much difficulty, this one has me stumped. I'd like to code an indicator which plots the average cumulative volume per time bar over a user defined lookback period.
For example, on the opening bar of the day, the indicator would plot the average volume of the previous [x] opening bars. On the next bar, the indicator would plot the average cumulative volume of the first two bars of the day over the lookback period [x].
A reference sample of code, or a link to where I might find information how to code this would be very much appreciated. Thanks in advance.
NinjaTrader_Ray
06-25-2007, 12:58 PM
I am not sure I completely follow.
Lets say you have 3 days.
Current day (day 3) bar 1 value = Day1 bar1 + Day2 bar 1 + day3 bar1 / 3
then
Current day bar 2 value = (Day 1 bar1 + Day 1 bar 2) + (Day 2 bar1 + Day 2 bar 2) + (Day 3 bar1 + Day 3 bar 2) / 3
ClayB1
06-25-2007, 02:05 PM
Ray - Sorry if I wasn't very clear - I'll be more explicit:
I'd like to code an indicator which plots the median trading volume in the ES futures contract for every 15 minute period over the last month. In other words, each 15 minute bar would show the median trading volume of the last 20 or so days.
This analysis technique is detailed more thoroughly in these two posts in Brett Steenbarger's TraderFeed blog:
http://traderfeed.blogspot.com/2007/04/volume-and-opportunity-in-stock-market.html
http://traderfeed.blogspot.com/2007/02/finding-opportunity-in-stock-market.html
I hope this clarifies what I am trying to code. Thanks again.
NinjaTrader_Ray
06-25-2007, 02:23 PM
Thanks for clarification.
I can provide guidance on how to accomplish this.
Calculate the number of bars within a session. For example:
7:30 AM to 2:15 PM session yields 25 - 15 minute bars.
Therefore, if I wanted to calculate the average over the past two days:
volumeAverage = Volume[0] + Volume[25] / 2
Since you are calculating over a n periods, you would have to utilize a loop to skip through the bars to get the correct values.
Keep in mind, you have to check to make sure there are enough bars in your chart.
if (CurrentBar < period * 25)
return;
ClayB1
06-25-2007, 02:57 PM
Thanks Ray - that helps a lot.
Does NinjaScript support the statistical function median? I was unable to find it mentioned in any of the documentation. If not, do you have any suggestions for work-around?
Thanks!
NinjaTrader_Ray
06-26-2007, 07:00 AM
No we do not support a function to calculate the mean. You would have to code your own at this time.