Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Tick Data and Volume based Backtest
Collapse
X
-
Tick Data and Volume based Backtest
I am trying to run a back test that requires me to analyze the volume of each trade that happened in the past. I try to setup a strategy based on an indicator that I created that uses Tick and Last. I don't seem to get volume data when I run the back test. This is the first time I am using the strategy analyzer so please advice if I am doing anything wrong? I am using the ES Jun contract for the test. -
e-Mini Jun 2014
protected override void OnMarketData(MarketDataEventArgs e)
{
if (e.MarketDataType == MarketDataType.Last)
{
// Print("Last = " + e.Price + " " + e.Volume);
trade.volume = e.Volume; // ? or size
trade.size = e.Volume;
trade.price = e.Price;
}
}
Comment
-
Hello newworldguy,
The OnMarketData() method is only run when real-time data is received and does not work historically.
This is mentioned in the help guide in OnMarketData().
http://www.ninjatrader.com/support/h...marketdata.htm
However, if a tick series is the primary or secondary data series, you can access the volume of the tick series using Volume[bars ago value] or Volumes[bars in progress index][bars ago value].
(edit)
Also here is a link to the help guide on Volume and Volumes.
Volume - http://www.ninjatrader.com/support/h...t7/volume2.htm
Volumes - http://www.ninjatrader.com/support/h...t7/volumes.htmLast edited by NinjaTrader_ChelseaB; 04-23-2014, 08:42 AM.Chelsea B.NinjaTrader Customer Service
Comment
-
-
assume I have to set CalculateOnBarClose= false
Then the question is how do I know that the 5 minute bar is over? Since I need to take actions every 5 minutes?
appreciate your input.
Comment
-
Hi newworldguy,
Calculate on bar close is always true in backtest even if it is set to false in the script or parameters.
This is mentioned in our help guide on Calculate on bar close.
http://www.ninjatrader.com/support/h...onbarclose.htm
I am suggesting that you add a secondary dataseries of 1 tick, if you are wanting the volume of each tick.
If you want the volume but from a 5 minute bar, then the secondary series of 1 tick is not needed.
Below is a link to the help guide on the Add() command.
http://www.ninjatrader.com/support/h...s/nt7/add3.htmChelsea B.NinjaTrader Customer Service
Comment
-
also how do I differentiate between bid, ask and last quotes: is it by checking if volume is = 0? I need to take actions every time a trade is done as well as every 5 minutes. Thanks
Comment
-
-
Hi newworldguy,
To check historical bid and ask, you will need to have that data downloaded or have it available from your data provider as historical data.
You will need to add a secondary data series using Bid data. This would be the MarketDataType overload parameter in the Add() command I linked in my last post.Chelsea B.NinjaTrader Customer Service
Comment
-
Hi newworldguy,
By running in the BarsInProgress of the 5 minute series (likely the primary series), you can call any data of the secondary series. For example:
if (BarsInProgress == 0)
Print(Volumes[1][0]);
On the 5 minute series bar close this would print the volume of the last received tick.
Below is a link to the help guide on BarsInProgress.
http://www.ninjatrader.com/support/h...inprogress.htmChelsea B.NinjaTrader Customer Service
Comment
-
I created an indicator did the following based on your instruction, but the OnBarUpdate() is not being called for every tick:
protected override void Initialize()
{
/*
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot5min"));
Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "PlotTick"));
*/
Add(PeriodType.Minute, 5);
Add(PeriodType.Tick, 1);
Overlay = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
/*
Plot5min.Set(Close[0]);
PlotTick.Set(Close[0]);
*/
if (BarsInProgress == 0)
Print("TIME(5 min) " + Times[0][0] + " Volume " + Volumes[0][0]);
if (BarsInProgress == 1)
Print("Time(Tick) " + Times[1][0] + " Volume " + Volumes[1][0]);
}
Comment
-
Hello newworldguy,
What is the data series of the chart?
You have added a secondary data series of 5 minute. This would mean that the tick series would be the 3rd data series and would be BarsInProgress 2.
If your chart is a 5 minute chart, there is no need to add a secondary 5 minute series.Chelsea B.NinjaTrader Customer Service
Comment
-
ok thanks! one question: I notice all ticks reported have a volume of at least 1. Does this mean that updates to say bid and ask are not reported as a part of OnBarUpdate?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
649 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
576 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment