Help Intrabar backtest - NinjaTrader | futures io social day trading
futures io futures trading


Help Intrabar backtest
Updated: Views / Replies:864 / 5
Created: by SodyTexas Attachments:0

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
 

Help Intrabar backtest

  #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

Help Intrabar backtest

Hey Guys,

I am struggling to make a system with intrabar backtest capabilities. Is this even possible in NT7? I was able to do this in 6.5 a few years back. But now that I no longer have 6.5 and would like to use just NT7; I need a solution.

I tried the following (Strategy: Backtesting NinjaScript Strategies with an intrabar granularity - NinjaTrader Support Forum) just to get it to work but all this code does is fills the trade at 6:01 opposed to 6:00, meaning it waited 1 minute to run the code.

Has anyone seen this same issue in NT7 or have sample code that actually works to backtest intrabar.

Thanks in advance, Cheers,

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."
Reply With Quote
 
  #2 (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,353 given, 83,234 received

In real time, there is CalculateOnBarClose = false meaning it will execute the tick that changes your signal to enter a position.

But for backtesting, there is no such thing.

Instead, you'll need to use actual tick data for backtesting. I suggest using a 1 range bar, I found it most accurate. Use that for your execution dataseries, and you can use a secondary bar series for your signal. You'll need to research using multiple time frames in strategies.

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:
 
  #3 (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

Help


Thanks Mike for taking the time, I know you are a busy guy!

I believe that is exactly what I was doing, with the exception of using 1 minute bars on the BarsInProgress == 1 on a 15 min backtest.

 
Code
Add(PeriodType.Minute, 1);
&

 
Code
		if (BarsInProgress == 0)
			{
				if (CrossAbove(EMA(Fast), EMA(Slow), 1))
				{
					//BarsInProgress = 1
					EnterLong(1, 1, "Long: 1min");				
				}
				
				else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
				{
					//BarsInProgress = 1
					EnterShort(1, 1, "Short: 1min");
				}
			}
			
			if (BarsInProgress == 1)
			{
				
			}
When the backtest runs I get the follow execution times:

Entry: 8:01 AM
Exit: 9:31 AM

Entry: 6:01 PM
Exit: 9:01 PM

Entry: 10:31 PM
Exit: 11:31 PM

and so on...

Do you see what I am doing wrong?

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
 
  #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

Here is the entire 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 SampleIntrabarBacktesV2t : 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(PeriodType.Minute, 1);
			
			// 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 (BarsInProgress == 0)
			{
				if (CrossAbove(EMA(Fast), EMA(Slow), 1))
				{
					//BarsInProgress = 1
					EnterLong(1, 1, "Long: 1min");				
				}
				
				else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
				{
					//BarsInProgress = 1
					EnterShort(1, 1, "Short: 1min");
				}
			}
			
			if (BarsInProgress == 1)
			{
				
			}
			
			
			
			// 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
    }
}

"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
 
  #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,353 given, 83,234 received


SodyTexas View Post
Do you see what I am doing wrong?

Not using tick based bars, like a 1-range bar.

Edit: Sorry I see you were trying to do a 15 minute. Entries would figure once per minute.

Print debug output in the loops and you'll see where you went wrong.

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:
 
  #6 (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

thanks!

Thanks Mike,

Debugging with Print helped. I used:

 
Code
Print(ToTime(Time[0]))
And I found the issue with the sample, instead of adding the entry on BarsInProgress == 0, I moved the code to BarsInProgress == 1, doing nothing on the 15 min bar (BarsInProgress == 0).

The backtest smaple provided from Ninjatrader.com is now working correcltly and I can start my project of building out my system. I will also use your suggestion with the range bar with tick granulation.

Here is the corrected code that provides minute granulation:

 
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 SampleIntrabarBacktesV2t : 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(PeriodType.Minute, 1);
			
			// 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 (BarsInProgress == 0)
			{
				
			}
			
			if (BarsInProgress == 1)
			{
				if (CrossAbove(EMA(BarsArray[0],Fast), EMA(BarsArray[0],Slow), 1))
				{
					//BarsInProgress = 1
					EnterLong(1, "Long: 1min");	
					//Print(ToTime(Time[0]));
				}
				else if (CrossBelow(EMA(BarsArray[0],Fast), EMA(BarsArray[0],Slow), 1))
				{
					//BarsInProgress = 1
					EnterShort(1, "Short: 1min");
				}
			}
			
			
			
			// 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
    }
}
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:

Reply



futures io > > > > Help Intrabar backtest

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
How to cancel and reorder within 1 min intrabar? ericson NinjaTrader Programming 6 February 19th, 2014 02:45 AM
Renko/manual backtest/hybrid backtest BrianH NinjaTrader 0 November 4th, 2013 02:07 PM
Deny intrabar updating in a strategy rdixey TradeStation 1 September 11th, 2013 11:06 PM
Intrabar VWAP Eubie NinjaTrader Programming 6 February 3rd, 2012 06:12 PM
Plot RSI intrabar extremes jtrade The Elite Circle 13 April 12th, 2010 02:25 PM


All times are GMT -4. The time now is 07:13 AM.

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-16 in 0.10 seconds with 19 queries on phoenix via your IP 54.226.113.250