VWAP on Straddle & Strangle Strategy
FREE VWAP on Straddle & Strangle Pinescript​
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("VWAP on Straddle & Strangle", overlay = false)
var bool first = true
var strike_gap = map.new<string, int>()
if first
first := false
strike_gap.put("NIFTY", 50)
strike_gap.put("BANKNIFTY", 100)
strike_gap.put("FINNIFTY", 50)
strike_gap.put("MIDCPNIFTY", 25)
spot = input.string( "NIFTY" , title = "Spot Symbol", options = ["NIFTY","BANKNIFTY", "FINNIFTY", "MIDCPNIFTY"], group = "Index")
tooltip_day = "Enter the day of the expiry. Add 0 infront, if day is in single digit. For eg : 05 instead of 5"
tooltip_month = "Enter the month of the expiry. Add 0 infront, if month is in single digit. For eg : 06 instead of 6"
tooltip_year = "Enter the year of the expiry. Use last digit of the year. For eg : 24 instead of 2024"
_day = input.string( "11" , title = "Expiry Day", tooltip = tooltip_day, group="Expiry Date")
_month = input.string( "07" , title = "Expiry Month", tooltip = tooltip_month, group="Expiry Date")
_year = input.string( "24" , title = "Expiry Year", tooltip = tooltip_year, group="Expiry Date")
tooltip_ = "You can select any Strike, you can also have VWAP on Straddle, Strangle"
strike_ce = input.int(24300, "Call Strike", tooltip = tooltip_, group = "Select Strike")
strike_pe = input.int(24300, "Put Strike", tooltip = tooltip_, group = "Select Strike")
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)
[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 )
straddle_open = call_open + put_open
straddle_close = call_close + put_close
straddle_high = math.max(straddle_open, straddle_close)
straddle_low = math.min(straddle_open, straddle_close)
straddle_volume = call_volume + put_volume
var float sumPriceVolume = 0.0
var float sumVolume = 0.0
var float vwap = 0.0
if (dayofweek != dayofweek[1])
sumPriceVolume := 0.0
sumVolume := 0.0
vwap := 0.0
sumPriceVolume += straddle_close * straddle_volume
sumVolume += straddle_volume
vwap := sumPriceVolume / sumVolume
plotcandle ( straddle_open , straddle_high , straddle_low , straddle_close , title = "Straddle" , color = straddle_close > straddle_open ? color.green : color.red )
// vwap = ta.vwap(straddle_close)
plot ( vwap , title = "VWAP on Straddle" , color = color.blue , linewidth = 2 )
entry = straddle_close < vwap and straddle_close[1] >= vwap[1]
exit = straddle_close >= vwap and straddle_close[1] < vwap[1]
plotshape(exit, title = "Exit", text = 'Exit', style = shape.labeldown, location = location.top, color= color.red, textcolor = color.white, size = size.tiny)
plotshape(entry, title = "Entry", text = 'Entry', style = shape.labelup, location = location.bottom, color= color.green, textcolor = color.white, size = size.tiny)
alertcondition(exit, "Exit", "Exit")
alertcondition(entry, "Entry", "Entry")
How to Automate VWAP Straddle Option Selling Strategy​
This document explains the automation of the "VWAP Straddle Strategy," a technical analysis method created to capture theta on expiry days. The strategy uses the Volume Weighted Average Price (VWAP) indicator to pinpoint potential entry and exit points for trades on a Straddle/Strangle chart.
What is the VWAP Straddle Strategy?​
The VWAP Straddle strategy uses the Volume Weighted Average Price (VWAP) technical indicator to spot opportunities for selling straddle or strangle options to capture theta on expiry days. VWAP calculates the average price of a stock based on its trading volume and helps smooth out price fluctuations, revealing the trend of theta.Â
This strategy is used for intraday trading by plotting the VWAP indicator on a Straddle/Strangle chart. When a 1-minute candle closes below VWAP, the straddle is shorted, and when a 1-minute candle closes above VWAP, the short straddle position is exited. You can also use a different time frame according to your preference.
Selecting a timeframe for a strategy is very important. Whether you choose shorter timeframe candles, such as 1, 2, or 5 minutes, or opt for a higher timeframe, like 10 or 15 minutes, it can affect your strategy in both good and bad ways. Let's delve into how different timeframes affect your strategy.
Pros & Cons | Smaller Time Frame (1 minute to 5 minutes) | Higher Time Frame (10-15 minutes and above) |
---|---|---|
Entry & Exit | Using a smaller time frame can provide early entry & exits which helps in targeting a big reward compared to a small stoploss. | Using a higher time frame may result in delayed entry, but it can improve signal accuracy. |
Risk Reward | Using 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. |
Accuracy | Accuracy 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 Trades | Number of Trades is higher with a smaller time frame which may result in higher charges. | Number of trades is lower with a higher time frame |
Risk of Loss | 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 larget losses. |
Market Conditions | Works well in a low-volatility market. | Can perform effectively in both low-volatility and high-volatility markets. |
The Power of the VWAP​
Imagine VWAP as a dynamic line on your trading chart. When the price is above VWAP, it often suggests that the price is in an uptrend and there is a high possibility that it will further go up. When the price is below VWAP, it suggests that the price is in a downtrend and there is a high possibility that it will further go down.
The VWAP Straddle strategy is a theta eater strategy based on the logic that if a straddle/strangle combined price is below VWAP then there is a high possibility that it will go further down to zero. Thus, in the VWAP Straddle strategy, we look for the 1-minute candle to close below VWAP on the straddle/strange chart. You can choose any other time frame as per your preference.Â
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 candle to close below VWAP to initiate short trades, aiming to profit if the price continues its downward journey.
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 opening of the 1-minute candle should be above VWAP and the close of the same 1-minute candle should be below VWAP on a straddle/strangle chart as shown in the image below.
The opening price of the 1-minute candle should be above VWAP, and the closing price of the same 1-minute candle should be below VWAP on a straddle/strangle chart, as shown in the image below.
As shown in the image above, this is a straddle chart of Nifty 28900 CE and 28900 PE. When the highlighted candle closed below the VWAP, it was time to short 28900 CE and 28900 PE.
Exiting Gracefully: Stop-Loss and Take Profit​
No trading strategy is complete without a solid risk management plan. Here's how the VWAP Straddle strategy incorporates stop-loss and take-profit orders:
- Stop-Loss: To minimise potential losses, we will close our Nifty ATM Straddle position if any 1-minute candle closes above VWAP, as depicted in the image below.
- 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:29 on the same day.
Automating VWAP Straddle 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 VWAP Straddle 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 VWAP Straddle Indicator with AlgoTest​
To automate the VWAP Straddle 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 VWAP Straddle strategy gives a sell signal in TradingView, AlgoTest will capture the alert and sell the ATM CE and ATM 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 VWAP Straddle indicator in TradingView​
To incorporate VWAP on a Straddle/Strangle Chart, you can utilise a custom Pine Script code that we have developed. This code will display the VWAP indicator on the chart and enable you to choose option strikes in the settings. To understand how to add the VWAP Straddle 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.
Remember to click on the settings button on the indicator and choose the latest expiry and ATM strike where you want to place the VWAP indicator, as shown in the image below.
For instance, if you want to plot VWAP on the Nifty 1st August 2024 contract 24300 CE & PE Leg, then you should set the inputs as illustrated 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 VWAP Straddle 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 "Add Alert" button as shown in the image below.
- We need to create an alert for two conditions: Short Entry and Short Exit. We'll start by setting up an alert for the Short Entry condition, as illustrated in the image below.
- Similarly, we will create another alert i.e. Short Exit as shown in the image below.
- 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 VWAP Straddle Short 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 Exit 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:00, 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 'Strategy 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 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 and 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 VWAP Straddle indicator according to our strategy conditions.