calendar wrapper with retry, histo bars with retry

This commit is contained in:
David Brazda
2024-02-06 11:14:38 +07:00
parent c1ad713a12
commit 1f8afef042
5 changed files with 162 additions and 33 deletions

View File

@ -0,0 +1,26 @@
from v2realbot.strategyblocks.indicators.custom.classes.indicatorbase import IndicatorBase
import pywt
import numpy as np
class DWT(IndicatorBase):
def __init__(self, state=None, wavelet='db1', levels=2):
super().__init__(state)
self.wavelet = wavelet
self.levels = levels
def next(self, close):
coeffs = pywt.wavedec(close, self.wavelet, level=self.levels)
# Zeroing out all detail coefficients
coeffs = [coeffs[0]] + [np.zeros_like(c) for c in coeffs[1:]]
# Reconstruct the signal using only the approximation coefficients
reconstructed_signal = pywt.waverec(coeffs, self.wavelet)
# Handle length difference
length_difference = len(close) - len(reconstructed_signal)
if length_difference > 0:
reconstructed_signal = np.pad(reconstructed_signal, (0, length_difference), 'constant', constant_values=(0, 0))
self.state.indicators["MultiLevelDWT"] = reconstructed_signal.tolist()
return float(reconstructed_signal[-1])