Strategy · Pine Script v4 · On the chart

NostalgiaForInfinityV2

by viktors1982· code credited to viktors.s@gmail.com

NostalgiaForInfinityV2 is a multi-timeframe mean-reversion strategy derived from the popular Freqtrade algorithmic trading framework.

View on GitHub

Repaints

GitHub stars36on the repository
Pine versionv4older, still runs
Lines of code118
Settings14inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago10 Apr 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

118 lines of Pine Script v4 from tradingview/pinescripts/strategies/NostalgiaForInfinityV2.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

NostalgiaForInfinityV2.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © viktors.s@gmail.com


//@version=4
strategy("NostalgiaForInfinityV2", overlay=true, currency=currency.EUR, default_qty_type=strategy.cash, default_qty_value=150, initial_capital = 33000, calc_on_every_tick=true,commission_type=strategy.commission.percent, commission_value =0.15)


startDate  = input(title="Start Strat", type=input.time, defval=timestamp("01 Jan 2021 00:00 +0000") )

buy_bb40_length            = input(title="Buy bb40 length", type=input.integer,          defval= 40, step =1, minval = 5, maxval = 100) 
buy_bb40_bbdelta_close     = input(title="Buy bb40 bbdelta close", type=input.float,     defval= 0.017, step =0.001, minval = 0.005, maxval = 0.1)
buy_bb40_closedelta_close  = input(title="Buy bb40 closedelta close", type=input.float,  defval= 0.013, step =0.001, minval = 0.01,  maxval = 0.03)
buy_bb40_tail_bbdelta      = input(title="Buy bb40 tail bbdelta", type=input.float,      defval= 0.445, step =0.001, minval = 0.15,  maxval = 0.45)

buy_bb20_length            = input(title="Buy bb20 length", type=input.integer,          defval= 20, step =1, minval = 5, maxval = 100) 
buy_bb20_close_bblowerband = input(title="Buy bb20 close bblowerband", type=input.float, defval= 0.992, step =0.001, minval = 0.8,   maxval = 1.1)
buy_bb20_volume            = input(title="Buy bb20 volume", type=input.integer,          defval= 27,    step =1,     minval = 18,    maxval = 34 )
buy_rsi_diff               = input(title="Buy RSI Diff", type=input.float,               defval= 52.438,  step =0.1,   minval = 36.0,  maxval = 54.0)

sell_rsi_bb                = input(title="Sell RSI bb",   type=input.float,              defval= 79.706,  step =1,   minval = 60.0,  maxval = 80.0)
sell_rsi_main              = input(title="Sell RSI main", type=input.float  ,            defval= 85.023,  step =1,   minval = 50.0,  maxval = 90.0)
sell_rsi_2                 = input(title="Sell RSI 2",   type=input.float,               defval= 87.545,  step =1,   minval = 50.0,  maxval = 90.0)
sell_ema_relative          = input(title="Sell EMA relative", type=input.float,          defval= 0.03, step =0.001, minval = 0.005, maxval = 0.1)
sell_rsi_diff              = input(title="Sell RSI diff", type=input.float,              defval= 0.873,  step =0.1, minval = 0.0, maxval = 10.0)




//strategy bb40
[middle, upper, lower] = bb(close, buy_bb40_length, 2)
bbdelta = abs(middle - lower)
closedelta = abs(close -close[1])
tail = abs(close - low)


//strategy bb20
[middle2, upper2, lower2] = bb(close, buy_bb20_length, 2)
p_middle = plot(middle2, color=color.aqua)
p_upper = plot(upper2, color=color.silver)
p_lower = plot(lower2, color=color.silver)
fill(p_lower,p_upper)

ema_slow = ema(close,50)
volume_mean_slow = sum(volume,30)/30
plot(ema_slow, color=color.red)

ema_20  =  ema(close,20)
ema_50  =  ema(close,50)
ema_200 =  ema(close,200)
sma_5   =  sma(close,5)
sma_9   =  sma(close,9)

rsi_5m     =  rsi(close,14)

atr_5m  = atr(14)
sma_high = sma(high,20)
sma_low= sma(low,20)


plotchar(rsi_5m, "rsi_5m", "", location = location.top)

//1h ... !


ema_20_1h = security(syminfo.tickerid, '60', ema_20)
ema_50_1h = security(syminfo.tickerid, '60', ema_50)
ema_200_1h = security(syminfo.tickerid, '60', ema_200)
rsi_1h = security(syminfo.tickerid, '60', rsi_5m)
atr_1h = security(syminfo.tickerid, '60', atr_5m)
sma_high_1h = security(syminfo.tickerid, '60', sma_high) + atr_1h
sma_low_1h = security(syminfo.tickerid, '60', sma_low) - atr_1h
close_1h = security(syminfo.tickerid, '60', close)

float Hlv_1h = na
Hlv_1h := close_1h > sma_high_1h ? 1 : close_1h < sma_low_1h ? -1 : Hlv_1h[1]
sslDown_1h = Hlv_1h < 0 ? sma_high_1h: sma_low_1h
sslUp_1h   = Hlv_1h < 0 ? sma_low_1h : sma_high_1h


//  BUY logic :)
bb40_long = close < sma_9 and close > ema_200_1h and ema_50 > ema_200 and ema_50_1h > ema_200_1h and lower[1] > 0 and bbdelta > close * buy_bb40_bbdelta_close and  closedelta > close * buy_bb40_closedelta_close and tail < bbdelta * buy_bb40_tail_bbdelta and close < lower[1] and close <= close[1] 
bb20_long = close < sma_9 and close > ema_200 and close > ema_200_1h and close < ema_slow and close < buy_bb20_close_bblowerband * lower2 and volume < volume_mean_slow[1] * buy_bb20_volume 
ssl_long  = close < sma_5 and close > ema_200 and close > ema_200_1h and sslUp_1h > sslDown_1h and ema_50 > ema_200 and ema_50_1h > ema_200_1h and rsi_5m < rsi_1h - buy_rsi_diff
//-------------------------
 
//SELL logic
bb_rsi_close_sell    = rsi_5m > sell_rsi_bb and close > upper2 and close[1] > upper2[1] and close[2] > upper2[2]
rsi_main_sell        = rsi_5m > sell_rsi_main
rsi2_ema_close_sell  = close < ema_200 and close > ema_50 and rsi_5m > sell_rsi_2
rsi1h_rsirel_close_ema_sell = close < ema_200 and ((ema_200 - close)/close) < sell_ema_relative and rsi_5m > rsi_1h + sell_rsi_diff
//--------------------------
 
 

//DEBUG 
plotchar(bb40_long, "bb40_long", "", location = location.top)
plotchar(bb20_long, "bb20_long", "", location = location.top)
plotchar(ssl_long, "ssl_long", "", location = location.top)
plotchar(bb_rsi_close_sell, "bb_rsi_close_sell", "", location = location.top)
plotchar(rsi_main_sell, "rsi_main_sell", "", location = location.top)
plotchar(rsi2_ema_close_sell, "rsi2_ema_close_sell", "", location = location.top)
plotchar(rsi1h_rsirel_close_ema_sell, "rsi1h_rsirel_close_ema_sell", "", location = location.top)
//--------------


afterStartDate = (time >= startDate)
longCondition = (bb40_long == 1 or bb20_long == 1 or ssl_long ==1) and afterStartDate and strategy.position_size <= 0
if (longCondition)
    strategy.entry("Entry", strategy.long, when=(bb40_long) , comment = 'bb40_long')
    strategy.entry("Entry", strategy.long, when=(bb20_long) , comment = 'bb20_long')
    strategy.entry("Entry", strategy.long, when=(ssl_long)  , comment = 'ssl_long')

if (strategy.position_size > 0)
    strategy.close(id="Entry", when=(bb_rsi_close_sell) , comment = 'bb_rsi_close_sell')
    strategy.close(id="Entry", when=(rsi_main_sell)     , comment = 'rsi_main_sell')
    strategy.close(id="Entry", when=(rsi2_ema_close_sell) , comment = 'bb_rsi_close_sell')
    strategy.close(id="Entry", when=(rsi1h_rsirel_close_ema_sell) , comment = 'rsi1h_rsirel_close_ema_sell')

Overview

NostalgiaForInfinityV2 evaluates price behavior using dual Bollinger Bands, RSI, exponential moving averages, and ATR volatility metrics sampled across both chart and 1-hour timeframes. Buy signals trigger when price interacts with lower Bollinger Bands alongside volume and RSI filters, while exits execute upon reaching overbought RSI levels. The indicator overlays plots directly on the main chart. Note that higher-timeframe data causes repainting on lower-timeframe bars and no stop loss is defined by default.

Details

Published by

viktors1982 on GitHub

Code credit

viktors.s@gmail.com, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Trend, Oscillators & momentum, Volatility & bands, Moving averages

Markets

Crypto

Timeframes

M1-M5, M15-H1

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
Start Strattimetimestamp("01 Jan 2021 00:00 +0000")startDate
Buy bb40 lengthint40buy_bb40_length
Buy bb40 bbdelta closefloat0.017buy_bb40_bbdelta_close
Buy bb40 closedelta closefloat0.013buy_bb40_closedelta_close
Buy bb40 tail bbdeltafloat0.445buy_bb40_tail_bbdelta
Buy bb20 lengthint20buy_bb20_length
Buy bb20 close bblowerbandfloat0.992buy_bb20_close_bblowerband
Buy bb20 volumeint27buy_bb20_volume
Buy RSI Difffloat52.438buy_rsi_diff
Sell RSI bbfloat79.706sell_rsi_bb
Sell RSI mainfloat85.023sell_rsi_main
Sell RSI 2float87.545sell_rsi_2
Show all 14 settings
SettingTypeDefaultVariable
Sell EMA relativefloat0.03sell_ema_relative
Sell RSI difffloat0.873sell_rsi_diff
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

106 stars

This trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3 x EMA + Stochastic RSI + ATR

Momentum Rider DAILY FINAL

by greenpeas007
58 stars

This strategy combines exponential moving averages (EMA 9, 21, 50), RSI, MACD, and Supertrend indicators to enter long positions. It triggers trades using six dynamic setups based on momentum breakouts, EMA crossovers, and pullbacks. Position sizing is compute

Strategy v6 TrendOscillators & momentum Repaints
Updated 4 months ago · Custom licence GitHub repository of Momentum Rider DAILY FINAL

BB Swing

by benso87
24 stars

This strategy calculates Bollinger Bands, a configurable moving average slope, Stochastic RSI, ATR, and ADX directly on the price chart. It evaluates trend bias and momentum conditions to generate long and short swing entries using percent-of-equity sizing. Th

Strategy v5 Volatility & bandsOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of BB Swing

This strategy trades long and short on the price chart using a multi-timeframe TradingLatino setup. It requires EMA 10 to cross or sit above or below EMA 55 on the one-hour, four-hour, and daily charts, together with a positive ADX slope, a directional monitor

Strategy v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard ABCBitcoin TradingLatino A010

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