View Full Version : Simple "Volume projection at close" indicator
:::grimReaper:::
12-01-2011, 11:17 AM
(edited this entire post)
Function:
A simple indicator that projects the volume at the close of minute-based bars. Jumps in the projection can be inferred as the "pace of tape" increasing.
Instructions:
1) Download this file HERE (http://www.ninjatrader.com/support/forum/local_links.php?action=jump&catid=4&id=504) and import it into NT7 via File>Utilities>Import NinjaScript
2) Add this indicator to the same panel as your preferred volume indicator. This must be a minute-based chart.
3) Turn the plot color to the exact color as your chart background. The line it plots is meaningless.
4) Verify your system's time is in sync by looking at bar timer, e.g it resets exactly to 5:00 on 5min bars, as opposed to resetting to 5:05, for example. To synchronize it, click on your clock in the bottom right corner > Change date and time settings > Internet Time tab > Change settings > select time.nist.gov in the pulldown menu > and update now.
5) Verify AutoScale is False (to prevent any large jumps at the beginning of the bar), CalculateOnClose is False, PriceMarker is True and Displacement is 0.
Disclaimer:
This is intended for use in a demo or sim account only. By downloading this indicator you agree to not hold me accountable for any financial loss that may result from this indicator, such as but not limited to any trade signals this indicator may produce or any computer instability it may cause (though I don't foresee any). This indicator is free and not intended for resale.
Exported using NT Version 7.0.1000.8
Thanks for downloading.
NinjaTrader_RyanM
12-01-2011, 11:28 AM
Hi :::grimReaper:::,
I would do this but I own the direct edition.
If you want access to create NinjaScript, you can use the following license key.
Please copy/paste and enter under the Control Center -> Help--> License Key
@SIM-F82F-D583-40B1-AE74-B79F-705D-1952
If you manage to create, I'm sure other community members will appreciate and you can post the results to the file sharing section. Thanks for offering.
:::grimReaper:::
12-01-2011, 12:03 PM
Thanks! I'll take a look Friday afteroon.
:::grimReaper:::
12-02-2011, 12:31 AM
Done with most of it. Some questions:
1) I only want a "Price Marker," not plot lines. How do I do that?
2) I noticed at the beginning of a new bar, e.g a 10 min bar, bar timer says the remaining time is around 10:05. Why is that?
3) How can I determine what timeframe the user is on?
4) It updates every tick. For those who trade less active markets, how can I tell it to update every second as an option?
5) I'm currently plotting this in the same panel as my VolumeUpDown, would it be better/efficient if I built my own volume bars?
Thanks
NinjaTrader_AdamP
12-02-2011, 07:23 AM
Done with most of it. Some questions:
1) I only want a "Price Marker," not plot lines. How do I do that?
2) I noticed at the beginning of a new bar, e.g a 10 min bar, bar timer says the remaining time is around 10:05. Why is that?
3) How can I determine what timeframe the user is on?
4) It updates every tick. For those who trade less active markets, how can I tell it to update every second as an option?
5) I'm currently plotting this in the same panel as my VolumeUpDown, would it be better/efficient if I built my own volume bars?
Thanks
1) What sort of price marker do you want? Text or some sort of drawn object?
Most indicators will paint a price marker on the y axis unless PaintPriceMarkers = false.
2) I am currently unable to replicate this behavior on a 10 minute chart. Are you using the BarTimer indicator code directly from the one that comes with NinjaTrader?
3) You could use BarsPeriod : http://www.ninjatrader.com/support/helpGuides/nt7/index.html?barsperiod.htm
4) You could probably make a flag that either activates or deactivates the strategy ignoring any ticks that don't occur on the beginning of each second. The way I would probably do this is check the time stamp of each tick using Time[0], and if the seconds from the previous tick is different from the seconds of the current tick, then you are allowed to run the indicator updates.
Here is some more information on DateTime objects : http://www.ninjatrader.com/support/helpGuides/nt7/index.html?c_method_functions_reference.htm
5) This is up to you. I am not sure what exactly you are going for so its difficult to make a recommendation. Perhaps if you could clarify and/or post some screenshots of your indicator we could comment further.
:::grimReaper:::
12-02-2011, 08:52 AM
1) What sort of price marker do you want? Text or some sort of drawn object?
Just text on the Volume's y-axis.
2) I am currently unable to replicate this behavior on a 10 minute chart.
I also see this repeatedly on a 1min and 3min chart. It'll jump from around 0:06-0:08 to 1:07 and 0:06-0:08 to 3:07.
Are you using the BarTimer indicator code directly from the one that comes with NinjaTrader?
yes
NinjaTrader_AdamP
12-02-2011, 09:26 AM
grimReaper,
I would suggest debugging your code. If you use volumeupdown and bartimer separately, there are no issues. Please see the attached screenshot.
Please make sure PaintPriceMarkers = true in Initialize(); It should default to true however.
If you post your code, perhaps we could help debug anything minor.
:::grimReaper:::
12-02-2011, 05:47 PM
I would suggest debugging your code. If you use volumeupdown and bartimer separately, there are no issues. Please see the attached screenshot.
It's not my code, it's the code associated with BarTimer. I paid close attention today to my regular charts/indicator while trading and saw my 3min chart go from 0:06 to 3:07, and a similar story with my 15min chart. And I believe I've seen this before but didn't mind.
Please make sure PaintPriceMarkers = true in Initialize(); It should default to true however.
It creates a price marker, I just want to get rid of the line it plots.
If you post your code, perhaps we could help debug anything minor.
Here's my code. It worked yesterday, since then I've made a couple of changes: 1) see below 2) changed "Plot0" to "ProjectionPlot." Compiled fine, but can't test it b/c markets are closed. Btw, doesn't work accurately on historical data, only on live data and historical data that was seen live. And let me know if you want a screenshot of anything.
protected override void OnBarUpdate(){
TimeSpan barTimeLeft = Bars.GetTime(Bars.Count - 1).Subtract(Now);
int secondsleft = barTimeLeft.Seconds + barTimeLeft.Minutes*60 + barTimeLeft.Hours*360;
int volume = (int) Volume[0];
int timeframe = BarsPeriod.Value*60; //recent change #1, before it was 600 which is 10 minutes
int projection = volume*timeframe/(timeframe-secondsleft);
ProjectionPlot.Set(projection);
}
//Below is BarTime code created by NT
private DateTime Now{
get
{
DateTime now = (Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay ? Bars.MarketData.Connection.Now : DateTime.Now);
if (now.Millisecond > 0)
now = Cbi.Globals.MinDate.AddSeconds((long) System.Math.Floor(now.Subtract(Cbi.Globals.MinDate ).TotalSeconds));
return now;
}
}
//....more code
NinjaTrader_AdamP
12-03-2011, 01:19 PM
grimreaper,
Does the indicator BarTImer by itself exhibit the same behavior on your system? I watched it yesterday and it wasn't doing so.
Additionally, could you please post your Initialize() method as well as variables section from your code?
:::grimReaper:::
12-03-2011, 03:21 PM
Does the indicator BarTImer by itself exhibit the same behavior on your system? I watched it yesterday and it wasn't doing so.
I'll see and post screenshots by Monday.
Additionally, could you please post your Initialize() method as well as variables section from your code?
Haven't implemented variables so far
public class VolumeProjecter : Indicator
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#endregion
protected override void Initialize(){
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "ProjectionPlot"));
Overlay = false;
}
protected override void OnBarUpdate(){
//..... code from last post
:::grimReaper:::
12-04-2011, 08:49 PM
I attached the bartimer pic. And I also noticed that it doesn't happen on every bar.
So right now my indicator plots a line, how do I make it so it only plots the price marker, and nothing else.
NinjaTrader_AdamP
12-05-2011, 08:14 AM
grimReaper,
Im going to go ahead and test this on my end for awhile and see if I can identify some issue. Thank you for your patience.
As far as your second question. You don't want it to plot anything at all? Just the current value?
:::grimReaper:::
12-05-2011, 08:44 AM
As far as your second question. You don't want it to plot anything at all? Just the current value?
Correct. Right now it's not plotting unobserved historical data correctly, and even if it did, it would be a line that connects the top of every volume bar, which isn't useful.
NinjaTrader_AdamP
12-05-2011, 08:53 AM
grimReaper,
I would suggest using DrawTextFixed(), and then DrawOnPricePanel = true in Initialize();
The other alternative is to just set the plot to transparent color.
:::grimReaper:::
12-05-2011, 10:11 PM
I would suggest using DrawTextFixed(), and then DrawOnPricePanel = true in Initialize();
This works. Though there's one bug: after a few bars, the indicator (number) just stops updating. It happens on a new bar (so the value is stuck at 0 or a negative #, depending which code I have compiled, it'll make sense below). Here's my code if you're interested
public class VolumeProjecter : Indicator
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize(){
//Add(new Plot(Color.FromKnownColor(KnownColor.Transparent), PlotStyle.Line, "ProjectionPlot"));
Overlay = false;
DrawOnPricePanel = false; //want it in volume panel
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate(){
TimeSpan barTimeLeft = Bars.GetTime(Bars.Count - 1).Subtract(Now);
int secondsleft = barTimeLeft.Seconds + barTimeLeft.Minutes*60 + barTimeLeft.Hours*360;
int volume = (int) Volume[0];
int timeframe = BarsPeriod.Value*60;
//int projection = volume*timeframe/(timeframe-secondsleft);
int projection = Math.Max(0,volume*timeframe/(timeframe-secondsleft)); //to prevent negative values when BarTimer > timeframe
//ProjectionPlot.Set(projection);
string projectionstr = "" + projection;
DrawTextFixed("","",TextPosition.TopRight); //clear previous text
DrawTextFixed("",projectionstr,TextPosition.TopRight); //write text
}
//Below is BarTime code created by NT
private DateTime Now{
//more code....
}
The other alternative is to just set the plot to transparent color.
I'll go with the other method you suggested, so this is just fyi: Transparent doesn't work, it hides everything, but setting it to the same color as the background almost works. By almost, I mean since it doesn't plot unobserved historical data correctly, the indicator sometimes displays large spikes, which scales the volume panel, so the preferable method is to stop it from plotting anything, it's also a bit more efficient.
Btw, thanks for all of the help you provided this far. I'm learning a lot and hopefully won't require so many questions if I decide to write another indicator.
:::grimReaper:::
01-05-2012, 11:41 AM
Hi,
I was wondering if any solutions were found. In summary, these are the two problems:
1) Bar Timer resets a time greater than the current timeframe on a new bar, e.g if looking at 5 min chart, it'll countdown to 0:06, then print a new bar and the timer resets is at 5:05. This happens on almost all new bars.
2) The indicator will stop working after a few bars. It'll be stuck on a number and stop updating.
NinjaTrader_RyanM
01-05-2012, 01:08 PM
Hi grimReaper,
BarTimer can be out of sync if there is any difference in your computer clock with the data providers' clock.
Please use the steps below to change your Time Zone and sync the PC clock, note to set the server to time.nist.gov.
You can sync your PC clock by double clicking on the clock in the lower right corner of your desktop. Press 'Change time zone...' Set the Time zone and press 'OK'.
Once you have done that, click on Internet Time tab set the server to time.nist.gov and then click Update. Your PC clock should now be updated.
:::grimReaper:::
01-06-2012, 05:37 PM
Thanks, it works fine now. Before I release it, quick question: Is there anyway to get rid of the line it plots (setting it to transparent doesn't work b/c then the price marker disappears also)? If not, is there a way I can detect the user's background color and set it to that color?
And I'm guessing I have permission to use NT's bartimer code? Don't want to violate copyright:o
NinjaTrader_RyanM
01-09-2012, 08:32 AM
You can set the plot to the same color as chart background. Unfortunately there are no supported properties to read from the chart background, but for a hint could try ChartControl.BackColor.
Yes, there's no problem using BarTimer code.
jackh
01-22-2012, 07:13 AM
grimReaper,
Why do you use the term "infer" when talking about the pace of the tape?
jackh
01-22-2012, 07:16 AM
Ryan,
Can this indicator be installed in a live, licensed NT version.
:::grimReaper:::
01-22-2012, 01:53 PM
grimReaper,
Why do you use the term "infer" when talking about the pace of the tape?
No real reason. My understanding is that pace of tape is like velocity, and my projected volume is like distance, so to get pace of tape you have to notice the jumps in the projected volume yourself.
I personally use it to get an idea of what the volume will be at the close of my 5 and 15min bars, but if you want to use it to understand pace of the tape, it's better to use it for small time frame charts like 1-3min.
Ryan,
Can this indicator be installed in a live, licensed NT version.
It should be able to install in any NT version. (I mentioned "sim" just to cover myself)