feat(market): add Donchian channel calculation

Add calculateDonchian function to compute highest high and lowest low
over a specified period. This is the foundation for box (range) detection
in the multi-period box indicator system for grid trading.
This commit is contained in:
tinkle-community
2026-01-17 21:39:21 +08:00
parent 0a2c62885b
commit 5c79aa451e
2 changed files with 69 additions and 0 deletions

View File

@@ -500,3 +500,40 @@ func TestIsStaleData_EmptyKlines(t *testing.T) {
t.Error("Expected false for empty klines, got true")
}
}
func TestCalculateDonchian(t *testing.T) {
// Create test klines with known high/low values
klines := []Kline{
{High: 100, Low: 90},
{High: 105, Low: 88},
{High: 102, Low: 92},
{High: 108, Low: 85},
{High: 103, Low: 91},
}
upper, lower := ExportCalculateDonchian(klines, 5)
if upper != 108 {
t.Errorf("Expected upper = 108, got %v", upper)
}
if lower != 85 {
t.Errorf("Expected lower = 85, got %v", lower)
}
}
func TestCalculateDonchian_PartialPeriod(t *testing.T) {
klines := []Kline{
{High: 100, Low: 90},
{High: 105, Low: 88},
}
upper, lower := ExportCalculateDonchian(klines, 10)
// Should use all available klines when period > len(klines)
if upper != 105 {
t.Errorf("Expected upper = 105, got %v", upper)
}
if lower != 88 {
t.Errorf("Expected lower = 88, got %v", lower)
}
}