TradeStatsEquityHistory¶
Stats and the equity curve and the trade list โ the combined analytics payload in one call.
API Information:
- Low-level API:
MT4Account.TradeStatsEquityHistory(ctx, from, fromUtc, excludeSameBars)(defined inmt4/MT4Account.go) - gRPC service:
mt4_term_api.AccountHelper - Payload:
StatsWithChartsData
๐ฌ Just the essentials¶
- What it is. Everything
TradeStatsandEquityHistoryreturn, plus the trade list โ in a single round-trip. - Why you need it. Build a full report page without three separate calls.
- When to use. Report/export screens that need KPIs, the curve and the trades together.
๐ฏ Purpose¶
- The full
StatsDataKPI block - The equity-curve points (
EquityPointData) - The closed-trade list and the currently-open trades
- One round-trip for a complete analytics view
Method Signature¶
func (a *MT4Account) TradeStatsEquityHistory(ctx context.Context, from, fromUtc *string, excludeSameBars *bool) (*pb.StatsWithChartsData, error)
Request message:
message TradeStatsEquityHistoryRequest {
optional string from = 1; // server-time "yyyy-MM-ddTHH:mm:ss"; nil = account start
optional string from_utc = 2;
optional bool exclude_same_bars = 3; // collapse consecutive equal equity points
}
Payload message:
message StatsWithChartsData {
StatsData stats = 1;
repeated EquityPointData charts = 2;
repeated TradeHistoryItemData trades = 3;
repeated TradeHistoryItemData open_trades = 4;
}
๐ฝ Input¶
| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context |
yes | Cancellation / timeout. |
from |
*string |
no | Server-time start "yyyy-MM-ddTHH:mm:ss"; nil = account start. |
fromUtc |
*string |
no | Same start in UTC (send one of from / fromUtc). |
excludeSameBars |
*bool |
no | true collapses consecutive identical equity points. |
โฌ๏ธ Output โ *pb.StatsWithChartsData¶
| Field | Proto Type | Go getter | Description |
|---|---|---|---|
stats |
StatsData | GetStats() |
Full KPI block โ see TradeStats |
charts |
repeated EquityPointData | GetCharts() |
Equity-curve points โ see EquityHistory |
trades |
repeated TradeHistoryItemData | GetTrades() |
Closed trades in the window |
open_trades |
repeated TradeHistoryItemData | GetOpenTrades() |
Currently open trades |
๐งฉ Notes & Tips¶
- One call, three datasets. Prefer this over calling
TradeStats+EquityHistoryseparately for a report. - Nested
statscan be nil on an empty history โ guardGetStats()before reading KPIs. excludeSameBarsapplies tocharts(the equity points), trimming flat stretches.
๐ Usage Examples¶
1) One-call report header¶
func reportHeader(ctx context.Context, acc *mt4.MT4Account) error {
d, err := acc.TradeStatsEquityHistory(ctx, nil, nil, nil)
if err != nil { return err }
if s := d.GetStats(); s != nil {
fmt.Printf("trades=%d PF=%.2f maxDD=%.1f%%\n",
s.GetTrades(), s.GetProfitFactor(), s.GetMaxEquityDrawdownRelative())
}
fmt.Printf("curve points=%d closed=%d open=%d\n",
len(d.GetCharts()), len(d.GetTrades()), len(d.GetOpenTrades()))
return nil
}
2) Export the equity curve¶
func exportCurve(ctx context.Context, acc *mt4.MT4Account) error {
collapse := true
d, err := acc.TradeStatsEquityHistory(ctx, nil, nil, &collapse)
if err != nil { return err }
for _, p := range d.GetCharts() {
fmt.Printf("%s,%.2f,%.2f\n", p.GetTime().AsTime().Format(time.RFC3339),
p.GetBalance(), p.GetEquity())
}
return nil
}
3) Month-to-date bundle¶
func monthBundle(ctx context.Context, acc *mt4.MT4Account) (*pb.StatsWithChartsData, error) {
from := time.Now().Format("2006-01") + "-01T00:00:00"
return acc.TradeStatsEquityHistory(ctx, &from, nil, nil)
}
โ ๏ธ Pitfalls¶
- Heavier payload. It carries stats + curve + trades โ window and
excludeSameBarsit for big histories. - Nil sub-messages.
GetStats()may benil; the slices may be empty โ guard both. - Two time axes. Don't send both
fromandfromUtc.
๐งช Testing Suggestions¶
- Happy path (demo).
GetStats() != nil;len(GetCharts()) > 0;len(GetTrades())matchesGetStats().GetTrades()for the all-time call. - Collapse.
excludeSameBars=truereduceslen(GetCharts()). - Window. A recent
fromshrinks all three datasets.