Select Page

While trading in Options pine script can be used on charts of Nifty Cash/Future for applying your NSE options Algo Strategy in TradingView. Note this strategy works good with even free version of TradingView.

Strategy Premise

The Relative Strength Index (RSI) is a momentum oscillator that measures the speed and change of price movements. The RSI oscillates between zero and 100. Increasing RSI shows increasing bullish momentum. Decreasing RSI shows increasing bearish momentum. We take RSI upper bound as 80 to indicate bullish momentum and RSI lower bound as 20 to indicate bearish momentum.

We use the above premise to create options buy-only strategy which trades in ATM strikes by default. This strategy requires very less margin (Rs. 15000 should be sufficient).

NSE Options Algo Strategy Logic

Long Entry: When RSI goes above 80, send LE in auto-calculated option strike Call. When RSI goes below 20, send LE in auto-calculated option strike Put.
Long Exit: When we hit Stop loss or Target. In case SL/TGT do not hit and reverse RSI goes above 80 send Long Exit in auto-calculated option. Put as per last trade; RSI goes below 20, send LX in auto-calculated option call as per last trade.

For Long and Short entry the order is fired in option buying side with auto strike price selection.

TradingView Settings

Open the desired chart in trading view with the normal candlestick. Click on Indicators-> public library and search for “APIBridge Nifty Options Algo Strategy” Or click here to select the strategy directly. Apply it to the chart.

Nifty options Algo strategy in Trading View.

Option Strategy Parameters for TraingView Charts

  1. RSI Length(Mandatory): Number of bars used to calculated RSI.
  2. Upper Band(Mandatory): To specify upper band of RSI.
  3. Lower Band(Mandatory): For specifying lower band of RSI.
  4. Use reversal from Upper Band (Optional): This will enable short entry when RSI is falling below 80 from upper band. Recommended to keep unchecked initially.
  5. Use reversal from Lower Band (Optional): This will enable long entry when RSI is raising above 20 from lower band. Recommended to keep unchecked initially.
  6. Quantity: We use this specify the trade quantity (for Nifty min 75)
  7. Custom Stop Loss in Points: Movement in chart price against the momentum which will trigger exit in options positions
  8. Custom Target in Points: Movement in chart price against the momentum which will trigger exit in options positions
  9. Base symbol: This is the base instrument symbol like NIFTY or BANK NIFTY.
  10. Strike distance from ATM: Our default strike selection is considered as first ATM option (with nearest distance, only 100s are considered ). This strike distance allows to calculate ATM options which are at fixed distance.
  11. Expiry: Expiry of option. Weekly and monthly both expiry are allowed.
  12. Instrument: For index instrument will be OPTIDX, for stock instrument will be OPTSTK
  13. Strategy Tag: The Strategy of Nifty options configured in Api bridge.

Setting Up Alert

Before setting up alert make sure that you have selected desired script, time frame, strategy settings and APIbridge configuration. Click in settings add alert and paste {{strategy.order.comment}} in message box.

Important: Do not change any settings during live trading. It may break the sequence of exit for the correct call/put.

NOTE: The pinescript works both with webhook alerts (TV Pro plan) and normal popup alerts (TV free plan).

TradingView settings

APIBridge Settings – New Users

This is an advanced strategy. In conclusion you are first requested to complete TradingView Jump Start Setup. Make sure you use the extension v4.1 for this strategy.

We advised to add all the option symbols in Apibridge before setting alerts, to avoid order rejections. In addition make sure you use same expiry, and strategy tag as given in trading view. Since we send quantity in alerts there would be no need to specify quantity in APIBridge Symbol Settings.

Apibridge settings

APIBridge Settings – Advanced Users

You can completely bypass the symbol settings using config file edit as given on the bottom of this page. However the pine script code uses optimal alerts which do not require any symbol settings.

Sample Trades

See sample trades below with RSI on 1-minute chart.

The first entry for day is taken at 9:35:02 and second at 9:45:01. As RSI swings to other extreme as a result previous option position was closed and new position was created.

Note : All the trades show price as 0, because market orders are used.

In APIBridge paper trading mode, you will not be able to see correct PnL because underlying instrument is different from trading instrument. However, in live trading you will see actual option prices in trades.

Apibridge settings

Pine script Coding Guide

In extension v4.1 and webhooks, you can use full power of APIBridge signals as per given format here in Example 7. To calculate option strike, use in alert SYMBOL:NIFTY|29 October 2020|11100|CE.