Skip to content

Commit 90e2935

Browse files
committed
Add trade_duration parameter to custom_roi
1 parent 12cd654 commit 90e2935

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

docs/strategy-callbacks.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ class AwesomeStrategy(IStrategy):
527527

528528
# ... populate_* methods
529529

530-
def custom_roi(self, pair: str, trade: Trade, current_time: datetime,
530+
def custom_roi(self, pair: str, trade: Trade, current_time: datetime, trade_duration: int,
531531
entry_tag: str | None, side: str, **kwargs) -> float | None:
532532
"""
533533
Custom ROI logic, returns a new minimum ROI threshold (as a ratio, e.g., 0.05 for +5%).
@@ -540,6 +540,7 @@ class AwesomeStrategy(IStrategy):
540540
:param pair: Pair that's currently analyzed.
541541
:param trade: trade object.
542542
:param current_time: datetime object, containing the current datetime.
543+
:param trade_duration: Current trade duration in minutes.
543544
:param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.
544545
:param side: 'long' or 'short' - indicating the direction of the current trade.
545546
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
@@ -561,7 +562,7 @@ class AwesomeStrategy(IStrategy):
561562

562563
# ... populate_* methods
563564

564-
def custom_roi(self, pair: str, trade: Trade, current_time: datetime,
565+
def custom_roi(self, pair: str, trade: Trade, current_time: datetime, trade_duration: int,
565566
entry_tag: str | None, side: str, **kwargs) -> float | None:
566567

567568
stake = trade.stake_currency
@@ -587,7 +588,7 @@ class AwesomeStrategy(IStrategy):
587588

588589
# ... populate_* methods
589590

590-
def custom_roi(self, pair: str, trade: Trade, current_time: datetime,
591+
def custom_roi(self, pair: str, trade: Trade, current_time: datetime, trade_duration: int,
591592
entry_tag: str | None, side: str, **kwargs) -> float | None:
592593

593594
roi_by_tag = {
@@ -616,7 +617,7 @@ class AwesomeStrategy(IStrategy):
616617
# <...>
617618
dataframe["atr"] = ta.ATR(dataframe, timeperiod=10)
618619

619-
def custom_roi(self, pair: str, trade: Trade, current_time: datetime,
620+
def custom_roi(self, pair: str, trade: Trade, current_time: datetime, trade_duration: int,
620621
entry_tag: str | None, side: str, **kwargs) -> float | None:
621622

622623
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)

freqtrade/strategy/interface.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ def custom_roi(
472472
pair: str,
473473
trade: Trade,
474474
current_time: datetime,
475+
trade_duration: int,
475476
entry_tag: str | None,
476477
side: str,
477478
**kwargs,
@@ -487,6 +488,7 @@ def custom_roi(
487488
:param pair: Pair that's currently analyzed.
488489
:param trade: trade object.
489490
:param current_time: datetime object, containing the current datetime.
491+
:param trade_duration: Current trade duration in minutes.
490492
:param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.
491493
:param side: 'long' or 'short' - indicating the direction of the current trade.
492494
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
@@ -1686,6 +1688,7 @@ def min_roi_reached_entry(
16861688
pair=trade.pair,
16871689
trade=trade,
16881690
current_time=current_time,
1691+
trade_duration=trade_dur,
16891692
entry_tag=trade.enter_tag,
16901693
side=trade.trade_direction,
16911694
)

0 commit comments

Comments
 (0)