Strategy · Pine Script v5 · On the chart

Stock and NQ Futures Convergence Strategy

by jawauntb

The Stock and NQ Futures Convergence Strategy identifies trading opportunities by comparing the Relative Strength Index of the active chart stock against NQ futures.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code45
Settings4inputs
LicenceGPL-3.0
Last update2 years ago22 May 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

45 lines of Pine Script v5 from stock-nq-convergence-strat.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

stock-nq-convergence-strat.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jawauntb

//@version=5
strategy("Stock and NQ Futures Convergence Strategy", overlay=true)

// Inputs
rsiSource = input(close, title="RSI Source")
rsiLength = input(14, title="RSI Length")
rsiUpperThreshold = input(50, title="RSI Upper Threshold")
rsiLowerThreshold = input(25, title="RSI Lower Threshold")

// Calculate the composite RSI for the stock
stockRSI = ta.rsi(rsiSource, rsiLength)

// Calculate the composite RSI for the NQ futures
nqRSI = request.security("NQ1!", timeframe.period, ta.rsi(close, rsiLength))

// Short entry condition
shortCondition = nqRSI < rsiLowerThreshold and stockRSI > rsiUpperThreshold

// Long entry condition
longCondition = nqRSI > rsiUpperThreshold and stockRSI < rsiLowerThreshold

// Entry and exit signals
shortEntry = shortCondition and strategy.position_size == 0
shortExit = nqRSI > rsiUpperThreshold and strategy.position_size < 0
longEntry = longCondition and strategy.position_size == 0
longExit = nqRSI < rsiLowerThreshold and strategy.position_size > 0

// Execute trades
if shortEntry
    strategy.entry("Short", strategy.short)
else if shortExit
    strategy.close("Short")
else if longEntry
    strategy.entry("Long", strategy.long)
else if longExit
    strategy.close("Long")

// Plot signals
plotshape(shortEntry, title="Short Entry", location=location.belowbar, style=shape.triangledown, size=size.small, color=color.red)
plotshape(shortExit, title="Short Exit", location=location.abovebar, style=shape.triangleup, size=size.small, color=color.red)
plotshape(longEntry, title="Long Entry", location=location.belowbar, style=shape.triangleup, size=size.small, color=color.green)
plotshape(longExit, title="Long Exit", location=location.abovebar, style=shape.triangledown, size=size.small, color=color.green)

Overview

Stock and NQ Futures Convergence Strategy enters a long position when NQ RSI rises above the upper threshold while the stock RSI stays below the lower threshold. Conversely, it enters a short position when NQ RSI drops below the lower threshold while the stock RSI exceeds the upper threshold. Trades are plotted directly on the price chart. Customizable settings include RSI length, source, and threshold levels. The strategy relies on exit conditions and lacks a hard stop loss.

Details

Published by

jawauntb on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Divergence, Mean reversion

Markets

Stocks, Indices

Timeframes

Any timeframe

Risk Notes

  • 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
RSI SourcesourceclosersiSource
RSI Lengthint14rsiLength
RSI Upper Thresholdint50rsiUpperThreshold
RSI Lower Thresholdint25rsiLowerThreshold
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

1 stars

MACD Divergence - Reversal Hunter detects regular and hidden divergences between price action and the MACD line using pivot points. It generates buy signals on bullish divergences and sell signals on bearish divergences, with optional RSI filter for overbought

Strategy v5 DivergenceOscillators & momentum
Updated 7 months ago · None stated GitHub repository of MACD Divergence - Reversal Hunter

VMC Strat Flex Corrected

by matlaenousse
1 stars

This strategy evaluates market conditions using a combination of WaveTrend, RSI, Stochastic RSI, and a custom Money Flow Index calculation inspired by VuManChu. It enters long positions when multiple oscillators hit oversold thresholds and generate an upward c

Strategy v6 Oscillators & momentumDivergence
Updated 10 months ago · None stated GitHub repository of VMC Strat Flex Corrected
330 stars

Alert BB + RSI [Alorse] is a multi-symbol mean-reversion strategy designed for cryptocurrency trading. It evaluates Bollinger Bands and the Relative Strength Index (RSI) across up to 20 user-defined ticker symbols simultaneously. The strategy enters long posit

Strategy v4 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of Alert BB + RSI [Alorse]
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy

This strategy draws on the price chart and combines Stochastic RSI, the Money Flow Index, and an exponential moving average to open long or short trades. Longs use the lower oscillator thresholds and shorts use the upper ones, with direction limited to longs,

Strategy v5 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 3 Indicator Strategy (StochRSI, MFI & EMA) With Safety Orders

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