Strategy · Pine Script v4 · Own pane

Backtest Signal To Noise

by hasnocool· code credited to HPotter 05/01/2021

This strategy calculates a custom Signal-to-Noise ratio derived from logarithmic aggregation of inverse close prices and compares it against a Simple Moving Average.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code37
Settings3inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

37 lines of Pine Script v4 from Backtest Signal To Noise.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Backtest Signal To Noise.pine
//@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)
Expand (37 lines)

Overview

Backtest Signal To Noise plots both lines in a separate pane and alters price bar colors based on signal direction. The strategy enters long positions when the Signal-to-Noise value rises above its smoothed moving average and short positions when it falls below, with an option to reverse signals. Settings allow adjustments to calculation length and smoothing parameters. It operates without stop loss or profit target rules.

Details

Published by

hasnocool on GitHub

Code credit

HPotter 05/01/2021, as written in the script's header

Type

Strategy, Pine Script v4

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Daysint21length
Smoothint7Smooth
Trade reverseboolfalsereverse
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

330 stars

MACD + Divergences [Alorse] is a momentum strategy that calculates the MACD oscillator and identifies regular and hidden divergences using pivot high and low points. It filters trade signals with dual Exponential Moving Averages (EMA 150 and 600) to ensure tra

Strategy v4 Oscillators & momentumDivergence Repaints
Updated 2 months ago · None stated GitHub repository of MACD + Divergences [Alorse]

MACD Crossover (tutorial)

by pineforge-4pass
193 stars

This strategy calculates the Moving Average Convergence Divergence indicator and plots the MACD line, signal line, and histogram in a separate pane. It enters long positions when the MACD line crosses above the signal line and enters short positions when it cr

Strategy v6 Oscillators & momentumMoving averages
Updated today · Apache-2.0 GitHub repository of MACD Crossover (tutorial)

BTC Futures MACD

by iamrichardD
57 stars

This strategy plots a MACD oscillator in a separate pane and trades Bitcoin futures from zero-line and signal-line crosses. Optional early momentum signals, a volume filter, and a trend moving-average filter can confirm entries. It sizes positions as fixed con

Strategy v6 Oscillators & momentumMoving averages Repaints
Updated 1 year ago · Apache-2.0 GitHub repository of BTC Futures MACD
25 stars

This Pine Script strategy calculates Bayesian probabilities of price breaking up or down relative to Bollinger Bands and a Simple Moving Average. It plots these breakout and breakdown probability lines as oscillators in a separate pane. Long entries trigger wh

Strategy v4 Oscillators & momentumVolatility & bands
Updated 6 years ago · None stated GitHub repository of Bayesian BBSMA Oscillator Strategy

Greeffer BB Strategy

by SammyEnigma
18 stars

This strategy combines Bollinger Bands, Bollinger Band Width, and the Relative Strength Index (RSI) for mean-reversion trades. It enters long when price crosses below the lower band with oversold RSI, or when band width contracts under low volatility. Short en

Strategy v4 Mean reversionOscillators & momentum
Updated 6 years ago · None stated GitHub repository of Greeffer BB Strategy
13 stars

This strategy uses a 100-period RSI to generate long and short signals with 5% pre-entry buffers. Long entries trigger at RSI 45 and shorts at RSI 55. Exits occur at RSI 55 for longs and 47 for shorts, with emergency stops at RSI 10. Higher-timeframe EMA confi

Strategy v5 Oscillators & momentumMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard Fiery RSI A008

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers