Indicator · Pine Script v6 · Own pane

TR Margin Pulse

by Enesp4rl4k

TR Margin Pulse calculates and plots the ratio of marketwide margin calls to required margin using Takasbank data generated via MCP templates.

View on GitHub

GitHub stars7on the repository
Pine versionv6current
Lines of code63
Settings0inputs
LicenceMIT
Last update5 days ago23 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

63 lines of Pine Script v6 from src/bist_trader_mcp/pine_recipes/tr_margin_pulse.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

tr_margin_pulse.pine
//@version=6
// =============================================================================
// TR Margin Pulse — overlay marketwide VIOP margin call signal from Takasbank.
// Plots the ratio Margin Call Total / Required Margin as a separate pane, with
// alert thresholds for stress.
//
// Placeholders filled by the MCP at generation time:
//   {{MARGIN_CALL_TL}}     — latest margin call total (TL)
//   {{REQUIRED_MARGIN_TL}} — latest required margin total (TL)
//   {{HISTORY_JSON}}       — JSON array of {date, mc_tl, req_tl} (last N days)
//   {{STRESS_THRESHOLD}}   — ratio above which to alert (default 0.05)
//   {{AS_OF_DATE}}         — YYYY-MM-DD snapshot
// =============================================================================
indicator("TR Margin Pulse ({{AS_OF_DATE}})", overlay = false)

stressThreshold = {{STRESS_THRESHOLD}}

// Latest snapshot — displayed as a table.
mcLatest  = {{MARGIN_CALL_TL}}
reqLatest = {{REQUIRED_MARGIN_TL}}
ratioLatest = reqLatest > 0 ? mcLatest / reqLatest : na

// --- Time series (parallel arrays) ------------------------------------------
var int[]   histDates = array.new<int>(0)
var float[] histMc    = array.new<float>(0)
var float[] histReq   = array.new<float>(0)

if barstate.isfirst
    {{MARGIN_HISTORY_LOADER}}

getRatioOnBar() =>
    r = na
    if array.size(histDates) > 0
        for i = 0 to array.size(histDates) - 1
            ts = array.get(histDates, i)
            if ts >= time and ts <= time_close
                mc = array.get(histMc, i)
                rq = array.get(histReq, i)
                r := rq > 0 ? mc / rq : na
                break
    r

ratio = getRatioOnBar()
plot(ratio, title = "Margin Call / Required",
     color = ratio >= stressThreshold ? color.red : color.teal,
     linewidth = 2)
hline(stressThreshold, "Stress threshold", color = color.orange,
      linestyle = hline.style_dashed)
hline(0, "Zero", color = color.gray)

// Snapshot table
var table snap = table.new(position.top_right, 2, 3, frame_color = color.gray)
if barstate.islast
    table.cell(snap, 0, 0, "Margin Call (TL)", bgcolor = color.new(color.gray, 70))
    table.cell(snap, 1, 0, str.tostring(mcLatest, "#,###"))
    table.cell(snap, 0, 1, "Required (TL)", bgcolor = color.new(color.gray, 70))
    table.cell(snap, 1, 1, str.tostring(reqLatest, "#,###"))
    table.cell(snap, 0, 2, "Ratio", bgcolor = color.new(color.gray, 70))
    table.cell(snap, 1, 2, str.tostring(ratioLatest, "#.####"))

alertcondition(ratio >= stressThreshold,
               title   = "VIOP marketwide stress",
               message = "Margin call ratio crossed stress threshold")

Overview

Rendered in a separate pane, the line turns red when exceeding a predefined stress threshold and teal when below. A summary table in the top right displays the latest snapshot figures for total margin calls, required margin, and the current ratio. An alert condition triggers whenever the ratio breaches the stress threshold. It relies on populated template arrays for historical data.

Details

Published by

Enesp4rl4k on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Screeners & dashboards

Markets

Stocks, Indices

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

bistborsa-istanbulclaudeevdsfinancellmmcpmodel-context-protocolpine-scriptpython

Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

This indicator measures the chart symbol’s percentage change from the opening price at the start of each US presidential term and plots those values as histogram columns in a separate pane. Columns are offset so each administration appears separately, with a s

Indicator v6 Screeners & dashboards
Updated 10 days ago · GPL-3.0 GitHub repository of Presidents Performance

This indicator scans a pasted list of symbols for RSI directional momentum and shows matching long and short signals in a table in a separate pane. The user chooses continuous break, continuous retracement, flip break, flip retracement, divergence, or hidden d

Indicator v6 Oscillators & momentumDivergence
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Scanner

Tables-001

by ricardosantos79
261 stars

This indicator builds a TradingView table in a separate pane and fills its cells with fixed placeholder text according to whether each row and column index is even or odd. Users set the table position, the number of rows and columns, and the background, frame,

Indicator v4 Screeners & dashboards
Updated 4 years ago · None stated GitHub repository of Tables-001
257 stars

Donald SPX - Options Trading is an indicator designed to assist SPX index option traders by tracking session benchmarks and multi-timeframe moving average data. It calculates a 200-period weighted moving average (WMA) and requests multi-timeframe bar data from

Indicator v5 Moving averagesScreeners & dashboards Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald SPX - Options Trading

Index Member Distribution

by TradersPost
218 stars

Calculates and plots a weighted histogram of constituent returns for major market indices (NDX, SPX, DJIA, and RUT) in a separate pane. Each histogram bin reflects the summed weights of members within that percentage return bracket. The script renders vertical

Indicator v6 Screeners & dashboards
Updated 3 months ago · None stated GitHub repository of Index Member Distribution

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers