Securely Redirecting...

Connecting to Stripe

Live Data NinjaTrader 8 C# / NinjaScript USD Free Tier

NinjaTrader 8 Integration

Embed live central-bank and macroeconomic data directly in your NinjaTrader 8 charts, indicators, and strategies. The FXMacroDataService.cs helper class wraps the full REST API surface in clean C# — no third-party dependencies required.

Language

C# / NinjaScript

Authentication

?api_key=YOUR_API_KEY

HTTP method

System.Net.WebClient

USD endpoints are free. You can test the integration without an API key using any USD indicator. An API key is required for all other currencies. Get an API key

Files

Download

Two files make up the integration. Download each one and place it in your NinjaTrader 8 Custom folder as shown below.

FXMacroDataService.cs

API helper class — NinjaTrader 8

Core service class. Place in Documents\NinjaTrader 8\bin\Custom\. Reference it from any indicator or strategy.

Download .cs

FXMacroData_MacroPanel.cs

Macro panel indicator — NinjaTrader 8

Chart overlay showing Policy Rate, Inflation, Unemployment and GDP for the active pair. Place in Documents\NinjaTrader 8\bin\Custom\Indicators\.

Download .cs

Installation

Setup guide

1

Copy files to the NinjaTrader Custom folder

Place both files in the correct sub-directories of your NinjaTrader 8 Custom folder:

FXMacroDataService.cs → Documents\NinjaTrader 8\bin\Custom\ FXMacroData_MacroPanel.cs → Documents\NinjaTrader 8\bin\Custom\Indicators\
2

Compile the NinjaScript project

In NinjaTrader go to Tools › New NinjaScript Editor. Press F5 or use File › Compile All. Both files must compile with 0 errors.

3

Add the indicator to a chart

Right-click any FX chart and choose Indicators…. Find FXMacroData_MacroPanel in the list and click Add.

4

Enter your API key

In the indicator parameters dialog find the FXMacroData group and enter your API key in the API Key field. Leave empty to test with free USD tier data.

5

Click OK — the panel appears on the chart

The macro panel is drawn in the top-left corner on the first bar close. Currency codes are auto-detected from the chart instrument (e.g. EUR/USD → EUR + USD). Use Base Currency Override and Quote Currency Override to force specific currencies on non-FX instruments.

FXMacroDataService.cs

C# method reference

All public methods are static and live in the NinjaTrader.Custom.FXMacroDataService class. Use them from any NinjaScript indicator or strategy after compiling.

string GetIndicator(currency, indicator [, apiKey])

Fetches a macroeconomic time series. Returns a JSON string.

Parameter Type Notes
currencystringLowercase, e.g. "eur", "jpy"
indicatorstringSnake_case name — see table below
apiKeystringOptional. Omit for free USD tier. Required for all other currencies.
using NinjaTrader.Custom;

// EUR policy rate — requires an API key
string json = FXMacroDataService.GetIndicator("eur", "policy_rate", ApiKey);
double rate = FXMacroDataService.LastValue(json);
Print("EUR policy rate: " + rate);

// USD inflation — free, no key needed
string inf = FXMacroDataService.GetIndicator("usd", "inflation");
string GetCalendar(currency [, apiKey])

Returns upcoming release dates and announcement times for all tracked indicators in a currency.

string cal = FXMacroDataService.GetCalendar("aud", ApiKey);
Print(cal); // inspect in Output window
string GetForex(baseCcy, quoteCcy)

Returns FX spot rate history. Free — no API key needed.

string fx   = FXMacroDataService.GetForex("usd", "jpy");
double spot = FXMacroDataService.LastValue(fx);
Print("USD/JPY spot: " + spot);
string GetCOT(currency [, apiKey])

Returns CFTC Commitment of Traders positioning data. Currency code should be uppercase.

string cot = FXMacroDataService.GetCOT("EUR", ApiKey);
double net = FXMacroDataService.JsonDouble(cot, "net_non_commercial");
Utility methods

Helper methods for parsing JSON responses returned by the API.

Method Description
LastValue(json)Most recent non-null val from an announcements response
JsonDouble(json, key)Extract a numeric value by key name — returns double.NaN when absent
JsonString(json, key)Extract a string value by key name
string json = FXMacroDataService.GetIndicator("usd", "inflation");

// Get the most recent value
double val  = FXMacroDataService.LastValue(json);

// Extract a named field from the last record manually
double num  = FXMacroDataService.JsonDouble(json, "val");
string date = FXMacroDataService.JsonString(json, "date");

Available indicators

Pass any of these snake_case names as the indicator argument to GetIndicator(). Not every indicator is available for every currency — see the full endpoint documentation for coverage.

policy_rate inflation inflation_mom core_inflation ppi ppi_mom gdp gdp_quarterly unemployment employment participation_rate retail_sales trade_balance current_account_balance consumer_confidence business_confidence industrial_production m1 m2 m3 gov_bond_2y gov_bond_5y gov_bond_10y gov_bond_30y

Full list: fxmacrodata.com/documentation

Indicator

Macro Panel indicator

FXMacroData_MacroPanel.cs draws a live data panel in the top-left corner of the chart showing four key macro indicators for both currencies in the active pair.

Indicators displayed

  • Policy Rate (%)
  • CPI Inflation (%)
  • Unemployment Rate (%)
  • GDP Growth (%)

Configurable inputs

  • ApiKey — your FXMacroData key
  • BaseOverride / QuoteOverride
  • RefreshMinutes — polling interval (1–1440)
  • FontSize — panel font size (6–24 pt)

The panel refreshes on every bar close after RefreshMinutes have elapsed since the last API call. Currency codes are auto-detected from the instrument name (e.g. EUR/USD → EUR and USD). Override detection with BaseOverride and QuoteOverride.

Examples

Custom strategies & indicators

Reference NinjaTrader.Custom.FXMacroDataService in any NinjaScript indicator or strategy to access the full API surface.

Alert when rate divergence exceeds a threshold

using NinjaTrader.Custom;

protected override void OnBarUpdate()
{
    double eurRate = FXMacroDataService.LastValue(
                        FXMacroDataService.GetIndicator("eur", "policy_rate", ApiKey));
    double usdRate = FXMacroDataService.LastValue(
                        FXMacroDataService.GetIndicator("usd", "policy_rate"));

    if (double.IsNaN(eurRate) || double.IsNaN(usdRate)) return;

    double spread = Math.Abs(eurRate - usdRate);
    if (spread >= MinSpread)
        Alert("fmd_spread", Priority.High,
              "EUR/USD rate spread: " + spread.ToString("0.##") + "pp",
              NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert2.wav", 10, Brushes.Yellow, Brushes.Black);
}

Print upcoming releases to the Output window

using NinjaTrader.Custom;

protected override void OnStateChange()
{
    if (State == State.DataLoaded)
    {
        string cal = FXMacroDataService.GetCalendar("aud", ApiKey);
        Print("[FXMacroData] AUD calendar: " + cal);
    }
}

Gate strategy entries on macro context

using NinjaTrader.Custom;

private bool MacroConditionMet(string currency)
{
    string json = FXMacroDataService.GetIndicator(currency, "unemployment", ApiKey);
    double uemp = FXMacroDataService.LastValue(json);
    if (double.IsNaN(uemp)) return false; // fail-safe: skip entry
    return uemp < MaxUnemployment;
}

protected override void OnBarUpdate()
{
    if (!MacroConditionMet("usd")) return;
    // ... your entry logic here ...
}

Help

Troubleshooting

All values show "n/a" on the panel

Open the NinjaTrader Output window (View › Output) and look for WebException or timeout messages. Common causes:

  • API key is missing or invalid for a non-USD currency
  • The indicator you requested is not available for that currency
  • Your machine blocked outbound HTTPS — check firewall rules
Compile error: "FXMacroDataService does not exist in namespace NinjaTrader.Custom"

FXMacroDataService.cs is not in the Custom folder or was not compiled. Ensure the file is at Documents\NinjaTrader 8\bin\Custom\FXMacroDataService.cs and run File › Compile All in the NinjaScript Editor.

The panel text does not appear on the chart

The indicator fetches data on the first bar close after loading, so the panel appears once the first bar completes. On a live chart this can take a few seconds. On a replay or historical chart advance one bar to trigger OnBarUpdate().

Wrong currencies displayed for my instrument

Auto-detection parses the first three and last three characters of the full instrument name (e.g. EURUSD). If your broker uses a different symbol format (e.g. EUR_USD or EURUSDm), set BaseOverride to eur and QuoteOverride to usd manually.

How do I check which currencies and indicators are available?

Print the data catalogue from NinjaScript:

Print(FXMacroDataService.GetIndicator("usd", "policy_rate"));

Or browse the full catalogue at fxmacrodata.com/documentation.

Can I use FXMacroDataService inside a Strategy?

Yes. Add using NinjaTrader.Custom; at the top of your strategy file and call any FXMacroDataService method directly. For best performance call GetIndicator() from OnStateChange() during State.DataLoaded to cache the result, and avoid calling it on every tick.

Still stuck? Open a ticket at fxmacrodata.com/support or email support@fxmacrodata.com.