Как сделать сглаживание цены
Формула:
Y = 0.75*sum((P(i) — P(i-1))+P(i), n)/n + 0.25*sum((P(i) — P(i-2))+P(i), n)/n
Тут фактор опережение балансирует с фактором запаздывания, в результате получаем приближенный близкий к реальной цене результат
Данная публикация является личным мнением автора. Мнение владельца сайта может не совпадать с мнением автора.
Сенкс, чел!![]()
Сделал новенький индикатор из твоей формулы
import backtrader as bt class WeightedPriceDelta(bt.Indicator): """ Weighted average of price plus one-bar and two-bar price changes. Formula: Y = 0.75 * Sum((P(i) - P(i-1)) + P(i), n) / n + 0.25 * Sum((P(i) - P(i-2)) + P(i), n) / n """ lines = ("y",) params = dict(period=14) plotinfo = dict(subplot=False) plotlines = dict(y=dict(color="tab:blue")) def __init__(self) -> None: period = int(self.p.period) if period <= 0: raise ValueError("period must be positive") one_bar_component = (self.data - self.data(-1)) + self.data two_bar_component = (self.data - self.data(-2)) + self.data one_bar_average = bt.ind.SumN(one_bar_component, period=period) / period two_bar_average = bt.ind.SumN(two_bar_component, period=period) / period self.lines.y = 0.75 * one_bar_average + 0.25 * two_bar_average self.addminperiod(period + 2)