Files
plot/tests/indicator_test.zi
T

56 lines
2.1 KiB
Ziran

#import "candle_chart"
#import "kryon/geometry"
#program_export
main :: () -> s32 {
bars: [5]PriceBar
closes: [5]float32 = .{1.0, 2.0, 3.0, 10.0, 5.0}
index: s32 = 0
while index < 5 {
bars[index].timestamp = 1000 + cast(s64)index * 86400
bars[index].close = closes[index]
bars[index].high = closes[index]
bars[index].low = closes[index]
bars[index].volume = cast(float32)(index + 1)
index += 1
}
values: []PriceBar = bars[:]
if SMAAt(values, 1, 3) != 0.0 { return 1 }
if SMAAt(values, 2, 3) != 2.0 { return 2 }
if SMAAt(values, 4, 3) != 6.0 { return 3 }
if EMAAt(values, 2, 3) != 2.0 { return 4 }
if EMAAt(values, 3, 3) != 6.0 { return 5 }
if EMAAt(values, 4, 3) != 5.5 { return 6 }
if CandleVisibleStart(5, 3) != 2 { return 7 }
range: CandleRange = CandleRangeFor(values, 3)
if range.low != 3.0 || range.high != 10.0 ||
range.max_volume != 5.0 { return 8 }
bounds: Rectangle = Rectangle.{0.0, 0.0, 300.0, 100.0}
visible: float32 = CandleMarkerX(values, 3, bounds,
bars[3].timestamp)
missing: float32 = CandleMarkerX(values, 3, bounds,
bars[0].timestamp)
if visible != 150.0 { return 9 }
if missing != -1.0 { return 10 }
intrabar: float32 = CandleMarkerX(values, 3, bounds,
bars[3].timestamp + 1234)
if intrabar != visible { return 11 }
micro: [2]PriceBar
micro[0] = .{.timestamp = 1, .low = 0.000010,
.high = 0.000011, .close = 0.0000105}
micro[1] = .{.timestamp = 2, .low = 0.0000102,
.high = 0.0000112, .close = 0.000011}
micro_range: CandleRange = CandleRangeFor(micro[:], 2)
if micro_range.max_value - micro_range.min_value >= 0.001 {
return 12
}
single: [1]PriceBar
single[0].timestamp = 1000
if CandleMarkerX(single[:], 1, bounds, 1000) != 150.0 { return 13 }
if CandleMarkerX(single[:], 1, bounds, 999) != -1.0 { return 14 }
if CandleMarkerX(single[:], 1, bounds, 1001) != -1.0 { return 15 }
after_last: s64 = bars[4].timestamp + 86400
if CandleMarkerX(values, 3, bounds, after_last) != -1.0 { return 16 }
return 0
}