Modulo Logic With EMA Filter Strategy
Overview
This strategy combines modulo arithmetic operations and exponential moving averages to create a strong randomness filter for determining position direction. It first calculates the remainder of the price divided by a set number, and a trading signal is generated if the remainder is 0. If this signal is below the EMA line, go short; if above, go long. This strategy integrates the randomness of mathematical operations and the trend judgment of technical indicators, making use of cross validation between indicators of different cycles to effectively filter out some of the market noise.
Strategy Logic
- Set the price input value a to close, modifiable; set the divisor b to 4, modifiable.
- Calculate the remainder modulo of a divided by b, determine if modulo equals 0.
- Set length of the EMA (MALen) to 70 periods by default as a metric for medium-to-long term trend.
- When modulo equals 0, a trading signal evennumber is generated. Combined with EMA relationship it determines direction. When price crosses above EMA, a BUY signal is generated; when price crosses below EMA, a SELL signal is generated.
- Trading entries are opened long or short based on signal direction. Strategy can restrict reverse opening position to control number of trades.
- Stop loss conditions are set based on 3 options: fixed stop loss, ATR stop loss, price swing stop loss. Take profit condition is the reverse of stop loss.
- Trailing stop can be enabled to lock in more profits, disabled by default.
Advantage Analysis
- The randomness of modulo arithmetic avoids effects of price fluctuations, combined with trend judgment of moving averages, it can effectively filter out invalid signals.
- EMA as metric for medium-to-long term trend combined with short-term modulo signals realizes multi-layer verification and avoids false signals.
- Highly flexible customizable parameters, can be adjusted for different markets to find optimal parameter combinations.
- Integrates multiple stop loss methods to control risks. Take profit conditions also set to lock in profits.
- Supports direct reverse opening of positions for seamless switching of direction. Can also disable to reduce number of trades.
Risk Analysis
- Improper parameter settings may generate too many trading signals, increasing trading frequency and slippage costs.
- EMA as sole trend judgment metric may lag, missing price reversal moments.
- Fixed stop loss method can be too mechanical, unable to adjust for market fluctuations.
- Direct reverse opening increases frequency of position adjustments, adding to costs and risks.
Optimization Directions
- Test different moving averages instead of EMA, or combine EMA with other MAs, to see if profitability rate can be improved.
- Try combining modulo filter with other strategies like Bollinger Bands, candlestick patterns etc to create more stable filters.
- Research adaptive stop loss methods based on market volatility levels to adjust stop distance.
- Set limits on number of trades or profit/loss thresholds to restrict frequency of direct reverse opening.
Conclusion
This strategy effectively combines the randomness of modulo operations and trend judgment of moving averages through flexible parameter adjustments catered for different market environments, resulting in reliable trading signals. It also integrates various stop mechanisms to control risks as well as take profit and trailing stops to lock in profits. The overall logic is clear and easy to understand and modify. It has immense practical potential worth further testing and optimization.
/*backtest
start: 2023-11-12 00:00:00
end: 2023-12-12 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tweakerID
// To understand this strategy first we need to look into the Modulo (%) operator. The modulo returns the remainder numerator - 1

