Backtesting with Intrabar (Bid Ask) granularity - NinjaTrader | futures io social day trading
futures io futures trading


Backtesting with Intrabar (Bid Ask) granularity
Updated: Views / Replies:2,362 / 4
Created: by SodyTexas Attachments:1

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Backtesting with Intrabar (Bid Ask) granularity

  #1 (permalink)
Spread Trader
Austin TX
 
Futures Experience: Advanced
Platform: Ninjatrader, Python, & R
Broker/Data: RJO
Favorite Futures: Futures, Spreads
 
SodyTexas's Avatar
 
Posts: 313 since Sep 2013
Thanks: 96 given, 843 received

Backtesting with Intrabar (Bid Ask) granularity

Hey futures.io (formerly BMT) forum and friends,

I am trying to solve a issue with backtesting within Ninjatrader 7. What I am trying to do is backtest based on tick data, not the OHLC of a bar.

I found this site: Accurate NinjaTrader backtests - MetaTrader Expert Advisor

And it claims that I can backtest with Bid/Ask tick granularity.

First what I did was download Bid/Ask data for GC ##-## from 01/01/2013 to 03/31/2013.

From there I created a very very simple strategy following the instructions posted in the website mentioned above.

Here is my code
 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Reference sample demonstrating how to achieve intrabar backtesting.
    /// </summary>
    [Description("Reference sample demonstrating how to achieve intrabar backtesting.")]
    public class sIntraBar : Strategy
    {
        #region Variables
		private int	fast	= 10;
		private int	slow	= 25;
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
			/* Add a secondary bar series. 
			Very Important: This secondary bar series needs to be smaller than the primary bar series.
			
			Note: The primary bar series is whatever you choose for the strategy at startup. In this example I will
			reference the primary as a 5min bars series. */
			Add("GC ##-##", PeriodType.Tick, 1, MarketDataType.Bid);
			Add("GC ##-##", PeriodType.Tick, 1, MarketDataType.Ask);

			
			// Add two EMA indicators to be plotted on the primary bar series
			Add(EMA(Fast));
			Add(EMA(Slow));
			
			/* Adjust the color of the EMA plots.
			For more information on this please see this tip: http://www.ninjatrader-support.com/vb/showthread.php?t=3228 */
			EMA(Fast).Plots[0].Pen.Color = Color.Blue;
			EMA(Slow).Plots[0].Pen.Color = Color.Green;
			
            CalculateOnBarClose = true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			 if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired)
                return;
			
			if (BarsInProgress == 0)
			{
				if (CrossAbove(EMA(Fast), EMA(Slow), 1))
				{
					//BarsInProgress = 1
					EnterLong(1, "Long: 1min");	
					//Print(ToTime(Time[0]));
				}
				else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
				{
					//BarsInProgress = 1
					EnterShort(1, "Short: 1min");
					//Print(ToTime(Time[0]));
				}
			}
			// When the OnBarUpdate() is called from the secondary bar series, do nothing.
			else
			{
				return;
			}
        }

        #region Properties
		/// <summary>
		/// </summary>
		[Description("Period for fast MA")]
		[Category("Parameters")]
		public int Fast
		{
			get { return fast; }
			set { fast = Math.Max(1, value); }
		}

		/// <summary>
		/// </summary>
		[Description("Period for slow MA")]
		[Category("Parameters")]
		public int Slow
		{
			get { return slow; }
			set { slow = Math.Max(1, value); }
		}
        #endregion
    }
}
If you look at the attached image, it looks like the exit is executing not on the close of the bar, but the trade opening the trade are filling at the open.

Has anyone ran into a similar issue when trying to create a intrabar backtest?

Cheerrs,

SodyTexas

"The great Traders have always been humbled by the market early on in their careers creating a deep respect for the market. Until one has this respect indelibly engraved in their makeup, the concept of money management and discipline will never be treated seriously."
Attached Thumbnails
Backtesting with Intrabar (Bid Ask) granularity-ninjatrader-trade-list-1_1_2013-3_31_2013.jpg  
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
 Vendor: www.innovative-trading-solutions-online.com 
Hartford, CT. USA
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: AMP/CQG, Kinetick
Favorite Futures: TF
 
RJay's Avatar
 
Posts: 677 since Jun 2009
Thanks: 726 given, 740 received


Hi SodyTexas,

Yea, in my opinion, that code's not going to work very well.

NinjaTrader 7 does not sequence its Bid, Ask, Last back test data in a single file.

The Bid, Ask, and Last historic data are stored in three separate files.

On a one second granularity, there is no way to correctly re-sequence these three files for back testing.

Using Tick like in your code won't work because The Bid, Ask, and Last tables do not have equal numbers of entries in the stored data table for accurate back testing.

The data gets retrieved out of sequence.

I did the same thing talked about in that article, tested it, then scrapped the project.

I'm glad they found it usable, I did not.

In my opinion, try using Market Replay or wait for NinjaTrader 8 . Any year now. Sigh...

RJay

Reply With Quote
The following user says Thank You to RJay for this post:
 
  #4 (permalink)
Spread Trader
Austin TX
 
Futures Experience: Advanced
Platform: Ninjatrader, Python, & R
Broker/Data: RJO
Favorite Futures: Futures, Spreads
 
SodyTexas's Avatar
 
Posts: 313 since Sep 2013
Thanks: 96 given, 843 received


RJay View Post
Hi SodyTexas,

Yea, in my opinion, that code's not going to work very well.

NinjaTrader 7 does not sequence its Bid, Ask, Last back test data in a single file.

The Bid, Ask, and Last historic data are stored in three separate files.

On a one second granularity, there is no way to correctly re-sequence these three files for back testing.

Using Tick like in your code won't work because The Bid, Ask, and Last tables do not have equal numbers of entries in the stored data table for accurate back testing.

The data gets retrieved out of sequence.

I did the same thing talked about in that article, tested it, then scrapped the project.

I'm glad they found it usable, I did not.

In my opinion, try using Market Replay or wait for NinjaTrader 8 . Any year now. Sigh...

RJay

Right, "sigh..." NT8 would solve this problem..

I have been using Replay for most everything, but now I am looking to optimize a system which can not without the back test functionality.

At the moment, I am trying to find a solution until NT8 comes out, since I can't count on NT time-frame on the release of NT8 Beta so, I thought I would explore my options. NT is going to lose customers if they don't get there act together, but then again I already bought there Muti-Broker option, so in there mind they go there money out of me.

Thanks for the reply,

Cheers,

Sody

"The great Traders have always been humbled by the market early on in their careers creating a deep respect for the market. Until one has this respect indelibly engraved in their makeup, the concept of money management and discipline will never be treated seriously."
Reply With Quote
The following user says Thank You to SodyTexas for this post:
 
  #5 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,357 given, 83,238 received

Accurate bid/ask data (associated with proper last) is in Elite section of futures.io (formerly BMT). If you want, you could make this work with some custom programming. But it would be better to write your own app to do it like others have done, or just wait for NT8 which should be around the corner in beta form.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:

Reply



futures io > > > > Backtesting with Intrabar (Bid Ask) granularity

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
If an transaction occurs BELOW the bid vrs AT the bid a bullish or bearish move Angelo1 Emini Index Futures Trading 4 April 11th, 2014 12:00 AM
Advanced managed orders ninjascript with intrabar granularity iPipper427 NinjaTrader Programming 7 June 5th, 2013 12:21 AM
Intrabar VWAP Eubie NinjaTrader Programming 6 February 3rd, 2012 06:12 PM
Is GomCD Delta: Bid/Ask or Bid (-) Ask? An Appropriate Substitute??? tdaman The Elite Circle 3 May 13th, 2011 05:06 PM
NASDAQ, ICE Bid for NYSE; Trump Deutsche Bourse Bid Quick Summary News and Current Events 0 April 1st, 2011 09:10 AM


All times are GMT -4. The time now is 04:15 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-18 in 0.11 seconds with 20 queries on phoenix via your IP 54.221.136.62