The VolatilitySystem strategy is designed to backtest trading signals based on market volatility. Here's a brief overview of how the strategy works:
Indicators Calculation:
The strategy first calculates several technical indicators on the provided market data. These indicators include the Average True Range (ATR) with a time period of 14, multiplied by a factor of 2.0.
It also calculates the changes in the closing price and the absolute value of these changes.
The data is resampled to a 3-hour interval.
Entry Signals:
The strategy then populates buy and sell signals based on the calculated indicators. If the recent change in the closing price (close_change) is greater than the previous ATR value, a "long" entry signal (enter_long) is generated. Similarly, if the negative change in closing price is greater than the previous ATR value, a "short" entry signal (enter_short) is generated. Exit Signals:
The strategy uses the entry signals to determine exit points. If a "long" entry signal was generated, an "exit_short" signal is produced, and if a "short" entry signal was generated, an "exit_long" signal is produced. Position Sizing:
The proposed stake for each trade is calculated by dividing the proposed stake by 2. Position Adjustment:
Position adjustment is enabled, meaning that position-related parameters can be adjusted during trading. Trade Management:
The strategy also includes a method for managing trades. It checks the current and previous candle data to identify entry signals. If the current candle's entry signal is 1 and the previous candle's entry signal was not 1, and if the number of successful entries for the trade is less than 2, and if the last order's date is before the prior date, then the strategy returns the stake amount for the trade. This helps manage the position size for each trade. Leverage Customization:
The strategy offers a method to customize leverage for each new trade, but it's designed for futures trading. It takes into account the proposed leverage, maximum leverage, trade direction (long or short), and provides a leverage amount between 1.0 and max_leverage (2.0 in this case). In summary, the VolatilitySystem strategy uses calculated indicators to generate buy and sell signals based on market volatility. It adjusts position sizing, manages trades, and offers leverage customization for each new trade in futures mode.