{
  "title": "BlazeScript public website reference",
  "source": "https://www.testalgo.com/blaze-script/",
  "scope": "This reference publishes all entries and examples in the current website documentation. It is not a compiler specification or a promise of runtime compatibility. Example snippets may depend on platform-provided instruments, data or other variables; configure those in Cipher AI before running them.",
  "agentNotes": "For code generation, read the relevant function signatures, mandatory and optional parameters, built-in variables and example context. Keep entry, exit and canvas files distinct. Do not invent missing APIs, timeframe formats, instrument bindings or results. If the reference is ambiguous, state the ambiguity and request the runtime details needed to resolve it.",
  "quickStart": "A project uses entry_logic.ta, exit_logic.ta and canvas.ta. Entry logic defines a signal and registers an Entry call. Exit logic can use entry variables and registers Exit. Canvas code can use entry and exit variables to draw results. The examples below reproduce the current website examples without modifying their syntax.",
  "syntaxNotes": [
    "Assign values with =. Use # for comments. Names and spelling follow the individual reference entries.",
    "The platform provides price data such as open, high, low, close and volume. You do not need to import indicator functions in the introductory example.",
    "Examples pass positional arguments, such as EMA(close, 9), and keyword arguments, such as index=1. Use the argument list of the specific function.",
    "Examples use comparisons, arithmetic, and both and/or and &/| conditions. Parenthesize comparisons when combining them with & or |. Follow the documented example for the relevant series operation.",
    "Entry must be a top-level call. The introductory Exit call is also top-level. Buy and Sell are keyword variables in the Entry reference; order_type uses a quoted string.",
    "This documentation does not define a complete grammar, type system or supported Python subset. Do not assume that arbitrary Python libraries or Pine Script functions are supported."
  ],
  "limitations": [
    "Check a function name, capitalization and argument list against this reference before generating code. A grouped reference entry may describe multiple names.",
    "Resolve missing names using the built-in variable reference or the strategy setup. Instrument names such as RELIANCE and banknifty_spot are example context, not user-defined strings.",
    "The source examples are inconsistent about Entry timeframe: the introductory project uses \"5m\", while library examples use numbers such as 5 and 15. Confirm the accepted format in your installed Cipher AI runtime; this page does not silently choose a format.",
    "Some snippets are partial demonstrations with inputs defined elsewhere. Do not present every snippet as a standalone program.",
    "The current website reference does not provide a compiler error-code catalog or a version compatibility matrix. Do not invent error codes or claim examples were executed merely because they appear here."
  ],
  "files": [
    {
      "name": "entry_logic.ta",
      "code": "# --- entry_logic.ta ---\n# Pythonic execution. No imports required.\nfast_ema = EMA(close, 9)\nslow_ema = EMA(close, 21)\n\n# Simple crossing over strategy\nlong_condition = crossover(fast_ema, slow_ema)\n\n# Keyword vars for action, string for order_type\nEntry(index=1, logic=long_condition, timeframe=\"5m\", script=banknifty_spot, action=Buy, order_type=\"MARKET\")"
    },
    {
      "name": "exit_logic.ta",
      "code": "# --- exit_logic.ta ---\n# Variables declared in entry_logic (fast_ema, slow_ema) are natively accessible here.\n\n# Multiple Exit Conditions\nstop_loss = open_pnl < -500\ntake_profit = open_pnl > 1500\ntrend_reversal = crossunder(fast_ema, slow_ema)\n\n# Combine logic\nexit_signal = stop_loss | take_profit | trend_reversal\n\n# Top-level exit call\nExit(index=1, logic=exit_signal, exit_type=\"MARKET\")"
    },
    {
      "name": "canvas.ta",
      "code": "# --- canvas.ta ---\n# Variables from entry & exit logic flow directly into canvas scope.\n\n# Paint the chart background green while Fast EMA is above Slow EMA\ndebug_paint_background(fast_ema > slow_ema, frame=0, color=\"rgba(0, 255, 0, 0.1)\")\n\n# Draw standard indicators on the main chart (frame=0)\ndraw(fast_ema, title=\"Fast 9 EMA\", frame=0, color=\"blue\")\ndraw(slow_ema, title=\"Slow 21 EMA\", frame=0, color=\"orange\")\n\n# Display trade execution visuals natively\nmarker_trades(frame=0, show_pnl=True, show_signal_line=True)"
    }
  ],
  "categories": [
    {
      "category": "Strategy & Execution",
      "items": [
        {
          "name": "Entry",
          "args": "(index, logic, timeframe, script, action, order_type, limit_price)",
          "desc": "Registers strategy entry signals. Must be a top-level call.",
          "example": "# Keyword vars for action, string for order_type\nEntry(index=1, logic=long_condition, timeframe=5, script=banknifty_spot, action=Buy, order_type=\"MARKET\")",
          "hasArgsSection": true,
          "argsSection": {
            "mandatory": [
              {
                "name": "index",
                "desc": "Unique trade identifier."
              },
              {
                "name": "logic",
                "desc": "Boolean condition that triggers the entry."
              },
              {
                "name": "timeframe",
                "desc": "Strategy execution timeframe."
              },
              {
                "name": "script",
                "desc": "Instrument to trade."
              },
              {
                "name": "action",
                "desc": "Trade direction (Buy or Sell)."
              },
              {
                "name": "order_type",
                "desc": "Order execution method (\"MARKET\" or \"LIMIT\")."
              }
            ],
            "optional": [
              {
                "name": "limit_price",
                "desc": "Required only for LIMIT orders. Specifies the exact entry price."
              }
            ],
            "exampleCode": "Entry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)"
          },
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "EMA Crossover",
              "desc": "Entry triggers when EMA 9 crosses above EMA 21 — a classic trend-following setup.",
              "code": "# Fast EMA for short-term trend\nfast_ema = EMA(close, 9)\n# Slow EMA for overall trend direction\nslow_ema = EMA(close, 21)\n# Entry triggers when EMA 9 crosses above EMA 21\nlong_condition = crossover(fast_ema, slow_ema)\n# Register a BUY entry order\nEntry(\n    index=1,\n    logic=long_condition,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)"
            },
            {
              "title": "RSI Momentum",
              "desc": "Entry triggers when RSI rises above 60, indicating bullish momentum.",
              "code": "# Calculate RSI using a 14-period lookback\nrsi_val = RSI(close, 14)\n# Entry triggers when RSI moves above 60,\n# indicating strong bullish momentum\nlong_condition = rsi_val > 60\n# Register a BUY entry order\nEntry(\n    index=1,\n    logic=long_condition,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)"
            },
            {
              "title": "Trend + Momentum",
              "desc": "Combines EMA 20/50 for trend direction and RSI 14 for momentum confirmation. Both must agree before entry.",
              "code": "# EMA 20 is used to identify the short-to-medium term trend\nema20 = EMA(close, 20)\n# EMA 50 is used to identify the overall market direction\nema50 = EMA(close, 50)\n# RSI measures bullish and bearish momentum\nrsi_val = RSI(close, 14)\n# Entry triggers only when:\n# - EMA 20 is above EMA 50 (Bullish Trend)\n# - RSI is above 55 (Bullish Momentum)\nlong_condition = ema20 > ema50 and rsi_val > 55\n# Register a BUY entry order\nEntry(\n    index=1,\n    logic=long_condition,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)"
            }
          ]
        },
        {
          "name": "Exit",
          "args": "(index, logic, exit_price, exit_type)",
          "desc": "Registers strategy exit signals. Must be a top-level call.",
          "example": "# Top-level exit call\nExit(index=1, logic=exit_signal, exit_type=\"MARKET\")",
          "hasArgsSection": true,
          "argsSection": {
            "mandatory": [
              {
                "name": "index",
                "desc": "Trade identifier to close."
              },
              {
                "name": "logic",
                "desc": "Boolean condition that triggers the exit."
              },
              {
                "name": "exit_type",
                "desc": "Exit execution method (\"MARKET\" or \"LIMIT\")."
              }
            ],
            "optional": [
              {
                "name": "exit_price",
                "desc": "Required only for LIMIT exits. Specifies the exact exit price."
              }
            ],
            "exampleCode": "Exit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)"
          },
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "EMA Crossover",
              "desc": "Exit triggers when EMA 9 crosses below EMA 21, signalling the trend has reversed.",
              "code": "# Fast EMA for short-term trend\nfast_ema = EMA(close, 9)\n# Slow EMA for overall trend direction\nslow_ema = EMA(close, 21)\n# Exit triggers when EMA 9 crosses below EMA 21\nlong_exit = crossunder(fast_ema, slow_ema)\n# Close the open position\nExit(\n    index=1,\n    logic=long_exit,\n    exit_type=\"MARKET\"\n)"
            },
            {
              "title": "RSI Momentum",
              "desc": "Exit triggers when RSI falls below 50, indicating momentum is weakening.",
              "code": "# Calculate RSI using a 14-period lookback\nrsi_val = RSI(close, 14)\n# Exit triggers when RSI falls below 50,\n# indicating momentum is weakening\nlong_exit = rsi_val < 50\n# Close the open position\nExit(\n    index=1,\n    logic=long_exit,\n    exit_type=\"MARKET\"\n)"
            },
            {
              "title": "Trend + Momentum",
              "desc": "Exits when either EMA 20 falls below EMA 50 OR RSI drops below 45 — whichever weakens first.",
              "code": "# EMA 20 is used to monitor trend strength\nema20 = EMA(close, 20)\n# EMA 50 is used as the trend filter\nema50 = EMA(close, 50)\n# RSI is used to monitor momentum weakness\nrsi_val = RSI(close, 14)\n# Exit triggers when:\n# - EMA 20 falls below EMA 50 (Trend Reversal)\n# OR\n# - RSI falls below 45 (Momentum Weakness)\nlong_exit = ema20 < ema50 or rsi_val < 45\n# Close the open position\nExit(\n    index=1,\n    logic=long_exit,\n    exit_type=\"MARKET\"\n)"
            }
          ]
        }
      ]
    },
    {
      "category": "Indicators",
      "items": [
        {
          "name": "SMA / EMA / WMA / HMA",
          "args": "(series, length)",
          "desc": "Various Moving Averages (Simple, Exponential, Weighted, Hull).",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "SMA 200 Trend Filter Strategy",
              "desc": "Demonstrates trend filtering using SMA 200.",
              "code": "# ==================================================\n# SMA 200 Trend Filter Strategy\n# Demonstrates trend filtering using SMA 200\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Calculate the 200-period Simple Moving Average.\n#\n# SMA 200 is one of the most widely used\n# long-term trend indicators.\nsma_200 = SMA(close, 200)\n# Market is considered bullish when\n# price is trading above the SMA 200.\nuptrend = close > sma_200\n# Buy only when:\n#\n# 1. Price crosses above SMA 200\n# 2. Market is in an uptrend\nbuy_signal = crossover(close, sma_200) & uptrend\n# Enter a long position.\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit when price falls below SMA 200.\n#\n# This suggests the long-term trend\n# may be weakening.\nsell_signal = close < sma_200\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Calculate SMA 200 again for chart display.\nsma_200 = SMA(close, 200)\n# Determine trend direction.\nuptrend = close > sma_200\n# Plot SMA 200 on the chart.\n#\n# Many traders use this line to determine\n# whether a market is bullish or bearish.\ndraw(\n    sma_200,\n    title=\"SMA 200\",\n    frame=0,\n    color=\"yellow\"\n)\n# Mark buy signals.\n#\n# Green triangles appear when price\n# crosses above the SMA 200.\ndrawshape(\n    condition=crossover(close, sma_200),\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"normal\"\n)\n# Mark sell signals.\n#\n# Red triangles appear when price\n# falls below the SMA 200.\ndrawshape(\n    condition=close < sma_200,\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\",\n    size=\"normal\"\n)\n# Display trend information.\nmarker_text(\n    frame=0,\n    text=\"SMA 200 Trend Filter\",\n    anchor=\"top_right\"\n)\n# Display strategy statistics.\nmarker_table(\n    frame=0,\n    data=[\n        [\"Trend Filter\", \"SMA 200\"],\n        [\"Uptrend\", uptrend]\n    ],\n    position=\"bottom_right\"\n)\n# Show completed trades and PnL.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "EMA Crossover Strategy",
              "desc": "Demonstrates crossover entry and crossunder exit using two EMAs.",
              "code": "# =================================================\n# EMA Crossover Strategy\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Calculate the fast EMA.\n#\n# EMA 9 reacts quickly to recent\n# price movements.\nfast_ema = EMA(close, 9)\n# Calculate the slow EMA.\n#\n# EMA 21 reacts more slowly and helps\n# identify the broader trend.\nslow_ema = EMA(close, 21)\n# Bullish crossover occurs when the\n# fast EMA crosses above the slow EMA.\n#\n# This suggests bullish momentum may\n# be starting.\nbullish_cross = crossover(fast_ema, slow_ema)\n# Enter a long position when a\n# bullish crossover occurs.\nEntry(\n    index=1,\n    logic=bullish_cross,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit when the fast EMA crosses\n# below the slow EMA.\n#\n# This suggests bullish momentum\n# is weakening.\nbearish_cross = crossunder(fast_ema, slow_ema)\nExit(\n    index=1,\n    logic=bearish_cross,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Calculate the fast EMA.\nfast_ema = EMA(close, 9)\n# Calculate the slow EMA.\nslow_ema = EMA(close, 21)\n# Bullish crossover signal.\nbullish_cross = crossover(fast_ema, slow_ema)\n# Bearish crossover signal.\nbearish_cross = crossunder(fast_ema, slow_ema)\n# Plot the fast EMA.\n#\n# Green line follows price more closely.\ndraw(\n    fast_ema,\n    title=\"EMA 9\",\n    frame=0,\n    color=\"green\"\n)\n# Plot the slow EMA.\n#\n# Red line reacts more slowly and\n# filters market noise.\ndraw(\n    slow_ema,\n    title=\"EMA 21\",\n    frame=0,\n    color=\"red\"\n)\n# Draw a green triangle whenever\n# a bullish crossover occurs.\ndrawshape(\n    condition=bullish_cross,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"normal\"\n)\n# Draw a red triangle whenever\n# a bearish crossover occurs.\ndrawshape(\n    condition=bearish_cross,\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\",\n    size=\"normal\"\n)\n# Display strategy name.\nmarker_text(\n    frame=0,\n    text=\"EMA Crossover Strategy\",\n    anchor=\"top_right\"\n)\n# Show current EMA values.\nmarker_table(\n    frame=0,\n    data=[\n        [\"EMA 9\", round(fast_ema, 2)],\n        [\"EMA 21\", round(slow_ema, 2)]\n    ],\n    position=\"bottom_right\"\n)\n# Display completed trades and PnL.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "WMA Rejection Strategy",
              "desc": "Demonstrates WMA() based rejection strategy.",
              "code": "# ==================================================\n# WMA Rejection Strategy\n# Demonstrates WMA()\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Calculate the 30-period Weighted Moving Average.\n#\n# WMA gives more importance to recent prices\n# compared to a Simple Moving Average.\nwma_30 = WMA(close, 30)\n# Price rejection above WMA.\n#\n# Condition becomes TRUE when the entire candle\n# remains above the WMA.\n#\n# This suggests buyers are defending the trend.\nbullish = low > wma_30\n# Enter a long position whenever\n# the bullish condition is satisfied.\nEntry(\n    index=1,\n    logic=bullish,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit when price falls below WMA.\n#\n# This suggests trend strength may be weakening.\nsell_signal = close < wma_30\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Calculate WMA 30 again for visualization.\nwma_30 = WMA(close, 30)\n# Plot the WMA on the chart.\n#\n# The line reacts faster than an SMA\n# because recent prices receive more weight.\ndraw(\n    wma_30,\n    title=\"WMA 30\",\n    frame=0,\n    color=\"orange\"\n)\n# Bullish rejection condition.\n#\n# Entire candle remains above WMA.\nbullish = low > wma_30\n# Bearish condition.\n#\n# Price closes below WMA.\nbearish = close < wma_30\n# Mark bullish rejection candles.\ndrawshape(\n    condition=bullish,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"normal\"\n)\n# Mark bearish candles.\ndrawshape(\n    condition=bearish,\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\",\n    size=\"normal\"\n)\n# Display strategy name.\nmarker_text(\n    frame=0,\n    text=\"WMA 30 Rejection Strategy\",\n    anchor=\"top_right\"\n)\n# Display WMA information.\nmarker_table(\n    frame=0,\n    data=[\n        [\"WMA 30\", round(wma_30, 2)],\n        [\"Bullish\", bullish]\n    ],\n    position=\"bottom_right\"\n)\n# Display completed trades and PnL.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "RSI",
          "args": "(series, period)",
          "desc": "Relative Strength Index.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "RSI Bullish Momentum Strategy",
              "desc": "Buy when RSI crosses above 50, indicating bullish momentum.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate 14-period RSI\nrsi_val = RSI(close, 14)\n# Buy when RSI crosses above 50, indicating bullish momentum\nbuy_signal = crossover(rsi_val, 50)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when RSI crosses below 50, indicating bearish momentum\nsell_signal = crossunder(rsi_val, 50)\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot RSI in a separate panel\ndraw(\n    rsi_val,\n    title=\"RSI (14)\",\n    frame=1,\n    color=\"blue\",\n    y_range=[0,100]\n)\n# Display Entry and Exit markers on the chart\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "RSI Bearish Momentum Strategy",
              "desc": "Sell when RSI crosses below 50, indicating bearish momentum.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate 14-period RSI\nrsi_val = RSI(close, 14)\n# Sell when RSI crosses below 50, indicating bearish momentum\nsell_signal = crossunder(rsi_val, 50)\nEntry(\n    index=1,\n    logic=sell_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Sell,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when RSI crosses above 50, indicating bullish momentum\nbuy_signal = crossover(rsi_val, 50)\nExit(\n    index=1,\n    logic=buy_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot RSI in a separate panel\ndraw(\n    rsi_val,\n    title=\"RSI (14)\",\n    frame=1,\n    color=\"blue\",\n    y_range=[0,100]\n)\n# Display Entry and Exit markers on the chart\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Volume RSI Strategy",
              "desc": "Use volume instead of price to calculate RSI.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate 14-period RSI using Volume instead of Price\nrsi_volume = RSI(volume, 14)\n# Buy when Volume RSI crosses above 50, indicating increasing buying activity\nbuy_signal = crossover(rsi_volume, 50)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when Volume RSI crosses below 50, indicating weakening buying activity\nsell_signal = crossunder(rsi_volume, 50)\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot Volume RSI\ndraw(\n    rsi_volume,\n    title=\"RSI Volume\",\n    frame=1,\n    color=\"red\"\n)\n# Overbought level\ndraw(\n    80,\n    title=\"Overbought\",\n    frame=1,\n    color=\"red\"\n)\n# Midline\ndraw(\n    50,\n    title=\"Midline\",\n    frame=1,\n    color=\"white\"\n)\n# Oversold level\ndraw(\n    20,\n    title=\"Oversold\",\n    frame=1,\n    color=\"green\"\n)\n# Display Entry and Exit markers\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "MACD",
          "args": "(source, fastlen, slowlen, siglen)",
          "desc": "Moving Average Convergence Divergence. Returns [macd, signal, hist].",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "RSI Snapshot Strategy",
              "desc": "Capture indicator values exactly when RSI crosses 70.",
              "code": "# ==================================================\n# RSI Snapshot Strategy | entry_logic.ta\n# ==================================================\nema20 = EMA(close, 20)\nrsi14 = RSI(close, 14)\natr14 = ATR(14)\ntrend_up = close > ema20\nrsi_entry = crossover(rsi14, 50)\nbuy_signal = trend_up & rsi_entry\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# exit_logic.ta\n# ==================================================\noverbought = crossover(rsi14, 70)\n# Capture indicator values exactly when RSI crosses 70\nlog_snapshot_on_event(\n    overbought,\n    close_price=close,\n    ema20=ema20,\n    rsi_value=rsi14,\n    atr_value=atr14,\n    open_profit=open_pnl,\n    bars_held=bars_in_trade\n)\nexit_signal = overbought | DayLastBar\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# ==================================================\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\ndraw(\n    rsi14,\n    title=\"RSI 14\",\n    frame=1,\n    color=\"purple\"\n)\ndraw(\n    70,\n    title=\"Overbought\",\n    frame=1,\n    color=\"red\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)\ndrawshape(\n    condition=buy_signal,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"green\",\n    size=\"small\"\n)"
            },
            {
              "title": "MACD Snapshot Strategy",
              "desc": "Capture market state at exit using log_snapshot_on_event with MACD.",
              "code": "# ==================================================\n# MACD Snapshot Strategy | entry_logic.ta\n# ==================================================\n# Indicators\nmacd_line, signal_line, histogram = MACD(close, 12, 26, 9)\nema50 = EMA(close, 50)\n# Entry Conditions\ntrend_up = close > ema50\nmacd_bull = crossover(macd_line, signal_line)\nlong_entry = trend_up & macd_bull\nEntry(\n    index=1,\n    logic=long_entry,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# exit_logic.ta\n# ==================================================\n# Exit Condition\nmacd_bear = crossunder(macd_line, signal_line)\n# Capture market state at exit\nlog_snapshot_on_event(\n    macd_bear,\n    close_price=close,\n    macd=macd_line,\n    signal=signal_line,\n    histogram=histogram,\n    ema50=ema50,\n    pnl=open_pnl,\n    bars=bars_in_trade\n)\nExit(\n    index=1,\n    logic=macd_bear,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# ==================================================\ndraw(\n    ema50,\n    title=\"EMA 50\",\n    frame=0,\n    color=\"orange\"\n)\ndraw(\n    macd_line,\n    title=\"MACD\",\n    frame=1,\n    color=\"blue\"\n)\ndraw(\n    signal_line,\n    title=\"Signal\",\n    frame=1,\n    color=\"red\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)\ndrawshape(\n    condition=long_entry,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"green\",\n    size=\"small\"\n)"
            }
          ]
        },
        {
          "name": "bb",
          "args": "(series, length, mult)",
          "desc": "Bollinger Bands. Returns [mid, upper, lower].",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Bollinger Bands Breakout Strategy",
              "desc": "Buy when price breaks above the Upper Band.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate Bollinger Bands (20 Period, 2 Standard Deviations)\nupper_band, middle_band, lower_band = bb(close, 20, 2)\n# Buy when price breaks above the Upper Band,\n# indicating a bullish breakout\nbuy_signal = crossover(close, upper_band)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price crosses below the Middle Band,\n# indicating bullish momentum is weakening\nexit_signal = crossunder(close, middle_band)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot Bollinger Bands\ndraw(\n    upper_band,\n    title=\"BB Upper\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    middle_band,\n    title=\"BB Middle\",\n    frame=0,\n    color=\"white\"\n)\ndraw(\n    lower_band,\n    title=\"BB Lower\",\n    frame=0,\n    color=\"green\"\n)\n# Highlight the Bollinger Band range\nmarker_fill(\n    frame=0,\n    line1=upper_band,\n    line2=lower_band,\n    color=\"rgba(0,150,255,0.08)\"\n)\n# Mark Buy signals\ndrawshape(\n    condition=buy_signal,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"small\"\n)\n# Display executed trades\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Bollinger Bands Reversal Strategy",
              "desc": "Buy when price crosses back above the Lower Band.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate Bollinger Bands (20 Period, 2 Standard Deviations)\nupper_band, middle_band, lower_band = bb(close, 20, 2)\n# Buy when price crosses back above the Lower Band,\n# indicating a potential reversal from an oversold condition\nbuy_signal = crossover(close, lower_band)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price reaches the Middle Band,\n# which acts as the mean of the Bollinger Bands\nexit_signal = crossover(close, middle_band)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# Bollinger Bands Indicator\n# Displays the Upper, Middle, and Lower Bollinger Bands.\n# ==================================================\ndraw(\n    upper_band,\n    title=\"BB Upper\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    middle_band,\n    title=\"BB Middle\",\n    frame=0,\n    color=\"white\"\n)\ndraw(\n    lower_band,\n    title=\"BB Lower\",\n    frame=0,\n    color=\"green\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "SuperTrend",
          "args": "(atrPeriod=10, factor=3.0)",
          "desc": "SuperTrend indicator. Returns (trend, dir).",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "SuperTrend Strategy 1",
              "desc": "Buy when SuperTrend turns bullish.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate SuperTrend\nst_val, st_dir = SuperTrend(atrPeriod=10, factor=3.0)\n# Buy when SuperTrend turns bullish\nbuy_signal = st_dir == 1\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when SuperTrend turns bearish\nexit_signal = st_dir == -1\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot SuperTrend\ndraw(\n    st_val,\n    title=\"SuperTrend\",\n    frame=0,\n    color=\"green\"\n)\n# Display Entry and Exit markers\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "SuperTrend Strategy 2",
              "desc": "Buy when SuperTrend changes from bearish to bullish.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate SuperTrend\nst_val, st_dir = SuperTrend(\n    atrPeriod=10,\n    factor=3.0\n)\n# Buy when SuperTrend changes from bearish to bullish\nbuy_signal = crossover(st_dir, 0)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when SuperTrend changes from bullish to bearish\nexit_signal = crossunder(st_dir, 0)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot SuperTrend\ndraw(\n    st_val,\n    title=\"SuperTrend\",\n    frame=0,\n    color=\"green\"\n)\n# Mark Buy signals\ndrawshape(\n    condition=buy_signal,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"small\"\n)\n# Strategy name\nmarker_text(\n    frame=0,\n    text=\"SuperTrend Strategy\",\n    anchor=\"top_right\"\n)\n# Display Entry and Exit markers\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "VWAP",
          "args": "(source=hlc3)",
          "desc": "Volume-Weighted Average Price.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "VWAP Strategy 1",
              "desc": "Buy when price crosses above VWAP.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate VWAP\nvwap_line = VWAP(ohlc4)\n# Buy when price crosses above VWAP,\n# indicating bullish momentum\nbuy_signal = crossover(close, vwap_line)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price crosses below VWAP,\n# indicating weakening bullish momentum\nexit_signal = crossunder(close, vwap_line)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# VWAP Indicator\n# Displays Volume Weighted Average Price (VWAP).\n# ==================================================\ndraw(\n    vwap_line,\n    title=\"VWAP\",\n    frame=0,\n    color=\"yellow\"\n)\nmarker_text(\n    frame=0,\n    text=\"VWAP Indicator\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "VWAP Strategy 2",
              "desc": "Buy when price crosses above VWAP.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate VWAP\nvwap_val = VWAP(hlc3)\n# Buy when price crosses above VWAP,\n# indicating bullish momentum\nbuy_signal = crossover(close, vwap_val)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price crosses below VWAP,\n# indicating bearish momentum\nexit_signal = crossunder(close, vwap_val)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot VWAP\ndraw(\n    vwap_val,\n    title=\"VWAP\",\n    frame=0,\n    color=\"yellow\"\n)\n# Mark Buy signals\ndrawshape(\n    condition=buy_signal,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"small\"\n)\n# Display Entry and Exit markers\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "Ichimoku",
          "args": "(conversionLinePeriod, baseLinePeriod, ...)",
          "desc": "Returns [tenkan, kijun, senkou_a, senkou_b, chikou].",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Tenkan & Kijun Crossover Strategy",
              "desc": "Buy when the Tenkan Line crosses above the Kijun Line.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate Ichimoku Cloud\ntenkan, kijun, senkou_a, senkou_b, chikou = Ichimoku(\n    9,\n    26,\n    52,\n    26\n)\n# Buy when the Tenkan Line crosses above the Kijun Line,\n# indicating a bullish trend reversal\nbuy_signal = crossover(tenkan, kijun)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when the Tenkan Line crosses below the Kijun Line,\n# indicating a bearish trend reversal\nexit_signal = crossunder(tenkan, kijun)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# Ichimoku Cloud Indicator\n# Displays all Ichimoku Cloud components.\n# ==================================================\ndraw(\n    tenkan,\n    title=\"Tenkan\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    kijun,\n    title=\"Kijun\",\n    frame=0,\n    color=\"blue\"\n)\ndraw(\n    senkou_a,\n    title=\"Senkou A\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    senkou_b,\n    title=\"Senkou B\",\n    frame=0,\n    color=\"orange\"\n)\ndraw(\n    chikou,\n    title=\"Chikou\",\n    frame=0,\n    color=\"purple\"\n)\n# Cloud Area\nmarker_fill(\n    frame=0,\n    line1=senkou_a,\n    line2=senkou_b,\n    color=\"rgba(0,255,0,0.08)\"\n)\nmarker_text(\n    frame=0,\n    text=\"Ichimoku Cloud\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Cloud Breakout Strategy",
              "desc": "Buy when price breaks above the Ichimoku Cloud.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate Ichimoku Cloud\ntenkan, kijun, senkou_a, senkou_b, chikou = Ichimoku(\n    9,\n    26,\n    52,\n    26\n)\n# Buy when price breaks above the Ichimoku Cloud,\n# indicating a strong bullish trend\nbuy_signal = crossover(close, senkou_a)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price falls below the Kijun Line,\n# indicating the bullish trend is weakening\nexit_signal = crossunder(close, kijun)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# Ichimoku Cloud Indicator\n# Displays all Ichimoku Cloud components.\n# ============================================================\ndraw(\n    tenkan,\n    title=\"Tenkan\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    kijun,\n    title=\"Kijun\",\n    frame=0,\n    color=\"blue\"\n)\ndraw(\n    senkou_a,\n    title=\"Senkou A\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    senkou_b,\n    title=\"Senkou B\",\n    frame=0,\n    color=\"orange\"\n)\ndraw(\n    chikou,\n    title=\"Chikou\",\n    frame=0,\n    color=\"purple\"\n)\nmarker_fill(\n    frame=0,\n    line1=senkou_a,\n    line2=senkou_b,\n    color=\"rgba(0,255,0,0.08)\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "ATR / STDDEV",
          "args": "(length)",
          "desc": "Average True Range and Standard Deviation volatility indicators.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "High Volatility ATR Strategy",
              "desc": "Buy when current ATR is greater than the 50-period ATR.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate ATR\natr_val = ATR(14)\n# Buy when current ATR is greater than the 50-period ATR,\n# indicating increasing market volatility\nbuy_signal = atr_val > ATR(50)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when current ATR falls below the 50-period ATR,\n# indicating volatility is decreasing\nexit_signal = atr_val < ATR(50)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ATR Indicator\n# Displays the current ATR and the 50-period ATR.\n# ============================================================\ndraw(\n    atr_val,\n    title=\"ATR (14)\",\n    frame=1,\n    color=\"orange\"\n)\ndraw(\n    ATR(50),\n    title=\"ATR (50)\",\n    frame=1,\n    color=\"blue\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Volatility Expansion STDDEV Strategy",
              "desc": "Buy when volatility increases above its recent average.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate Standard Deviation\nstd_20 = STDDEV(close, 20)\n# Buy when volatility increases above its recent average\nbuy_signal = crossover(std_20, SMA(std_20, 10))\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when volatility falls below its recent average\nexit_signal = crossunder(std_20, SMA(std_20, 10))\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# Standard Deviation Indicator\n# ============================================================\ndraw(\n    std_20,\n    title=\"STDDEV 20\",\n    frame=1,\n    color=\"orange\"\n)\ndraw(\n    SMA(std_20, 10),\n    title=\"STDDEV SMA\",\n    frame=1,\n    color=\"blue\"\n)\nmarker_text(\n    frame=1,\n    text=\"STDDEV Indicator\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "ATR Trend Filter Strategy",
              "desc": "Buy when price crosses above the EMA during high volatility.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate EMA and ATR\nema20 = EMA(close, 20)\natr14 = ATR(14)\n# Buy when price crosses above the EMA during high volatility\nbuy_signal = crossover(close, ema20) & (atr14 > 10)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price falls below the EMA\nexit_signal = crossunder(close, ema20)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ATR Trend Filter Strategy\n# ============================================================\n# EMA\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\n# ATR\ndraw(\n    atr14,\n    title=\"ATR 14\",\n    frame=1,\n    color=\"orange\"\n)\n# ATR Threshold\ndraw(\n    10,\n    title=\"Volatility Threshold\",\n    frame=1,\n    color=\"red\"\n)\n# Display trades\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)\nmarker_text(\n    frame=0,\n    text=\"ATR Trend Filter\",\n    anchor=\"top_right\"\n)"
            }
          ]
        },
        {
          "name": "Stochastic",
          "args": "(source, high, low, length)",
          "desc": "Stochastic Oscillator momentum indicator.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Stochastic Overbought / Oversold Reversal Strategy",
              "desc": "Buy when %K crosses above %D in the oversold zone.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate Stochastic\nk_line, d_line = Stochastic(close, high, low, 14, 3, 3)\n# Buy when %K crosses above %D in the oversold zone\nbuy_zone = (k_line < 20) | (d_line < 20)\nbuy_signal = crossover(k_line, d_line) & buy_zone\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Calculate Stochastic\nk_line, d_line = Stochastic(close, high, low, 14, 3, 3)\n# Exit when %K crosses below %D in the overbought zone\nsell_zone = (k_line > 80) | (d_line > 80)\nexit_signal = crossunder(k_line, d_line) & sell_zone\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Calculate Stochastic\nk_line, d_line = Stochastic(close, high, low, 14, 3, 3)\n# Overbought / Oversold Levels\nob_line = k_line * 0 + 80\nos_line = k_line * 0 + 20\n# Plot %K and %D\ndraw(\n    k_line,\n    title=\"%K Line\",\n    frame=1,\n    color=\"#00FFFF\"\n)\ndraw(\n    d_line,\n    title=\"%D Line\",\n    frame=1,\n    color=\"#FFA500\"\n)\ndraw(\n    ob_line,\n    title=\"Overbought\",\n    frame=1,\n    color=\"#FF3333\"\n)\ndraw(\n    os_line,\n    title=\"Oversold\",\n    frame=1,\n    color=\"#33FF33\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Stochastic Bullish Momentum Strategy",
              "desc": "Buy when %K crosses above %D while both are above 50.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate Stochastic\nk_line, d_line = Stochastic(close, high, low, 14, 3, 3)\n# Buy when %K crosses above %D while both are above 50,\n# indicating bullish momentum\nbuy_signal = crossover(k_line, d_line) & (k_line > 50)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when %K crosses below %D or falls below 50,\n# indicating weakening momentum\nexit_signal = crossunder(k_line, d_line) | (k_line < 50)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot %K and %D\ndraw(\n    k_line,\n    title=\"%K Line\",\n    frame=1,\n    color=\"#00FFFF\"\n)\ndraw(\n    d_line,\n    title=\"%D Line\",\n    frame=1,\n    color=\"#FFA500\"\n)\n# Midline\ndraw(\n    50,\n    title=\"Midline\",\n    frame=1,\n    color=\"white\"\n)\n# Overbought\ndraw(\n    80,\n    title=\"Overbought\",\n    frame=1,\n    color=\"#FF3333\"\n)\n# Oversold\ndraw(\n    20,\n    title=\"Oversold\",\n    frame=1,\n    color=\"#33FF33\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "DMI",
          "args": "(diLength=14, adxSmoothing=14)",
          "desc": "Directional Movement Index. Returns [di_plus, di_minus, adx].",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "DMI Crossover Strategy",
              "desc": "Buy when +DI crosses above -DI.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate DMI Components\ndi_plus, di_minus, adx = DMI(14, 14)\n# Buy when +DI crosses above -DI,\n# indicating buyers are gaining strength\nbuy_signal = crossover(di_plus, di_minus)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when -DI crosses above +DI,\n# indicating sellers are gaining strength\nexit_signal = crossover(di_minus, di_plus)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot +DI\ndraw(\n    di_plus,\n    title=\"+DI\",\n    frame=1,\n    color=\"green\"\n)\n# Plot -DI\ndraw(\n    di_minus,\n    title=\"-DI\",\n    frame=1,\n    color=\"red\"\n)\n# Plot ADX\ndraw(\n    adx,\n    title=\"ADX\",\n    frame=1,\n    color=\"orange\"\n)\nmarker_text(\n    frame=1,\n    text=\"DMI Indicator\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Strong Trend DMI Strategy",
              "desc": "Buy when ADX rises above 25 and DI+ is greater than DI-.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate DMI Components\ndi_plus, di_minus, adx = DMI(\n    diLength=14,\n    adxSmoothing=14\n)\n# Buy when ADX rises above 25 and DI+ is greater than DI-,\n# indicating a strong bullish trend\nbuy_signal = crossover(adx, 25) & (di_plus > di_minus)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when DI- becomes greater than DI+,\n# indicating bearish strength\nexit_signal = di_minus > di_plus\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# DMI Indicator\n# Displays DI+, DI-, and ADX trend strength lines.\n# ==================================================\ndi_plus, di_minus, adx = DMI(\n    diLength=14,\n    adxSmoothing=14\n)\ndraw(\n    di_plus,\n    title=\"DI+\",\n    frame=1,\n    color=\"green\"\n)\ndraw(\n    di_minus,\n    title=\"DI-\",\n    frame=1,\n    color=\"red\"\n)\ndraw(\n    adx,\n    title=\"ADX\",\n    frame=1,\n    color=\"yellow\"\n)\ndraw(\n    25,\n    title=\"Trend Strength\",\n    frame=1,\n    color=\"white\"\n)\nmarker_text(\n    frame=1,\n    text=\"DMI Indicator\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "PSAR",
          "args": "(start_af=0.02, step_af=0.02, max_af=0.20)",
          "desc": "Parabolic Stop and Reverse.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "PSAR Trend Reversal Strategy",
              "desc": "Buy when PSAR flips below the price.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate PSAR\npsar_val = PSAR(0.02, 0.02, 0.20)\n# Buy when PSAR flips below the price,\n# indicating the start of an uptrend\nbuy_signal = psar_val < close\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when PSAR moves above the price,\n# indicating a possible trend reversal\nexit_signal = psar_val > close\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# Parabolic SAR Indicator\n# Displays trend reversal levels.\n# ============================================================\npsar_val = PSAR(0.02, 0.02, 0.20)\ndraw(\n    psar_val,\n    title=\"PSAR\",\n    frame=0,\n    color=\"orange\"\n)\nmarker_text(\n    frame=0,\n    text=\"PSAR Indicator\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "PSAR + EMA Trend Filter Strategy",
              "desc": "Buy when price crosses above the 20 EMA while remaining above the PSAR.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate PSAR and EMA\npsar_val = PSAR(0.02, 0.02, 0.20)\nema20 = EMA(close, 20)\n# Buy when price crosses above the 20 EMA\n# while remaining above the PSAR\nbuy_signal = crossover(close, ema20) & (close > psar_val)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price closes below the PSAR\nexit_signal = crossunder(close, psar_val)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Calculate PSAR and EMA\npsar_val = PSAR(0.02, 0.02, 0.20)\nema20 = EMA(close, 20)\n# Plot PSAR\ndraw(\n    psar_val,\n    title=\"PSAR\",\n    frame=0,\n    color=\"orange\"\n)\n# Plot EMA\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\nmarker_text(\n    frame=0,\n    text=\"PSAR + EMA Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "CCI",
          "args": "(source=hlc3, length=20)",
          "desc": "Commodity Channel Index.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "CCI Oversold Recovery Strategy",
              "desc": "Buy when CCI crosses above -100.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate CCI\ncci_val = CCI(hlc3, 20)\n# Buy when CCI crosses above -100,\n# indicating recovery from an oversold condition\nbuy_signal = crossover(cci_val, -100)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when CCI enters the overbought zone\nexit_signal = cci_val > 100\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# CCI Indicator\n# ============================================================\n# Plot CCI\ndraw(\n    cci_val,\n    title=\"CCI (20)\",\n    frame=1,\n    color=\"orange\"\n)\n# Overbought Level\ndraw(\n    100,\n    title=\"Overbought\",\n    frame=1,\n    color=\"red\"\n)\n# Oversold Level\ndraw(\n    -100,\n    title=\"Oversold\",\n    frame=1,\n    color=\"green\"\n)\n# Zero Line\ndraw(\n    0,\n    title=\"Zero Line\",\n    frame=1,\n    color=\"white\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "CCI Zero Line Crossover Strategy",
              "desc": "Buy when CCI crosses above the Zero Line.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate CCI\ncci_val = CCI(hlc3, 20)\n# Buy when CCI crosses above the Zero Line,\n# indicating bullish momentum\nbuy_signal = crossover(cci_val, 0)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when CCI crosses below the Zero Line,\n# indicating bearish momentum\nexit_signal = crossunder(cci_val, 0)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# CCI Indicator\n# ============================================================\ndraw(\n    cci_val,\n    title=\"CCI (20)\",\n    frame=1,\n    color=\"orange\"\n)\ndraw(\n    100,\n    title=\"Overbought\",\n    frame=1,\n    color=\"red\"\n)\ndraw(\n    0,\n    title=\"Zero Line\",\n    frame=1,\n    color=\"white\"\n)\ndraw(\n    -100,\n    title=\"Oversold\",\n    frame=1,\n    color=\"green\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "PivotPoints",
          "args": "()",
          "desc": "Returns [P, BC, TC, R1, S1, R2, S2, R3, S3].",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Pivot Crossover Strategy",
              "desc": "Buy when price crosses above the Pivot Point.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate Pivot Points\nP, BC, TC, R1, S1, R2, S2, R3, S3 = PivotPoints()\n# Buy when price crosses above the Pivot Point,\n# indicating bullish momentum\nbuy_signal = crossover(close, P)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price reaches the first resistance level\nexit_signal = crossover(close, R1)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# Pivot Point Indicator\n# ============================================================\nP, BC, TC, R1, S1, R2, S2, R3, S3 = PivotPoints()\ndraw(\n    P,\n    title=\"Pivot\",\n    frame=0,\n    color=\"white\"\n)\ndraw(\n    BC,\n    title=\"Bottom Central\",\n    frame=0,\n    color=\"cyan\"\n)\ndraw(\n    TC,\n    title=\"Top Central\",\n    frame=0,\n    color=\"cyan\"\n)\ndraw(\n    R1,\n    title=\"Resistance 1\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    S1,\n    title=\"Support 1\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    R2,\n    title=\"Resistance 2\",\n    frame=0,\n    color=\"#FF8800\"\n)\ndraw(\n    S2,\n    title=\"Support 2\",\n    frame=0,\n    color=\"#00AA00\"\n)\nmarker_text(\n    frame=0,\n    text=\"Pivot Point Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Pivot Support Bounce Strategy",
              "desc": "Buy when price bounces above Support 1.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate Pivot Points\nP, BC, TC, R1, S1, R2, S2, R3, S3 = PivotPoints()\n# Buy when price bounces above Support 1,\n# indicating buyers are defending the support level\nbuy_signal = crossover(close, S1)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price reaches the Pivot Point\nexit_signal = crossover(close, P)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# Pivot Point Indicator\n# ============================================================\nP, BC, TC, R1, S1, R2, S2, R3, S3 = PivotPoints()\ndraw(P,  title=\"Pivot\", frame=0, color=\"white\")\ndraw(BC, title=\"BC\", frame=0, color=\"cyan\")\ndraw(TC, title=\"TC\", frame=0, color=\"cyan\")\ndraw(R1, title=\"R1\", frame=0, color=\"red\")\ndraw(S1, title=\"S1\", frame=0, color=\"green\")\ndraw(R2, title=\"R2\", frame=0, color=\"#FF8800\")\ndraw(S2, title=\"S2\", frame=0, color=\"#00AA00\")\ndraw(R3, title=\"R3\", frame=0, color=\"#FF4444\")\ndraw(S3, title=\"S3\", frame=0, color=\"#008800\")\nmarker_text(\n    frame=0,\n    text=\"Pivot Support Bounce\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "DonchianChannels",
          "args": "(length=20)",
          "desc": "Returns [upper, mid, lower].",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Donchian Channel Breakout Strategy",
              "desc": "Buy when price breaks above the Upper Channel.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate Donchian Channels\ndc_upper, dc_mid, dc_lower = DonchianChannels(20)\n# Buy when price breaks above the Upper Channel,\n# indicating a bullish breakout\nbuy_signal = crossover(close, dc_upper)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price falls below the Middle Channel,\n# indicating the trend is weakening\nexit_signal = crossunder(close, dc_mid)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# Donchian Channels Indicator\n# ============================================================\ndc_upper, dc_mid, dc_lower = DonchianChannels(20)\ndraw(\n    dc_upper,\n    title=\"DC Upper\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    dc_mid,\n    title=\"DC Middle\",\n    frame=0,\n    color=\"white\"\n)\ndraw(\n    dc_lower,\n    title=\"DC Lower\",\n    frame=0,\n    color=\"green\"\n)\nmarker_fill(\n    frame=0,\n    line1=dc_upper,\n    line2=dc_lower,\n    color=\"rgba(0,150,255,0.08)\"\n)\nmarker_text(\n    frame=0,\n    text=\"Donchian Breakout\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Donchian Midline Strategy",
              "desc": "Buy when price crosses above the Middle Channel.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate Donchian Channels\ndc_upper, dc_mid, dc_lower = DonchianChannels(30)\n# Buy when price crosses above the Middle Channel,\n# indicating bullish momentum\nbuy_signal = crossover(close, dc_mid)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price crosses below the Lower Channel,\n# indicating a bearish breakout\nexit_signal = crossunder(close, dc_lower)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# Donchian Channels Indicator\n# Displays upper, middle and lower channel bands.\n# ============================================================\ndc_upper, dc_mid, dc_lower = DonchianChannels(30)\ndraw(\n    dc_upper,\n    title=\"Upper\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    dc_mid,\n    title=\"Middle\",\n    frame=0,\n    color=\"white\"\n)\ndraw(\n    dc_lower,\n    title=\"Lower\",\n    frame=0,\n    color=\"green\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        }
      ]
    },
    {
      "category": "Built-in Variables",
      "items": [
        {
          "name": "Price Data",
          "args": "open, high, low, close, volume, oi, hl2, hlc3, ohlc4",
          "desc": "Core OHLCV data series.",
          "example": "# Access current bar data\ncurrent_close = close\ncurrent_volume = volume\n# Calculate typical price manually\nmy_hlc3 = (high + low + close) / 3"
        },
        {
          "name": "Trade State",
          "args": "position_size, position_avg_price, open_pnl, bars_in_trade, max_runup, max_drawdown",
          "desc": "Real-time in-trade metrics.",
          "example": "# Check if we are in a trade\nin_trade = position_size != 0\n# Stop loss based on PnL\npanic_exit = open_pnl < -1000"
        },
        {
          "name": "Daily OHLC",
          "args": "PDH, PDL, PDC, PDO, CDH, CDL, CDO",
          "desc": "Previous and Current Day's Open, High, Low, and Close.",
          "example": "# Breakout of Previous Day High\nbreakout = close > PDH\n# Gap up condition\ngap_up = CDO > PDC"
        },
        {
          "name": "Time & Date",
          "args": "time, Date, DayOfMonth, DayOfWeek, DayOfYear, DaysSince1900, DayFirstBar, DayLastBar",
          "desc": "Time and daily boundary booleans.",
          "example": "# 1. Time-based trading window (Format HHMM)\n# Example: 9:30 AM to 11:00 AM\ntrading_window = (time >= 930) & (time <= 1100)\n# 2. Day of Week (1=Monday, ..., 5=Friday)\nis_friday = DayOfWeek == 5\n# 3. Session Boundaries\n# Reset state on first bar of day\nif DayFirstBar:\n    my_var = 0\n# Close positions on last bar\nexit_on_close = DayLastBar\n# 4. Specific Date (YYYYMMDD)\nis_budget_day = Date == 20230201"
        }
      ]
    },
    {
      "category": "Logic & State",
      "items": [
        {
          "name": "crossover / crossunder",
          "args": "(series1, series2)",
          "desc": "True if series1 just crossed above or below series2.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "VWAP Crossover Strategy",
              "desc": "Buy when price crosses above VWAP.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate VWAP\nvwap_val = VWAP(hlc3)\n# Buy when price crosses above VWAP,\n# indicating bullish momentum\nbuy_signal = crossover(close, vwap_val)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Calculate VWAP\nvwap_val = VWAP(hlc3)\n# Exit when price crosses below VWAP,\n# indicating bearish momentum\nexit_signal = crossunder(close, vwap_val)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Calculate VWAP\nvwap_val = VWAP(hlc3)\n# Plot VWAP\ndraw(\n    vwap_val,\n    title=\"VWAP\",\n    frame=0,\n    color=\"yellow\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "RSI Crossover Strategy",
              "desc": "Buy when RSI crosses above 50.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate RSI\nrsi_14 = RSI(close, 14)\n# Buy when RSI crosses above 50,\n# indicating bullish momentum\nbuy_signal = crossover(rsi_14, 50)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when RSI crosses below 50,\n# indicating bearish momentum\nexit_signal = crossunder(rsi_14, 50)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Calculate RSI\nrsi_14 = RSI(close, 14)\n# Plot RSI\ndraw(\n    rsi_14,\n    title=\"RSI (14)\",\n    frame=1,\n    color=\"blue\"\n)\n# Overbought Level\ndraw(\n    70,\n    title=\"Overbought\",\n    frame=1,\n    color=\"red\"\n)\n# Midline\ndraw(\n    50,\n    title=\"Midline\",\n    frame=1,\n    color=\"white\"\n)\n# Oversold Level\ndraw(\n    30,\n    title=\"Oversold\",\n    frame=1,\n    color=\"green\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "iff",
          "args": "(condition, true_val, false_val)",
          "desc": "Vectorized if. Returns true_val if condition is true, else false_val.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "IFF Strategy (Dynamic EMA)",
              "desc": "Use iff to dynamically select between EMA 20 and EMA 50 based on volatility.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate ATR and EMAs\natr14 = ATR(14)\natr50 = ATR(50)\nema20 = EMA(close, 20)\nema50 = EMA(close, 50)\n# If volatility is high, use EMA 20.\n# Otherwise, use EMA 50.\ntrend_line = iff(atr14 > atr50, ema20, ema50)\n# Buy when price crosses above the selected trend line\nbuy_signal = crossover(close, trend_line)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price crosses below the selected trend line\nexit_signal = crossunder(close, trend_line)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\ndraw(\n    trend_line,\n    title=\"Dynamic EMA\",\n    frame=0,\n    color=\"yellow\"\n)\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    ema50,\n    title=\"EMA 50\",\n    frame=0,\n    color=\"red\"\n)\nmarker_text(\n    frame=0,\n    text=\"IFF Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "IFF Score Strategy",
              "desc": "Build a numeric signal score based on multiple conditions using nested iff.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate RSI and EMAs\nrsi_14 = RSI(close, 14)\nema20  = EMA(close, 20)\nema50  = EMA(close, 50)\n# Trend Filter\ntrend_ok = ema20 > ema50\n# Assign a score based on trend and RSI strength\n#  2 = Strong Bullish\n#  1 = Moderate Bullish\n#  0 = Neutral\n# -1 = Bearish\nscore = iff(\n    trend_ok & (rsi_14 > 60),\n    2,\n    iff(\n        trend_ok & (rsi_14 > 50),\n        1,\n        iff(\n            rsi_14 < 40,\n            -1,\n            0\n        )\n    )\n)\n# Buy only when the score is strongly bullish\nbuy_signal = score == 2\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when the score becomes neutral or bearish\nexit_signal = score <= 0\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot EMAs\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    ema50,\n    title=\"EMA 50\",\n    frame=0,\n    color=\"red\"\n)\n# Plot Score\ndraw(\n    score,\n    title=\"Trend Score\",\n    frame=1,\n    color=\"blue\"\n)\nmarker_text(\n    frame=1,\n    text=\"IFF Score Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "IFF Time-Based Strategy",
              "desc": "Select different RSI thresholds depending on the time of day.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate RSI\nrsi_14 = RSI(close, 14)\n# Morning session uses a lower RSI threshold,\n# while the afternoon requires stronger momentum.\nmorning = time < 1130\nthreshold = iff(\n    morning,\n    55,\n    62\n)\n# Buy when RSI is above the selected threshold\nbuy_signal = rsi_14 > threshold\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=BANKNIFTY,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when RSI falls below the active threshold\nexit_signal = rsi_14 < threshold\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot RSI\ndraw(\n    rsi_14,\n    title=\"RSI (14)\",\n    frame=1,\n    color=\"blue\"\n)\n# Plot Dynamic Threshold\ndraw(\n    threshold,\n    title=\"Dynamic RSI Threshold\",\n    frame=1,\n    color=\"orange\"\n)\nmarker_text(\n    frame=1,\n    text=\"IFF Time-Based Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "valuewhen",
          "args": "(condition, source, occurrence=0)",
          "desc": "Gets the value of source when the n-th condition occurred.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "ValueWhen Strategy",
              "desc": "Retrieve the close price at the moment of the most recent buy signal.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate EMAs\nfast_ema = EMA(close, 9)\nslow_ema = EMA(close, 21)\n# Buy when the fast EMA crosses above the slow EMA\nbuy_signal = crossover(fast_ema, slow_ema)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Store the price where the last buy signal occurred\nentry_price = valuewhen(buy_signal, close, 0)\n# Calculate profit from the entry price\nunrealised_move = close - entry_price\n# Exit after gaining 100 points\nexit_signal = unrealised_move >= 100\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Calculate EMAs\nfast_ema = EMA(close, 9)\nslow_ema = EMA(close, 21)\n# Plot EMAs\ndraw(\n    fast_ema,\n    title=\"EMA 9\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    slow_ema,\n    title=\"EMA 21\",\n    frame=0,\n    color=\"red\"\n)\n# Plot Entry Price\ndraw(\n    entry_price,\n    title=\"Entry Price\",\n    frame=0,\n    color=\"yellow\"\n)\nmarker_text(\n    frame=0,\n    text=\"ValueWhen Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Pivot Breakout Strategy",
              "desc": "Get the high value at the last pivot peak — useful for resistance tracking.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Detect Pivot High\npivot_peak = peak(high, 5, 2)\n# Get the High of the most recent Pivot\nlast_swing_high = valuewhen(pivot_peak, high, 0)\n# Buy when price breaks above the last Pivot High\nbuy_signal = close > last_swing_high\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price falls below the 20 EMA\nema20 = EMA(close, 20)\nexit_signal = crossunder(close, ema20)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Detect Pivot High\npivot_peak = peak(high, 5, 2)\n# Get the High of the most recent Pivot\nlast_swing_high = valuewhen(pivot_peak, high, 0)\n# Plot Last Swing High\ndraw(\n    last_swing_high,\n    title=\"Last Swing High\",\n    frame=0,\n    color=\"red\"\n)\n# Plot EMA\ndraw(\n    EMA(close, 20),\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\nmarker_text(\n    frame=0,\n    text=\"Pivot Breakout Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "barssince",
          "args": "(condition, occurrence=1)",
          "desc": "Counts bars since a condition was true for the n-th time.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "EMA Cooldown Strategy",
              "desc": "Allow a new trade only if the last EMA crossover happened more than 10 bars ago.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate EMAs\nfast_ema = EMA(close, 9)\nslow_ema = EMA(close, 21)\n# EMA crossover signal\nraw_signal = crossover(fast_ema, slow_ema)\n# Allow a new trade only if the last EMA crossover\n# happened more than 10 bars ago\ncooldown_ok = barssince(raw_signal) > 10\nbuy_signal = raw_signal & cooldown_ok\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when the fast EMA crosses below the slow EMA\nexit_signal = crossunder(fast_ema, slow_ema)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot EMAs\ndraw(\n    fast_ema,\n    title=\"EMA 9\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    slow_ema,\n    title=\"EMA 21\",\n    frame=0,\n    color=\"red\"\n)\nmarker_text(\n    frame=0,\n    text=\"EMA Cooldown Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Time-Based Exit Strategy",
              "desc": "Exit after holding the trade for more than 20 bars.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate EMAs\nfast_ema = EMA(close, 9)\nslow_ema = EMA(close, 21)\n# Buy when the fast EMA crosses above the slow EMA\nbuy_signal = crossover(fast_ema, slow_ema)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Count the number of bars since the last buy signal\nbars_in_trade = barssince(buy_signal)\n# Exit after holding the trade for more than 20 bars\nexit_signal = bars_in_trade > 20\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot EMAs\ndraw(\n    fast_ema,\n    title=\"EMA 9\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    slow_ema,\n    title=\"EMA 21\",\n    frame=0,\n    color=\"red\"\n)\n# Plot bars since entry\ndraw(\n    bars_in_trade,\n    title=\"Bars Since Entry\",\n    frame=1,\n    color=\"blue\"\n)\n# Exit threshold\ndraw(\n    20,\n    title=\"20 Bars\",\n    frame=1,\n    color=\"orange\"\n)\nmarker_text(\n    frame=1,\n    text=\"Time-Based Exit Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "highest / lowest",
          "args": "(source, length)",
          "desc": "Highest/Lowest value over a lookback period.",
          "example": "# 20-day High and Low\nhigh_20 = highest(high, 20)\nlow_20 = lowest(low, 20)\n# Donchian Channel logic\nbreakout_high = close > high_20[1]",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Range Squeeze Strategy",
              "desc": "Buy when price breaks above the 5-bar High after a squeeze.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate the short-term and long-term trading ranges\nrange_5  = highest(high, 5)  - lowest(low, 5)\nrange_20 = highest(high, 20) - lowest(low, 20)\n# A squeeze occurs when the recent range is much\n# smaller than the longer-term range\nsqueeze = range_5 < (range_20 * 0.30)\n# Buy when price breaks above the 5-bar High\n# after a squeeze\nbuy_signal = squeeze & crossover(close, highest(high, 5))\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price falls below the 5-bar Low\nexit_signal = crossunder(close, lowest(low, 5))\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot the trading ranges\ndraw(\n    range_5,\n    title=\"5-Bar Range\",\n    frame=1,\n    color=\"green\"\n)\ndraw(\n    range_20,\n    title=\"20-Bar Range\",\n    frame=1,\n    color=\"orange\"\n)\nmarker_text(\n    frame=1,\n    text=\"Range Squeeze Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Lowest Recovery Strategy",
              "desc": "Buy when price recovers above the previous 20-bar Low after testing it.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate the 20-bar Low\nlow_20 = lowest(low, 20)\n# Buy when price recovers above the previous\n# 20-bar Low after testing it\nbuy_signal = crossover(close, low_20)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price reaches the 20 EMA\nema20 = EMA(close, 20)\nexit_signal = crossover(close, ema20)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\nlow_20 = lowest(low, 20)\nema20 = EMA(close, 20)\ndraw(\n    low_20,\n    title=\"20-Bar Low\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\nmarker_text(\n    frame=0,\n    text=\"Lowest Recovery Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "highestbars / lowestbars",
          "args": "(source, length)",
          "desc": "Bar offset to the highest/lowest value over a lookback period.",
          "example": "# Find how many bars ago the highest high occurred\noffset_high = highestbars(high, 50)\n# If offset is 0, the current bar is the highest\nis_new_high = offset_high == 0",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "HighestBars Strategy",
              "desc": "Check if the current bar has the highest High of the last 20 bars.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Check if the current bar has the highest High\n# of the last 20 bars\nis_new_20_high = highestbars(high, 20) == 0\nEntry(\n    index=1,\n    logic=is_new_20_high,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when the current bar has the lowest Low\n# of the last 20 bars\nexit_signal = lowestbars(low, 20) == 0\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot the 20-bar Highest High\ndraw(\n    highest(high, 20),\n    title=\"20-Bar High\",\n    frame=0,\n    color=\"red\"\n)\n# Plot the 20-bar Lowest Low\ndraw(\n    lowest(low, 20),\n    title=\"20-Bar Low\",\n    frame=0,\n    color=\"green\"\n)\nmarker_text(\n    frame=0,\n    text=\"HighestBars Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "LowestBars Reversal",
              "desc": "Buy when the current candle makes a new 20-bar low, indicating a potential reversal zone.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Find how many bars ago the lowest Low occurred\noffset_low = lowestbars(low, 20)\n# Buy when the current candle makes a new 20-bar low,\n# indicating a potential reversal zone\nbuy_signal = offset_low == 0\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price reaches the 20 EMA\nema20 = EMA(close, 20)\nexit_signal = crossover(close, ema20)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Calculate EMA\nema20 = EMA(close, 20)\n# Plot EMA\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\n# Plot Lowest Low of the last 20 bars\ndraw(\n    lowest(low, 20),\n    title=\"20-Bar Low\",\n    frame=0,\n    color=\"green\"\n)\nmarker_text(\n    frame=0,\n    text=\"LowestBars Reversal\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Market Structure Strategy",
              "desc": "If the last High is old but a new Low has formed recently, the market structure is turning bearish.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate EMA\nema20 = EMA(close, 20)\n# Buy when price crosses above the 20 EMA\nbuy_signal = crossover(close, ema20)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Find the age of the highest High and lowest Low\nage_high = highestbars(high, 30)\nage_low  = lowestbars(low, 30)\n# If the last High is old but a new Low has formed recently,\n# the market structure is turning bearish\nbearish_struct = (age_high > 10) & (age_low < 3)\nExit(\n    index=1,\n    logic=bearish_struct,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot EMA\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\n# Plot Age of Highest High\ndraw(\n    age_high,\n    title=\"High Age\",\n    frame=1,\n    color=\"red\"\n)\n# Plot Age of Lowest Low\ndraw(\n    age_low,\n    title=\"Low Age\",\n    frame=1,\n    color=\"green\"\n)\nmarker_text(\n    frame=1,\n    text=\"Market Structure Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "increasing / decreasing",
          "args": "(source, length)",
          "desc": "Checks if a series has been consistently rising or falling.",
          "example": "# Check if RSI has been rising for 3 bars\nrsi_rising = increasing(rsi_14, 3)\n# Check if volume is falling\nvol_falling = decreasing(volume, 5)",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Increasing EMA Strategy",
              "desc": "Enter only when EMA 20 has been consistently rising for 3 bars — confirmed trend.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate EMA and RSI\nema20 = EMA(close, 20)\nrsi_14 = RSI(close, 14)\n# EMA has been rising for the last 3 bars\nema_rising = increasing(ema20, 3)\n# RSI confirms bullish momentum\nrsi_bull = rsi_14 > 55\n# Buy when both conditions are satisfied\nbuy_signal = ema_rising & rsi_bull\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when the EMA starts falling for 2 consecutive bars\nema_falling = decreasing(ema20, 2)\nExit(\n    index=1,\n    logic=ema_falling,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot EMA\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\n# Plot RSI\ndraw(\n    rsi_14,\n    title=\"RSI (14)\",\n    frame=1,\n    color=\"orange\"\n)\n# RSI Confirmation Level\ndraw(\n    55,\n    title=\"RSI 55\",\n    frame=1,\n    color=\"green\"\n)\nmarker_text(\n    frame=1,\n    text=\"Increasing EMA Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Volume Contraction Strategy",
              "desc": "Detect when volume has been decreasing for 4 bars — potential breakout setup.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Volume has been decreasing for the last 4 bars\nvol_contracting = decreasing(volume, 4)\n# Price range is tight relative to ATR\nrange_tight = (high - low) < (ATR(14) * 0.5)\n# Coil setup\ncoil_setup = vol_contracting & range_tight\n# Buy when price breaks above the current High\n# after a coil setup\nbuy_signal = coil_setup & crossover(close, high)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price falls below the 10 EMA\nema10 = EMA(close, 10)\nexit_signal = crossunder(close, ema10)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot EMA\ndraw(\n    ema10,\n    title=\"EMA 10\",\n    frame=0,\n    color=\"blue\"\n)\n# Plot ATR\ndraw(\n    ATR(14),\n    title=\"ATR (14)\",\n    frame=1,\n    color=\"orange\"\n)\nmarker_text(\n    frame=1,\n    text=\"Volume Contraction Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "RSI Momentum Fade Strategy",
              "desc": "Exit when RSI has been falling for 2 consecutive bars — momentum weakening.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Calculate RSI\nrsi_14 = RSI(close, 14)\n# Buy when RSI crosses above 50,\n# indicating bullish momentum\nbuy_signal = crossover(rsi_14, 50)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# RSI has been falling for 2 consecutive bars\nrsi_fading = decreasing(rsi_14, 2)\n# Exit only if RSI is still in the strong momentum zone\nabove_65 = rsi_14 > 65\nexit_signal = rsi_fading & above_65\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot RSI\ndraw(\n    rsi_14,\n    title=\"RSI (14)\",\n    frame=1,\n    color=\"blue\"\n)\n# Overbought Level\ndraw(\n    65,\n    title=\"RSI 65\",\n    frame=1,\n    color=\"red\"\n)\n# Midline\ndraw(\n    50,\n    title=\"RSI 50\",\n    frame=1,\n    color=\"white\"\n)\nmarker_text(\n    frame=1,\n    text=\"RSI Momentum Fade Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "for_loop",
          "args": "(logic_func, args, initial_state, reset)",
          "desc": "Executes a multi-line procedural block bar-by-bar.",
          "example": "# Define a custom logic function\ndef my_accumulator(acc, val):\n    return acc + val\n# Run the loop\n# args must be a list of series\ntotal_volume = for_loop(my_accumulator, [volume], 0)",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "For Loop Volume Strategy",
              "desc": "Accumulate volume bar-by-bar and buy when cumulative volume crosses a threshold.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Function to accumulate volume\ndef vol_accumulator(acc, vol):\n    return acc + vol\n# Cumulative volume\ndaily_vol = for_loop(\n    vol_accumulator,\n    [volume],\n    0\n)\n# Buy when cumulative volume crosses the threshold\nbuy_signal = crossover(daily_vol, 1000000)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\nema20 = EMA(close, 20)\nexit_signal = crossunder(close, ema20)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\ndraw(\n    daily_vol,\n    title=\"Accumulated Volume\",\n    frame=1,\n    color=\"blue\"\n)\ndraw(\n    1000000,\n    title=\"Volume Threshold\",\n    frame=1,\n    color=\"red\"\n)\nmarker_text(\n    frame=1,\n    text=\"For Loop Volume Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Running High Strategy",
              "desc": "Keep track of the highest High seen so far and buy when price makes a new running High.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Function to keep track of the highest High seen so far\ndef running_max(acc, h):\n    return h if h > acc else acc\n# Running maximum High\nsession_high = for_loop(\n    running_max,\n    [high],\n    0\n)\n# Buy when price makes a new running High\nbuy_signal = high >= session_high\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price crosses below EMA 20\nema20 = EMA(close, 20)\nexit_signal = crossunder(close, ema20)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot Running High\ndraw(\n    session_high,\n    title=\"Running High\",\n    frame=0,\n    color=\"red\"\n)\n\n# Plot EMA 20\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\nmarker_text(\n    frame=0,\n    text=\"Running High Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Bullish Candle Count Strategy",
              "desc": "Count consecutive bullish candles and enter after 4 consecutive bullish candles.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Function to count consecutive bullish candles\ndef bullish_counter(count, o, c):\n    if c > o:\n        return count + 1\n    return 0\n# Count consecutive bullish candles\nbull_count = for_loop(\n    bullish_counter,\n    [open, close],\n    0\n)\n# Buy after 4 consecutive bullish candles\nbuy_signal = bull_count >= 4\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit on the first bearish candle\nexit_signal = close < open\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot consecutive bullish candle count\ndraw(\n    bull_count,\n    title=\"Bullish Candle Count\",\n    frame=1,\n    color=\"green\"\n)\n# Entry threshold\ndraw(\n    4,\n    title=\"Threshold\",\n    frame=1,\n    color=\"red\"\n)\nmarker_text(\n    frame=1,\n    text=\"Bullish Candle Count Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "state",
          "args": "(initial_series, update_condition, update_value, reset_condition)",
          "desc": "Computes a path-dependent state series.",
          "example": "# Track the highest high since a buy signal\n# Initialize with 0\n# Update when high > current_state\n# Reset when sell_signal is True\ntrailing_stop = state(0, high > trailing_stop, high, sell_signal)",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "State Counter Strategy",
              "desc": "Reset a counter whenever a new buy signal occurs, and exit after 15 bars.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\nfast_ema = EMA(close, 9)\nslow_ema = EMA(close, 21)\nbuy_signal = crossover(fast_ema, slow_ema)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Reset whenever a new buy signal occurs\nbars_in_trade = state(\n    0,\n    buy_signal,\n    0,\n    1\n)\n# Exit after the state reaches 15 bars\nexit_signal = bars_in_trade >= 15\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\ndraw(\n    fast_ema,\n    title=\"EMA 9\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    slow_ema,\n    title=\"EMA 21\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    bars_in_trade,\n    title=\"State Counter\",\n    frame=1,\n    color=\"orange\"\n)\nmarker_text(\n    frame=1,\n    text=\"State Counter Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Session Open Strategy",
              "desc": "Store the session opening price and use it as a reference for entry and exit.",
              "code": "# ============================================================\n# entry_logic.ta\n# ============================================================\n# Store the session opening price\nsession_open = state(\n    open,\n    close > open,\n    open,\n    DayFirstBar\n)\n# Buy when price is above the stored session open\nbuy_signal = close > session_open\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when price falls below the session open\nexit_signal = close < session_open\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\ndraw(\n    session_open,\n    title=\"Session Open\",\n    frame=0,\n    color=\"orange\"\n)\nmarker_text(\n    frame=0,\n    text=\"Session Open Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Track Drawdown Strategy",
              "desc": "Track the current drawdown from entry and exit if it exceeds a panic limit.",
              "code": "# ============================================================\n# entry_logic.ta\n# Track Drawdown Strategy\n# ============================================================\nfast_ema = EMA(close, 9)\nslow_ema = EMA(close, 21)\nbuy_signal = crossover(fast_ema, slow_ema)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\nfast_ema = EMA(close, 9)\nslow_ema = EMA(close, 21)\nsell_signal = crossunder(fast_ema, slow_ema)\n# Entry price\nentry_close = valuewhen(buy_signal, close, 0)\n# Current drawdown from entry\ndrawdown = ((entry_close - close) / entry_close) * 100\n# Exit if drawdown exceeds 3%\npanic_exit = drawdown >= 3\nExit(\n    index=1,\n    logic=panic_exit,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\nfast_ema = EMA(close, 9)\nslow_ema = EMA(close, 21)\nentry_close = valuewhen(crossover(fast_ema, slow_ema), close, 0)\ndrawdown = ((entry_close - close) / entry_close) * 100\ndraw(\n    fast_ema,\n    title=\"EMA 9\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    slow_ema,\n    title=\"EMA 21\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    drawdown,\n    title=\"Drawdown %\",\n    frame=1,\n    color=\"orange\"\n)\ndraw(\n    3,\n    title=\"3% Limit\",\n    frame=1,\n    color=\"red\"\n)\nmarker_text(\n    frame=1,\n    text=\"Drawdown Exit Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "evolve",
          "args": "(initial_value, update_expression_str, series_args, reset_condition)",
          "desc": "Computes a recursive series bar-by-bar via a string expression.",
          "example": "# Exponential Moving Average calculation manually\n# \"p\" refers to previous value\n# \"args[0]\" refers to the first series in the list (close)\nmy_ema = evolve(close[0], \"0.2 * args[0] + 0.8 * p\", [close])",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Custom Momentum Decay Strategy",
              "desc": "Create a smoothed momentum line using exponential decay.",
              "code": "# ============================================================\n# entry_logic.ta\n# Custom Momentum Decay Strategy\n# ============================================================\n# Calculate the 14-period RSI to measure market momentum.\nrsi_14 = RSI(close, 14)\n# Create a smoothed momentum line using exponential decay.\nmomentum_decay = evolve(\n    rsi_14.shift(1),\n    \"0.1 * args[0] + 0.9 * p\",\n    [rsi_14]\n)\n# Generate a Buy signal when the Momentum Decay line crosses above the RSI.\nbuy_signal = crossover(momentum_decay, rsi_14)\n# Execute the Buy order.\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Calculate the 14-period RSI.\nrsi_14 = RSI(close, 14)\n# Recalculate the Momentum Decay line.\nmomentum_decay = evolve(\n    rsi_14.shift(1),\n    \"0.1 * args[0] + 0.9 * p\",\n    [rsi_14]\n)\n# Exit the trade when Momentum Decay crosses below the RSI.\nexit_signal = crossunder(momentum_decay, rsi_14)\n# Execute the Exit order.\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Calculate the 14-period RSI.\nrsi_14 = RSI(close, 14)\n# Calculate the Momentum Decay line using the evolve() function.\nmomentum_decay = evolve(\n    rsi_14.shift(1),\n    \"0.1 * args[0] + 0.9 * p\",\n    [rsi_14]\n)\n# Plot the Momentum Decay line.\ndraw(\n    momentum_decay,\n    title=\"Momentum Decay\",\n    frame=1,\n    color=\"orange\"\n)\n# Plot the RSI for comparison.\ndraw(\n    rsi_14,\n    title=\"RSI (14)\",\n    frame=1,\n    color=\"blue\"\n)\n# Display the strategy title on the chart.\nmarker_text(\n    frame=1,\n    text=\"Momentum Decay Strategy\",\n    anchor=\"top_right\"\n)\n# Display buy, sell and PnL trade markers.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Adaptive Trend Score Strategy",
              "desc": "Demonstrates an adaptive score calculated via evolve().",
              "code": "# ============================================================\n# entry_logic.ta\n# Adaptive Trend Score Strategy\n# ============================================================\n# Calculate Fast and Slow EMA\nfast_ema = EMA(close, 20)\n# Fast trend moving average\nslow_ema = EMA(close, 50)\n# Trend direction\ntrend_up = fast_ema > slow_ema\n# Adaptive Trend Score\n# Increases by 1 while bullish\n# Decreases by 1 while bearish\n# Score is limited between -10 and +10\ntrend_score = evolve(\n    0,\n    \"args[0] ? min(p + 1, 10) : max(p - 1, -10)\",\n    [trend_up]\n)\n# Buy after sustained bullish momentum\nbuy_signal = crossover(trend_score, 5)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Calculate Fast and Slow EMA\nfast_ema = EMA(close, 20)\nslow_ema = EMA(close, 50)\n# Trend direction\ntrend_up = fast_ema > slow_ema\n# Adaptive Trend Score\ntrend_score = evolve(\n    0,\n    \"args[0] ? min(p + 1, 10) : max(p - 1, -10)\",\n    [trend_up]\n)\n# Exit when bullish momentum weakens\nexit_signal = crossunder(trend_score, 0)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Calculate Fast and Slow EMA\nfast_ema = EMA(close, 20)\nslow_ema = EMA(close, 50)\n# Trend direction\ntrend_up = fast_ema > slow_ema\n# Adaptive Trend Score\ntrend_score = evolve(\n    0,\n    \"args[0] ? min(p + 1, 10) : max(p - 1, -10)\",\n    [trend_up]\n)\n# Plot Fast EMA\ndraw(\n    fast_ema,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\n# Plot Slow EMA\ndraw(\n    slow_ema,\n    title=\"EMA 50\",\n    frame=0,\n    color=\"orange\"\n)\n# Plot Adaptive Trend Score\ndraw(\n    trend_score,\n    title=\"Adaptive Trend Score\",\n    frame=1,\n    color=\"green\"\n)\n# Strategy Title\nmarker_text(\n    frame=1,\n    text=\"Adaptive Trend Score Strategy\",\n    anchor=\"top_right\"\n)\n# Show Trade Markers\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "consecutive",
          "args": "(condition)",
          "desc": "Counts consecutive bars where a condition is true.",
          "example": "# Count consecutive green candles\ngreen_streak = consecutive(close > open)\n# Buy if 3 green candles in a row\nbuy = green_streak == 3",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "High Volume Confirmation Strategy",
              "desc": "Require at least 2 consecutive high-volume candles and a trend filter before buying.",
              "code": "# ============================================================\n# entry_logic.ta\n# High Volume Confirmation Strategy\n# ============================================================\n# Average Volume\navg_vol = SMA(volume, 20)\n# Count consecutive high-volume bars\nvol_streak = consecutive(volume > avg_vol * 1.5)\n# Require at least 2 consecutive high-volume candles\nvol_confirm = vol_streak >= 2\n# Trend filter\nema20 = EMA(close, 20)\n# Buy only when volume confirms and price is above EMA\nbuy_signal = vol_confirm & (close > ema20)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when volume streak ends or price falls below EMA\nexit_signal = (vol_streak == 0) | crossunder(close, ema20)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot EMA\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\n# Plot consecutive high-volume count\ndraw(\n    vol_streak,\n    title=\"High Volume Streak\",\n    frame=1,\n    color=\"green\"\n)\n# Confirmation threshold\ndraw(\n    2,\n    title=\"Confirmation Level\",\n    frame=1,\n    color=\"red\"\n)\nmarker_text(\n    frame=1,\n    text=\"Volume Streak Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Green Candle Continuation Strategy",
              "desc": "Buy after 3 consecutive green candles and exit after 2 consecutive red candles.",
              "code": "# ============================================================\n# entry_logic.ta\n# Green Candle Continuation Strategy\n# ============================================================\n# Count consecutive green candles\ngreen_streak = consecutive(close > open)\n# Buy after 3 consecutive green candles\nbuy_signal = green_streak >= 3\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Count consecutive red candles\nred_streak = consecutive(close < open)\n# Exit after 2 consecutive red candles\nexit_signal = red_streak >= 2\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot Green Candle Streak\ndraw(\n    green_streak,\n    title=\"Green Streak\",\n    frame=1,\n    color=\"green\"\n)\n# Plot Red Candle Streak\ndraw(\n    red_streak,\n    title=\"Red Streak\",\n    frame=1,\n    color=\"red\"\n)\n# Entry Threshold\ndraw(\n    3,\n    title=\"Entry Level\",\n    frame=1,\n    color=\"blue\"\n)\n# Exit Threshold\ndraw(\n    2,\n    title=\"Exit Level\",\n    frame=1,\n    color=\"orange\"\n)\nmarker_text(\n    frame=1,\n    text=\"Consecutive Candle Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "NotOthers",
          "args": "(trigger_series, reset_series)",
          "desc": "Utility function for exclusive signal generation.",
          "example": "# Ensure only one signal is active at a time\n# If buy is True, it stays True until sell becomes True\nin_long = NotOthers(buy_signal, sell_signal)",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "EMA Trend State Strategy",
              "desc": "Stay in a long state after a Buy signal until a Sell signal occurs.",
              "code": "# ============================================================\n# entry_logic.ta\n# EMA Trend State Strategy\n# ============================================================\n# Calculate EMAs\nfast_ema = EMA(close, 9)\nslow_ema = EMA(close, 21)\n# Buy and Sell Signals\nbuy_signal = crossover(fast_ema, slow_ema)\nsell_signal = crossunder(fast_ema, slow_ema)\n# Stay in a long state after a Buy signal\n# until a Sell signal occurs\nin_long = NotOthers(buy_signal, sell_signal)\n# Enter only when a new Buy signal occurs\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit on EMA bearish crossover\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot EMAs\ndraw(\n    fast_ema,\n    title=\"EMA 9\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    slow_ema,\n    title=\"EMA 21\",\n    frame=0,\n    color=\"red\"\n)\n# Plot Long State (1 = Long, 0 = Flat)\ndraw(\n    in_long,\n    title=\"In Long State\",\n    frame=1,\n    color=\"blue\"\n)\nmarker_text(\n    frame=1,\n    text=\"NotOthers Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Bull Market Regime Strategy",
              "desc": "Stay in Bull Regime until a Death Cross occurs, and take trades only during this regime.",
              "code": "# ============================================================\n# entry_logic.ta\n# Bull Market Regime Strategy\n# ============================================================\n# Calculate Moving Averages\nsma_50 = SMA(close, 50)\nsma_200 = SMA(close, 200)\n# Market regime signals\nbull_start = crossover(sma_50, sma_200)\nbear_start = crossunder(sma_50, sma_200)\n# Stay in Bull Regime until a Death Cross occurs\nbull_regime = NotOthers(bull_start, bear_start)\n# Momentum confirmation\nrsi_14 = RSI(close, 14)\n# Buy only when RSI is strong during a Bull Regime\nbuy_signal = (rsi_14 > 55) & bull_regime\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=60,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ============================================================\n# exit_logic.ta\n# ============================================================\n# Exit when the market leaves the Bull Regime\nexit_signal = bear_start\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ============================================================\n# canvas.ta\n# ============================================================\n# Plot Moving Averages\ndraw(\n    sma_50,\n    title=\"SMA 50\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    sma_200,\n    title=\"SMA 200\",\n    frame=0,\n    color=\"red\"\n)\n# Plot Bull Regime State\ndraw(\n    bull_regime,\n    title=\"Bull Regime\",\n    frame=1,\n    color=\"blue\"\n)\nmarker_text(\n    frame=1,\n    text=\"Bull Regime Strategy\",\n    anchor=\"top_right\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        }
      ]
    },
    {
      "category": "Pattern Recognition",
      "items": [
        {
          "name": "is_doji",
          "args": "(max_body_perc=0.05)",
          "desc": "Identifies Doji candles.",
          "example": "# Detect Doji\ndoji = is_doji(0.05)\n# Filter for high volume Dojis\nvalid_doji = doji & (volume > avg(volume, 20))",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Doji Candle Strategy",
              "desc": "Demonstrates is_doji()",
              "code": "# ==================================================\n# Doji Candle Strategy\n# Demonstrates is_doji()\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Detect Doji candles.\n# A Doji forms when the opening and closing\n# prices are nearly equal.\n#\n# This indicates market indecision because\n# neither buyers nor sellers gained control.\ndoji = is_doji()\n# Enter a trade whenever a Doji appears.\n#\n# This simple example is intended to\n# demonstrate how pattern detection\n# functions can be used inside Entry().\nEntry(\n    index=1,\n    logic=doji,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit when a bearish candle appears.\n#\n# A bearish candle closes below its opening price,\n# indicating that sellers have gained control.\nExit(\n    index=1,\n    logic=close < open,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Detect Doji candles again for visualization.\ndoji = is_doji()\n# Draw a yellow diamond above every Doji candle.\n#\n# This makes it easy to visually verify\n# where the pattern occurred on the chart.\ndrawshape(\n    condition=doji,\n    shape=\"diamond\",\n    location=\"AboveBar\",\n    color=\"yellow\",\n    size=\"small\"\n)\n# Display the strategy name.\n#\n# The text appears in the top-right corner\n# of the chart so users know which example\n# is currently running.\nmarker_text(\n    frame=0,\n    text=\"Doji Pattern Strategy\",\n    anchor=\"top_right\"\n)\n# Display completed trades and PnL.\n#\n# This helps users see exactly which\n# Doji candles generated entries and exits.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Advanced Doji Strategy",
              "desc": "Demonstrates is_doji(threshold)",
              "code": "# ==================================================\n# Advanced Doji Strategy\n# Demonstrates is_doji(threshold)\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Detect Doji candles using a custom threshold.\n#\n# The threshold controls how close the open\n# and close prices must be to qualify as a Doji.\n#\n# Smaller value = Stricter Doji detection.\n# Larger value = More Doji candles detected.\ndoji = is_doji(0.05)\n# Bullish Doji condition.\n#\n# A Doji candle forms and the candle closes\n# above its opening price.\n#\n# This suggests buyers gained a slight advantage.\nlong_entry = doji & (close > open)\n# Bearish Doji condition.\n#\n# A Doji candle forms and the candle closes\n# below its opening price.\n#\n# This suggests sellers gained a slight advantage.\nshort_entry = doji & (close < open)\n# Enter a long trade when a bullish\n# Doji pattern appears.\nEntry(\n    index=1,\n    logic=long_entry,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# Enter a short trade when a bearish\n# Doji pattern appears.\nEntry(\n    index=2,\n    logic=short_entry,\n    timeframe=5,\n    script=RELIANCE,\n    action=Sell,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit long positions when a bearish candle appears.\n#\n# This suggests buyers are losing control.\nlong_exit = close < open\n# Exit short positions when a bullish candle appears.\n#\n# This suggests sellers are losing control.\nshort_exit = close > open\n# Close long trades.\nExit(\n    index=1,\n    logic=long_exit,\n    exit_type=\"MARKET\"\n)\n# Close short trades.\nExit(\n    index=2,\n    logic=short_exit,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Detect Doji candles again for visualization.\ndoji = is_doji(0.05)\n# Draw a yellow diamond above every\n# detected Doji candle.\n#\n# This allows users to visually verify\n# where the pattern occurred.\ndrawshape(\n    condition=doji,\n    shape=\"diamond\",\n    location=\"AboveBar\",\n    color=\"yellow\",\n    size=\"small\"\n)\n# Display strategy name.\n#\n# Appears in the top-right corner\n# of the chart.\nmarker_text(\n    frame=0,\n    text=\"Doji Strategy\",\n    anchor=\"top_right\"\n)\n# Display completed trades.\n#\n# Entry points, exit points and PnL\n# are shown directly on the chart.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "is_hammer",
          "args": "(max_body_perc=0.3)",
          "desc": "Identifies the Hammer candle shape.",
          "example": "# Detect Hammer pattern\nhammer = is_hammer(0.3)\n# Confirm with next candle\nconfirmed = hammer[1] & (close > high[1])",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Hammer Pattern Strategy",
              "desc": "Demonstrates is_hammer()",
              "code": "# ==================================================\n# Hammer Pattern Strategy\n# Demonstrates is_hammer()\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Detect Hammer candlestick patterns.\n#\n# A Hammer candle usually appears after a decline\n# and signals that buyers stepped in aggressively\n# after sellers pushed prices lower.\n#\n# Characteristics:\n# - Small real body\n# - Long lower shadow\n# - Little or no upper shadow\nhammer = is_hammer()\n# Enter a long trade whenever\n# a Hammer pattern is detected.\n#\n# This strategy assumes the Hammer may\n# signal a bullish reversal.\nEntry(\n    index=1,\n    logic=hammer,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit when a bearish candle appears.\n#\n# A bearish candle closes below its open,\n# indicating sellers may be regaining control.\nExit(\n    index=1,\n    logic=close < open,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Detect Hammer patterns again for visualization.\nhammer = is_hammer()\n# Draw a green triangle below every\n# Hammer candle detected.\n#\n# This helps traders quickly identify\n# potential bullish reversal areas.\ndrawshape(\n    condition=hammer,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"small\"\n)\n# Display strategy name on the chart.\n#\n# Appears in the top-right corner\n# for easy identification.\nmarker_text(\n    frame=0,\n    text=\"Hammer Pattern Strategy\",\n    anchor=\"top_right\"\n)\n# Display completed trades and PnL.\n#\n# Shows:\n# - Entry points\n# - Exit points\n# - Profit/Loss for each trade\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Advanced Hammer Strategy",
              "desc": "Demonstrates is_hammer(threshold)",
              "code": "# ==================================================\n# Advanced Hammer Strategy\n# Demonstrates is_hammer(threshold)\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Detect Hammer candles using a custom threshold.\n#\n# The threshold controls how strict the\n# Hammer pattern detection should be.\n#\n# Lower values:\n# - Fewer Hammer candles detected\n# - Stricter pattern requirements\n#\n# Higher values:\n# - More Hammer candles detected\n# - Looser pattern requirements\nhammer = is_hammer(0.3)\n# Bullish Hammer setup.\n#\n# Conditions:\n# 1. Hammer pattern detected\n# 2. Candle closes above its opening price\n#\n# This suggests buyers were able to push\n# the candle higher before the close.\nlong_entry = hammer & (close > open)\n# Bearish Hammer setup.\n#\n# Conditions:\n# 1. Hammer pattern detected\n# 2. Candle closes below its opening price\n#\n# This suggests sellers maintained slight\n# control despite the Hammer structure.\nshort_entry = hammer & (close < open)\n# Open a long trade when the bullish\n# Hammer setup is detected.\nEntry(\n    index=1,\n    logic=long_entry,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# Open a short trade when the bearish\n# Hammer setup is detected.\nEntry(\n    index=2,\n    logic=short_entry,\n    timeframe=5,\n    script=RELIANCE,\n    action=Sell,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit long trades when a bearish candle appears.\n#\n# This suggests buyers may be losing control.\nlong_exit = close < open\n# Exit short trades when a bullish candle appears.\n#\n# This suggests sellers may be losing control.\nshort_exit = close > open\n# Close long trades.\nExit(\n    index=1,\n    logic=long_exit,\n    exit_type=\"MARKET\"\n)\n# Close short trades.\nExit(\n    index=2,\n    logic=short_exit,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Detect Hammer patterns again for chart display.\nhammer = is_hammer(0.3)\n# Draw a green triangle below every\n# detected Hammer candle.\n#\n# This helps visually verify where\n# the pattern appeared.\ndrawshape(\n    condition=hammer,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"small\"\n)\n# Display strategy name.\n#\n# Appears in the top-right corner\n# of the chart.\nmarker_text(\n    frame=0,\n    text=\"Hammer Strategy\",\n    anchor=\"top_right\"\n)\n# Display all completed trades.\n#\n# Shows:\n# - Entry points\n# - Exit points\n# - Profit/Loss values\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "is_bullish_engulfing / is_bearish_engulfing",
          "args": "()",
          "desc": "Identifies the two-bar engulfing patterns.",
          "example": "# Engulfing patterns\nbull_eng = is_bullish_engulfing()\nbear_eng = is_bearish_engulfing()\n# Trade on pattern\nEntry(1, bull_eng, \"5m\", banknifty, Buy, \"MARKET\")",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Bearish Engulfing Strategy",
              "desc": "Demonstrates is_bearish_engulfing()",
              "code": "# ==================================================\n# Bearish Engulfing Strategy\n# Demonstrates is_bearish_engulfing()\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Detect Bearish Engulfing candlestick patterns.\n#\n# A Bearish Engulfing pattern occurs when:\n#\n# 1. The previous candle is bullish.\n# 2. The current candle is bearish.\n# 3. The body of the bearish candle completely\n#    engulfs the body of the previous bullish candle.\n#\n# This pattern is commonly interpreted as\n# a potential bearish reversal signal.\nbearish_engulfing = is_bearish_engulfing()\n# Enter a short trade whenever a\n# Bearish Engulfing pattern is detected.\n#\n# A Sell action opens a bearish position,\n# allowing the strategy to profit from\n# falling prices.\nEntry(\n    index=1,\n    logic=bearish_engulfing,\n    timeframe=5,\n    script=RELIANCE,\n    action=Sell,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit the short position when a\n# bullish candle appears.\n#\n# A bullish candle closes above its opening price,\n# suggesting buyers may be regaining control.\nExit(\n    index=1,\n    logic=close > open,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Detect Bearish Engulfing patterns again\n# for visualization purposes.\nbearish_engulfing = is_bearish_engulfing()\n# Draw a red triangle above every\n# Bearish Engulfing pattern.\n#\n# This helps traders quickly identify\n# potential bearish reversal signals.\ndrawshape(\n    condition=bearish_engulfing,\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\",\n    size=\"normal\"\n)\n# Display the strategy name.\n#\n# Appears in the top-right corner\n# of the chart.\nmarker_text(\n    frame=0,\n    text=\"Bearish Engulfing\",\n    anchor=\"top_right\"\n)\n# Display completed trades.\n#\n# Shows:\n# - Entry points\n# - Exit points\n# - Profit/Loss values\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Bullish Engulfing Strategy",
              "desc": "Demonstrates is_bullish_engulfing()",
              "code": "# ==================================================\n# Bullish Engulfing Strategy\n# Demonstrates is_bullish_engulfing()\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Detect a Bullish Engulfing candlestick pattern.\n# Returns True when the current bullish candle completely engulfs\n# the body of the previous bearish candle, indicating a potential\n# bullish reversal.\nbullish_engulfing = is_bullish_engulfing()\nEntry(\n    index=1,\n    logic=bullish_engulfing,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit the Buy position when the current candle closes below its open,\n# indicating bearish price action.\nExit(\n    index=1,\n    logic=close < open,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Detect the same Bullish Engulfing pattern for visualization.\nbullish_engulfing = is_bullish_engulfing()\n# Plot a green upward triangle below every Bullish Engulfing candle.\ndrawshape(\n    condition=bullish_engulfing,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"normal\"\n)\n# Display the strategy name on the chart.\nmarker_text(\n    frame=0,\n    text=\"Bullish Engulfing\",\n    anchor=\"top_right\"\n)\n# Display executed trades and their profit/loss.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "is_morning_star / is_evening_star",
          "args": "(star_max_body_perc=0.3)",
          "desc": "Identifies three-bar star reversal patterns.",
          "example": "# Star patterns\nm_star = is_morning_star(0.3)\ne_star = is_evening_star(0.3)",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Morning Star Strategy",
              "desc": "Demonstrates is_morning_star(threshold)",
              "code": "# ==================================================\n# Morning Star Strategy\n# Demonstrates is_morning_star(threshold)\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Detect Morning Star candlestick patterns.\n#\n# The Morning Star is a bullish reversal pattern\n# consisting of three candles.\n#\n# The threshold parameter controls how strict\n# the pattern recognition should be.\n#\n# Lower values:\n# - Stricter pattern matching\n# - Fewer signals\n#\n# Higher values:\n# - Looser pattern matching\n# - More signals\nmorning_star = is_morning_star(0.3)\n# Enter a long trade whenever a\n# Morning Star pattern is detected.\n#\n# The pattern suggests that bearish momentum\n# may be ending and buyers may be taking control.\nEntry(\n    index=1,\n    logic=morning_star,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit when a bearish candle appears.\n#\n# A bearish candle closes below its opening price,\n# which may indicate weakening bullish momentum.\nExit(\n    index=1,\n    logic=close < open,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Detect Morning Star patterns again\n# for chart visualization.\nmorning_star = is_morning_star(0.3)\n# Draw a green triangle below every\n# detected Morning Star pattern.\n#\n# This makes it easy to identify\n# bullish reversal zones on the chart.\ndrawshape(\n    condition=morning_star,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"normal\"\n)\n# Display strategy name.\n#\n# Appears in the top-right corner\n# of the chart.\nmarker_text(\n    frame=0,\n    text=\"Morning Star\",\n    anchor=\"top_right\"\n)\n# Display completed trades and PnL.\n#\n# Shows:\n# - Entry points\n# - Exit points\n# - Profit/Loss values\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Evening Star Strategy",
              "desc": "Demonstrates is_evening_star(threshold)",
              "code": "# ==================================================\n# Evening Star Strategy\n# Demonstrates is_evening_star(threshold)\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Detect Evening Star candlestick patterns.\n#\n# The Evening Star is a bearish reversal pattern\n# consisting of three candles.\n#\n# The threshold parameter controls how strict\n# the pattern recognition should be.\n#\n# Lower values:\n# - Stricter pattern matching\n# - Fewer signals\n#\n# Higher values:\n# - Looser pattern matching\n# - More signals\nevening_star = is_evening_star(0.3)\n# Enter a short trade whenever an\n# Evening Star pattern is detected.\n#\n# The pattern suggests that bullish momentum\n# may be ending and sellers may be taking control.\nEntry(\n    index=1,\n    logic=evening_star,\n    timeframe=5,\n    script=RELIANCE,\n    action=Sell,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit the short trade when a bullish candle appears.\n#\n# A bullish candle closes above its opening price,\n# suggesting buyers may be regaining control.\nExit(\n    index=1,\n    logic=close > open,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Detect Evening Star patterns again\n# for chart visualization.\nevening_star = is_evening_star(0.3)\n# Draw a red triangle above every\n# detected Evening Star pattern.\n#\n# This makes it easy to identify\n# bearish reversal zones on the chart.\ndrawshape(\n    condition=evening_star,\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\",\n    size=\"normal\"\n)\n# Display strategy name.\n#\n# Appears in the top-right corner\n# of the chart.\nmarker_text(\n    frame=0,\n    text=\"Evening Star\",\n    anchor=\"top_right\"\n)\n# Display completed trades and PnL.\n#\n# Shows:\n# - Entry points\n# - Exit points\n# - Profit/Loss values\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Morning Star + SMA 50 Trend Filter",
              "desc": "Demonstrates candlestick patterns with trend filtering",
              "code": "# ==================================================\n# Morning Star + SMA 50 Trend Filter Strategy\n# Demonstrates candlestick patterns with trend filtering\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Calculate the 50-period Simple Moving Average.\n#\n# SMA 50 is commonly used as a trend filter.\n# Price above SMA 50 suggests an uptrend.\nsma_50 = SMA(close, 50)\n# Detect Morning Star pattern.\n#\n# Morning Star is a bullish reversal pattern\n# consisting of three candles.\nmorning_star = is_morning_star(0.3)\n# Buy only when:\n#\n# 1. Morning Star appears\n# 2. Price is above SMA 50\n#\n# This helps filter out weak reversal signals\n# that occur against the prevailing trend.\nbuy_signal = morning_star & (close > sma_50)\n# Open a long position.\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Exit when price falls below SMA 50.\n#\n# This suggests the uptrend may be weakening\n# or reversing.\nExit(\n    index=1,\n    logic=close < sma_50,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# ==================================================\n# Calculate SMA 50 for visualization.\nsma_50 = SMA(close, 50)\n# Plot SMA 50 on the chart.\n#\n# This allows traders to easily identify\n# the overall market trend.\ndraw(\n    sma_50,\n    title=\"SMA 50\",\n    frame=0,\n    color=\"yellow\"\n)\n# Mark all Morning Star patterns.\n#\n# Green triangles appear below candles\n# where the pattern is detected.\ndrawshape(\n    condition=is_morning_star(0.3),\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"normal\"\n)\n# Display strategy title.\nmarker_text(\n    frame=0,\n    text=\"Morning Star + SMA 50\",\n    anchor=\"top_right\"\n)\n# Show completed trades and PnL.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "is_GapUp / is_GapDown",
          "args": "(percentage=None)",
          "desc": "Identifies percentage gaps in price."
        },
        {
          "name": "is_InsideBar / is_OutsideBar",
          "args": "(percentage=99.99)",
          "desc": "Identifies inside and outside bar patterns."
        }
      ]
    },
    {
      "category": "Math & Structure",
      "items": [
        {
          "name": "Basic Math",
          "args": "abs, round, min, max, avg, sum",
          "desc": "Standard mathematical functions.",
          "example": "# Calculate average price\navg_price = avg(open, high, low, close)\n# Round to 2 decimal places\nrounded_rsi = round(rsi_14, 2)\n# Sum of volume over 10 bars\nvol_sum = sum(volume, 10)"
        },
        {
          "name": "Advanced Math",
          "args": "pow, sqrt, square, log, exp, sign, ceil, floor",
          "desc": "Algebraic and logarithmic operations.",
          "example": "# Logarithmic return\nlog_ret = log(close / close[1])\n# Standard deviation calculation steps\nvariance = sum(square(close - avg(close, 20)), 20) / 20\nstd_dev = sqrt(variance)"
        },
        {
          "name": "Trigonometry & Constants",
          "args": "sin, cos, tan, asin, acos, atan, e_const, pi_const, phi_const",
          "desc": "Trig functions and constants.",
          "example": "# Sine wave based on bar index\ncycle = sin(BarIndex * pi_const / 10)\n# Use constants\ncircumference = 2 * pi_const * radius"
        },
        {
          "name": "peak / trough",
          "args": "(source, leftbars, rightbars)",
          "desc": "Identifies local pivot points.",
          "example": "# Find a pivot high (5 bars left, 2 bars right)\npivot_high = peak(high, 5, 2)\n# Find a pivot low\npivot_low = trough(low, 5, 2)"
        },
        {
          "name": "peakbars / troughbars",
          "args": "(source, leftbars, rightbars, n=1)",
          "desc": "Bar offset to local pivot points.",
          "example": "# Bars since last pivot high\nbars_since_peak = peakbars(high, 5, 2)\n# Get the value of that peak\npeak_val = high[bars_since_peak]"
        },
        {
          "name": "HigherHigh / LowerLow / HigherLow / LowerHigh",
          "args": "(source, leftbars, rightbars)",
          "desc": "Trend structure identification.",
          "example": "# Check for Higher High\nis_hh = HigherHigh(high, 5, 2)\n# Check for Lower Low\nis_ll = LowerLow(low, 5, 2)"
        },
        {
          "name": "Array Ops",
          "args": "BarIndex, BeginValue, EndValue, median",
          "desc": "Array position indexing and statistical utilities.",
          "example": "# Current bar number\ncurrent_bar = BarIndex\n# Median price over 20 bars\nmed_price = median(close, 20)"
        }
      ]
    },
    {
      "category": "Utility Tools",
      "items": [
        {
          "name": "input",
          "args": "(defval, title, tooltip, group, min, max, options)",
          "desc": "Creates a user-configurable setting for the strategy.",
          "example": "# User inputs\nrsi_len = input(14, title=\"RSI Length\", min=1)\nma_type = input(\"SMA\", title=\"MA Type\", options=[\"SMA\", \"EMA\"])",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Configurable SMA Strategy",
              "desc": "Demonstrates input().",
              "code": "# ==================================================\n# Configurable SMA Strategy\n# Demonstrates input()\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Create a user-configurable SMA length.\n# Users can change this value from the\n# strategy settings panel.\nma_length = input(\n    20,\n    title=\"SMA Length\",\n    min=1\n)\n# Calculate the SMA using the selected length.\nma = SMA(close, ma_length)\n# Buy when price crosses above the SMA.\n# This suggests a potential bullish trend.\nbuy_signal = crossover(close, ma)\n# Enter a long position.\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Use the same configurable SMA length.\nma_length = input(\n    20,\n    title=\"SMA Length\",\n    min=1\n)\n# Recalculate SMA.\nma = SMA(close, ma_length)\n# Exit when price crosses below SMA.\n# This suggests weakening momentum.\nsell_signal = crossunder(close, ma)\n# Close the position.\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# Demonstrates input()\n# ==================================================\n# Create a user-configurable SMA length.\n# Users can modify the moving average period\n# without changing the strategy code.\nma_length = input(\n    20,\n    title=\"SMA Length\",\n    min=1\n)\n# Calculate the SMA using the selected value.\nma = SMA(close, ma_length)\n# Plot the SMA on the main chart.\ndraw(\n    ma,\n    title=\"SMA\",\n    frame=0,\n    color=\"yellow\"\n)\n# Generate buy and sell signals for visualization.\nbuy_signal = crossover(close, ma)\nsell_signal = crossunder(close, ma)\n# Draw buy markers below bullish crossover candles.\ndrawshape(\n    buy_signal,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\"\n)\n# Draw sell markers above bearish crossover candles.\ndrawshape(\n    sell_signal,\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\"\n)\n# Display the currently selected SMA length.\n# This updates automatically when the user\n# changes the input value.\nmarker_table(\n    frame=0,\n    data=[\n        [\"SMA Length\", ma_length]\n    ],\n    position=\"top_right\"\n)\n# Add a strategy title to the chart.\nmarker_text(\n    frame=0,\n    text=\"Configurable SMA Strategy\",\n    color=\"yellow\",\n    x=0.5,\n    y=0.1,\n    anchor=\"custom\"\n)\n# Display completed trades and profit/loss.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Configurable RSI Strategy",
              "desc": "Demonstrates input().",
              "code": "# ==================================================\n# Configurable RSI Strategy\n# Demonstrates input()\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Create a user-configurable RSI period.\n# Users can change RSI sensitivity from settings.\nrsi_length = input(\n    14,\n    title=\"RSI Length\",\n    min=2\n)\n# Calculate RSI using the selected period.\nrsi_val = RSI(close, rsi_length)\n# Buy when RSI enters the oversold zone.\n# Oversold conditions may indicate a reversal.\nbuy_signal = rsi_val < 30\n# Enter a long position.\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Recalculate RSI using the same user input.\nrsi_length = input(\n    14,\n    title=\"RSI Length\",\n    min=2\n)\nrsi_val = RSI(close, rsi_length)\n# Exit when RSI enters the overbought zone.\n# This may indicate momentum exhaustion.\nsell_signal = rsi_val > 70\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# Demonstrates input()\n# ==================================================\n# User-configurable RSI period.\nrsi_length = input(\n    14,\n    title=\"RSI Length\",\n    min=2\n)\n# Calculate RSI.\nrsi_val = RSI(close, rsi_length)\n# Plot RSI in a separate indicator panel.\ndraw(\n    rsi_val,\n    title=\"RSI\",\n    frame=1,\n    color=\"blue\"\n)\n# Generate visual signals.\nbuy_signal = rsi_val < 30\nsell_signal = rsi_val > 70\n# Mark oversold conditions.\ndrawshape(\n    buy_signal,\n    shape=\"circle\",\n    location=\"BelowBar\",\n    color=\"green\"\n)\n# Mark overbought conditions.\ndrawshape(\n    sell_signal,\n    shape=\"circle\",\n    location=\"AboveBar\",\n    color=\"red\"\n)\n# Display current RSI settings.\nmarker_table(\n    frame=0,\n    data=[\n        [\"RSI Length\", rsi_length],\n        [\"RSI Value\", round(rsi_val, 2)]\n    ],\n    position=\"top_right\"\n)\n# Strategy title.\nmarker_text(\n    frame=0,\n    text=\"Configurable RSI Strategy\",\n    color=\"blue\",\n    x=0.5,\n    y=0.1,\n    anchor=\"custom\"\n)\n# Show completed trades.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "mtf_data",
          "args": "(timeframe, expression, script=None)",
          "desc": "Requests data from a higher timeframe.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Multi-Timeframe (MTF) Daily Close Strategy",
              "desc": "Demonstrates how to use mtf_data() to fetch higher timeframe data inside an intraday strategy.",
              "code": "# ==================================================\n# Multi-Timeframe (MTF) Daily Close Strategy\n# Demonstrates how to use mtf_data() to fetch\n# higher timeframe data inside an intraday strategy.\n# ==================================================\n# ------------------------------------------\n# User Inputs\n# ------------------------------------------\n# ATR multiplier used for stop-loss calculation.\natr_sl_mult = input(\n    1.5,\n    title=\"ATR Stop Multiplier\",\n    min=0.5,\n    max=4.0\n)\n# RSI length.\nrsi_len = input(\n    14,\n    title=\"RSI Length\",\n    min=5,\n    max=50\n)\n# ------------------------------------------\n# Multi-Timeframe Data\n# ------------------------------------------\n# Function that returns the Daily Close.\n# mtf_data() executes this function on the\n# requested higher timeframe.\ndef get_daily_close():\n    return close\n# Fetch the Daily Close of HDFCBANK while\n# running this strategy on a lower timeframe\n# such as 15 minutes.\ndaily_close = mtf_data(\n    \"1440\",\n    get_daily_close,\n    script=\"HDFCBANK\"\n)\n# ------------------------------------------\n# Calculate Indicators\n# ------------------------------------------\n# ATR for stop-loss calculation.\natr_val = ATR(14)\n# VWAP used as an intraday trend filter.\nvwap_val = VWAP(hlc3)\n# RSI confirms momentum.\nrsi_val = RSI(close, rsi_len)\n# ------------------------------------------\n# Entry Conditions\n# ------------------------------------------\n# Current price should be above the\n# Higher Timeframe Daily Close.\nabove_daily = close > daily_close\n# Price should also trade above VWAP.\nabove_vwap = close > vwap_val\n# RSI confirms bullish momentum.\nrsi_ok = rsi_val > 45\n# Only trade during market hours.\nmorning_ok = (time >= 915) & (time <= 1515)\n# Allow only one open trade.\nflat_filter = position_size == 0\n# Final Buy Signal.\nbuy_signal = (\n    above_daily &\n    above_vwap &\n    rsi_ok &\n    morning_ok &\n    flat_filter\n)\n# ------------------------------------------\n# Place Buy Order\n# ------------------------------------------\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=HDFCBANK,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ------------------------------------------\n# Exit Conditions\n# ------------------------------------------\n# Entry price used for ATR stop-loss.\nentry_price = valuewhen(\n    buy_signal,\n    close,\n    0\n)\n# Dynamic ATR stop-loss.\nstop_level = entry_price - (atr_sl_mult * atr_val)\n# Exit if stop-loss is hit.\nhit_stop = close < stop_level\n# Exit if price falls below the Daily Close.\nbelow_daily = close < daily_close\n# Force exit at the end of the trading day.\nforce_exit = DayLastBar\n# Final Exit Signal.\nexit_signal = (\n    hit_stop |\n    below_daily |\n    force_exit\n)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ------------------------------------------\n# Canvas\n# ------------------------------------------\n# Plot the Higher Timeframe Daily Close.\ndraw(\n    daily_close,\n    title=\"MTF Daily Close\",\n    frame=0,\n    color=\"yellow\"\n)\n# Plot VWAP.\ndraw(\n    vwap_val,\n    title=\"VWAP\",\n    frame=0,\n    color=\"cyan\"\n)\n# Plot RSI.\ndraw(\n    rsi_val,\n    title=\"RSI 14\",\n    frame=1,\n    color=\"purple\"\n)\n# Show Buy Signals.\ndrawshape(\n    buy_signal,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"green\",\n    size=\"small\",\n    frame=0\n)\n# Show Exit Signals.\ndrawshape(\n    exit_signal,\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\",\n    size=\"small\",\n    frame=0\n)\n# Highlight bars where price is above\n# the Higher Timeframe Daily Close.\ndebug_paint_background(\n    above_daily,\n    frame=0,\n    color=\"green\"\n)\n# Display completed trades.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Multi-Timeframe Daily High Breakout Strategy",
              "desc": "Demonstrates mtf_data() using the Daily High.",
              "code": "# ==================================================\n# Multi-Timeframe Daily High Breakout Strategy\n# Demonstrates mtf_data() using the Daily High.\n# ==================================================\n# ------------------------------------------\n# User Inputs\n# ------------------------------------------\natr_mult = input(\n    2.0,\n    title=\"ATR Stop Multiplier\",\n    min=1.0,\n    max=5.0\n)\n# ------------------------------------------\n# Multi-Timeframe Data\n# ------------------------------------------\n# Function returns the Daily High.\ndef get_daily_high():\n    return high\n# Fetch Daily High from the higher timeframe.\ndaily_high = mtf_data(\n    \"1440\",\n    get_daily_high,\n    script=\"RELIANCE\"\n)\n# ------------------------------------------\n# Indicators\n# ------------------------------------------\natr_val = ATR(14)\nema20 = EMA(close, 20)\n# ------------------------------------------\n# Entry Conditions\n# ------------------------------------------\n# Price breaks above the Daily High.\nbreakout = crossover(close, daily_high)\n# Trend confirmation.\ntrend_ok = close > ema20\n# Only allow one open position.\nflat_filter = position_size == 0\n# Final Buy Signal.\nbuy_signal = breakout & trend_ok & flat_filter\n# ------------------------------------------\n# Place Entry\n# ------------------------------------------\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ------------------------------------------\n# Exit Conditions\n# ------------------------------------------\nentry_price = valuewhen(\n    buy_signal,\n    close,\n    0\n)\nstop_price = entry_price - (atr_mult * atr_val)\nhit_stop = close < stop_price\nema_break = close < ema20\nexit_signal = hit_stop | ema_break | DayLastBar\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ------------------------------------------\n# Canvas\n# ------------------------------------------\ndraw(\n    daily_high,\n    title=\"MTF Daily High\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\ndrawshape(\n    buy_signal,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"green\",\n    size=\"small\",\n    frame=0\n)\ndrawshape(\n    exit_signal,\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\",\n    size=\"small\",\n    frame=0\n)\ndebug_paint_background(\n    breakout,\n    frame=0,\n    color=\"green\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "SeriesWrapper",
          "args": "(data)",
          "desc": "Wraps raw arrays for engine compatibility.",
          "example": "# Wrap a raw list into a Series\nmy_list = [10, 20, 30, 40, 50]\nmy_series = SeriesWrapper(my_list)\n# Now you can use series functions\navg_val = avg(my_series, 5)",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "SeriesWrapper SMA Strategy",
              "desc": "Demonstrates SeriesWrapper().",
              "code": "# ==================================================\n# SeriesWrapper SMA Strategy\n# Demonstrates SeriesWrapper()\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Wrap the close price series.\n# Some engine functions may require\n# data to be wrapped before processing.\nclose_series = SeriesWrapper(close)\n# Calculate a 20-period SMA using\n# the wrapped series.\nsma_20 = SMA(close_series, 20)\n# Buy when price crosses above the SMA.\n# This indicates potential bullish momentum.\nbuy_signal = crossover(close_series, sma_20)\n# Enter a long position.\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Wrap the close series again.\nclose_series = SeriesWrapper(close)\n# Calculate SMA.\nsma_20 = SMA(close_series, 20)\n# Exit when price crosses below SMA.\n# This indicates weakening momentum.\nsell_signal = crossunder(close_series, sma_20)\n# Close the position.\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# Demonstrates SeriesWrapper()\n# ==================================================\n# Wrap the close price series.\n# SeriesWrapper ensures compatibility\n# with engine functions that expect\n# wrapped series objects.\nclose_series = SeriesWrapper(close)\n# Calculate a moving average using\n# the wrapped series.\nsma_20 = SMA(close_series, 20)\n# Plot the original close price.\ndraw(\n    close,\n    title=\"Close Price\",\n    frame=0,\n    color=\"white\"\n)\n# Plot the SMA calculated from\n# the wrapped series.\ndraw(\n    sma_20,\n    title=\"Wrapped SMA 20\",\n    frame=0,\n    color=\"yellow\"\n)\n# Generate visual signals.\nbuy_signal = crossover(close_series, sma_20)\nsell_signal = crossunder(close_series, sma_20)\n# Mark buy signals.\ndrawshape(\n    buy_signal,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\"\n)\n# Mark sell signals.\ndrawshape(\n    sell_signal,\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\"\n)\n# Explain what is being demonstrated.\nmarker_text(\n    frame=0,\n    text=\"SeriesWrapper Example\",\n    anchor=\"top_right\"\n)\n# Show current values in a table.\nmarker_table(\n    frame=0,\n    data=[\n        [\"Close\", round(close, 2)],\n        [\"SMA 20\", round(sma_20, 2)]\n    ],\n    position=\"bottom_right\"\n)\n# Display completed trades.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "SeriesWrapper Momentum Strategy",
              "desc": "Demonstrates SeriesWrapper().",
              "code": "# ==================================================\n# SeriesWrapper Momentum Strategy\n# Demonstrates SeriesWrapper()\n# ==================================================\n# ==================================================\n# Entry Logic\n# ==================================================\n# Wrap the close price series.\n# Some advanced engine functions may\n# require wrapped series objects.\nclose_series = SeriesWrapper(close)\n# Calculate a 10-period EMA using\n# the wrapped close series.\nema_10 = EMA(close_series, 10)\n# Calculate a 30-period EMA using\n# the wrapped close series.\nema_30 = EMA(close_series, 30)\n# Buy when the fast EMA crosses\n# above the slow EMA.\nbuy_signal = crossover(ema_10, ema_30)\n# Enter a long position.\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Exit Logic\n# ==================================================\n# Wrap the close series again.\nclose_series = SeriesWrapper(close)\n# Recalculate EMAs.\nema_10 = EMA(close_series, 10)\nema_30 = EMA(close_series, 30)\n# Exit when the fast EMA crosses\n# below the slow EMA.\nsell_signal = crossunder(ema_10, ema_30)\n# Close the trade.\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Canvas\n# Demonstrates SeriesWrapper()\n# ==================================================\n# Wrap the close price series.\nclose_series = SeriesWrapper(close)\n# Calculate EMAs using wrapped data.\nema_10 = EMA(close_series, 10)\nema_30 = EMA(close_series, 30)\n# Plot the original close series.\ndraw(\n    close,\n    title=\"Close Price\",\n    frame=0,\n    color=\"white\"\n)\n# Plot the fast EMA.\ndraw(\n    ema_10,\n    title=\"EMA 10\",\n    frame=0,\n    color=\"green\"\n)\n# Plot the slow EMA.\ndraw(\n    ema_30,\n    title=\"EMA 30\",\n    frame=0,\n    color=\"red\"\n)\n# Generate crossover signals.\nbuy_signal = crossover(ema_10, ema_30)\nsell_signal = crossunder(ema_10, ema_30)\n# Mark buy signals.\ndrawshape(\n    buy_signal,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\"\n)\n# Mark sell signals.\ndrawshape(\n    sell_signal,\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\"\n)\n# Display strategy information.\nmarker_text(\n    frame=0,\n    text=\"SeriesWrapper EMA Cross\",\n    anchor=\"top_right\"\n)\n# Display indicator values.\nmarker_table(\n    frame=0,\n    data=[\n        [\"EMA 10\", round(ema_10, 2)],\n        [\"EMA 30\", round(ema_30, 2)]\n    ],\n    position=\"bottom_right\"\n)\n# Show completed trades and PnL.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        }
      ]
    },
    {
      "category": "Debugging Tools",
      "items": [
        {
          "name": "log_series_comparison",
          "args": "(name, *series, maxrows, startdate)",
          "desc": "Prints a comparison table of series values.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Bollinger Breakout Strategy",
              "desc": "Breakout strategy using Bollinger Bands and volume, with log output.",
              "code": "# ==================================================\n# entry_logic.ta\n# Bollinger Breakout Strategy\n# ==================================================\n# Indicators\nbb_upper, bb_mid, bb_lower = bb(close, 20, 2)\nrsi14 = RSI(close, 14)\nvolume_avg = SMA(volume, 20)\n# Entry\nbuy_signal = crossover(close, bb_upper) & (volume > volume_avg)\n# Log comparison\nlog_series_comparison(\n    name=\"BB Breakout\",\n    close_price=close,\n    upper_band=bb_upper,\n    middle_band=bb_mid,\n    lower_band=bb_lower,\n    rsi_value=rsi14,\n    volume=volume,\n    avg_volume=volume_avg,\n    maxrows=20\n)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# exit_logic.ta\n# ==================================================\nexit_signal = crossunder(close, bb_mid) | (rsi14 < 45)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# ==================================================\ndraw(\n    bb_upper,\n    title=\"Upper Band\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    bb_mid,\n    title=\"Middle Band\",\n    frame=0,\n    color=\"yellow\"\n)\ndraw(\n    bb_lower,\n    title=\"Lower Band\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    rsi14,\n    title=\"RSI 14\",\n    frame=1,\n    color=\"purple\"\n)\nmarker_fill(\n    frame=0,\n    line1=bb_upper,\n    line2=bb_lower,\n    color=\"rgba(0,150,255,0.10)\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Log Series Comparison Strategy",
              "desc": "Simple EMA crossover with series comparison logging.",
              "code": "# ==================================================\n# entry_logic.ta\n# Log Series Comparison Strategy\n# ==================================================\n# Indicators\nema20 = EMA(close, 20)\nrsi14 = RSI(close, 14)\natr14 = ATR(14)\n# Entry Condition\nbuy_signal = crossover(close, ema20)\n# Log series comparison\nlog_series_comparison(\n    name=\"EMA vs Price\",\n    close_price=close,\n    ema20=ema20,\n    rsi14=rsi14,\n    atr14=atr14,\n    maxrows=20\n)\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# exit_logic.ta\n# ==================================================\nexit_signal = crossunder(close, ema20)\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# ==================================================\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\ndraw(\n    rsi14,\n    title=\"RSI 14\",\n    frame=1,\n    color=\"purple\"\n)\ndraw(\n    atr14,\n    title=\"ATR 14\",\n    frame=2,\n    color=\"orange\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "debug_logic_breakdown",
          "args": "(title, final_signal, ...)",
          "desc": "Prints a report explaining why a boolean signal was True/False.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "SuperTrend Debug Strategy",
              "desc": "Debug individual conditions making up a SuperTrend entry signal.",
              "code": "# ==================================================\n# SuperTrend Debug Strategy | entry_logic.ta\n# ==================================================\n# Indicators\nst_val, st_dir = SuperTrend(10, 3.0)\nrsi_val = RSI(close, 14)\n# Individual Conditions\ntrend_up = st_dir > 0\nrsi_ok = rsi_val > 55\nprice_above_st = close > st_val\n# Final Entry\nlong_entry = trend_up & rsi_ok & price_above_st\n# Debug why entry is or isn't happening\ndebug_logic_breakdown(\n    \"SuperTrend Entry\",\n    long_entry,\n    trend_up=trend_up,\n    rsi_ok=rsi_ok,\n    price_above_st=price_above_st\n)\nEntry(\n    index=1,\n    logic=long_entry,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# exit_logic.ta\n# ==================================================\nlong_exit = (st_dir < 0) | (rsi_val < 45) | DayLastBar\nExit(\n    index=1,\n    logic=long_exit,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# ==================================================\ndraw(\n    st_val,\n    title=\"SuperTrend\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    rsi_val,\n    title=\"RSI 14\",\n    frame=1,\n    color=\"purple\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)\ndrawshape(\n    condition=long_entry,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"green\",\n    size=\"small\"\n)"
            },
            {
              "title": "Bollinger Breakout Debug Strategy",
              "desc": "Break down the components of a Bollinger breakout entry.",
              "code": "# ==================================================\n# Bollinger Breakout Debug Strategy | entry_logic.ta\n# ==================================================\n# Indicators\nbb_upper, bb_mid, bb_lower = bb(close, 20, 2)\nrsi_val = RSI(close, 14)\navg_vol = SMA(volume, 20)\n# Individual Conditions\nprice_breakout = close > bb_upper\nvolume_confirm = volume > avg_vol\nrsi_confirm = rsi_val > 60\n# Final Entry\nlong_entry = price_breakout & volume_confirm & rsi_confirm\n# Debug why entry passed or failed\ndebug_logic_breakdown(\n    \"BB Breakout Entry\",\n    long_entry,\n    price_breakout=price_breakout,\n    volume_confirm=volume_confirm,\n    rsi_confirm=rsi_confirm\n)\nEntry(\n    index=1,\n    logic=long_entry,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# exit_logic.ta\n# ==================================================\nlong_exit = (close < bb_mid) | (rsi_val < 45) | DayLastBar\nExit(\n    index=1,\n    logic=long_exit,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# ==================================================\ndraw(\n    bb_upper,\n    title=\"Upper Band\",\n    frame=0,\n    color=\"red\"\n)\ndraw(\n    bb_mid,\n    title=\"Middle Band\",\n    frame=0,\n    color=\"white\"\n)\ndraw(\n    bb_lower,\n    title=\"Lower Band\",\n    frame=0,\n    color=\"green\"\n)\ndraw(\n    rsi_val,\n    title=\"RSI 14\",\n    frame=1,\n    color=\"purple\"\n)\nmarker_fill(\n    frame=0,\n    line1=bb_upper,\n    line2=bb_lower,\n    color=\"rgba(0,150,255,0.10)\"\n)\ndrawshape(\n    condition=long_entry,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"green\",\n    size=\"small\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "log_snapshot_on_event",
          "args": "(event_condition, date, time, **variables_to_log)",
          "desc": "Logs the values of key variables at a specific moment.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "RSI Snapshot Strategy",
              "desc": "Capture indicator values exactly when RSI crosses 70.",
              "code": "# ==================================================\n# RSI Snapshot Strategy | entry_logic.ta\n# ==================================================\nema20 = EMA(close, 20)\nrsi14 = RSI(close, 14)\natr14 = ATR(14)\ntrend_up = close > ema20\nrsi_entry = crossover(rsi14, 50)\nbuy_signal = trend_up & rsi_entry\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# exit_logic.ta\n# ==================================================\noverbought = crossover(rsi14, 70)\n# Capture indicator values exactly when RSI crosses 70\nlog_snapshot_on_event(\n    overbought,\n    close_price=close,\n    ema20=ema20,\n    rsi_value=rsi14,\n    atr_value=atr14,\n    open_profit=open_pnl,\n    bars_held=bars_in_trade\n)\nexit_signal = overbought | DayLastBar\nExit(\n    index=1,\n    logic=exit_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# ==================================================\ndraw(\n    ema20,\n    title=\"EMA 20\",\n    frame=0,\n    color=\"blue\"\n)\ndraw(\n    rsi14,\n    title=\"RSI 14\",\n    frame=1,\n    color=\"purple\"\n)\ndraw(\n    70,\n    title=\"Overbought\",\n    frame=1,\n    color=\"red\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)\ndrawshape(\n    condition=buy_signal,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"green\",\n    size=\"small\"\n)"
            },
            {
              "title": "MACD Snapshot Strategy",
              "desc": "Capture market state at exit using log_snapshot_on_event with MACD.",
              "code": "# ==================================================\n# MACD Snapshot Strategy | entry_logic.ta\n# ==================================================\n# Indicators\nmacd_line, signal_line, histogram = MACD(close, 12, 26, 9)\nema50 = EMA(close, 50)\n# Entry Conditions\ntrend_up = close > ema50\nmacd_bull = crossover(macd_line, signal_line)\nlong_entry = trend_up & macd_bull\nEntry(\n    index=1,\n    logic=long_entry,\n    timeframe=15,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# exit_logic.ta\n# ==================================================\n# Exit Condition\nmacd_bear = crossunder(macd_line, signal_line)\n# Capture market state at exit\nlog_snapshot_on_event(\n    macd_bear,\n    close_price=close,\n    macd=macd_line,\n    signal=signal_line,\n    histogram=histogram,\n    ema50=ema50,\n    pnl=open_pnl,\n    bars=bars_in_trade\n)\nExit(\n    index=1,\n    logic=macd_bear,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# canvas.ta\n# ==================================================\ndraw(\n    ema50,\n    title=\"EMA 50\",\n    frame=0,\n    color=\"orange\"\n)\ndraw(\n    macd_line,\n    title=\"MACD\",\n    frame=1,\n    color=\"blue\"\n)\ndraw(\n    signal_line,\n    title=\"Signal\",\n    frame=1,\n    color=\"red\"\n)\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)\ndrawshape(\n    condition=long_entry,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"green\",\n    size=\"small\"\n)"
            }
          ]
        },
        {
          "name": "debug_paint_background",
          "args": "(condition, frame, color)",
          "desc": "Paints the chart background based on a condition.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "EMA & RSI Bearish Paint Strategy",
              "desc": "Paint the main chart and RSI panel red when bearish conditions are met.",
              "code": "# ==========================================\n# 1. Calculate Indicators\n# ==========================================\nfast_ma = EMA(close, 9)\nslow_ma = EMA(close, 21)\nrsi_line = RSI(close, 14)\n# Plot indicators\ndraw(plot_data=fast_ma, title=\"9 EMA\", color=\"cyan\")\ndraw(plot_data=slow_ma, title=\"21 EMA\", color=\"green\")\ndraw(rsi_line, \"RSI\", 1, color=\"purple\")\n# ==========================================\n# 2. Define Core Logic Conditions\n# ==========================================\n# Bearish EMA crossover\nma_cross_down = crossunder(fast_ma, slow_ma)\n# RSI in bearish territory\nrsi_bearish = rsi_line < 45\n# Final Exit Logic\nsell_signal = ma_cross_down & rsi_bearish\n# ==========================================\n# 3. Visual Debugging\n# ==========================================\n# Paint the Main Chart RED whenever the sell signal is true.\ndebug_paint_background(\n    sell_signal,\n    frame=0,\n    color=\"red\"\n)\n# Paint the RSI panel RED whenever RSI is bearish.\ndebug_paint_background(\n    rsi_bearish,\n    frame=1,\n    color=\"red\"\n)"
            },
            {
              "title": "MACD Trend Background Painter",
              "desc": "Paint the main chart and MACD panel dynamically based on trend direction.",
              "code": "# ==========================================\n# 1. Calculate Indicators\n# ==========================================\nmacd_line, signal_line, histogram = MACD(close, 12, 26, 9)\n# Plot MACD\ndraw(macd_line, title=\"MACD\", frame=1, color=\"blue\")\ndraw(signal_line, title=\"Signal\", frame=1, color=\"orange\")\ndraw(histogram, title=\"Histogram\", frame=2, color=\"green\")\n# ==========================================\n# 2. Define Core Logic Conditions\n# ==========================================\n# Bullish MACD crossover\nmacd_bull = crossover(macd_line, signal_line)\n# Bearish MACD crossover\nmacd_bear = crossunder(macd_line, signal_line)\n# Positive / Negative momentum\nbullish_momentum = histogram > 0\nbearish_momentum = histogram < 0\n# ==========================================\n# 3. Visual Debugging\n# ==========================================\n# Paint the main chart GREEN on bullish MACD crossover\ndebug_paint_background(\n    macd_bull,\n    frame=0,\n    color=\"green\"\n)\n# Paint the main chart RED on bearish MACD crossover\ndebug_paint_background(\n    macd_bear,\n    frame=0,\n    color=\"red\"\n)\n# Paint MACD panel GREEN while histogram is positive\ndebug_paint_background(\n    bullish_momentum,\n    frame=1,\n    color=\"green\"\n)\n# Paint MACD panel RED while histogram is negative\ndebug_paint_background(\n    bearish_momentum,\n    frame=1,\n    color=\"red\"\n)"
            }
          ]
        },
        {
          "name": "debug_assert",
          "args": "(condition, message)",
          "desc": "Validates a condition and warns if it ever becomes false.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "EMA + RSI Trend Following Strategy",
              "desc": "Demonstrates how to use debug_assert() to validate important assumptions before placing trades.",
              "code": "# ==================================================\n# Debug Assert Strategy\n# EMA + RSI Trend Following Strategy\n# Demonstrates how to use debug_assert() to validate\n# important assumptions before placing trades.\n# ==================================================\n# ------------------------------------------\n# Calculate Indicators\n# ------------------------------------------\n# Fast EMA (9) reacts quickly to price movement.\nfast_ema = EMA(close, 9)\n# Slow EMA (21) represents the short-term trend.\nslow_ema = EMA(close, 21)\n# RSI measures market momentum.\nrsi_val = RSI(close, 14)\n# ATR measures market volatility.\n# Used here only for validation through debug_assert().\natr_val = ATR(14)\n# ------------------------------------------\n# Entry Conditions\n# ------------------------------------------\n# Fast EMA should be above Slow EMA,\n# indicating a bullish trend.\ntrend_ok = fast_ema > slow_ema\n# Current price should be above the Slow EMA,\n# confirming price strength.\nprice_ok = close > slow_ema\n# RSI should be above 45,\n# showing bullish momentum.\nrsi_ok = rsi_val > 45\n# Allow trades only during market hours\n# between 9:15 AM and 3:15 PM.\nmorning_ok = (time >= 915) & (time <= 1515)\n# Only enter if there is no open position.\nflat_filter = position_size == 0\n# Final Buy Signal\n# Trade is executed only when all conditions are true.\nlong_entry = trend_ok & price_ok & rsi_ok & morning_ok & flat_filter\n# ------------------------------------------\n# Debug Assertions\n# ------------------------------------------\n# Verify ATR calculation.\n# This assertion is intentionally written to fail\n# (ATR can never be less than zero) so you can\n# observe how debug_assert() reports errors.\ndebug_assert(\n    atr_val < 0,\n    \"CRITICAL: ATR invalid\"\n)\n# Verify candle data integrity.\n# Every candle must have High greater than or equal to Low.\n# If this fails, the market data is corrupted.\ndebug_assert(\n    high >= low,\n    \"CRITICAL: Candle high is below low\"\n)\n# ------------------------------------------\n# Place Buy Order\n# ------------------------------------------\nEntry(\n    index=1,\n    logic=long_entry,\n    timeframe=15,\n    script=HDFCBANK,\n    action=Buy,\n    order_type=\"MARKET\"\n)"
            }
          ]
        }
      ]
    },
    {
      "category": "Canvas & Visualization",
      "items": [
        {
          "name": "draw",
          "args": "(plot_data, title, frame, overlay, color)",
          "desc": "Plots a data series onto the main chart or a dedicated indicator panel.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "ATR Volatility Breakout Strategy",
              "desc": "Buy when ATR rises above its average.",
              "code": "# ==================================================\n# ATR Volatility Breakout Strategy\n# Buy when ATR rises above its average.\n# Higher ATR indicates increasing volatility.\n# ==================================================\n# Calculate the 14-period ATR.\n# ATR measures market volatility.\natr_val = ATR(14)\n# Calculate the average ATR over 20 periods.\n# Used as a baseline for comparison.\natr_avg = SMA(atr_val, 20)\n# Signal becomes True when ATR crosses\n# above its own average volatility.\nbuy_signal = crossover(atr_val, atr_avg)\n# Enter a long position when volatility expands.\nEntry(\n    index=1,                 # Strategy identifier\n    logic=buy_signal,        # Entry condition\n    timeframe=5,            # 5-minute chart\n    script=RELIANCE,        # Instrument to trade\n    action=Buy,             # Buy order\n    order_type=\"MARKET\"     # Execute immediately\n)\n# ==================================================\n# ATR Volatility Breakout Strategy\n# Exit when ATR falls below its average.\n# Lower ATR indicates volatility contraction.\n# ==================================================\n# Calculate ATR.\natr_val = ATR(14)\n# Calculate ATR average.\natr_avg = SMA(atr_val, 20)\n# Signal becomes True when ATR falls\n# back below its average.\nsell_signal = crossunder(atr_val, atr_avg)\n# Exit the position.\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# ATR Volatility Breakout Strategy\n# Canvas Visualization\n# ==================================================\n# Calculate the 14-period ATR.\n# ATR measures market volatility.\natr_val = ATR(14)\n# Calculate ATR average.\n# Helps identify volatility expansion.\natr_avg = SMA(atr_val, 20)\n# Plot ATR in a separate indicator panel.\n# Frame 1 creates a new panel below the chart.\ndraw(\n    atr_val,\n    title=\"ATR 14\",\n    frame=1,\n    color=\"orange\"\n)\n# Plot ATR average for comparison.\ndraw(\n    atr_avg,\n    title=\"ATR Average\",\n    frame=1,\n    color=\"blue\"\n)\n# ATR above average means volatility expansion.\nhigh_volatility = atr_val > atr_avg\n# Draw a marker whenever ATR crosses\n# above its average.\ndrawshape(\n    condition=crossover(atr_val, atr_avg),\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"small\"\n)\n# Draw a marker whenever ATR crosses\n# below its average.\ndrawshape(\n    condition=crossunder(atr_val, atr_avg),\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\",\n    size=\"small\"\n)\n# Display strategy name.\nmarker_text(\n    frame=1,\n    text=\"ATR Volatility Strategy\",\n    anchor=\"top_right\"\n)\n# Display completed trades.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "EMA + RSI Momentum Strategy",
              "desc": "Buy when short-term trend and momentum align.",
              "code": "# ==================================================\n# EMA + RSI Momentum Strategy\n# Buy when short-term trend and momentum align.\n# ==================================================\n# Calculate a fast EMA for short-term trend analysis.\n# EMA reacts quickly to recent price changes.\nema_9 = EMA(close, 9)\n# Calculate a fast RSI for momentum analysis.\n# RSI measures buying and selling pressure.\nrsi_7 = RSI(close, 7)\n# Trend condition:\n# Price must be trading above the EMA.\ntrend_up = close > ema_9\n# Momentum condition:\n# RSI above 60 indicates bullish momentum.\nstrong_momentum = rsi_7 > 60\n# Enter only when both trend and momentum agree.\nbuy_signal = trend_up & strong_momentum\n# Create a buy order.\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# EMA + RSI Momentum Strategy\n# Exit when trend weakens.\n# ==================================================\n# Calculate the same EMA used for entry.\nema_9 = EMA(close, 9)\n# Calculate the same RSI used for entry.\nrsi_7 = RSI(close, 7)\n# Exit if either:\n# Price falls below EMA\n# OR RSI drops below 50\nsell_signal = (close < ema_9) | (rsi_7 < 50)\n# Close the position.\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# EMA + RSI Momentum Strategy\n# Visualize trend and momentum together.\n# ==================================================\n# Calculate a fast EMA for short-term trend analysis.\nema_9 = EMA(close, 9)\n# Calculate a fast RSI for short-term momentum analysis.\nrsi_7 = RSI(close, 7)\n# Plot EMA on the main chart.\n# Helps identify the short-term trend direction.\ndraw(\n    ema_9,\n    title=\"EMA 9\",\n    frame=0,\n    color=\"green\"\n)\n# Plot RSI in a separate indicator panel.\n# Frame 1 creates a new panel below the chart.\ndraw(\n    rsi_7,\n    title=\"RSI 7\",\n    frame=1,\n    color=\"blue\"\n)\n# Trend condition:\n# Price is trading above EMA.\ntrend_up = close > ema_9\n# Momentum condition:\n# RSI is above 60.\nstrong_momentum = rsi_7 > 60\n# Combined entry condition.\nbuy_signal = trend_up & strong_momentum\n# Exit condition.\nsell_signal = (close < ema_9) | (rsi_7 < 50)\n# Draw buy markers.\n# Appears whenever both trend and momentum are bullish.\ndrawshape(\n    condition=buy_signal,\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\",\n    size=\"small\"\n)\n# Draw sell markers.\n# Appears whenever trend or momentum weakens.\ndrawshape(\n    condition=sell_signal,\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\",\n    size=\"small\"\n)\n# Display strategy name.\nmarker_text(\n    frame=0,\n    text=\"EMA + RSI Momentum\",\n    anchor=\"top_right\"\n)\n# Show completed trades and PnL.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "drawshape",
          "args": "(condition, shape, location, value, color, size, title)",
          "desc": "Draws geometric shapes (arrows, triangles, circles) tied to conditions on the chart.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "RSI Oversold Reversal Strategy",
              "desc": "Demonstrates drawshape().",
              "code": "# ==================================================\n# RSI Oversold Reversal Strategy\n# Demonstrates drawshape()\n# ==================================================\n# Calculate the 14-period RSI.\n# RSI measures momentum strength.\nrsi_val = RSI(close, 14)\n# Plot RSI in a separate indicator panel.\n# Frame 1 creates a panel below the price chart.\ndraw(\n    rsi_val,\n    title=\"RSI 14\",\n    frame=1,\n    color=\"blue\"\n)\n# Oversold condition.\n# RSI below 30 suggests excessive selling pressure.\noversold = rsi_val < 30\n# Overbought condition.\n# RSI above 70 suggests excessive buying pressure.\noverbought = rsi_val > 70\n# Draw a green circle whenever RSI enters\n# the oversold zone.\n# This helps traders spot potential reversals.\ndrawshape(\n    oversold,\n    shape=\"circle\",\n    location=\"BelowBar\",\n    color=\"green\"\n)\n# Draw a red circle whenever RSI enters\n# the overbought zone.\n# This helps traders identify potential exits.\ndrawshape(\n    overbought,\n    shape=\"circle\",\n    location=\"AboveBar\",\n    color=\"red\"\n)\n# Display strategy name on the chart.\nmarker_text(\n    frame=0,\n    text=\"RSI Drawshape Demo\",\n    anchor=\"top_right\"\n)\n# Show completed trades and profit/loss.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "Bullish Candle Strategy",
              "desc": "Demonstrates drawshape() using bullish candles.",
              "code": "# ==================================================\n# Bullish Candle Strategy\n# Demonstrates drawshape() using bullish candles.\n# ==================================================\n# Create a simple bullish condition.\n# TRUE whenever a candle closes above its opening price.\nbullish_candle = close > open\n# Enter a trade whenever a bullish candle appears.\n# This is intentionally simple so users can focus\n# on understanding the signal generation process.\nEntry(\n    index=1,\n    logic=bullish_candle,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Bullish Candle Strategy\n# Exit on bearish candle.\n# ==================================================\n# Create a bearish condition.\n# TRUE whenever a candle closes below its opening price.\nbearish_candle = close < open\n# Exit the trade when a bearish candle appears.\nExit(\n    index=1,\n    logic=bearish_candle,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Bullish Candle Strategy\n# Demonstrates drawshape()\n# ==================================================\n# Create a simple bullish condition.\n# TRUE whenever the candle closes above its opening price.\nbullish_candle = close > open\n# Create a bearish condition.\n# TRUE whenever the candle closes below its opening price.\nbearish_candle = close < open\n# Draw a yellow star above bullish candles.\n# This helps visually identify candles where\n# buyers were stronger than sellers.\ndrawshape(\n    bullish_candle,\n    shape=\"star\",\n    location=\"AboveBar\",\n    color=\"yellow\"\n)\n# Draw a red star below bearish candles.\n# This helps visually identify candles where\n# sellers were stronger than buyers.\ndrawshape(\n    bearish_candle,\n    shape=\"star\",\n    location=\"BelowBar\",\n    color=\"red\"\n)\n# Display the strategy name on the chart.\nmarker_text(\n    frame=0,\n    text=\"Bullish Candle Drawshape Demo\",\n    anchor=\"top_right\"\n)\n# Display completed trades and profit/loss.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "marker_label",
          "args": "(text, frame, when, location, color)",
          "desc": "Places a text label at a specific bar event on the chart.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "Bullish Candle Label Strategy",
              "desc": "Buy when a bullish candle appears.",
              "code": "# ==================================================\n# Bullish Candle Label Strategy\n# Buy when a bullish candle appears.\n# ==================================================\n# A bullish candle closes above its opening price.\n# This indicates buyers controlled the candle.\nbuy_signal = close > open\n# Enter a long trade on bullish candles.\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# Bullish Candle Label Strategy\n# Exit on bearish candles.\n# ==================================================\n# A bearish candle closes below its opening price.\n# This indicates sellers controlled the candle.\nsell_signal = close < open\n# Exit the position.\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# Bullish Candle Label Strategy\n# Demonstrates marker_label()\n# ==================================================\n# Bullish candle condition.\n# TRUE when the candle closes above its opening price.\nbuy_signal = close > open\n# Bearish candle condition.\n# TRUE when the candle closes below its opening price.\nsell_signal = close < open\n# Show BUY label below bullish candles.\n# Helps identify entry opportunities directly on chart.\nmarker_label(\n    text=\"Buy\",\n    frame=0,\n    when=buy_signal,\n    location=\"BelowBar\",\n    color=\"green\"\n)\n# Show SELL label above bearish candles.\n# Helps identify exit opportunities directly on chart.\nmarker_label(\n    text=\"Sell\",\n    frame=0,\n    when=sell_signal,\n    location=\"AboveBar\",\n    color=\"red\"\n)\n# Display strategy name.\nmarker_text(\n    frame=0,\n    text=\"Marker Label Demo\",\n    anchor=\"top_right\"\n)\n# Display completed trades and PnL.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            },
            {
              "title": "RSI Overbought Strategy",
              "desc": "Buy when RSI enters strong momentum territory.",
              "code": "# ==================================================\n# RSI Overbought Strategy\n# Buy when RSI enters strong momentum territory.\n# ==================================================\n# Calculate the 14-period RSI.\n# RSI measures momentum on a scale from 0 to 100.\nrsi_val = RSI(close, 14)\n# Buy when RSI crosses above 50.\n# This suggests bullish momentum is increasing.\nbuy_signal = crossover(rsi_val, 50)\n# Enter a long position.\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# RSI Overbought Strategy\n# Exit when momentum weakens.\n# ==================================================\n# Calculate RSI.\nrsi_val = RSI(close, 14)\n# Exit when RSI falls below 50.\n# This indicates weakening bullish momentum.\nsell_signal = crossunder(rsi_val, 50)\n# Close the position.\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# RSI Overbought Strategy\n# Demonstrates marker_label()\n# ==================================================\n# Calculate the 14-period RSI.\n# RSI measures market momentum.\nrsi_val = RSI(close, 14)\n# Plot RSI in a separate indicator panel.\n# Frame 1 creates a new panel below the chart.\ndraw(\n    rsi_val,\n    title=\"RSI 14\",\n    frame=1,\n    color=\"blue\"\n)\n# Overbought condition.\n# RSI above 70 indicates strong buying pressure.\noverbought = rsi_val > 70\n# Oversold condition.\n# RSI below 30 indicates strong selling pressure.\noversold = rsi_val < 30\n# Display an \"Overbought\" label whenever\n# RSI rises above 70.\n# Traders often watch this area for profit booking.\nmarker_label(\n    text=\"Overbought\",\n    frame=0,\n    when=overbought,\n    location=\"AboveBar\",\n    color=\"red\"\n)\n# Display an \"Oversold\" label whenever\n# RSI falls below 30.\n# Traders often watch this area for reversals.\nmarker_label(\n    text=\"Oversold\",\n    frame=0,\n    when=oversold,\n    location=\"BelowBar\",\n    color=\"green\"\n)\n# Display strategy name.\nmarker_text(\n    frame=0,\n    text=\"RSI Label Demo\",\n    anchor=\"top_right\"\n)\n# Display completed trades and PnL.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        },
        {
          "name": "marker_trades",
          "args": "(frame, show_pnl, show_signal_line)",
          "desc": "Displays entry/exit markers and connecting lines on the chart for all executed trades.",
          "hasMoreExamples": true,
          "moreExamples": [
            {
              "title": "EMA Crossover Strategy",
              "desc": "Demonstrates marker_trades().",
              "code": "# ==================================================\n# EMA Crossover Strategy\n# Demonstrates marker_trades()\n# ==================================================\n# Calculate a fast EMA.\n# Fast EMA reacts quickly to price changes.\nema_9 = EMA(close, 9)\n# Calculate a slow EMA.\n# Slow EMA helps identify the broader trend.\nema_21 = EMA(close, 21)\n# Buy when the fast EMA crosses above the slow EMA.\n# This suggests bullish momentum is beginning.\nbuy_signal = crossover(ema_9, ema_21)\n# Enter a long trade.\nEntry(\n    index=1,\n    logic=buy_signal,\n    timeframe=5,\n    script=RELIANCE,\n    action=Buy,\n    order_type=\"MARKET\"\n)\n# ==================================================\n# EMA Crossover Strategy\n# Exit Logic\n# ==================================================\n# Calculate EMAs again for exit logic.\nema_9 = EMA(close, 9)\nema_21 = EMA(close, 21)\n# Exit when the fast EMA crosses below the slow EMA.\n# This suggests bullish momentum is weakening.\nsell_signal = crossunder(ema_9, ema_21)\n# Close the position.\nExit(\n    index=1,\n    logic=sell_signal,\n    exit_type=\"MARKET\"\n)\n# ==================================================\n# EMA Crossover Strategy\n# Demonstrates marker_trades()\n# ==================================================\n# Calculate a fast EMA.\nema_9 = EMA(close, 9)\n# Calculate a slow EMA.\nema_21 = EMA(close, 21)\n# Plot the fast EMA on the chart.\ndraw(\n    ema_9,\n    title=\"EMA 9\",\n    frame=0,\n    color=\"green\"\n)\n# Plot the slow EMA on the chart.\ndraw(\n    ema_21,\n    title=\"EMA 21\",\n    frame=0,\n    color=\"red\"\n)\n# Mark bullish crossovers.\ndrawshape(\n    crossover(ema_9, ema_21),\n    shape=\"triangle_up\",\n    location=\"BelowBar\",\n    color=\"lime\"\n)\n# Mark bearish crossunders.\ndrawshape(\n    crossunder(ema_9, ema_21),\n    shape=\"triangle_down\",\n    location=\"AboveBar\",\n    color=\"red\"\n)\n# Display strategy name.\nmarker_text(\n    frame=0,\n    text=\"EMA Crossover Strategy\",\n    anchor=\"top_right\"\n)\n# Show current EMA values.\nmarker_table(\n    frame=0,\n    data=[\n        [\"EMA 9\", round(ema_9, 2)],\n        [\"EMA 21\", round(ema_21, 2)]\n    ],\n    position=\"bottom_right\"\n)\n# Display completed trades and PnL.\nmarker_trades(\n    frame=0,\n    show_pnl=True\n)"
            }
          ]
        }
      ]
    }
  ]
}
