NexusFi: Find Your Edge


Home Menu

 





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 3,190 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 10 posts
    2. attach_file 0 attachments




 
Search this Thread

Correctly Backtesting With Tick data Entry

  #1 (permalink)
zaico
Barcelona Spain
 
Posts: 26 since Sep 2016
Thanks Given: 6
Thanks Received: 4

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

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Futures True Range Report
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
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
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


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 NexusFi Trade Journal Reply With Quote
  #4 (permalink)
zaico
Barcelona Spain
 
Posts: 26 since Sep 2016
Thanks Given: 6
Thanks Received: 4

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
  #5 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

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
Thanked by:
  #6 (permalink)
zaico
Barcelona Spain
 
Posts: 26 since Sep 2016
Thanks Given: 6
Thanks Received: 4

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
  #7 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


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
Thanked by:
  #8 (permalink)
zaico
Barcelona Spain
 
Posts: 26 since Sep 2016
Thanks Given: 6
Thanks Received: 4

good point! thanks!

Reply With Quote
  #9 (permalink)
zaico
Barcelona Spain
 
Posts: 26 since Sep 2016
Thanks Given: 6
Thanks Received: 4


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
  #10 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629



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




Last Updated on December 13, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts