Type/to search

Modulo Logic With EMA Filter Strategy

Cryptocurrency
Created: 2023-12-13 15:55:07
Last modified: 2 years ago
1
Follow
1779
Followers

img

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

  1. Set the price input value a to close, modifiable; set the divisor b to 4, modifiable.
  2. Calculate the remainder modulo of a divided by b, determine if modulo equals 0.
  3. Set length of the EMA (MALen) to 70 periods by default as a metric for medium-to-long term trend.
  4. 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.
  5. Trading entries are opened long or short based on signal direction. Strategy can restrict reverse opening position to control number of trades.
  6. 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.
  7. Trailing stop can be enabled to lock in more profits, disabled by default.

Advantage Analysis

  1. The randomness of modulo arithmetic avoids effects of price fluctuations, combined with trend judgment of moving averages, it can effectively filter out invalid signals.
  2. EMA as metric for medium-to-long term trend combined with short-term modulo signals realizes multi-layer verification and avoids false signals.
  3. Highly flexible customizable parameters, can be adjusted for different markets to find optimal parameter combinations.
  4. Integrates multiple stop loss methods to control risks. Take profit conditions also set to lock in profits.
  5. Supports direct reverse opening of positions for seamless switching of direction. Can also disable to reduce number of trades.

Risk Analysis

  1. Improper parameter settings may generate too many trading signals, increasing trading frequency and slippage costs.
  2. EMA as sole trend judgment metric may lag, missing price reversal moments.
  3. Fixed stop loss method can be too mechanical, unable to adjust for market fluctuations.
  4. Direct reverse opening increases frequency of position adjustments, adding to costs and risks.

Optimization Directions

  1. Test different moving averages instead of EMA, or combine EMA with other MAs, to see if profitability rate can be improved.
  2. Try combining modulo filter with other strategies like Bollinger Bands, candlestick patterns etc to create more stable filters.
  3. Research adaptive stop loss methods based on market volatility levels to adjust stop distance.
  4. 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.

Source
Pine
/*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 
Strategy parameters
Strategy parameters
Strategy Direction
-----------------Strategy Inputs-------------------
Dividend
Divisor
Use Modulo Logic
EMA Length
-----------------General Inputs-------------------
Use Stop Loss and Take Profit
Type Of Stop
Swing Point Lookback
Swing Point SL Perc Increment
ATR Length
ATR Multiple
Take Profit Risk Reward Ratio
Trailing Stop
Allow Direct Position Reverse
Reverse Trades
Comment
All comments (0)
No data
No data
  • 1
iPhone Download
Forums
PINE Language
© 2015 - ∞ INVENTOR PTE LTD (SG)