NIFTY 50 5mint Strategy

This is an intraday strategy for NIFTY50 Based First candle High and Low breakout.

The strategy takes user inputs for the start and end dates, start and end months, and start and end years, which define the time range to trade. The user can also specify the maximum number of trades to take during the time range and the length of the Exponential Moving Average ( EMA ) used in the strategy

In this strategy, the First candle's high and low are calculated and used as entry and exit points for trades. If the close price breaks above the First candle's high, a buy signal is generated. Conversely, if the close price breaks below the First candle's low, a sell signal is generated.

The strategy uses the Exponential Moving Average ( EMA ) as a filter to close entered positions either long or short, EMA also acts Target. If the close price falls below the EMA, a long position is closed, and if the close price rises above the EMA, a short position is closed or the PreviousCandleClose is above the First candle's high a short position is closed, When the PreviousCandleClose is below the First candle's low a long position is closed, First candle's high act as Stoploss

The strategy limits the number of trades taken within the specified time range, and if the time range is exceeded, all positions are closed.

Finally, the strategy plots the First candle's high and low, EMAs on the chart for visual reference.

Default settings work best with the 5mint candle, you may tweak settings according to your needs.

backtesting helps in interpreting how the trading strategy would have behaved in the past, and forward testing (paper trading) informs the traders how it would perform now.
Release Notes:
Updated the strategy.
  • removed Ema filter .
  • added stop loss and target (defined by the user ) based on the entry price().

the strategy performed, at least in the past, although obviously there is no guarantee that it will make money in the future. Always Future Test (Paper Trade) the new strategy.
Release Notes:
Quick Summary
This is a trading strategy script written in Pine Script language for trading the NIFTY 50 index in the 5-minutes time frame. The strategy is based on breakout trading where the high and low of the first candle of the session are used as breakout levels.

The script has inputs to define the start and end dates of the backtesting period, the trading session, the stop loss and target levels, the maximum number of trades, and the trade direction. The script also tracks the number of trades taken and submits buy/sell orders based on signals and maximum trades.

The script has some functions such as is_newbar() which checks if a new bar has formed, strategy.entry() to enter a long or short position, and strategy.close() to close a position. The script also uses variables such as counter_call and counter_put to track the number of trades taken and First_high and First_low to store the high and low of the first candle of the session.

Overall, the script is a simple breakout trading strategy that can be easily customized based on the user's preferences. However, it is important to note that trading strategies should be backtested thoroughly and validated before being used in live trading.

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.


The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?