tested and updated supertrand indicators to give us the same result as in original strategy

This commit is contained in:
Vasily.onl
2025-05-26 14:45:44 +08:00
parent 9376e13888
commit 3e94387dcb
2 changed files with 806 additions and 9 deletions

View File

@@ -65,12 +65,12 @@ class SupertrendState(OHLCIndicatorState):
# State variables
self.previous_close = None
self.previous_trend = 1 # Start with uptrend assumption
self.previous_trend = None # Don't assume initial trend, let first calculation determine it
self.final_upper_band = None
self.final_lower_band = None
# Current values
self.current_trend = 1
self.current_trend = None
self.current_supertrend = None
self.is_initialized = True
@@ -123,10 +123,11 @@ class SupertrendState(OHLCIndicatorState):
# Determine trend
if self.previous_close is None:
# First calculation
trend = 1 if close > final_lower_band else -1
# First calculation - match original logic
# If close <= upper_band, trend is -1 (downtrend), else trend is 1 (uptrend)
trend = -1 if close <= basic_upper_band else 1
else:
# Trend logic
# Trend logic for subsequent calculations
if self.previous_trend == 1 and close <= final_lower_band:
trend = -1
elif self.previous_trend == -1 and close >= final_upper_band:
@@ -174,10 +175,10 @@ class SupertrendState(OHLCIndicatorState):
"""Reset Supertrend state to initial conditions."""
self.atr_state.reset()
self.previous_close = None
self.previous_trend = 1
self.previous_trend = None
self.final_upper_band = None
self.final_lower_band = None
self.current_trend = 1
self.current_trend = None
self.current_supertrend = None
self.values_received = 0
self._current_values = {}
@@ -198,9 +199,9 @@ class SupertrendState(OHLCIndicatorState):
Get current trend direction.
Returns:
Current trend: +1 for uptrend, -1 for downtrend
Current trend: +1 for uptrend, -1 for downtrend, 0 if not initialized
"""
return self.current_trend
return self.current_trend if self.current_trend is not None else 0
def get_current_supertrend_value(self) -> Optional[float]:
"""