This algorithm, named "Vega-Shift Credit Spread Expiry," aims to capitalize on short-term opportunities in NIFTY options trading, specifically focusing on credit spreads close to expiry. The core strategy revolves around identifying moments when the implied volatility, reflected in option prices, is likely to shift, thus creating favorable conditions for a credit spread. It utilizes historical option chain data, technical indicators, and proprietary calculated signals, `alpha` and `alpha9`, to predict these shifts. The algorithm analyzes minute-by-minute data, combining price action with volume and open interest changes to pinpoint potential overbought or oversold conditions in specific option strikes. Based on these signals, it aims to execute credit spreads, selling a near-the-money option and buying a further out-of-the-money option to limit risk, profiting from the premium difference if the underlying asset stays within a predicted range.
The signal generation is driven by comparing the `alpha` and `alpha9` values to predefined thresholds (0.7 and 0.3). When `alpha` and `alpha9` are both above 0.7, a credit put spread is initiated; conversely, when both fall below 0.3, a credit call spread is initiated. Risk management is implemented through defining stop-loss and target profit levels calculated as percentages of the initial margin required for the trade. The algorithm dynamically calculates margin requirements and sets stop-loss and target levels based on a percentage of this margin. It considers market open/close times, skips trades on NIFTY expiry dates (can be disabled), and operates only within a specified intraday time window (10:15 AM to 2:15 PM) to align with backtested performance, ensuring trades are executed during optimal market conditions.