Indicator · Pine Script v4 · Own pane

Tykhe Rolling Sharpe Ratio Mansfield

by nvFede· code credited to Tykhe_Ideas

A Pine v4 indicator in a separate pane that computes a rolling Sharpe-style ratio over a 200-bar window and compares it with a benchmark symbol, SPY by default.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code74
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago19 Mar 2023

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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

74 lines of Pine Script v4 from TradingView_old/Sharpe_Mansfield.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Sharpe_Mansfield.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Tykhe_Ideas

//@version=4
study("Tykhe - Rolling Sharpe Ratio Mansfield", shorttitle="Tykhe - SM")

//--------------------------- Opciones ----------------------------------- 
src = input(close, title="Fuente: ")


len = input(200, title="Length: ", minval=0)

use_rf = input(type=input.bool, defval=false, title="¿Usar tasa libre de riesgo?")

rf_sec = security(input("DTB3", title="Tasa libre de riesgo: "), timeframe.period, close)

benchmark = security(input("SPY", title="Benchmark: "), timeframe.period, close)

smoothness = input(defval=5, minval=0, title="Suavizado: ")

mostrar_sma = input(type=input.bool, defval=true, title="¿Mostrar media móvil?")

sma_period = input(200, title="Media Móvil: ", minval=0)

//--------------------------- Hull Moving average -----------------------------------
hull(x, longitud) =>
    hullma = wma(2*wma(x, longitud/2)-wma(x, longitud), round(sqrt(longitud)))

//--------------------------- Colores -----------------------------------
bull_color = #058ac5
indecision_color = #dde4c5
bear_color = #ff583e



//--------------------------- Long Sharpe -----------------------------------


rf = use_rf ? rf_sec / 100 : 0

long_pc = (src - src[len]) / src
long_std = stdev(src, len)
long_stdaspercent = long_std / src
long_SR = hull((long_pc - rf) / long_stdaspercent, smoothness)



//--------------------------- Benchmark Sharpe -----------------------------------




short_pc = (benchmark - benchmark[len]) / src
short_std = stdev(benchmark, len)
short_stdaspercent = short_std / benchmark
short_SR = hull((short_pc - rf) / short_stdaspercent, smoothness)

//______Calc

sr = (sma(long_SR/short_SR, 5) / 100)

sma_1 = ema(sr, sma_period)
media = mostrar_sma ? sma_1 : na



plot(sr, style=plot.style_histogram, color=long_SR < 0 ? bear_color : bull_color, linewidth=3, transp=50 )
plot( sr, style=plot.style_line, color=indecision_color, linewidth=2, transp=50)



plot(media, style=plot.style_circles, color=indecision_color, linewidth=1)

hline(0, linestyle=hline.style_dashed, color=indecision_color)

Overview

An optional reference interest rate series can be subtracted, a Hull moving average smooths the output, and a moving average of the result can be displayed. Settings cover the window, benchmark, smoothing and average period. Input labels are in Spanish.

Details

Published by

nvFede on GitHub

Code credit

Tykhe_Ideas, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Volatility & bands

Markets

Stocks

Timeframes

H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
Fuente: sourceclosesrc
Length: int200len
¿Usar tasa libre de riesgo?boolfalseuse_rf
Tasa libre de riesgo: stringDTB3Tasa libre de riesgo:
Benchmark: stringSPYBenchmark:
Suavizado: int5smoothness
¿Mostrar media móvil?booltruemostrar_sma
Media Móvil: int200sma_period
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

This indicator calculates the distribution of close-to-close percentage changes using rate of change on closing prices. It bins percentage changes into intervals of 0.25 percent increments from negative to positive values and plots a normalized cumulative hist

Indicator v4 Volatility & bands
Updated 11 days ago · GPL-3.0 GitHub repository of Close-to-Close % Change Distribution

This indicator plots a Supertrend-based trend-following setup in a separate pane and skips conditions it treats as a sideways market. A volatility range is built from an ATR value, with RMA, SMA, EMA, or WMA smoothing, or from a fixed point distance. Optional

Indicator v5 TrendVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Trend Following Setup - Sideways Market Skipper
330 stars

This indicator plots candle range and open-to-close movement as percentages in a separate pane. Range is the high-low difference divided by the low, and change is the close-open difference divided by the open. Both series draw as columns. Teal columns show ran

Indicator v5 Volatility & bands
Updated 2 months ago · None stated GitHub repository of Percent & Volatility [Alorse]

Mojito v3 Strategy

by namuan
318 stars

The Mojito v3 Strategy indicator evaluates volatility term structure by calculating the ratio between front-month and second-month VIX futures contracts. It smooths this ratio using a configurable median filter and compares the result against user-defined uppe

Indicator v5 Volatility & bands
Updated 2 months ago · MIT GitHub repository of Mojito v3 Strategy

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers