Skip to main content

All-in-One Multi-Indicator Options Strategy

warning

These strategies are for demonstration purposes only and are not intended for actual trading. AlgoTest is not responsible for any profit or loss arising from the use of these sample strategies.

FREE All-in-One Multi-Indicator Options Strategy Pinescript​

info

To learn how to add this pinescript in TradingView, click here.


// This Pine Scriptâ„¢ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlgoTest
//@version=5

indicator("All-in-One Multi-Indicator Options Strategy",shorttitle = "All-in-One", overlay=false)

// Input for Index and Expiry Date
spot = input.string("BANKNIFTY", title = "Spot Symbol", options = ["NIFTY", "BANKNIFTY", "FINNIFTY", "MIDCPNIFTY"], group = "Index")

tooltip_day = "Enter the day of the expiry. Add 0 in front if the day is a single digit. For example: 05 instead of 5"
tooltip_month = "Enter the month of the expiry. Add 0 in front if the month is a single digit. For example: 06 instead of 6"
tooltip_year = "Enter the year of the expiry. Use the last two digits of the year. For example: 24 instead of 2024"

_day = input.string("21", title = "Expiry Day", tooltip = tooltip_day, group="Expiry Date")
_month = input.string("08", title = "Expiry Month", tooltip = tooltip_month, group="Expiry Date")
_year = input.string("24", title = "Expiry Year", tooltip = tooltip_year, group="Expiry Date")

// Input for Strikes
tooltip_ = "You can select any Strike, and choose to include both strikes or just one"
strike_ce = input.int(50800, "Call Strike", tooltip = tooltip_, group = "Select Strike")
strike_pe = input.int(50800, "Put Strike", tooltip = tooltip_, group = "Select Strike")

// Option to include both strikes
strike_choice = input.string("Combined", title = "Select Strike", options = ["Combined", "Only Call", "Only Put"], group = "Select Strike")

// Generate symbols for Call and Put options
var string symbol_CE = spot + _year + _month + _day + "C" + str.tostring(strike_ce)
var string symbol_PE = spot + _year + _month + _day + "P" + str.tostring(strike_pe)

// Request security data for both Call and Put options
[call_open, call_high, call_low, call_close] = request.security(symbol_CE, timeframe.period, [open, high, low, close])
[put_open, put_high, put_low, put_close] = request.security(symbol_PE, timeframe.period, [open, high, low, close])

call_volume = request.security( symbol_CE, timeframe.period , volume )
put_volume = request.security( symbol_PE, timeframe.period , volume )

var float combined_open = 0
var float combined_high = 0
var float combined_low = 0
var float combined_close = 0
var float combined_vol = 0

// Calculate combined premium based on strike choice
if strike_choice == "Combined"
combined_open := call_open + put_open
combined_close := call_close + put_close
combined_high := math.max(combined_open, combined_close)
combined_low := math.min(combined_open, combined_close)
combined_vol := call_volume + put_volume

else if strike_choice == "Only Call"
combined_open := call_open
combined_close := call_close
combined_high := call_high
combined_low := call_low
combined_vol := call_volume

else
combined_open := put_open
combined_close := put_close
combined_high := put_high
combined_low := put_low
combined_vol := put_volume

// Plot combined premium as a candle
plotcandle(combined_open, combined_high, combined_low, combined_close, title = "Combined Premium", color = combined_close > combined_open ? color.green : color.red)

// Indicator selection
use_ema_crossover = input.bool(true, title = "Use EMA Crossover", group = "Indicators")
use_supertrend = input.bool(false, title = "Use Supertrend", group = "Indicators")
use_vwap = input.bool(false, title = "Use VWAP", group = "Indicators")
use_rsi = input.bool(false, title = "Use RSI", group = "Indicators")
use_sma = input.bool(false, title = "Use SMA", group = "Indicators")

pine_supertrend_value(factor, atrPeriod) =>
src = combined_close
atr = ta.atr(atrPeriod)
upperBand = src + factor * atr
lowerBand = src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])

lowerBand := lowerBand > prevLowerBand or combined_close[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or combined_close[1] > prevUpperBand ? upperBand : prevUpperBand
int _direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
_direction := 1
else if prevSuperTrend == prevUpperBand
_direction := combined_close > upperBand ? -1 : 1
else
_direction := combined_close < lowerBand ? 1 : -1
superTrend := _direction == -1 ? lowerBand : upperBand
superTrend

pine_supertrend_dir(factor, atrPeriod) =>
src = combined_close
atr = ta.atr(atrPeriod)
upperBand = src + factor * atr
lowerBand = src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])

lowerBand := lowerBand > prevLowerBand or combined_close[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or combined_close[1] > prevUpperBand ? upperBand : prevUpperBand
int _direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
_direction := 1
else if prevSuperTrend == prevUpperBand
_direction := combined_close > upperBand ? -1 : 1
else
_direction := combined_close < lowerBand ? 1 : -1
superTrend := _direction == -1 ? lowerBand : upperBand
_direction


// Input for EMA lengths
fastLength = input.int(7, 'Fast EMA Length', group = "EMA")
slowLength = input.int(12, 'Slow EMA Length', group = "EMA")

// Input for SuperTrend
atrLength = input.int(7, 'ATR Length', group = "SuperTrend")
fac = input.float(2, 'Factor', group = "SuperTrend")

// Input for RSI
rsi_length = input.int(7, 'Length', group="RSI")
rsi_ob_level = input.int(80, 'Overbought', group="RSI")
rsi_os_level = input.int(20, 'Oversold', group="RSI")

// Input for SMA
sma_length = input.int(7, 'SMA Length', group = "SMA")


var float fast_ema = na
var float slow_ema = na
var float supertrend = na
var int direction = na
var float rsi_val = na
var float sma_val = na

var float sumPriceVolume = 0.0
var float sumVolume = 0.0
var float vwap = 0.0


// Fast EMA
if use_ema_crossover
fast_ema := ta.ema(combined_close, fastLength)
slow_ema := ta.ema(combined_close, slowLength)

// Supertrend
if use_supertrend
supertrend := pine_supertrend_value( fac, atrLength)
direction := pine_supertrend_dir( fac, atrLength)

// VWAP
if use_vwap
if (dayofweek != dayofweek[1])
sumPriceVolume := 0.0
sumVolume := 0.0
vwap := 0.0

sumPriceVolume += combined_close * combined_vol
sumVolume += combined_vol
vwap := sumPriceVolume / sumVolume

// RSI
if use_rsi
rsi_val := ta.rsi(combined_close, rsi_length)

// SMA
if use_sma
sma_val := ta.sma(combined_close, sma_length)

plot(fast_ema, title='Fast EMA', color=color.blue, linewidth=2)
plot(slow_ema, title='Slow EMA', color=color.yellow, linewidth=2)
plot(direction < 0 ? supertrend : na, "Up direction", color = color.green, style=plot.style_linebr)
plot(direction > 0 ? supertrend : na, "Down direction", color = color.red, style=plot.style_linebr)
plot(use_vwap? vwap : na, title='VWAP', color=color.purple, linewidth=2)
plot(sma_val, title='SMA', color=color.maroon, linewidth=2)

// Define buy and sell conditions based on selected indicators
var bool buy = false
var bool sell = false
var int buyC = 0
var int sellC = 0

if dayofweek != dayofweek[1]
buyC := 0
sellC := 0

if use_ema_crossover
buy := ( ta.crossover(fast_ema, slow_ema) ) and buyC == 0
sell := ( ta.crossunder(fast_ema, slow_ema) ) and sellC == 0

if use_vwap
buy := ( buy ? buy and ta.crossover(combined_close, vwap) : ta.crossover(combined_close, vwap) ) and buyC == 0
sell := ( sell ? sell and ta.crossunder(combined_close, vwap) : ta.crossunder(combined_close, vwap) ) and sellC == 0

if use_rsi
buy := ( buy ? buy and ta.crossover(rsi_val, rsi_ob_level) : ta.crossover(rsi_val, rsi_ob_level) ) and buyC == 0
sell := ( sell ? sell and ta.crossunder(rsi_val, rsi_os_level) : ta.crossunder(rsi_val, rsi_os_level) ) and sellC == 0

if use_sma
buy := ( buy ? buy and ta.crossover(combined_close, sma_val) : ta.crossover(combined_close, sma_val) ) and buyC == 0
sell := ( sell ? sell and ta.crossunder(combined_close, sma_val) : ta.crossunder(combined_close, sma_val) ) and sellC == 0

if use_supertrend
buy := ( buy ? direction == -1 : direction == -1 and direction[1] == 1 ) and buyC == 0
sell := ( sell ? direction == 1 : direction == 1 and direction[1] == -1 ) and sellC == 0

if buy
buyC := 1
sellC := 0

if sell
sellC := 1
buyC := 0

// Plot buy and sell signals
plotshape(buy, title = "Buy", text = 'Buy', style = shape.labeldown, location = location.top, color= color.green, textcolor = color.white, size = size.small)
plotshape(sell, title = "Sell", text = 'Sell', style = shape.labelup, location = location.bottom, color= color.red, textcolor = color.white, size = size.small)

// Alert conditions
alertcondition(buy, "Buy", "Buy")
alertcondition(sell, "Sell", "Sell")


All-in-One Indicator Strategy​

This document describes the automation of the "All in One Indicator Strategy," which is a technical analysis approach designed to give you buy or sell signals based on the combination of multiple indicators. The strategy utilises multiple indicators such as moving averages, supertrend, VWAP, and RSI to identify potential entry and exit points for trades on an individual strike/Straddle/Strangle chart.

What is the All in One Indicator Strategy?​

We will be using the All-in-One indicator strategy, involving a combination of indicators such as RSI, VWAP, Super Trend, and Moving Averages for defining our entries and exits. By using multiple indicators to establish our strategy for entry and exits, we aim to obtain multiple confirmations before entering a trade. 

While trades may be less frequent due to the reliance on multiple confirmations, the trade opportunities are more likely to be of higher quality and offer a greater probability of success. 

However, the choice of which indicators to enable for defining entry and exit conditions, as well as the timeframe to use, is left to your discretion. For our strategy demonstration, we will be utilizing all available indicators in a 5-minute timeframe.

Pros & ConsSmaller Time Frame (1 minute to 5 minutes)Higher Time Frame (10-15 minutes and above)
Entry & ExitUsing a smaller time frame can provide early entry & exit which helps in targeting a big reward compared to a small stop-loss.Using a higher time frame may result in delayed entry, but it can improve signal accuracy.
Risk RewardUsing a smaller timeframe offers a better risk-reward opportunity because of early entry, leading to a smaller stop loss.Using a higher time frame gives a moderate risk-reward opportunity as entry is a little bit late, resulting in a bigger stop loss.
AccuracyAccuracy will not be good with a smaller time frame due to many false signals.Accuracy will be better with a higher time frame as there are fewer but better signals.
Number of TradesThe number of Trades is higher with a smaller time frame which may result in higher charges.The number of trades is lower with a higher time frame
Risk of LossA high risk of loss is possible with a smaller time frame due to many small losses.Moderate risk of loss is possible with a higher time frame due to fewer but larger losses.
Market ConditionsWorks well in a low-volatility market.Can perform effectively in both low-volatility and high-volatility markets.

The Power of All-in-One Indicator Strategy​

Consider using multiple indicators for trading. For example, instead of relying solely on the VWAP indicator for buying above and selling below, you can use a combination of indicators for better confirmation. You can look for situations where the candle close is above/below vwap and supertrend. By using these multiple indicators, you can increase the accuracy of your trades. Additionally, you can plot these indicators on a combined chart or individual option chart to further enhance your strategy.

You can use this strategy for executing a short straddle or long straddle on combined charts or taking directional trades on individual option strike charts. This strategy will be applied on the straddle chart for option selling to benefit from theta decay on expiry.

This strategy capitalises on situations where the price seems to be losing the momentum of an uptrend and moves to a downtrend. We will look for a 5-minute candle whose close is below vwap and super trend on the straddle chart to initiate a short straddle aiming to profit if the price continues its downward journey.

It is important to note that the indicators we are using like super trend and vwap are for entry and exit are only for demonstration purposes. You may use other indicators as well for your preference.

Spotting Your Entry: The Entry Candle​

Our strategy hinges on a specific type of price action on a straddle or strangle chart -- the Entry candle. This isn't a fancy candlestick pattern; it's simply a candle that meets the following criteria:

Price Position: ​

The close of the 5-minute candle should be below VWAP and Supertrend.
You can view that entry criteria are fulfilled on a straddle chart as shown in the image below.

As shown in the image above, this is a straddle chart of Nifty 24300 CE and 24300 PE. When the highlighted candle closed below the VWAP and Supertrend and it generated a sell alert, it was time to short 24300 CE and 24300 PE.

Exiting Gracefully: Stop-Loss and Take Profit​

No trading strategy is complete without a solid risk management plan. Here's how the All in one indicator incorporates stop-loss and take-profit orders:

  • Stop-Loss: To minimise potential losses, we will close our Nifty ATM Straddle position if any 5-minute candle closes above VWAP and Supertrend, as depicted in the image below.

As shown in the above image when the candle closed above vwap and supertrend, it gave a buy alert. So as soon as it gives a buy alert it's time to exit our short straddle position.

  • Take-Profit: Since we employ this strategy on expiry days, our goal is to collect the entire premium of the straddle. Therefore, we anticipate that the value of the straddle will ultimately dwindle to 0. Consequently, we will close our positions at 03:15 on the same day.

Automating All-in-One Indicator Strategy on AlgoTest​

TradingView has a feature called Alerts, which allows you to set up notifications for your trading strategies. For example, if you want to sell an ATM Straddle when our All in One Indicator gives a Sell Signal, you can create an alert for that. Once the strategy conditions are met, you will receive an alert via SMS, email, or mobile notification. You can then manually execute the trade on your broker's platform.

Alternatively, if you prefer automation, you can use AlgoTest's Signals to automatically execute the trade based on the alert. You just need to set up the alert on TradingView and link it with AlgoTest Signals to automate your indicator-based strategy.

Requirements​

TradingView Essential Plan​

You should have a minimum TradingView Essential Plan activated on your TradingView account to use AlgoTest Signal.

AlgoTest Signals Plan​

You should have a Signals Plan activated on your AlgoTest account.

Broker Connect with AlgoTest​

You need to connect your broker with AlgoTest to use AlgoTest Signal. To connect your broker with AlgoTest click here.

Pine Script Code​

You will need a Pine Script Code that can generate buy or sell signals as per your conditions in AlgoTest. You can get this code on top of this page.

Connecting All in One Indicator with AlgoTest​

To automate the All in One Indicator Strategy on AlgoTest, you first need to create alerts in TradingView. Then, these alerts can be used to connect with AlgoTest via a webhook. You will create alerts in TradingView, which will generate entry and exit alerts based on our strategy conditions. Then, in AlgoTest, you will create an "ATM Straddle Sell" strategy in which you add CE and PE legs and connect both of them via webhook. When your All-in-One Indicator strategy gives a sell signal in TradingView, AlgoTest will capture the alert and sell the CE and PE leg position on the broker's end. Similarly, when your strategy gives an exit alert in TradingView, AlgoTest will capture the alert and exit your entire ATM Straddle position.

Adding All in One Indicator TradingView​

To incorporate All in One Indicator in TradingView, you can utilise a custom Pine Script code that we have developed. This code will display the indicator on the chart and enable you to choose option strikes in the settings. To understand how to add the All in One Indicator Pine Script Code, available at the top of this page, in TradingView, please click here. Once you've added the Pine Script code in TradingView, the indicator will be visible on the chart, as illustrated in the image below.

Please ensure that you update the indicator's expiry to the latest date and choose the strike where you want to place the indicator. This can prevent errors that may occur if the indicator's expiry is outdated. To do this, click on the settings button on the indicator and select the appropriate expiry and strike, as shown in the image below.

For instance, if you want to plot your indicator on the Nifty 1st August 2024 contract 24300 CE & PE Leg, then you should set the inputs as illustrated below.

Further, you can enable or disable the multiple indicators with just one click. As we want to use only Vwap and Supertrend indicators in our strategy, so we will enable vwap and Supertrend only as shown in the image below. However, if you want more indicators or a different set of indicators you can enable them as shown in the image below.

Creating Alerts in TradingView​

Alerts in TradingView notify you when entry or exit conditions are met. We'll set up alerts for our entry and exit conditions.

  • Assume we want to automate the All in One Indicator Strategy on the 5-minute chart. So we will open the Nifty 5 Minute chart in TradingView as shown in the image below. You can choose any time frame you prefer.

  • To create an alert, click on the "Alert" button as shown in the image below.

  • We need to set up an alert for two conditions: short entry (sell) and short exit (buy). We'll start by creating an alert for the Short Entry condition. We want to enter when our indicator alerts us to a sell signal. So we'll pick the sale condition displayed in the image below.

  • Similarly, we will create another alert i.e. Exit as shown in the image below. We will select buy condition in the condition tab as we want to exit our straddle when the buy alert comes.

  • Now you will be able to view these alerts in the alert section as shown in the image below.

As we have created our 2 alerts. Now we need to connect these alerts with AlgoTest for automation. So when the Sell condition in All in One Indicator condition is met, an alert will be generated in TradingView and it will be executed automatically on the broker end by AlgoTest. Similarly, when the Buy alert is generated it should automatically exit our entry position on the broker's end.

Connecting Alerts with AlgoTest​

We can connect TradingView Alerts with AlgoTest via webhooks. Follow some simple steps as shown below.

  • Launch a new browser tab. In this new tab, navigate to the AlgoTest website and log in.

  • Once logged in, find and choose the 'Signals' feature of AlgoTest, as seen in the figure below.

Choose 'New Signal' and the 'TradingView Indicator' option.

  • There are now two options available to you:

1. 'Live Deployment'

2. 'Forward Test'

Now, we will briefly explain the above options. 

Firstly, let me explain the word 'Deployment'. 'Deploying a Stratеgy' mеans to apply thе stratеgy in thе actual stock markеt.

What does Live Dеploymеnt mеan?​

This option allows you to deploy your trading strategy in the live market. Whеn you choosе this option, AlgoTеst monitors thе strategy entry and exit conditions in real-time and as soon as an alert comes from TradingView it will execute the order in your broker terminal.

What does the Forward Test mean? ​

Forward tеsting or paper trading means trading with virtual money using LIVE markеt data. You can see your trades and PnL in AlgoTest but you will not need any broker for forward testing. 

If you want to use this strategy in a live trading environment, select 'Live Deployment.' If you'd rather paper trade at first, select 'Forward Test.' Please keep in mind that the methods for linking live and forward trading are the same.

  • Click 'Create Strategy'. Now we have to create a strategy in which we will add a Nifty 24300 CE and Nifty 24300 PE Leg Sell Position.

  • Configure the 24300 CE leg in leg builder as shown in the image below and click on add leg.

Important Strategy Specifications:

  • Nifty Index

  • Time of Entry: 9:16
    (This implies that our strategy will start responding to alerts from TradingView only after the chosen entry time, in this example, 9:16. Please remember that this timing does not correspond to the execution at 9:16.)

  • Time of Exit: 3:15
    (Our strategy will no longer respond to the TradingView alerts after 3:15. Any alert generated after this time will not be considered. Until 3:15, the strategy will only respond to TradingView alerts.)

Due to the presence of an exit condition, we have not included a stop-loss in the strategy. You, on the other hand, have the option to include one if you wish.

  • Now you can see Leg1 is added under Strategy Legs as shown in the image below.

  • Similarly, we will also add another leg, i.e., the 24300 PE leg in the leg builder. So there will be a total of two legs in this strategy. If a sell signal comes from TradingView, it will execute both the ATM CE and PE legs. After this, click on the "Save and Continue" button.

  • Now, name the strategy. You will be asked to select your broker from the options shown in the image. Choose your preferred broker.

  • It will ask for execution parameters, We'll give you recommendations for the best execution. If you don't want to get into the specifics, just use the settings shown in the image below for both legs of your strategy. You can read about execution settings here.

After you've finished customising these options, click 'Save Settings, and Continue.'

  • You can name the entry alert 'Entry' (or any other name you like). Now, as seen in the figure below, copy the JSON Block code using the copy icon. We need to put this JSON Block in the TradingView entry alert.

  • Return to the TradingView tab and click on the settings button on our entry alert as shown in the image below.

  • Paste the JSON code that we copied from AlgoTest in the Message box of the alert as shown in the image below. After pasting the JSON code in the message box, we need to copy the webhook URL from AlgoTest and paste it into the webhook URL field of the same alert.

  • Navigate to the AlgoTest tab and click 'I have pasted.' The webhook URL will be shown, along with a 'Copy' button. Click 'Copy,' as seen in the figure below. This webhook URL must be pasted into the 'Notification' page we accessed in the previous step.

  • Then, as seen in the figure below, enter the copied Webhook URL into the 'Webhook URL' space under the 'Notification' tab and click on the Create button. If the Webhook URL is already filled in, please be sure to clear it before inserting the copied URL.

  • Our TradingView Entry alert has now been successfully established. The next step is to set up an exit alert. Return to the AlgoTest page, and you'll see an option for adding an exit alert (optional), as seen in the image below.

  • Click 'Add Exit Alert,' as seen in the figure above.

-Give it a distinct name and save the alert configuration.

-Then you'll notice a JSON block message. Make a copy of this message. 

-Go back to the TradingView tab.
We had already created an exit alert in TradingView. We need to paste this JSON code in the message box of the exit alert.

  • Paste the JSON Code in the message box of the exit alert as shown in the image below.

  • Now we need to copy the webhook URL from AlgoTest and paste that into the exit alert. To copy the webhook URL from AlgoTest, go to the AlgoTest tab, click on "I have pasted" and copy the webhook URL as shown in the image below.

  • Paste it into the notification tab's 'Webhook URL' option in the alert, just as we did when establishing the entry alert. Click on the save button.

  • Finally, return to the AlgoTest page and click on 'Start Listening,' as seen in the figure below by the green marker.

  • Your strategy will show up as "listening" on the SIGNAL tab of AlgoTest if all the stages have been followed successfully, as seen in the screenshot below.

Our strategy is now active and prepared to execute the trade in case any alerts are generated in TradingView by the All in one indicator according to our strategy conditions.