71 lines
2.9 KiB
Ziran
71 lines
2.9 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 }
|
|
log_range: CandleRange
|
|
log_range.min_value = 10.0; log_range.max_value = 1000.0
|
|
log_range.logarithmic = true
|
|
middle := CandleY(100.0, bounds, log_range)
|
|
if middle < 49.99 || middle > 50.01 { return 17 }
|
|
inverse := CandlePriceAtY(middle, bounds, log_range)
|
|
if inverse < 99.99 || inverse > 100.01 { return 18 }
|
|
if CandleY(0.0, bounds, log_range) != -1.0 { return 19 }
|
|
padded := CandleRangeFor(micro[:], 2, true)
|
|
if padded.min_value <= 0.0 || padded.min_value >= padded.low ||
|
|
padded.max_value <= padded.high { return 20 }
|
|
if CandleWindowEnd(values, bars[2].timestamp) != 3 { return 21 }
|
|
if CandlePanEnd(5, -20, 5, 3) != 3 { return 22 }
|
|
if CandlePanEnd(3, 20, 5, 3) != 5 { return 23 }
|
|
if CandlePanStepsFor(100.0, 200.0, bounds, 3) != -1 { return 24 }
|
|
return 0
|
|
}
|