NexusFi: Find Your Edge


Home Menu

 





Adding a wide range of contracts for backtesting


Discussion in NinjaTrader

Updated
    1. trending_up 1,922 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 vhanded 
Kuala Lumpur Malaysia
 
Experience: Beginner
Platform: NinjaTrader
Trading: Futures
Posts: 8 since Nov 2014
Thanks Given: 3
Thanks Received: 1

Hi, I am currently backtesting calendar spread using NinjaTrader 7, and I am adding a list of CL contracts in Initialize(), like this:

 
Code
Add("CL 03-10", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 04-10", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 05-10", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 06-10", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 07-10", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 08-10", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 09-10", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 10-10", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 11-10", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 12-10", BarsPeriod.Id, BarsPeriod.Value);
			
			
			Add("CL 01-11", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 02-11", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 03-11", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 04-11", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 05-11", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 06-11", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 07-11", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 08-11", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 09-11", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 10-11", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 11-11", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 12-11", BarsPeriod.Id, BarsPeriod.Value);
			
			
			Add("CL 01-12", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 02-12", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 03-12", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 04-12", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 05-12", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 06-12", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 07-12", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 08-12", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 09-12", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 10-12", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 11-12", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 12-12", BarsPeriod.Id, BarsPeriod.Value);
			
			
			Add("CL 01-13", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 02-13", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 03-13", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 04-13", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 05-13", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 06-13", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 07-13", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 08-13", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 09-13", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 10-13", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 11-13", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 12-13", BarsPeriod.Id, BarsPeriod.Value);
			
			
			
			Add("CL 01-14", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 02-14", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 03-14", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 04-14", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 05-14", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 06-14", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 07-14", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 08-14", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 09-14", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 10-14", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 11-14", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 12-14", BarsPeriod.Id, BarsPeriod.Value);
			
			
			Add("CL 01-15", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 02-15", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 03-15", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 04-15", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 05-15", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 06-15", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 07-15", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 08-15", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 09-15", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 10-15", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 11-15", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 12-15", BarsPeriod.Id, BarsPeriod.Value);
			
			
			Add("CL 01-16", BarsPeriod.Id, BarsPeriod.Value);
			Add("CL 02-16", BarsPeriod.Id, BarsPeriod.Value);

And in my OnBarUpdate(), for demonstration purpose, I will just have:
 
Code
Print("Hello World");
The backtest period is from 1/1/2010 till 19/3/2015, using daily bar, and BarRequired = 0;


Th expected behavior is a list of "Hello World" in console output, but, I am not getting even 1. Seems like OnBarUpdate is not running at all.

However, remove CL 01-16 and CL 02-16 then "Hello World" will be printed. Why is this happening?


Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Five Days Until the Gap Dies -- CME Goes 24/7 on All Dig …
Traders Hideout
OneChronos Launches First Combinatorial Auction FX Venue …
Currencies
Kharg Island at 6%, Regime Fall at 1.5% -- The Black Swa …
Prediction Markets & Event Contracts
Hormuz Normalization Collapses to 19.5% -- Iran Regime F …
Prediction Markets & Event Contracts
Kalshi Sets $4.13B All-Time Weekly Record as Polymarket …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #2 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,971 since Jun 2009
Thanks Given: 534
Thanks Received: 3,711

Check the "Log" tab in the Control Center to see if there are any error messages, you may have some error messages that occurred in the Initialize() method.


vhanded View Post
Th expected behavior is a list of "Hello World" in console output, but, I am not getting even 1. Seems like OnBarUpdate is not running at all.

However, remove CL 01-16 and CL 02-16 then "Hello World" will be printed. Why is this happening?


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,557


Can you actually chart 01-16 and 02-16? May be a data problem

Sent from my phone




We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 vhanded 
Kuala Lumpur Malaysia
 
Experience: Beginner
Platform: NinjaTrader
Trading: Futures
Posts: 8 since Nov 2014
Thanks Given: 3
Thanks Received: 1


Big Mike View Post
Can you actually chart 01-16 and 02-16? May be a data problem

Sent from my phone

Hi Big Mike, yes, I can add just CL 01-16 and CL 02-16, and "Hello World" is printing. No problem.


Started this thread Reply With Quote
  #5 (permalink)
 vhanded 
Kuala Lumpur Malaysia
 
Experience: Beginner
Platform: NinjaTrader
Trading: Futures
Posts: 8 since Nov 2014
Thanks Given: 3
Thanks Received: 1


shodson View Post
Check the "Log" tab in the Control Center to see if there are any error messages, you may have some error messages that occurred in the Initialize() method.

Nothing is printing in Log...


Started this thread Reply With Quote
  #6 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,971 since Jun 2009
Thanks Given: 534
Thanks Received: 3,711


vhanded View Post
Hi Big Mike, yes, I can add just CL 01-16 and CL 02-16, and "Hello World" is printing. No problem.

Daily bars or intraday bars?


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 vhanded 
Kuala Lumpur Malaysia
 
Experience: Beginner
Platform: NinjaTrader
Trading: Futures
Posts: 8 since Nov 2014
Thanks Given: 3
Thanks Received: 1


shodson View Post
Daily bars or intraday bars?

This is daily bar.


Started this thread Reply With Quote




Last Updated on March 30, 2015


© 2026 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 - Downloads - Top
no new posts