-
Notifications
You must be signed in to change notification settings - Fork 708
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
Feature: trade-dependent indicators #757
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reservation against this indicator type. Similar to #761 why should we mix up Trades
and indicators
? Wouldn't a Rule
be the place for such a decisions? In a Rule
you have access to the TradingRecord
of the current run. Having access to a TradingRecord
in an Indicator
means that you have to create another Strategy
with Rules
and Indicators
and so on just to apply this TradingRecord
to this indicator. There may be special cases for this, but I am not sure if ta4j should support this by default and within the current architecture of this framework
CHANGELOG.md
Outdated
@@ -17,6 +17,8 @@ Changelog for `ta4j`, roughly following [keepachangelog.com](http://keepachangel | |||
- :tada: **Enhancement** Added possibility to use CostModels when backtesting with the BacktestExecutor | |||
- :tada: **Enhancement** added Num#zero, Num#one, Num#hundred | |||
- **Example** added a json serialization and deserialization example of BarSeries using google-gson library | |||
- :tada: **Enhancement** Implemented an (abstract) TradeBasedIndicator, which can perform calculations based on the last trade | |||
- :tada: **Enhancement** Implemented a BreakEvenIndicator, which returns the needed break even regarding the last trade according to given transaction fees |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change Implemented ... to Added ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reservation against this indicator type. Similar to #761 why should we mix up
Trades
andindicators
? Wouldn't aRule
be the place for such a decisions? In aRule
you have access to theTradingRecord
of the current run. Having access to aTradingRecord
in anIndicator
means that you have to create anotherStrategy
withRules
andIndicators
and so on just to apply thisTradingRecord
to this indicator. There may be special cases for this, but I am not sure if ta4j should support this by default and within the current architecture of this framework
Mhm, not sure if that can be handled in Rules. If you have any ideas how to do it, I'm open to every suggestion.
I use the trade-based indicator quite much in my trading bot.
Examples:
- Break even indicator
- --> if break even is reached, the exit criterion of the strategy is changed (needs only true and false)
- --> place an order 2% above the break even (needs the concrete value/Num of the break even for every trade. Thats why it is an "calculator"(Indicator) and not a "condition"(Rule))
- Lowest/highest since last sell
- Restart of rules/conditions after a sell
- --> example: Buy if EMA(20)>EMA(200). Sell on 2% gain. Without a "reset", the bot would directly buy again if the EMA(20) is still over EMA(200).
- BuyPrice-Indicator --> Indicator which holds the buy price during the lifetime of a trade
- IsBuyPhase indicator ..> true if in BuyPhase and false if not
- ...
If it is an indicator, other indicators and rules can easily depend on it.
For example TransformIndicator.muplitply(breakEvenIndicator, 1.04) directly contains the value which is 4% above the break even in EVERY Buy-Phase. new OverIndicatorRule(closePrice, breakEven) is true if the break even is reached...No need to handle multiple indicators, swich rules, swich strategies, adapt indicators... The only thing that must be handled is storing TradingRecords in my bot on every real executed trade on the market while it is running.
And those indicators can easily be used also in backtesting. They are really powerful!
Yes, I also think you should create a new Rule instead of an Indicator. Because Indicator is linked with Bars and nothing else. I will look to create a new PR |
After rethinking, I guess, such trade based decisions would not be solely possible with a Rule because we need the already executed TradingRecord (till the observed index) to look for. We need to add Indicators within Rules to determine if the Rule is satisfied. That's why we could make use of the To demonstrate this, look at the following code which ought to replace the CriterionIndicator with a CriterionRule:
You see that the tradingRecord cannot be filled without another rule or indicator. That's also the case for this TradeBasedIndicator - you cannot replace it solely by a Rule. I think this |
I think we have to distinguish between different use cases: live trading (e.g. implementing a bot) and backtesting. So far the only use case for
We cannot add trade based indicators or criterion based indicators to this lib just because you are using it during live trading in a specific situation. It will get confusing for the user if we mix things up this way. |
For the moment, I dont need Crtierion. I personally need Indicators, which can calculate their current value according the the current trade state. For live-trading I could workaround that by replacing my complete strategy with new indicators and rules as soon as a position changed. But for Backtesting, I need calculators, which change if the last position is opened, closed or there is no last position. (And here I cannot change the complete Strategy and indicators, because Backtesting would not work). There are simple features like wait at least 200 ticks after an exit. Or get the current buy price in running open positions to calculate borders for gain and loss accordingly. Its no problem for me if you are not interested in this (in my opinion very useful) indicator and dont want to merge it into your project. --> PR closed |
Fixes #742.
Changes proposed in this pull request:
Allow trade based indicators, which can easily calculate their values by using the last executed trade
Added a break even indicator based on the last executed entry position
added an entry with related ticket number(s) to the unreleased section of
CHANGES.md