From 576b2445f8919c34bb7a51c3bbb72d207f41dbb7 Mon Sep 17 00:00:00 2001 From: David Brazda Date: Tue, 6 Feb 2024 11:16:09 +0700 Subject: [PATCH] ok --- .../indicators/custom/classes/SuperTrendTV.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/v2realbot/strategyblocks/indicators/custom/classes/SuperTrendTV.py b/v2realbot/strategyblocks/indicators/custom/classes/SuperTrendTV.py index bd4171a..945437f 100644 --- a/v2realbot/strategyblocks/indicators/custom/classes/SuperTrendTV.py +++ b/v2realbot/strategyblocks/indicators/custom/classes/SuperTrendTV.py @@ -10,6 +10,7 @@ class SuperTrendTV(IndicatorBase): See conversation: [Indicator Plugin Builder](https://chat.openai.com/g/g-aCKuSmbIe-indicator-plugin-builder/c/1ad650dc-05f1-4cf6-b936-772c0ea86ffa) inspirace https://www.tradingview.com/script/r6dAP7yi/ """ + def __init__(self, atr_period=10, atr_multiplier=3.0, state=None): super().__init__(state) self.atr_period = atr_period @@ -19,7 +20,7 @@ class SuperTrendTV(IndicatorBase): self.closes = deque(maxlen=atr_period) self.up = None self.down = None - self.trend = 1 + self.trend = 0 def next(self, high, low, close): self.highs.append(high[-1]) @@ -44,7 +45,14 @@ class SuperTrendTV(IndicatorBase): self.up = max(up, self.up) if close[-2] > self.up else up self.down = min(dn, self.down) if close[-2] < self.down else dn - previous_trend = self.trend - self.trend = 1 if (self.trend == -1 and close[-1] > self.down) else -1 if (self.trend == 1 and close[-1] < self.up) else self.trend + # Update trend for the first time if it's still at initial state + if self.trend == 0: + self.trend = 1 if close[-1] > self.down else -1 if close[-1] < self.up else 0 + else: + # Update trend based on previous values if it's not at initial state + self.trend = 1 if (self.trend == -1 and close[-1] > self.down) else -1 if (self.trend == 1 and close[-1] < self.up) else self.trend + + #previous_trend = self.trend + #self.trend = 1 if (self.trend == -1 and close[-1] > self.down) else -1 if (self.trend == 1 and close[-1] < self.up) else self.trend return [self.up, self.down, self.trend]