> 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.

# OnAddTrade()

## Definition

This method is called as each trade is added. You would add any custom math you wanted to do here.

If your performance metric only needs to iterate through all trades at the end to perform its calculation and does not need to be calculated on each trade then using the **property approach** (On demand example) will have less of a performance impact.

## Syntax

`protected override void OnAddTrade(Cbi.Trade trade)`

## Examples

```csharp

protected override void OnAddTrade(Cbi.Trade trade)
{
     Values[(int)Cbi.PerformanceUnit.Currency] += trade.ProfitCurrency;
     Values[(int)Cbi.PerformanceUnit.Percent]  += trade.ProfitPercent;
     Values[(int)Cbi.PerformanceUnit.Pips]     += trade.ProfitPips;
     Values[(int)Cbi.PerformanceUnit.Points]   += trade.ProfitPoints;
     Values[(int)Cbi.PerformanceUnit.Ticks]    += trade.ProfitTicks;
}
```