Strategy · Pine Script v5 · On the chart

DX Strat

by jawauntb

DX Strat is an intraday directional trading strategy that combines a composite RSI momentum calculation, moving averages, Keltner Channels, and VWAP to execute trades.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code81
Settings7inputs
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

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

directional-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("DX Strat", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// ————————————————————— Composite RSI —————————————————————

rsiSource = input(close, title="RSI Source")
RSIDelta = ta.rsi(rsiSource, 14) - ta.rsi(rsiSource, 14)[1]
RSIsma = ta.sma(ta.rsi(rsiSource, 3), 3)
momentumRSI = RSIDelta + RSIsma
sma13 = ta.sma(momentumRSI, 13)
sma33 = ta.sma(momentumRSI, 33)

// ————————————————————— EMA 13 and MA 30 —————————————————————

ema13 = ta.ema(close, 13)
ma30 = ta.sma(close, 30)

// ————————————————————— Keltner Channel —————————————————————

length = input.int(20, minval=1)
mult = input(2.0, "Multiplier")
src = input(close, title="Source")
exp = input(true, "Use Exponential MA")
BandsStyle = input.string("Average True Range", options=["Average True Range", "True Range", "Range"], title="Bands Style")
atrlength = input(10, "ATR Length")

ma = exp ? ta.ema(src, length) : ta.sma(src, length)
rangema = BandsStyle == "True Range" ? ta.tr(true) : BandsStyle == "Average True Range" ? ta.atr(atrlength) : ta.rma(high - low, length)
upper = ma + rangema * mult
lower = ma - rangema * mult

// ————————————————————— VWAP —————————————————————

vwap = ta.vwap(hlc3)

// ————————————————————— Trading Conditions —————————————————————

longCondition1 = momentumRSI > 77
shortCondition1 = momentumRSI < 25
longCondition2 = ema13 > ma30
shortCondition2 = ma30 > ema13
longCondition3 = ta.highest(close, 30) > ta.highest(upper, 30)
shortCondition3 = ta.lowest(close, 30) < ta.lowest(lower, 30) and strategy.position_size < 0
longCondition4 = close > vwap and close[1] > vwap[1] and close[2] > vwap[2] and close[3] > vwap[3] and close[4] > vwap[4] and close[5] > vwap[5]
shortCondition4 = close < vwap and close[1] < vwap[1] and close[2] < vwap[2] and close[3] < vwap[3] and close[4] < vwap[4] and close[5] < vwap[5] and close[6] < vwap[6] and close[7] < vwap[7]

// ————————————————————— Entry and Exit —————————————————————

var int longHoldPeriod = 8
var int shortHoldPeriod = 5
var int longEntryBar = 0
var int shortEntryBar = 0

if (longCondition1)
    strategy.entry("Long", strategy.long)
    longEntryBar := bar_index
    if (longCondition2)
        longHoldPeriod := longHoldPeriod + 1
    if (shortCondition2)
        longHoldPeriod := longHoldPeriod - 5
    if (longCondition3)
        longHoldPeriod := longHoldPeriod + 1
    if (longCondition4)
        longHoldPeriod := longHoldPeriod + 3
else
    if (strategy.position_size > 0 and bar_index >= longEntryBar + longHoldPeriod)
        strategy.close("Long")

if (shortCondition1)
    strategy.entry("Short", strategy.short)
    shortEntryBar := bar_index
    if (shortCondition3)
        shortHoldPeriod := shortHoldPeriod + 1
    if (shortCondition4)
        shortHoldPeriod := shortHoldPeriod + 1
else
    if (strategy.position_size < 0 and bar_index >= shortEntryBar + shortHoldPeriod)
        strategy.close("Short")

Overview

DX Strat initiates long positions when composite momentum RSI crosses above 77 and short positions when it drops below 25. Position exits are entirely time-based; the strategy adjusts the target holding bar duration dynamically according to moving average alignment, Keltner band breakouts, and VWAP persistence. It displays entries directly on the price chart and does not utilize stop loss orders.

Details

Published by

jawauntb on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

M15-H1

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
lengthint20length
Multiplierfloat2.0mult
Sourcesourceclosesrc
Use Exponential MAbooltrueexp
Bands StylestringAverage True RangeBandsStyle
ATR Lengthint10atrlength
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
57 stars

This strategy identifies trend reversals through market structure changes (CHoCH) filtered by MACD momentum. It initiates long positions on bullish structure breaks when MACD is positive and above its signal line, and short positions on bearish breaks when MAC

Strategy v6 SMC / ICT / price actionOscillators & momentum Repaints
Updated 1 year ago · Apache-2.0 GitHub repository of Market Structure MACD 4H + Trailing

CombinedBinHAndClucV6

by viktors1982
36 stars

CombinedBinHAndClucV6 is a trading strategy based on the popular BinHV45 and ClucMay72018 algorithms. It calculates dual Bollinger Bands, Exponential Moving Averages, Relative Strength Index, Average True Range, and volume metrics across primary and one-hour h

Strategy v4 Volatility & bandsOscillators & momentum Repaints
Updated 2 years ago · None stated GitHub repository of CombinedBinHAndClucV6
27 stars

LuxAlgo Hybrid Gold Scalper is a price-chart strategy aimed at gold. It stacks a fast, slow, trend and 200-period bias EMA to mark trend direction, then filters strength with RSI, ADX and an intraday VWAP. Swing highs and lows are marked from pivot length. Set

Strategy v5 TrendOscillators & momentum
Updated 5 months ago · None stated GitHub repository of LuxAlgo Hybrid Gold Scalper

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers