This strategy runs on the price chart and enters long when a fast simple moving average crosses above a slow one, and short on the opposite cross, while closing the other side.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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
47 lines of Pine Script v5 from 9-22 5 MIN 15 MIN BANKNIFTY.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
9-22 5 MIN 15 MIN BANKNIFTY.pine
//@version=5
strategy("9:22 5 MIN 15 MIN BANKNIFTY", overlay=true)
fastLength = input(9, title="Fast MA Length")
slowLength = input(22, title="Slow MA Length")
atrLength = input(14, title="ATR Length")
atrFilter = input(0.5, title="ATR Filter")
trailingStop = input(1.5, title="Trailing Stop Percentage")
pullbackThreshold = input(0.5, title="Pullback Threshold")
minCandleBody = input(0.5, title="Minimum Candle Body Percentage")
breakoutConfirmation = input(true, title="Use Breakout Confirmation")
price = close
mafast = ta.sma(price, fastLength)
maslow = ta.sma(price, slowLength)
atrValue = ta.atr(atrLength)
long_entry = ta.crossover(mafast, maslow) and atrValue > atrFilter
short_entry = ta.crossunder(mafast, maslow) and atrValue > atrFilter
// Pullback Filter
pullbackLong = ta.crossover(price, mafast) and ta.change(price) <= -pullbackThreshold
pullbackShort = ta.crossunder(price, mafast) and ta.change(price) >= pullbackThreshold
// Include pullback condition only if a valid entry signal is present
long_entry := long_entry and (pullbackLong or not ta.crossover(price, mafast))
short_entry := short_entry and (pullbackShort or not ta.crossunder(price, mafast))
// Filter based on candle body size
validLongEntry = long_entry and ta.change(price) > 0 and ta.change(price) >= minCandleBody
validShortEntry = short_entry and ta.change(price) < 0 and ta.change(price) <= -minCandleBody
// Breakout confirmation filter
breakoutLong = breakoutConfirmation ? (close > ta.highest(high, fastLength)[1]) : true
breakoutShort = breakoutConfirmation ? (close < ta.lowest(low, fastLength)[1]) : true
long_entry := validLongEntry and breakoutLong
short_entry := validShortEntry and breakoutShort
if (long_entry)
strategy.entry("Long", strategy.long)
strategy.close("Short")
alert("Long trade iniated")
if (short_entry)
strategy.entry("Short", strategy.short)
strategy.close("Long")
alert("Short trade initated")
// Trailing Stop-Loss
long_stop = strategy.position_avg_price * (1 - trailingStop / 100)
short_stop = strategy.position_avg_price * (1 + trailingStop / 100)
strategy.exit("Exit Long", "Long", stop = long_stop)
strategy.exit("Exit Short", "Short", stop = short_stop)
plot(mafast, color=color.green, linewidth=2, title="Fast MA")
plot(maslow, color=color.red, linewidth=2, title="Slow MA")
Expand (59 lines)
Overview
Entries also need ATR above a filter, a pullback check, a minimum candle-body change, and an optional close beyond the recent high or low. A percentage stop is set from the average entry price, with no separate take-profit rule. Lengths, the ATR filter, pullback and body thresholds, the stop percentage, and breakout confirmation are adjustable. The title cites five-minute and fifteen-minute Bank Nifty use, but the shown code does not request those timeframes.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Fast MA Length
int
9
fastLength
Slow MA Length
int
22
slowLength
ATR Length
int
14
atrLength
ATR Filter
float
0.5
atrFilter
Trailing Stop Percentage
float
1.5
trailingStop
Pullback Threshold
float
0.5
pullbackThreshold
Minimum Candle Body Percentage
float
0.5
minCandleBody
Use Breakout Confirmation
bool
true
breakoutConfirmation
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.
This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the
This strategy plots Donchian channels, trailing stops, and profit targets directly on the price chart. It enters breakout trades using a 55-bar Donchian channel and sizes positions according to an ATR-based risk percentage per unit. The system adds units as pr
This strategy combines channel breakout concepts with an ATR-ADX volatility trailing framework and multi-timeframe moving averages. It evaluates trend conditions using configurable moving average types, including SMA, EMA, Hull MA, and Tilson T3, paired with d
This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries
This strategy plots running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos
STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions