Trade

View as Markdown

Definition

A Trade is a completed buy/sell or sell/buy transaction. It consists of an entry and exit execution.

Example 1Example 2
Buy 1 contract at a price of 1000 and sell 1 contract at a price of 1001 is one complete trade.Buy 2 contracts at a price of 1000 and sell the 1st contract at a price of 1001, then sell the 2nd contract at a price of 1002 are two completed trades.

In the second example above, two trade objects are created to represent each individual trade. Each trade object will hold the same entry execution for two contracts since this single execution was the opening execution for both individual trades.

Methods and Properties

PropertyDescription
CommissionA double value representing the commission of the trade
EntryGets an Execution object representing the entry
EntryEfficiencyA double value representing the entry efficiency of the trade
ExitGets an Execution object representing the exit
ExitEfficiencyA double value representing the exit efficiency of the trade
MaeCurrencyA double value representing max adverse excursion in currency
MaePercentA double value representing max adverse excursion as a percentage
MaePipsA double value representing max adverse excursion in pips
MaePointsA double value representing max adverse excursion in points
MaeTicksA double value representing max adverse excursion in ticks
MfeCurrencyA double value representing max favorable excursion in currency
MfePercentA double value representing max favorable excursion as a percentage
MfePipsA double value representing max favorable excursion in pips
MfePointsA double value representing max favorable excursion in points
MfeTicksA double value representing max favorable excursion in ticks
ProfitCurrencyA double value representing profit quoted in currency.
ProfitPercentA double value representing profit as a percentage
ProfitPipsA double value representing profit in pips
ProfitPointsA double value representing profit in points
ProfitTicksA double value representing profit in ticks
QuantityAn int value representing the quantity of the trade
TotalEfficiencyA double value representing the total efficiency of the trade
TradeNumberAn int value representing the trade number by the sequence it occurred
ToString()A string representation of the Trade object

Examples

1{
2 if (SystemPerformance.RealTimeTrades.Count > 0)
3 {
4 // Check to make sure there is at least one trade in the collection
5 Trade lastTrade = SystemPerformance.RealTimeTrades[SystemPerformance.RealTimeTrades.Count - 1];
6
7 // Calculate the PnL for the last completed real-time trade
8 double lastProfitCurrency = lastTrade.ProfitCurrency;
9
10 // Store the quantity of the last completed real-time trade
11 double lastTradeQty = lastTrade.Quantity;
12
13 // Print the PnL to the NinjaScript Output window
14 Print("The last trade's profit in currency is " + lastProfitCurrency);
15 // The trade profit is quantity aware, we can easily print the profit per traded unit as well
16 Print("The last trade's profit in currency per traded unit is " + (lastProfitCurrency / lastTradeQty));
17 }
18}