Correctly Backtesting With Tick data Entry - futures io
futures io



Correctly Backtesting With Tick data Entry


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one zaico with 6 posts (0 thanks)
    2. looks_two sam028 with 3 posts (2 thanks)
    3. looks_3 rleplae with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 1,477 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 10 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
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

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

 
Search this Thread
 

Correctly Backtesting With Tick data Entry

(login for full post details)
  #1 (permalink)
zaico
Barcelona Spain
 
 
Posts: 26 since Sep 2016
Thanks: 6 given, 4 received

I've been reading about tick data after xplorer told me about it in a post I wrote, about my concern of entrys on the same bar. I concluded that the most accurate way of backtesting is using tickdata, wich according to NinjatradeForum would be something like this:

 
Code
protected override void Initialize()
        {
			
			Add(PeriodType.Tick, 1);
			CalculateOnBarClose = true;
        }

             protected override void OnBarUpdate()
        {
			
			if (BarsInProgress == 0)
			{
				
				/* The entry condition is triggered on the primary bar series, but the order is sent and filled on the
				secondary bar series. The way the bar series is determined is by the first parameter: 0 = primary bars,
					1 = secondary bars, 2 = tertiary bars, etc. */
					EnterLong(1, 1, "Long: 1min");
				
				
			}
			
			// When the OnBarUpdate() is called from the secondary bar series, do nothing.
			else
			{
				return;
			}
        }
the problem is that if I set a stop loss or a limit profit it stills check at the close of the bar. Any clue on what I'm doing wrong?

I'm correct assuming that using tick data will be and accurate backtesting?

thanks

Reply With Quote

Journal Challenge April 2021 results (now extended!):
Competing for $1800 in prizes from Jigsaw
looks_oneMaking a Living with the Microsby sstheo
(82 thanks from 10 posts)
looks_twoDeetee’s DAX Trading Journal (time based)by Deetee
(25 thanks from 9 posts)
looks_3Salao's Journalby Salao
(24 thanks from 6 posts)
looks_4Learning to Profit - A journey in algorithms and optionsby Syntax
(12 thanks from 7 posts)
looks_5Maybe a little bit different journalby Malykubo
(5 thanks from 2 posts)
 
Best Threads (Most Thanked)
in the last 7 days on futures io
futures io site changelog and issues/problem reporting
73 thanks
The Crude Dude Oil Trading System
73 thanks
Would You Sell Your System?
71 thanks
FIO Journal Challenge - April 2021 w/Jigsaw Trading
32 thanks
Big Mike in Ecuador
25 thanks
 
(login for full post details)
  #3 (permalink)
 rleplae 
Gits (Hooglede) Belgium
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,991 since Sep 2013
Thanks: 2,437 given, 5,801 received


Take a look at how i implemented tick entry/exit in the Oil Bot v36..

You will see that with OnMarketUpdate, it is possible to follow the tick data,
but it has a performance price, you should keep your code efficient.



This is just to give you a working example, probably many other ideas are possible.

Personally i stopped writing strategies in NT, i wrote an engine completely outside of NT
that gives me a good control, while i'm still able to follow the trades in chart trader, i
can intervene if necessary..

Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #4 (permalink)
zaico
Barcelona Spain
 
 
Posts: 26 since Sep 2016
Thanks: 6 given, 4 received

From ninjatrader forum they told me to implement something like this:

 
Code
 protected override void Initialize()
        {
            CalculateOnBarClose = false;
            ExitOnClose = true;
            IncludeCommission = true;
            Add(PeriodType.Tick, 1);
            SetProfitTarget(CalculationMode.Ticks, 10);
            SetStopLoss(CalculationMode.Ticks, 10);
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        
            if (BarsInProgress != 1)
            {
				return;
            }
       	    if (condition){//example
                   EnterLongLimit(0, true, 1, MIN(Low, 3)[0], "Long Entry");
      		Print("Time: " + Time[0]+"       Stochastic: K" + Stochastics(7,14,3).K[0]+"   D:"+Stochastics(7,14,3).D[0]); //to check if ever arrives here

             }
                
        }
wich will lead in to stop and limit checked at every tick. Is that correct? because now the condition is never accomplished wich was before implementing the ticks.

Reply With Quote
 
(login for full post details)
  #5 (permalink)
 sam028 
Site Moderator
 
 
sam028's Avatar
 
Posts: 3,670 since Jun 2009
Thanks: 3,789 given, 4,505 received

BarsInProgress == 0 : this is your primary bar
BarsInProgress == 1 : this is your secondary bar, 1 tick in your case

So you can do something like this:
 
Code
public class yourStrategyName : Strategy 	{
        private bool longready = false;
        private bool shortready = false;

        protected override void Initialize()
        {
            CalculateOnBarClose = false;
            ExitOnClose = true;
            IncludeCommission = true;
            Add(PeriodType.Tick, 1);
            SetProfitTarget(CalculationMode.Ticks, 10);
            SetStopLoss(CalculationMode.Ticks, 10);
        }

        protected override void OnBarUpdate()
        {       
            if (BarsInProgress == 0)
            {
                if (condition)
                     longready = true;
            }
       	    if ( (BarsInProgress == 1) && (longready) ){
                   EnterLongLimit(0, true, 1, MIN(Low, 3)[0], "Long Entry");
                   longready = false;      		
             }                
        }

zaico View Post
From ninjatrader forum they told me to implement something like this:

 
Code
 protected override void Initialize()
        {
            CalculateOnBarClose = false;
            ExitOnClose = true;
            IncludeCommission = true;
            Add(PeriodType.Tick, 1);
            SetProfitTarget(CalculationMode.Ticks, 10);
            SetStopLoss(CalculationMode.Ticks, 10);
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        
            if (BarsInProgress != 1)
            {
				return;
            }
       	    if (condition){//example
                   EnterLongLimit(0, true, 1, MIN(Low, 3)[0], "Long Entry");
      		Print("Time: " + Time[0]+"       Stochastic: K" + Stochastics(7,14,3).K[0]+"   D:"+Stochastics(7,14,3).D[0]); //to check if ever arrives here

             }
                
        }
wich will lead in to stop and limit checked at every tick. Is that correct? because now the condition is never accomplished wich was before implementing the ticks.


Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
The following user says Thank You to sam028 for this post:
 
(login for full post details)
  #6 (permalink)
zaico
Barcelona Spain
 
 
Posts: 26 since Sep 2016
Thanks: 6 given, 4 received

Thanks so much! I was going crazy with the Ninja Support Team. The "MIN(Low, 3)[0]" is not applicable in this case since it's being called from a tick bar not the general. The only solution I found is to save it in a double when (BarsInProgress == 0). Is there a way to call it directly without using the variable?

Thanks again!

Reply With Quote
 
(login for full post details)
  #7 (permalink)
 sam028 
Site Moderator
 
 
sam028's Avatar
 
Posts: 3,670 since Jun 2009
Thanks: 3,789 given, 4,505 received


zaico View Post
Thanks so much! I was going crazy with the Ninja Support Team. The "MIN(Low, 3)[0]" is not applicable in this case since it's being called from a tick bar not the general. The only solution I found is to save it in a double when (BarsInProgress == 0). Is there a way to call it directly without using the variable?

Thanks again!

Keep this principle.
In a 1 tick dataserie the less you'll ask to your CPU the better.

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
The following user says Thank You to sam028 for this post:
 
(login for full post details)
  #8 (permalink)
zaico
Barcelona Spain
 
 
Posts: 26 since Sep 2016
Thanks: 6 given, 4 received

good point! thanks!

Reply With Quote
 
(login for full post details)
  #9 (permalink)
zaico
Barcelona Spain
 
 
Posts: 26 since Sep 2016
Thanks: 6 given, 4 received


sam028 View Post
Keep this principle.
In a 1 tick dataserie the less you'll ask to your CPU the better.

Using one tick data, if my strategy is profitable. Can we say it will be in real trading? or is there anything else to fix on coding to make it closer to reality?

Reply With Quote
 
(login for full post details)
  #10 (permalink)
 sam028 
Site Moderator
 
 
sam028's Avatar
 
Posts: 3,670 since Jun 2009
Thanks: 3,789 given, 4,505 received



zaico View Post
Using one tick data, if my strategy is profitable. Can we say it will be in real trading? or is there anything else to fix on coding to make it closer to reality?

Try in Market Replay or with a live data feed with a sim account, this will give you some clues.

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
 
(login for full post details)
  #11 (permalink)
zaico
Barcelona Spain
 
 
Posts: 26 since Sep 2016
Thanks: 6 given, 4 received

But concerning back testing is there anything else to look for?
Market replay can't go as far before as back test

Sent using the futures.io mobile app

Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > Correctly Backtesting With Tick data Entry


Last Updated on December 13, 2016


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1,800 in prizes!

April
 

Seven Trading Mistakes Solved With Smart Trading Tools w/Brannigan Barrett

Elite only
     



Copyright © 2021 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