Add create-ticker function
Implements the `create-ticker` function, which allows for the creation of a ticker stream based on a provided condition closure. This function is crucial for synchronizing pipeline execution based on specific events or conditions.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
;; Benchmark: 2.0us
|
||||
;; Benchmark-Repeat: 1015
|
||||
;; Output: PipelineNode[last: Some(110.45243843391206)]
|
||||
|
||||
(do
|
||||
;; Set the random seed to match the existing test output exactly
|
||||
(seed! 42)
|
||||
|
||||
;; Use our new generic create-ticker to pulse 3 times
|
||||
(def cnt 3)
|
||||
(def ticker (create-ticker (fn [] (> (assign cnt (- cnt 1)) -1))))
|
||||
|
||||
;; The candle generator reacting to the ticker
|
||||
(def last-close 100.0)
|
||||
|
||||
(def src1
|
||||
(pipe [ticker]
|
||||
(fn [_]
|
||||
(do
|
||||
(def change (* (- (random) 0.5) 2.0)) ; Matches Rust: (rng.f64() - 0.5) * 2.0
|
||||
(def open last-close)
|
||||
(def high (+ open (abs (* (random) 2.0))))
|
||||
(def low (- open (abs (* (random) 2.0))))
|
||||
(assign last-close (+ open change))
|
||||
{:open open :high high :low low :close last-close}
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(def combined
|
||||
(pipe [src1]
|
||||
(fn [t1]
|
||||
(.close t1)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(def my_indicator
|
||||
(pipe [combined]
|
||||
(fn [close_price]
|
||||
(+ close_price 10.0)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
my_indicator
|
||||
)
|
||||
Reference in New Issue
Block a user