types: add total net profit field to trade states

Signed-off-by: c9s <yoanlin93@gmail.com>
This commit is contained in:
c9s 2022-06-28 21:48:40 +08:00 committed by Austin Liu
parent 1617005114
commit 32c76105b0

View File

@ -16,6 +16,8 @@ type TradeStats struct {
Losses []fixedpoint.Value `json:"losses" yaml:"losses"`
MostProfitableTrade fixedpoint.Value `json:"mostProfitableTrade" yaml:"mostProfitableTrade"`
MostLossTrade fixedpoint.Value `json:"mostLossTrade" yaml:"mostLossTrade"`
ProfitFactor fixedpoint.Value `json:"profitFactor" yaml:"profitFactor"`
TotalNetProfit fixedpoint.Value `json:"totalNetProfit" yaml:"totalNetProfit"`
}
func (s *TradeStats) Add(pnl fixedpoint.Value) {
@ -30,6 +32,7 @@ func (s *TradeStats) Add(pnl fixedpoint.Value) {
s.GrossLoss = s.GrossLoss.Add(pnl)
s.MostLossTrade = fixedpoint.Min(s.MostLossTrade, pnl)
}
s.TotalNetProfit = s.TotalNetProfit.Add(pnl)
// The win/loss ratio is your wins divided by your losses.
// In the example, suppose for the sake of simplicity that 60 trades were winners, and 40 were losers.
@ -39,6 +42,8 @@ func (s *TradeStats) Add(pnl fixedpoint.Value) {
} else {
s.WinningRatio = fixedpoint.NewFromFloat(float64(s.NumOfProfitTrade) / float64(s.NumOfLossTrade))
}
s.ProfitFactor = s.GrossProfit.Div(s.GrossLoss)
}
func (s *TradeStats) String() string {