For the complete documentation index, see llms.txt. This page is also available as Markdown.
Futures to Options Module
The "Futures to Options Execution Module" is a highly modular and extensible Pine Script template designed for advanced TradingView users, particularly those interested in automating options trading based on futures signals. Here’s a concise overview of the template and how traders can build on it:
Sample Template Overview
This module is structured into 8 distinct blocks, each with a specific function:
OpenAlgo API Controls: Connects to OpenAlgo for live execution, allowing integration with real trading APIs.
Backtesting & Risk Controls: Defines trading timeframes, and configurable risk parameters including Stoploss/Target (fixed, percentage, or ATR-based).
Trading Strategy Block: Users can plug in any logic here. The default implementation includes a HalfTrend + ATR channel-based strategy.
Signal Mapping & Intraday Filtering: Converts strategy conditions into buy/sell signals and handles intraday session logic.
Option Symbol Generation & API Messaging: Frames CE/PE option symbols dynamically based on spot price, expiry, and strike intervals.
Trade Execution Logic: Executes trades based on signal, handles square-off and mode control (Enable, Long-only, Short-only).
SL/TP Visualization: Plots stoploss and target markers based on the selected risk model.
Trading Dashboard: Displays real-time trade info (entry/exit signals) on the chart using tables.
Ensure Position Size is handled in the Properties Section
Ensure Alert Message is Set
Creating the Alert
Every block in this template builds its payload into an alert_message on the strategy.entry, strategy.close and strategy.exit calls. Nothing reaches OpenAlgo until you wire that through a TradingView alert.
Add the strategy to the chart, open the alert dialog and choose the strategy (not an indicator condition) as the alert source.
In the Message box put exactly:
That placeholder is what pushes the JSON that Block 5 assembled. If you leave TradingView's default message in place, OpenAlgo receives text it cannot parse and no order is placed.
Under Notifications, tick Webhook URL and enter your OpenAlgo placeorder endpoint:
The template always sends a plain order for a named option symbol, so /api/v1/placeorder is the correct endpoint. Do not point it at /api/v1/placesmartorder, which expects a position_size field the template never emits.
Set the alert to expire as late as TradingView allows, and remember it fires on the strategy's own events, so the alert's trigger condition is driven by the script rather than by a chart condition you pick.
Things to check before going live
Your OpenAlgo instance must be reachable from the internet. TradingView cannot post to 127.0.0.1. Set HOST_SERVER in .env to your tunnel or custom domain.
Expiry is the OpenAlgo expiry in DDMMMYY form, for example 30JAN25. Update it on every rollover, because the script concatenates it into the option symbol verbatim.
Quantity(Lots) is multiplied by LotSize before it is sent, so OpenAlgo receives the total number of units. That matches what the API expects. Keep LotSize in step with the exchange's current lot size.
Strike Interval must match the underlying, for example 50 for NIFTY and 100 for BANKNIFTY, otherwise the strike arithmetic in Block 1 produces a symbol that does not exist.
The spot price used for strike selection is taken from the previous bar (SpotC = SpotC1[1]), which keeps the symbol stable within the bar but means a fast gap can leave the strike one interval behind.
Test with the OpenAlgo API Analyzer switched on before sending real orders.
How Traders Can Use It
Plug-and-Play Strategy Development: Insert your own logic into Block 3 to test strategies like Moving Average Crossovers, RSI signals, or ML-driven logic.
Backtest Ready: Instantly simulate performance with adjustable historical timeframes.
Options Execution: Automatically converts directional futures signals into options trades with customizable offsets.
Risk Management: Activate dynamic SL/TP configurations for robust risk control.
API Alerts: Sends alert messages structured for API consumption, ready for auto-execution platforms.