π
π Get Deals This Week (GetDealsThisWeek)ΒΆ
Sugar method: Returns all closed positions (deals) from this week (Monday 00:00 to now).
API Information:
- Method:
sugar.GetDealsThisWeek() - Timeout: 5 seconds
- Returns: Slice of position history info
π Method SignatureΒΆ
π½ Input / β¬οΈ OutputΒΆ
| Input | Type | Description |
|---|---|---|
| None | - | No parameters (auto-calculates week range) |
| Output | Type | Description |
|---|---|---|
[]*pb.PositionHistoryInfo |
slice | All closed positions from this week |
error |
error |
Error if retrieval failed |
π¬ Just the EssentialsΒΆ
- What it is: Get all closed trades from Monday 00:00 to current time.
- Why you need it: Weekly performance tracking, strategy analysis, week-over-week comparison.
- Sanity check: Returns empty slice if no deals this week. Week starts on Monday.
π― When to UseΒΆ
β Weekly reports - Generate week-to-date summaries
β Performance tracking - Monitor weekly profit/loss
β Strategy analysis - Review week's trading decisions
β Goal tracking - Check progress toward weekly targets
π Usage ExamplesΒΆ
1) Basic usage - show this week's dealsΒΆ
deals, err := sugar.GetDealsThisWeek()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
if len(deals) == 0 {
fmt.Println("No deals this week")
return
}
fmt.Printf("This week's deals: %d\n\n", len(deals))
totalProfit := 0.0
for i, deal := range deals {
fmt.Printf("%d. #%d %s: $%.2f\n",
i+1, deal.Ticket, deal.Symbol, deal.Profit)
totalProfit += deal.Profit
}
fmt.Printf("\nWeek total: $%.2f\n", totalProfit)
2) Weekly performance summaryΒΆ
deals, _ := sugar.GetDealsThisWeek()
if len(deals) == 0 {
fmt.Println("No trading this week")
return
}
totalProfit := 0.0
winCount := 0
lossCount := 0
for _, deal := range deals {
totalProfit += deal.Profit
if deal.Profit > 0 {
winCount++
} else if deal.Profit < 0 {
lossCount++
}
}
winRate := float64(winCount) / float64(len(deals)) * 100
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β THIS WEEK'S PERFORMANCE β")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Total trades: %d\n", len(deals))
fmt.Printf("Winners: %d (%.1f%%)\n", winCount, winRate)
fmt.Printf("Losers: %d (%.1f%%)\n", lossCount, 100-winRate)
fmt.Printf("Total P/L: $%.2f\n", totalProfit)
if totalProfit > 0 {
fmt.Println("\nβ
Profitable week so far")
} else {
fmt.Println("\nβ Losing week so far")
}
3) Daily breakdown of this weekΒΆ
deals, _ := sugar.GetDealsThisWeek()
if len(deals) == 0 {
fmt.Println("No deals this week")
return
}
// Group by day
dailyDeals := make(map[string][]float64)
for _, deal := range deals {
dayKey := deal.TimeClose.Format("Mon 01/02")
dailyDeals[dayKey] = append(dailyDeals[dayKey], deal.Profit)
}
fmt.Println("This Week - Daily Breakdown:")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
// Get days in order (Monday to Sunday)
now := time.Now()
weekday := int(now.Weekday())
if weekday == 0 {
weekday = 7 // Sunday becomes 7
}
for i := 0; i < weekday; i++ {
day := now.AddDate(0, 0, -(weekday - 1 - i))
dayKey := day.Format("Mon 01/02")
profits, exists := dailyDeals[dayKey]
if !exists {
fmt.Printf("%s: No trades\n", dayKey)
continue
}
dayProfit := 0.0
for _, p := range profits {
dayProfit += p
}
status := "β
"
if dayProfit < 0 {
status = "β"
}
fmt.Printf("%s %s: %d trades, $%.2f\n",
status, dayKey, len(profits), dayProfit)
}
4) Check weekly target progressΒΆ
weeklyTarget := 500.0 // $500 per week
deals, _ := sugar.GetDealsThisWeek()
if len(deals) == 0 {
fmt.Printf("Weekly target: $%.2f\n", weeklyTarget)
fmt.Println("No trades yet this week")
return
}
actualProfit := 0.0
for _, deal := range deals {
actualProfit += deal.Profit
}
progress := (actualProfit / weeklyTarget) * 100
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β WEEKLY TARGET PROGRESS β")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Target: $%.2f\n", weeklyTarget)
fmt.Printf("Current: $%.2f\n", actualProfit)
fmt.Printf("Progress: %.1f%%\n\n", progress)
remaining := weeklyTarget - actualProfit
if actualProfit >= weeklyTarget {
fmt.Printf("π― Target achieved! (+$%.2f)\n",
actualProfit-weeklyTarget)
} else if progress >= 80 {
fmt.Printf("π‘ Almost there! ($%.2f remaining)\n", remaining)
} else {
fmt.Printf("π In progress ($%.2f remaining)\n", remaining)
}
5) Best trading day this weekΒΆ
deals, _ := sugar.GetDealsThisWeek()
if len(deals) == 0 {
fmt.Println("No deals this week")
return
}
// Group by day and calculate daily profit
dailyProfit := make(map[string]float64)
for _, deal := range deals {
dayKey := deal.TimeClose.Format("Monday 01/02")
dailyProfit[dayKey] += deal.Profit
}
var bestDay string
var bestProfit float64 = -999999
for day, profit := range dailyProfit {
if profit > bestProfit {
bestProfit = profit
bestDay = day
}
}
fmt.Println("This Week's Best Day:")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Day: %s\n", bestDay)
fmt.Printf("Profit: $%.2f\n", bestProfit)
6) Symbol performance this weekΒΆ
deals, _ := sugar.GetDealsThisWeek()
if len(deals) == 0 {
fmt.Println("No deals this week")
return
}
symbolStats := make(map[string]struct {
Count int
Profit float64
})
for _, deal := range deals {
stats := symbolStats[deal.Symbol]
stats.Count++
stats.Profit += deal.Profit
symbolStats[deal.Symbol] = stats
}
fmt.Println("This Week - Symbol Performance:")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
for symbol, stats := range symbolStats {
avgProfit := stats.Profit / float64(stats.Count)
status := "β
"
if stats.Profit < 0 {
status = "β"
}
fmt.Printf("%s %-8s: %d trades, $%.2f (avg: $%.2f)\n",
status, symbol, stats.Count, stats.Profit, avgProfit)
}
7) Week-over-week comparisonΒΆ
thisWeekDeals, _ := sugar.GetDealsThisWeek()
// Get last week's range
now := time.Now()
weekday := int(now.Weekday())
if weekday == 0 {
weekday = 7
}
// Last week: previous Monday to Sunday
lastMonday := now.AddDate(0, 0, -(weekday + 6))
lastSunday := now.AddDate(0, 0, -(weekday))
lastWeekDeals, _ := sugar.GetDealsDateRange(lastMonday, lastSunday)
thisWeekProfit := 0.0
for _, deal := range thisWeekDeals {
thisWeekProfit += deal.Profit
}
lastWeekProfit := 0.0
for _, deal := range lastWeekDeals {
lastWeekProfit += deal.Profit
}
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β WEEK-OVER-WEEK COMPARISON β")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Last week: %d trades, $%.2f\n",
len(lastWeekDeals), lastWeekProfit)
fmt.Printf("This week: %d trades, $%.2f\n",
len(thisWeekDeals), thisWeekProfit)
diff := thisWeekProfit - lastWeekProfit
fmt.Printf("\nDifference: $%.2f ", diff)
if diff > 0 {
pct := (diff / lastWeekProfit) * 100
fmt.Printf("π (+%.1f%%)\n", pct)
} else if diff < 0 {
pct := (-diff / lastWeekProfit) * 100
fmt.Printf("π (-%.1f%%)\n", pct)
} else {
fmt.Println("β‘οΈ (No change)")
}
8) Weekly consistency checkΒΆ
deals, _ := sugar.GetDealsThisWeek()
if len(deals) == 0 {
fmt.Println("No deals this week")
return
}
// Group by day
dailyProfit := make(map[string]float64)
for _, deal := range deals {
dayKey := deal.TimeClose.Format("Mon")
dailyProfit[dayKey] += deal.Profit
}
positiveDays := 0
for _, profit := range dailyProfit {
if profit > 0 {
positiveDays++
}
}
consistency := float64(positiveDays) / float64(len(dailyProfit)) * 100
fmt.Println("Weekly Consistency:")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Trading days: %d\n", len(dailyProfit))
fmt.Printf("Profitable days: %d (%.1f%%)\n",
positiveDays, consistency)
if consistency >= 80 {
fmt.Println("β
Excellent consistency")
} else if consistency >= 60 {
fmt.Println("π‘ Good consistency")
} else {
fmt.Println("β οΈ Needs improvement")
}
9) Week projection (estimate end-of-week)ΒΆ
deals, _ := sugar.GetDealsThisWeek()
if len(deals) == 0 {
fmt.Println("No deals this week yet")
return
}
currentProfit := 0.0
for _, deal := range deals {
currentProfit += deal.Profit
}
now := time.Now()
weekday := int(now.Weekday())
if weekday == 0 {
weekday = 7
}
// Days elapsed in week (including today)
daysElapsed := weekday
// Project to end of week (5 trading days)
projectedProfit := (currentProfit / float64(daysElapsed)) * 5.0
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β WEEKLY PROJECTION β")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Printf("Days elapsed: %d\n", daysElapsed)
fmt.Printf("Current profit: $%.2f\n", currentProfit)
fmt.Printf("Daily average: $%.2f\n",
currentProfit/float64(daysElapsed))
fmt.Printf("Week projection: $%.2f\n", projectedProfit)
fmt.Println("\nβ οΈ Note: Projection assumes consistent daily performance")
10) Advanced weekly statistics analyzerΒΆ
type WeeklyStats struct {
TotalDeals int
TotalProfit float64
WinRate float64
BestDay string
BestDayProfit float64
WorstDay string
WorstDayProfit float64
MostTradedDay string
DaysTraded int
AvgDailyProfit float64
}
func AnalyzeWeeklyPerformance(sugar *mt5.MT5Sugar) (*WeeklyStats, error) {
deals, err := sugar.GetDealsThisWeek()
if err != nil {
return nil, err
}
stats := &WeeklyStats{
TotalDeals: len(deals),
}
if len(deals) == 0 {
return stats, nil
}
winCount := 0
dailyProfit := make(map[string]float64)
dailyCount := make(map[string]int)
for _, deal := range deals {
stats.TotalProfit += deal.Profit
if deal.Profit > 0 {
winCount++
}
dayKey := deal.TimeClose.Format("Mon 01/02")
dailyProfit[dayKey] += deal.Profit
dailyCount[dayKey]++
}
stats.WinRate = float64(winCount) / float64(len(deals)) * 100
stats.DaysTraded = len(dailyProfit)
if stats.DaysTraded > 0 {
stats.AvgDailyProfit = stats.TotalProfit / float64(stats.DaysTraded)
}
// Find best/worst days
maxCount := 0
stats.BestDayProfit = -999999
stats.WorstDayProfit = 999999
for day, profit := range dailyProfit {
if profit > stats.BestDayProfit {
stats.BestDayProfit = profit
stats.BestDay = day
}
if profit < stats.WorstDayProfit {
stats.WorstDayProfit = profit
stats.WorstDay = day
}
if dailyCount[day] > maxCount {
maxCount = dailyCount[day]
stats.MostTradedDay = day
}
}
return stats, nil
}
func (s *WeeklyStats) Print() {
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β WEEKLY STATISTICS ANALYSIS β")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
if s.TotalDeals == 0 {
fmt.Println("No trading activity this week")
return
}
fmt.Printf("Total Deals: %d\n", s.TotalDeals)
fmt.Printf("Total Profit: $%.2f\n", s.TotalProfit)
fmt.Printf("Win Rate: %.1f%%\n", s.WinRate)
fmt.Printf("Days Traded: %d\n", s.DaysTraded)
fmt.Printf("Avg Daily Profit: $%.2f\n\n", s.AvgDailyProfit)
fmt.Printf("Best Day: %s ($%.2f)\n",
s.BestDay, s.BestDayProfit)
fmt.Printf("Worst Day: %s ($%.2f)\n",
s.WorstDay, s.WorstDayProfit)
fmt.Printf("Most Traded Day: %s\n", s.MostTradedDay)
fmt.Println("\nWeek Assessment:")
if s.TotalProfit > 0 && s.WinRate >= 60 {
fmt.Println("π Excellent week")
} else if s.TotalProfit > 0 && s.WinRate >= 50 {
fmt.Println("β
Good week")
} else if s.TotalProfit >= 0 {
fmt.Println("π‘ Breakeven week")
} else {
fmt.Println("β Losing week - review strategy")
}
}
// Usage:
stats, _ := AnalyzeWeeklyPerformance(sugar)
stats.Print()
π Related MethodsΒΆ
π¬ Other time periods:
GetDealsToday()- Today's dealsGetDealsYesterday()- Yesterday's dealsGetDealsThisMonth()- This month's dealsGetDealsDateRange()- Custom date range
π¬ Profit calculations:
GetProfitThisWeek()- Just this week's profit total
β οΈ Common PitfallsΒΆ
1) Assuming week starts on SundayΒΆ
// β WRONG - week starts Monday in MT5
// Your local culture might use Sunday
// β
CORRECT - aware that week starts Monday
deals, _ := sugar.GetDealsThisWeek()
// Returns Monday 00:00 to now
2) Comparing incomplete week to complete weekΒΆ
// β WRONG - comparing mid-week to full week
thisWeekProfit, _ := sugar.GetProfitThisWeek() // Mon-Wed
lastWeekProfit := 500.0 // Mon-Fri
// Not fair comparison!
// β
CORRECT - note the difference
fmt.Println("This week (incomplete) vs last week (complete)")
3) Empty slice on Sunday/MondayΒΆ
// β WRONG - not handling early week
deals, _ := sugar.GetDealsThisWeek()
avgProfit := totalProfit / len(deals) // Panic if empty!
// β
CORRECT - check for empty
if len(deals) > 0 {
avgProfit := totalProfit / float64(len(deals))
}
π Pro TipsΒΆ
-
Week starts Monday - MT5 uses Monday as first day of week
-
Incomplete data - Mid-week calls return partial week data
-
Performance - 5-second timeout, suitable for regular calls
-
Empty OK - Returns empty slice if no trades (not error)
-
Auto-range - Automatically calculates Monday 00:00 to now
π Week Range CalculationΒΆ
Week range calculation:
now = time.Now()
weekday = int(now.Weekday())
if weekday == 0 { weekday = 7 } // Sunday becomes 7
startOfWeek = now - (weekday - 1) days at 00:00:00
Returns all deals from startOfWeek to now
See also: GetDealsToday.md, GetDealsThisMonth.md, GetProfitThisWeek.md, GetDealsDateRange.md