Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't use DEFAULT_CANDLES if Hexital.timeframe is given #49

Closed
wants to merge 1 commit into from

Conversation

powellnorma
Copy link
Contributor

No description provided.

@@ -32,6 +32,8 @@ class Hexital:
candle_life: Optional[timedelta] = None
candlestick: Optional[CandlestickType] = None

default_tf: str = DEFAULT_CANDLES
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this a private attribute and rename it -> _timeframe_name

This is because it's just _timeframe but the str version. Having it duplicated just means we dont need to call timedelta_to_str or convert_timeframe_to_timedelta regularly.
We make it private because there is a timeframe property to get this information out, we should update this too.

@@ -53,16 +55,19 @@ def __init__(
if candlestick:
self.candlestick = validate_candlesticktype(candlestick)

if self._timeframe is not None:
self.default_tf = self.timeframe
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this is correct, self.timeframe does not exist. We parse timeframe into self._timeframe. As this is just the name version of timeframe we should have:

self._timeframe_name = timedelta_to_str(self._timeframe)

candles if isinstance(candles, list) else [],
candle_life=self.candle_life,
timeframe=self._timeframe,
timeframe_fill=self.timeframe_fill,
candlestick=self.candlestick,
)
}
self._candles[DEFAULT_CANDLES].name = DEFAULT_CANDLES
self._candles[self.default_tf].name = self.default_tf
Copy link
Owner

@MerlinR MerlinR Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we need this line at all, not your fault of course.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property

def timeframe(self) -> str | None:
    return timedelta_to_str(self._timeframe) if self._timeframe else None

Can just be updated now:

def timeframe(self) -> str | None:
    return self._timeframe_name if self._timeframe else None

@MerlinR
Copy link
Owner

MerlinR commented Feb 1, 2025

I like this fix, simple and affective, we are effectivly saving the _timeframe as str as well, which is not a bad thing as means we can remove extra calls to timedelta_to_str and convert_timeframe_to_timedelta for a tiny memory usage. made a few comments are extra notes:

  • Might as well add the Fix to Changelog 👍
  • Let's add some unit tests under test_hexital.py, something like
class TestMultiTimeframes:
    def test_timeframe_default(self, candles):
        strat = Hexital("Test Strategy", candles)
        assert list(strat._candles.keys()) == ["default"]

    def test_timeframe_multi(self, candles):
        strat = Hexital("Test Strategy", candles, [EMA(timeframe="T1")])
        assert list(strat._candles.keys()) == ["default", "T1"]

    def test_duplicate_indicators(self, candles):
        strat = Hexital("Test Strategy", candles, [EMA(timeframe="T1"), SMA(timeframe="T1")])
        assert list(strat._candles.keys()) == ["default", "T1"]

    def test_clash_hexital(self, candles):
        strat = Hexital("Test Strategy", candles, [EMA(timeframe="T1")], timeframe="T1")
        assert list(strat._candles.keys()) == ["T1"]

    def test_multi_hexital(self, candles):
        strat = Hexital("Test Strategy", candles, [EMA(timeframe="T5")], timeframe="T1")
        assert list(strat._candles.keys()) == ["T1", "T5"]

@powellnorma
Copy link
Contributor Author

powellnorma commented Feb 1, 2025

Thanks for the review! I’ve enabled 'Allow edits by maintainers,' so feel free to commit the changes directly to the branch. Let me know if you need anything else.

@MerlinR
Copy link
Owner

MerlinR commented Feb 4, 2025

Pr been abandoned

@MerlinR MerlinR closed this Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Hexital] Bug when setting same TImeframe in Hexital and Indicator
2 participants