Explore Operators on Python Indicators
Expected Behavior
All operators work in comparing indicators. +, -, *, /.
Actual Behavior
Only < and > work. The other operators require referencing Current.Value
Potential Solution
Explore and understand why < > work and apply lessons to other operators.
Reproducing the Problem
This shouldn't work but it does.
Checklist
- [x] I have completely filled out this template
- [x] I have confirmed that this issue exists on the current
masterbranch - [x] I have confirmed that this is not a duplicate issue by searching issues
These two issues might be related:
- https://github.com/pythonnet/pythonnet/issues/253
- https://github.com/pythonnet/pythonnet/issues/906
Has this issue been addressed? At least from the first Python tutorial https://www.quantconnect.com/tutorials/api-tutorials/consolidating-data-to-build-bars there is a line thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteBarHandler that indicates support for addition operator on events/handlers?
But I guess events are different from indicators, and only inequality operators are implemented e.g. GreaterThan https://github.com/QuantConnect/Lean/blob/03efc1b735bb8b841eb04434f537ac3d798f5877/Tests/Indicators/IndicatorTests.cs#L227
Not sure if this is related as well https://github.com/QuantConnect/Lean/blob/d1624ab8998deea2afd54a7db6b3694886665f14/Common/Python/PandasData.cs#L265
Sorry I just realized that the event += handler pattern is not exactly an operator, I'm not familiar with C#. It's surprising that the same syntax works in Python, seems like it's out of the box since it's used in the pythonnet demo for windows forms applications too
Edit: I see now that this is done by overloading nb_inplace_add etc. in eventbinding.cs via eventobject.cs
- Something with https://stackoverflow.com/questions/11544056/how-to-cast-implicitly-on-a-reflected-method-call/11563904#11563904 on the indicator object then converting indicator result to a decimal.
- No need for an elegant universal solution should aim at getting indicators to work.