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

Introduce easier way to use movement methods. #17

Open
MerlinR opened this issue Apr 26, 2024 · 1 comment
Open

Introduce easier way to use movement methods. #17

MerlinR opened this issue Apr 26, 2024 · 1 comment

Comments

@MerlinR
Copy link
Owner

MerlinR commented Apr 26, 2024

Prior to 1.1.0 the Movement patterns where partially implemented within the Hexital/Indicator class's, the purpose was to make it very easy to call/use them, E.G:
we could easily call the "above" movement method for two indicators as follows.

strategy = Hexital("Test strategy", candles, [EMA(), SMA()])
strategy.calculate()
strategy.above("EMA_10", "SMA_10") 

However this was removed in 1.1.0 due to the fact everytime a new movement/pattern was added the Hexital and Indicator class would need to implement the method as well, this would quickly become a hassle and extremely messy. However now to do the same movement call is as follows:

from hexital.analysis import movement
strategy = Hexital("Test strategy", candles, [EMA(), SMA()])
strategy.calculate()
movement.above(strategy.candles(), "EMA_10", "SMA_10") 

or worse with timeframes:

from hexital.analysis import movement
strategy = Hexital("Test strategy", candles, [EMA(timeframe="T5"), SMA(timeframe="T5")])
strategy.calculate()
movement.above(strategy.candles("T5"), "EMA_10_T5", "SMA_10_T5") 

A new approach is needed to find some middle ground between the two. The user simplicity of it existing within Hexital/Indicator and the maintainability of it being external.

@MerlinR
Copy link
Owner Author

MerlinR commented Apr 26, 2024

Possible options:

1: Using Python's getattr to hack Movements/patterns into Hexital/Indicator. Essentially Having them check if a pattern or movement named the given indicator exist and then calling them. This is fairly hacky and wont support typing or IDE type hinting, could also be a pain to debug.

strategy = Hexital("Test strategy", candles, [EMA(), SMA()])
strategy.calculate()
strategy.above("EMA_10", "SMA_10") 

2: Update Movement/Patterns argument to accept List[Candles] | Indicator | Hexital. Where it can call the previous method _verify_indicators to find and verify the List[Candles] for the given indicators.

from hexital.analysis import movement
strategy = Hexital("Test strategy", candles, [EMA(timeframe="T5"), SMA(timeframe="T5")])
strategy.calculate()
movement.above(strategy, "EMA_10_T5", "SMA_10_T5") 

3:?

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

No branches or pull requests

1 participant