> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ninjatrader.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ninjatrader.com/_mcp/server.

# OnNextInstrument()

## Definition

The **OnNextInstrument()** method is called at the beginning of the import process for each file that is being imported. This method is only called after it has determined the file contains a valid instrument.

## Method Return Value

This method does not return a value.

## Syntax

See example below. The [NinjaScript code wizard](/developer/desktop-sdk/guides/ninjascript-editor-overview/ninjascript-wizard) automatically generates the method syntax for you.

## Examples

```csharp
private int currentInstrumentIdx = -1;

public string[] FileNames 
{ get; set; }

protected override void OnNextInstrument()
{
    if (FileNames == null)
        return;

    // Try to read from file into the FileNames array created above
    // Log an error and continue if the data is unreadable
    try
    {
        reader = new StreamReader(FileNames[currentInstrumentIdx]);
    }
    catch (Exception exp)
    {
        NinjaScript.Log(FileNames[currentInstrumentIdx], exp.Message, LogLevel.Error);
        continue;
    }
}
```