Anand's Strategy is a multi-timeframe breakout strategy that determines overall bias using daily candle data and triggers entries on 15-minute breakouts.
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
72 lines of Pine Script v5 from Anand's Strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
Anand's Strategy.pine
//@version=5
strategy("Anand's Strategy", overlay=true)
// Get the high and low of the previous day's candle
prev_high = request.security(syminfo.tickerid, "D", high[2])
prev_low = request.security(syminfo.tickerid, "D", low[2])
// var float prev_high = na
// var float prev_low = na
prev_close = request.security(syminfo.tickerid, "D", close[1])
getDayIndexedHighLow(_bar) =>
_indexed_high = request.security(syminfo.tickerid, "D", high[_bar])
_indexed_low = request.security(syminfo.tickerid, "D", low[_bar])
[_indexed_high, _indexed_low]
var index = 2
while index >= 0
[indexed_high_D, indexed_low_D] = getDayIndexedHighLow(index)
if prev_close > indexed_high_D or prev_close < indexed_low_D
prev_high := indexed_high_D
prev_low := indexed_low_D
break
// Decrease the index to move to the previous 15-minute candle
index := index - 1
// Determine the trade direction based on the candle criterion
trade_direction = prev_close > prev_high ? 1 : (prev_close < prev_low ? -1 : 0)
// Get the current close from 15-minute timeframe
current_close = request.security(syminfo.tickerid, "15", close[1])
prev_high_15m = request.security(syminfo.tickerid, "15", high[2])
prev_low_15m = request.security(syminfo.tickerid, "15", low[2])
// var float prev_high_15m = na
// var float prev_low_15m = na
getIndexedHighLow(_bar) =>
_indexed_high = request.security(syminfo.tickerid, "15", high[_bar])
_indexed_low = request.security(syminfo.tickerid, "15", low[_bar])
[_indexed_high, _indexed_low]
// Loop through previous 15-minute candles until the condition is met
var i = 2
while i >= 2
[indexed_high_15m, indexed_low_15m] = getIndexedHighLow(i)
if current_close > indexed_high_15m or current_close < indexed_low_15m
prev_high_15m := indexed_high_15m
prev_low_15m := indexed_low_15m
break
// Decrease the index to move to the previous 15-minute candle
i := i - 1
buy_condition = trade_direction == 1 and current_close > prev_high_15m
stop_loss_buy = prev_low_15m
// Sell Trade Criteria in Negative Trend
sell_condition = trade_direction == -1 and current_close < prev_low_15m
stop_loss_sell = prev_high_15m
// Trailing Stop Loss for Buy Trade
// Custom Trailing Stop Function for Buy Trade
var float trail_stop_buy = na
trailing_buy_condition = buy_condition and current_close > trail_stop_buy
if trailing_buy_condition
trail_stop_buy := current_close
// Custom Trailing Stop Function for Sell Trade
var float trail_stop_sell = na
trailing_sell_condition = sell_condition and current_close < trail_stop_sell
if trailing_sell_condition
trail_stop_sell := current_close
// Take Buy Trade with Stop Loss
if (buy_condition)
strategy.entry("Buy", strategy.long)
strategy.exit("Buy Stop Loss", "Buy", stop=stop_loss_buy)
// Take Sell Trade with Stop Loss
if (sell_condition)
strategy.entry("Sell", strategy.short)
strategy.exit("Sell Stop Loss", "Sell", stop=stop_loss_sell)
// Set the background color based on the trade direction
bgcolor(trade_direction == 1 ? color.new(color.green, 90) : trade_direction == -1 ? color.new(color.red, 90) : na)
Expand (96 lines)
Overview
Anand's Strategy calculates higher-timeframe trend direction by comparing previous daily closes against daily high and low ranges. When the daily trend aligns with a 15-minute breakout, it enters a long or short position. Exits are managed with fixed stop losses based on recent 15-minute highs or lows. The strategy highlights trend direction using background color shading on the main price chart.
Multi-timeframe trend filter using daily candle data
15-minute high and low breakout entry signals
Dynamic stop loss placement based on timeframe extremes
Visual background shading indicating overall market direction
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 trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr
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
The Chained Linear Regression Reversal Strategy plots linear regression channels with upper and lower standard deviation bands directly on the price chart across a user-defined time window. When price breaks out of the static channel for a confirmed number of
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 enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low. A tim
This strategy executes trades on short-term cryptocurrency charts using a combination of pivot support and resistance levels and a multi-pole smoothed trend filter. Entries trigger when price crosses the smoothed trend line and confirms above or below a short-