Tags:

Signal-to-Noise Moving Average Trading Strategy

This strategy realizes quantitative trading by calculating the signal-to-noise ratio over a certain period and combining it with moving average trading signals. The basic idea is:

- Calculate the signal-to-noise ratio over a certain period (adjustable)
- Apply moving average to smooth the signal-to-noise ratio
- Compare current signal-to-noise ratio with moving average value to generate trading signals
- Long or short based on trading signals

- The formula for calculating signal-to-noise ratio (StN) is: StN = -10*log(Σ(1/close)/n), where n is the length of the period
- Apply Simple Moving Average (SMA) to the signal-to-noise ratio to obtain smoothed StN
- Compare current StN with smoothed SMAStN: (1) If SMAStN > StN, go short (2) If SMAStN < StN, go long (3) Otherwise, close position

The main advantages of this strategy are:

- StN can judge market fluctuation and risk, SMA has noise reduction capability
- Combining StN to judge market risk and SMA to generate trading signals makes use of the advantages of different indicators
- Adjustable parameters to adapt to different market conditions
- Stdout signals directly indicate long or short, intuitive judgment of market characteristics

There are also some risks with this strategy:

- Crossing judgment between StN and MA exists deviation risk
- Improper period settings may cause false signals
- Relative fewer short opportunities, optimizable via parameter adjustment
- Extreme fluctuations caused by black swan events may trigger stop loss

Solutions:

- Adjust MA parameters to avoid over-smoothing
- Optimize period parameters and test adaptability in different markets
- Adjust short conditions to provide more short opportunities
- Set stop loss to control maximum losses

The strategy can be optimized in the following ways:

- Test combination of more types of moving averages
- Add stop loss mechanism to control risks
- Add position management, adjust positions based on fluctuations
- Incorporate more factors to improve stability
- Use machine learning methods to automatically optimize parameters

This strategy realizes quantitative trading by judging market risk via signal-to-noise ratio and generating trading signals from moving average. Compared to single technical indicators, this strategy integrates the advantages of both StN and SMA to improve stability while controlling risks. With parameter optimization and machine learning, this strategy has great potential for improvement and is a reliable and effective quantitative trading strategy.

/*backtest start: 2023-12-25 00:00:00 end: 2023-12-29 10:00:00 period: 30m basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 //////////////////////////////////////////////////////////// // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © HPotter 05/01/2021 // The signal-to-noise (S/N) ratio. // And Simple Moving Average. // Thank you for idea BlockchainYahoo // // WARNING: // - For purpose educate only // - This script to change bars colors. //////////////////////////////////////////////////////////// SignalToNoise(length) => StN = 0.0 for i = 1 to length-1 StN := StN + (1/close[i])/length StN := -10*log(StN) strategy(title="Backtest Signal To Noise ", shorttitle="StoN", overlay=false) length = input(title="Days", type=input.integer, defval=21, minval=2) Smooth = input(title="Smooth", type=input.integer, defval=7, minval=2) reverse = input(false, title="Trade reverse") StN = SignalToNoise(length) SMAStN = sma(StN, Smooth) pos = iff(SMAStN[1] > StN[1] , -1, iff(SMAStN[1] < StN[1], 1, 0)) possig = iff(reverse and pos == 1, -1, iff(reverse and pos == -1 , 1, pos)) if (possig == 1) strategy.entry("Long", strategy.long) if (possig == -1) strategy.entry("Short", strategy.short) if (possig == 0) strategy.close_all() barcolor(possig == -1 ? #b50404: possig == 1 ? #079605 : #0536b3 ) plot(StN, title='StN' ) plot(SMAStN, title='Smooth', color=#00ff00)template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6