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

A strategy using an indicator and profit-loss ratio as stop-loss and take-profit #317

Open
DayJun opened this issue Jan 25, 2025 · 3 comments
Labels
Strategy Request Requests asking for an implementation of a specific strategy

Comments

@DayJun
Copy link

DayJun commented Jan 25, 2025

I want to use ATR as a stop-loss indicator and set the take-profit at a position where the profit-loss ratio is 2.0. After reading the documentation, I still don’t understand how to write the strategy and am seeking help for this.

Step 1: What indicators are required?

ATR(Average True Range)

Step 2: Explain the Buy Strategy

pass

Step 1: Explain the Sell Strategy

When executing a buy order, use the lower line of the ATR of the current K-line as the stop-loss position, and then set the take-profit position at a profit-loss ratio of 2.0. There are two methods, and I’m not sure if both can be implemented:

Place a stop-loss and take-profit order directly at the time of purchase.
Wait for the price to reach the target and then sell at market price or limit price.

Source

Sorry but there are no sources

@DayJun DayJun added the Strategy Request Requests asking for an implementation of a specific strategy label Jan 25, 2025
@xmatthias
Copy link
Member

well it might be beneficial if you're sharing what you got so far - so we can help you where you encounter problems.

@DayJun
Copy link
Author

DayJun commented Jan 25, 2025

A simple entry:

def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (
                (dataframe['close'] > dataframe['open']) &
                (dataframe['low'] < dataframe['nwe_lower']) & 
                (dataframe['high'] > dataframe['nwe_lower']) &
                (dataframe['rsi'] <= 30) &
                (dataframe["volume"] > 0)  # Make sure Volume is not 0
            ),
            "enter_long"] = 1

The problem is how to write exit, stop loss, and take profit.

I found populate_exit_trend is where populates the exit signal immediatly, so can not use this function to set the stop-loss and the take-profit.

Then I found custom_stoploss.

def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,
                        current_rate: float, current_profit: float, after_fill: bool, 
                        **kwargs) -> float | None:
        dataframe, last_updated = self.dp.get_analyzed_dataframe(pair, self.timeframe)
        # dataframe['atr_lower'].iat[-1]
        '''
        How can I obtain my actual purchase price and the percentage difference between the purchase price and the ATR lower band?
        '''

And I can't find afunction to set take-profit like custom_stoploss.

@xmatthias

@froggleston
Copy link
Contributor

froggleston commented Jan 25, 2025

There's an example of setting trailing stop in the examples here: https://github.com/freqtrade/freqtrade-strategies/blob/main/user_data/strategies/CustomStoplossWithPSAR.py

There's another example with immediate take-profit in the examples here: https://github.com/freqtrade/freqtrade-strategies/blob/main/user_data/strategies/Strategy001_custom_exit.py

(custom_exit is always immediate, custom_stoploss is always trailing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Strategy Request Requests asking for an implementation of a specific strategy
Projects
None yet
Development

No branches or pull requests

3 participants