Skip to main content

Momentum on Straddle & Strangle Charts (Combined Premium)

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 Momentum on Straddle & Strangle Charts (Combined Premium)​

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("Momentum on Straddle & Strangle Charts",shorttitle = "Momentum on SC", overlay=false)

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

momentum_type = input.string(defval="Percentages", title="Momentum Type",options = ["Percentages", "Points"] , group="Momentum")
momentum_value = input.float(defval=5, title="Momentum Value", group="Momentum")
momentum_dir = input.string(defval="Downwards", title="Momentum direction",options = ["Upwards", "Downwards"] , group="Momentum")


entry_hour = input.int(defval=9, title="Hour", group="Entry Time")
entry_min = input.int(defval=20, title = "Minutes", group="Entry Time")

exit_hour = input.int(defval=15, title="Hour", group="Exit Time")
exit_min = input.int(defval=15, title = "Minutes", group="Exit Time")

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("18", title = "Expiry Day", tooltip = tooltip_day, group="Expiry Date")
_month = input.string("09", 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(52200, "Call Strike", tooltip = tooltip_, group = "Select Strike")
strike_pe = input.int(52200, "Put Strike", tooltip = tooltip_, group = "Select Strike")

// Option to include both strikes
strike_choice = "Combined"

// 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

// 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)


// 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)

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

if dayofweek != dayofweek[1]
buyC := 0
sellC := 0
momentum := na
momentum_calc := false

if hour == exit_hour and minute >= exit_min
if buyC == 1
buyC := 0
sell := true

if sellC == 1
sellC := 0
buy := true

if (hour == entry_hour and minute == entry_min) and not( hour == exit_hour and minute >= exit_min )

momentum_calc := true

if momentum_dir == "Upwards"
if momentum_type == "Points"
momentum := combined_close + momentum_value
if momentum_type == "Percentages"
momentum := combined_close * ( 1 + momentum_value/100)

if momentum_dir == "Downwards"
if momentum_type == "Points"
momentum := combined_close - momentum_value
if momentum_type == "Percentages"
momentum := combined_close * ( 1 - momentum_value/100)


if momentum_calc == true

if momentum_dir == "Upwards" and combined_close >= momentum and buyC == 0
buy := true
buyC := 1
momentum_calc := false

if momentum_dir == "Downwards" and combined_close <= momentum and sellC == 0
sell := true
sellC := 1
momentum_calc := false

plot(momentum, title = "Momentum", color = color.blue, trackprice = true, style = plot.style_linebr)

// 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")

buy := false
sell := false