Strategy vault / Machine learning
Signal to Noise Moving Average Trading Strategy Based on Quantitative Trading
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…

I. Strategy Name
Signal-to-Noise Moving Average Trading Strategy
II. Strategy Overview
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
III. Strategy Principle
- 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
IV. Advantage Analysis
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
V. Risk Analysis
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
VI. Optimization Direction
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
VII. Summary
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.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 21 | Days |
| v_input_2 | 7 | Smooth |
| v_input_3 | false | Trade reverse |
Source Pine Script
/*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)Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-02. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Signal-to-Noise-Moving-Average-Trading-Strategy-Based-on-Quantitative-Trading.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- AI Driven Dynamic Volatility Adaptive Trend Breakout Trading StrategyPine Script · Machine learning · 2d
- AI Powered Volatility Price System Divergence Trading StrategyPine Script · Machine learning · 1h
- Configurable BBRSIAroon Strategy BacktestPine Script · Machine learning · 5m
- Dual Moving Average Matching Strategy Based on Bollinger BandsPine Script · Machine learning · 1h
- Dynamic Weighted Moving Average Trading StrategyPine Script · Machine learning · 1d
- EMA and RSI Quantitative Trading StrategyPine Script · Machine learning · 1h