This strategy implements arbitrage trading between different markets by calculating an adaptive regularized moving average line. The strategy features cross-market arbitrage, dynamic parameter adjustment, risk control, etc.
The strategy first defines a scaleMinimax function to standardize the time series to a specified range. Then it defines an adaptive regularized moving average function rema to calculate the smoothed signal line sig. The calculation of the signal line is:
Define a sliding window, default length 5 days.
The sig value for each day is the weighted average of the previous sig value and the current closing price. The weighting uses an adaptive weighting mechanism, where values closer to the current price are weighted higher.
Add a λ parameter as a regularizer to make the sig transition smoother.
After obtaining the signal line, the strategy determines long/short based on the golden/dead cross of the signal line and price. Specifically:
When sig crosses above price, go long.
When sig crosses below price, go short.
In addition, the strategy adds the smooth factor and show_line as adjustable parameters to increase flexibility.
Compared with traditional moving average strategies, this strategy has the following advantages:
The adaptive weighting mechanism can respond faster to price changes.
The added regularizer makes the signal line smoother, avoiding wrong signals from drastic price fluctuations.
Cross-market arbitrage can profit from price differences between markets.
Flexible adjustable parameters can be optimized according to market conditions.
The strategy also has some risks:
The probability of wrong signals from double crossovers is higher. The solution is to properly adjust the smooth parameter to avoid oscillation of the signal line.
Cross-market arbitrage requires that the two markets have price correlation and consistent trends. The solution is to select highly correlated markets for arbitrage.
Parameter optimization requires sufficient historical data for backtesting. The solution is to cautiously adjust parameters in live trading.
The strategy can also be optimized in the following aspects:
In parameter selection, machine learning algorithms can be introduced to automatically optimize parameter combinations.
In signal generation, more indicators can be introduced to construct more stable trading signals.
In risk control, stop loss can be set to limit the loss per trade.
In cross-market arbitrage, it can be extended to more highly correlated trading assets.
This strategy implements arbitrage trading between markets by adaptively calculating moving averages. Compared with traditional moving average strategies, it has the advantages of adaptive parameters, smoothed processing, cross-market arbitrage, etc. Next steps are to further optimize the strategy through machine learning, combined signals, risk management, etc.
/*backtest start: 2023-10-01 00:00:00 end: 2023-10-31 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=3 strategy("Crossover82%", overlay=true) // // Functions // scaleMinimax(X, p, min, max) => hi = highest(X, p), lo = lowest(X, p) (max - min) * (X - lo)/(hi - lo) + min rema(ts, p) => // regularized ma rm = 0.0, lambda = .5, a = 2 / (p + 1) rm := (nz(rm[1]) + a * (ts - nz(rm[1])) + lambda * (2 * nz(rm[1]) - nz(rm[2]))) / (lambda + 1) rm // // Inputs // X = input(close, title="Data source") smooth = input(2, title="REMA smooth factor") show_line = input(true, title="Show signal line") // // Main // p = 5 sig = rema(scaleMinimax(pow(X*p,-X) - 0.1, 100, lowest(X, 100), highest(X, 100)), smooth) plot(show_line ? sig : na, linewidth=1) plot(cross(sig, X) ? ohlc4 : na, style=circles, linewidth=8, color=blue, transp=50) longCondition = crossover(sig, X) if (longCondition) strategy.entry("LE", strategy.long) shortCondition = crossunder(sig, X) if (shortCondition) strategy.entry("SE", strategy.short)template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6