Skip to main content

Data Export

Utility strategy that exports indicator data to CSV files — no trading, no decision tree. Demonstrates conditional indicator creation based on enabled export groups, per-indicator IndicatorExport objects with independent data schemas, and the ExportDataSource/ExportGranularity system.

Source: [INSTALL PATH]/API/Strategies/Data_Export/Data_Export.cs

What It Covers

  • Non-trading strategy (no OnCreateAlgoStrategy delegate)
  • Conditional indicator creation — only enabled indicators are instantiated
  • Per-indicator IndicatorExport with DataSchema builder methods
  • Export configuration: temporality (Historical/Realtime), granularity (Bar/Tick/Update), signed volumes
  • OnStateChange DataLoaded phase for export setup and schema building

Architecture

Data_Export : MZpackStrategyBase
├── StrategyFootprintIndicator (conditional)
│ └── IndicatorExport (Level 1, Bar granularity)
│ └── DataSchema with ~30 footprint fields
├── StrategyVolumeProfileIndicator (conditional)
│ └── IndicatorExport (Level 1, Bar or Tick granularity)
│ └── DataSchema with profile fields
├── StrategyBigTradeIndicator (conditional)
│ └── IndicatorExport (Level 1, Tick granularity)
│ └── DataSchema with trade fields
└── StrategyMarketDepthIndicator (conditional)
└── IndicatorExport (Level 2, Update granularity)
└── DataSchema with DOM fields

Strategy Setup

Constructor

The constructor only wires the indicator creation delegate — there is no OnCreateAlgoStrategy since this strategy doesn't trade:

public Data_Export() : base()
{
OnCreateIndicators = new OnCreateIndicatorsDelegate(CreateIndicators);
}

CreateIndicators

Indicators are created conditionally based on which export groups are enabled:

protected List<TickIndicator> CreateIndicators()
{
List<TickIndicator> indicators = new List<TickIndicator>();

if (Footprint_Enable)
{
footprintIndicator = new StrategyFootprintIndicator(this, FOOTPRINT)
{
SaveSettings = true,
ShowVersionInfo = false
};
indicators.Add(footprintIndicator);
}

if (VolumeProfile_Enable)
{
volumeProfileIndicator = new StrategyVolumeProfileIndicator(this, VOLUMEPROFILE)
{
SaveSettings = true,
ShowVersionInfo = false
};
indicators.Add(volumeProfileIndicator);
}

if (BigTrade_Enable)
{
bigTradeIndicator = new StrategyBigTradeIndicator(this, BIGTRADE)
{
SaveSettings = true,
ShowVersionInfo = false
};
indicators.Add(bigTradeIndicator);
}

if (MarketDepth_Enable)
{
marketDepthIndicator = new StrategyMarketDepthIndicator(this, MARKETDEPTH)
{
SaveSettings = true,
ShowVersionInfo = false
};
indicators.Add(marketDepthIndicator);
}

return indicators;
}

Export Setup (DataLoaded)

During State.DataLoaded, each enabled indicator gets an IndicatorExport object with its own data schema. The footprint export demonstrates the schema builder pattern:

if (State == State.DataLoaded)
{
char delimiter = !string.IsNullOrEmpty(Export_Delimiter)
? Export_Delimiter[0] : Export.DELIMITER;

// Footprint export
if (Footprint_Enable)
{
var fpExport = new IndicatorExport(this, footprintIndicator,
ExportDataSource.Level1,
Footprint_Export_Temporality,
ExportGranularity.Bar,
new ExportArgs()
{
IsExportWhileCollecting = false,
IsFile = true,
IsHeader = Export_Header,
IsTime = Export_Time,
Delimiter = delimiter,
FileName = Export_File,
IsBatch = Export_Batch,
IsNinjaScriptOutput = Export_NinjaScriptOutput,
});

// Build schema with enabled fields
DataSchema schema = new DataSchema();
if (Footprint_OHLC) schema.Append("Open", ValueKind.Feature, ...);
if (Footprint_OHLC) schema.Append("Close", ValueKind.Feature, ...);
if (Footprint_OHLC) schema.Append("High", ValueKind.Feature, ...);
if (Footprint_OHLC) schema.Append("Low", ValueKind.Feature, ...);
// ... ~30 fields conditionally added
if (Footprint_Volume) schema.Append("Volume", ValueKind.Feature, ...);
if (Footprint_Delta) schema.Append("Delta", ValueKind.Feature, ...);
if (Footprint_POC) schema.Append("POC", ValueKind.Feature, ...);
// etc.

fpExport.DataSet.Schema = schema;
Register(fpExport);
}

// Volume Profile, Big Trade, Market Depth exports follow same pattern
// ...
}

Footprint Schema Fields

Each field is conditionally added based on a boolean property. The value is read from the footprint bar via a delegate:

// Representative schema builder delegates
public double GetOpen(GeneralExport e, ValueDescriptor d, object data)
{
IFootprintBar bar = data as IFootprintBar;
return bar != null ? bar.Open : 0;
}

public double GetDelta(GeneralExport e, ValueDescriptor d, object data)
{
IFootprintBar bar = data as IFootprintBar;
return bar != null ? bar.Delta : 0;
}

// Volume ladders use signed format when enabled
public string GetVolumes(GeneralExport e, ValueDescriptor d, object data)
{
IFootprintBar bar = data as IFootprintBar;
if (bar == null) return "";
return Footprint_SignedVolume
? bar.GetSignedVolumesString()
: bar.GetVolumesString();
}

Configurable Properties

Export (Global)

PropertyDefaultDescription
Export_HeadertrueInclude column headers
Export_TimetrueInclude timestamp column
Export_BatchfalseBatch write mode
Export_Delimiter;Column separator
Export_File""Custom file path (optional)
Export_NinjaScriptOutputfalseWrite to NinjaScript output window

Footprint

PropertyDefaultDescription
Footprint_EnabletrueEnable footprint export
Footprint_Export_TemporalityHistoricalHistorical or Realtime
Footprint_OHLCtrueExport Open, Close, High, Low
Footprint_VolumetrueExport bar total volume
Footprint_BuyVolumetrueExport buy volume
Footprint_SellVolumetrueExport sell volume
Footprint_DeltatrueExport bar delta
Footprint_POCtrueExport POC price
Footprint_SignedVolumefalse+/- prefix for buy/sell
note

The Data_Export source file contains 100+ boolean properties for fine-grained control over which fields are exported per indicator. Check the source file for the complete list — the properties follow the naming pattern Footprint_*, VolumeProfile_*, BigTrade_*, MarketDepth_*.

Volume Profile

PropertyDefaultDescription
VolumeProfile_EnablefalseEnable volume profile export
VolumeProfile_Export_TemporalityHistoricalHistorical or Realtime

Big Trade

PropertyDefaultDescription
BigTrade_EnablefalseEnable big trade export
BigTrade_Export_TemporalityRealtimeHistorical or Realtime

Market Depth

PropertyDefaultDescription
MarketDepth_EnablefalseEnable market depth export (Level 2)
MarketDepth_Export_TemporalityRealtimeHistorical or Realtime

Output File Location

By default, exported files are saved to:

Documents\NinjaTrader 8\mzpack\strategy\...\Data_Export\data\<instrument>_<id>.csv

See Also