COT: Charts are not enough

CtrlAltDaveLargeAs the Chinese say, 1001 words is worth more than a picture.

John McCarthy

I suspect such heresy may result in getting little fish thrown at me but systems can get surprisingly complex quickly, and you need to ensure they are working correctly.

And just sometimes, the chart may not be the best method of displaying all the details.

The NinjaTrader platform does supply the Output Window, as well as the platform Log, but full control over your own separate logging system can really help matters.

The ability to use third party libraries within the trading platform is amazing yet probably rarely done. I recommend the log4net library, available for free at

http://logging.apache.org/log4net/release/features.html

Please see the official NinjaTrader documentation on how to add this dependency after downloading the library. First you should add the following using directives,

using log4net;

using log4net.Config;

using log4net.Appender;

using log4net.Layout;

And the logger instance variable,

private ILog logger;

The logging system needs to be configured so call this function once, perhaps in OnStartUp() but not Initialize() since that is actually called more often than you think, including when the platform lists them all available indicators in the Indicator selection window.

protected void configureLogging( string basename )

{

if( !Directory.Exists( NinjaTrader.Cbi.Core.UserDataDir.ToString() + “Logs\\” ) )

{

Directory.CreateDirectory( NinjaTrader.Cbi.Core.UserDataDir.ToString() + “Logs\\” );

}

String name = basename + “.”;

int count = 1;

while( File.Exists( NinjaTrader.Cbi.Core.UserDataDir.ToString() + “Logs\\” + name + count + “.log” ) )

{

count++;

}

var layout = new PatternLayout( “%date [%thread] %-5level – %message%newline” );

var appender = new RollingFileAppender

{

Name = ( name + count ),

File = NinjaTrader.Cbi.Core.UserDataDir.ToString() + “Logs\\” + name + count + “.log”,

Layout = layout,

};

layout.ActivateOptions();

appender.ActivateOptions();

BasicConfigurator.Configure( appender );

logger = LogManager.GetLogger( name + count );

((log4net.Repository.Hierarchy.Logger)logger.Logger).AddAppender( appender );

((log4net.Repository.Hierarchy.Logger)logger.Logger).Additivity = false;

}

This will create a Logs directory in your NinjaTrader installation, if needed, and then create a new log file on each run. This was really useful to have each test attempt in a separate log file when building our Commitment of Traders Indicator.

I’ll let the documentation of log4net bore you with all the possible options. Fortunately, using the logger is simply,

logger.Info( “This is clearly not as much fun as a chart” );

Always polite to clean up the resources like,

protected override void OnTermination()

{

if( logger != null )

{

((log4net.Repository.Hierarchy.Logger)logger.Logger).RemoveAllAppenders();

}

}

I have spent too much of my adult life considering calendars, dates and times. The COT indicator calculates Federal Holidays, and adjusts the Reported date accordingly to help provide more reliable backtests.

In 2008, Independence Day fell on a Friday. This meant that the COT data was actually released on the following Monday, and thus there were two COT data releases that week.

There’s no chart to show the correct handling of this situation, but instead, a snipped log file.

It shows the used parameters, confirms that it has the latest COT data, caches the required data, and then supplies the correct data for the given date of each request,

2013-09-03 22:59:12,792 [NT main thread] INFO – Starting up
2013-09-03 22:59:12,792 [NT main thread] INFO – Contract = EuroFxChicagoMercantileExchange (099741 on CME)
2013-09-03 22:59:12,792 [NT main thread] INFO – Datapoint = Commercial Positions-Net Position (All)
2013-09-03 22:59:12,792 [NT main thread] INFO – Datapoint = Noncommercial Positions-Net Position (All)
2013-09-03 22:59:12,792 [NT main thread] INFO – Datapoint = Nonreportable Positions-Net Position (All)
2013-09-03 22:59:12,792 [NT main thread] INFO – Inverted = False
2013-09-03 22:59:12,792 [NT main thread] INFO – Used datapoints = 3
2013-09-03 22:59:12,792 [NT main thread] INFO – Date System = Released
2013-09-03 22:59:12,792 [NT main thread] INFO – Last Check = 03/09/2013 22:55:17
2013-09-03 22:59:12,792 [NT main thread] INFO – Last Download = 03/09/2013 22:55:20
2013-09-03 22:59:12,792 [NT main thread] INFO – 1995: Zip Size = 474461 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 1996: Zip Size = 674859 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 1997: Zip Size = 704215 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 1998: Zip Size = 733953 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 1999: Zip Size = 729099 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2000: Zip Size = 586699 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2001: Zip Size = 546370 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2002: Zip Size = 517960 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2003: Zip Size = 600884 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2004: Zip Size = 654434 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2005: Zip Size = 723861 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2006: Zip Size = 877200 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2007: Zip Size = 875050 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2008: Zip Size = 931474 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2009: Zip Size = 1006008 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2010: Zip Size = 1076547 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2011: Zip Size = 1099509 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2012: Zip Size = 1140086 Status = Complete
2013-09-03 22:59:12,792 [NT main thread] INFO – 2013: Zip Size = 877935 Status = Incomplete
2013-09-03 22:59:12,792 [NT main thread] INFO – Loading cache for 2008, at 03/09/2013 22:59:12
2013-09-03 22:59:12,995 [NT main thread] DEBUG – 22/12/2008 is a Monday
2013-09-03 22:59:12,995 [NT main thread] DEBUG – 04/07/2008 is a holiday
2013-09-03 22:59:13,041 [NT main thread] DEBUG – 11/01/2008 20:30:00 = -68094,53398,14696
2013-09-03 22:59:13,041 [NT main thread] DEBUG – 18/01/2008 20:30:00 = -60292,47243,13050
<Snip>
2013-09-03 22:59:13,041 [NT main thread] DEBUG – 27/06/2008 20:30:00 = -10636,2945,7691
2013-09-03 22:59:13,041 [NT main thread] DEBUG – 07/07/2008 20:30:00 = -32497,31160,1337
2013-09-03 22:59:13,041 [NT main thread] DEBUG – 11/07/2008 20:30:00 = -25688,25545,143
2013-09-03 22:59:13,041 [NT main thread] DEBUG – 18/07/2008 20:30:00 = -32197,25384,6814
<Snip>
2013-09-03 22:59:13,072 [NT main thread] DEBUG – Request for 03/07/2008 22:00:00, found 27/06/2008 20:30:00, stale = False
2013-09-03 22:59:13,072 [NT main thread] DEBUG – Request for 04/07/2008 22:00:00, found 27/06/2008 20:30:00, stale = False
2013-09-03 22:59:13,072 [NT main thread] DEBUG – Request for 07/07/2008 22:00:00, found 07/07/2008 20:30:00, stale = False
2013-09-03 22:59:13,072 [NT main thread] DEBUG – Request for 08/07/2008 22:00:00, found 07/07/2008 20:30:00, stale = False
2013-09-03 22:59:13,072 [NT main thread] DEBUG – Request for 09/07/2008 22:00:00, found 07/07/2008 20:30:00, stale = False
2013-09-03 22:59:13,072 [NT main thread] DEBUG – Request for 10/07/2008 22:00:00, found 07/07/2008 20:30:00, stale = False
2013-09-03 22:59:13,072 [NT main thread] DEBUG – Request for 11/07/2008 22:00:00, found 11/07/2008 20:30:00, stale = False
2013-09-03 22:59:13,072 [NT main thread] DEBUG – Request for 14/07/2008 22:00:00, found 11/07/2008 20:30:00, stale = False