The "BuyNStoploss" strategy is designed to backtest a trading strategy that involves buying a cryptocurrency pair within a specific price range and setting a stop loss to limit potential losses. Here's a breakdown of how the strategy works:
The strategy uses a 1-hour timeframe for analyzing price data. It has a predefined "minimal_roi" (minimal return on investment) parameter that specifies a fixed profit target of 10%.
The stop loss is set to -0.99, indicating a 99% loss threshold.
The strategy keeps track of certain flags, such as "bought_once," "stop_loss_once," "notify_buy," and "notify_stop_loss," to manage the execution of the strategy.
The "populate_indicators" function is responsible for populating indicators based on the price data. It also checks if the current price is within the specified buy zone range and triggers a buy signal if it meets the criteria. Similarly, if the price falls below the buy zone range, it triggers a sell signal as a stop loss measure. The "populate_buy_trend" function sets the "buy" column to 1 for the rows that meet the buy criteria. The "populate_sell_trend" function sets the "sell" column to 1 for the rows that meet the sell criteria. Overall, the strategy aims to buy a cryptocurrency pair when its price is within a specific range and sell it if the price falls below a certain threshold, acting as a stop loss. The strategy has a predefined profit target and uses flags to manage the execution and send notifications for buy and stop loss events.