← Todos los ejemplos
Ejemplo 35
Gamma wall absorption
the call wall and the put wall of the options market as levels on the chart, and a mark when the last closed bar was
- Categoría
- Espacio de trabajo: lee o cambia gráficos y paneles
- Permisos
- market.readworkspace.readworkspace.write
- Antes de ejecutarlo
- a terminal connected to a backend that reads the options chain (BTC, ETH), with a chart of a symbol of that asset open
- Qué hace
- DRAWS levels and a mark named "gamma_walls" on the active chart (run again: replaced); sounds the alert chime on an
- Cómo ejecutarlo
- grant market.read, workspace.read and workspace.write, Run on a BTCUSDT or ETHUSDT chart.
- Lenguaje
>=0.1.1, <0.2.0- Host
>=0.1.7, <0.2.0- Necesita
- options >=0.1.0, <0.2.0flow >=0.1.0, <0.2.0workspace >=0.1.0, <0.2.0plot >=0.1.0, <0.2.0alert >=0.1.0, <0.2.0event >=0.1.0, <0.2.0
Código
// Purpose: the call wall and the put wall of the options market as levels on the chart, and a mark when the last closed bar was // absorbed at the call wall: buyers lifted the offer there and it did not give. **Walls from an old chain are not walls**: when the // chain is unknown the program takes its levels off the chart instead of leaving the last ones up, and a bar the tape did not record // gets no verdict. // Category: workspace // Permissions: market.read, workspace.read, workspace.write // Preconditions: a terminal connected to a backend that reads the options chain (BTC, ETH), with a chart of a symbol of that asset open // Side effects: DRAWS levels and a mark named "gamma_walls" on the active chart (run again: replaced); sounds the alert chime on an // absorption. // Run: grant market.read, workspace.read and workspace.write, Run on a BTCUSDT or ETHUSDT chart. lang ">=0.1.1, <0.2.0"; host "ttt" ">=0.1.7, <0.2.0"; requires "options" ">=0.1.0, <0.2.0"; requires "flow" ">=0.1.0, <0.2.0"; requires "workspace" ">=0.1.0, <0.2.0"; requires "plot" ">=0.1.0, <0.2.0"; requires "alert" ">=0.1.0, <0.2.0"; requires "event" ">=0.1.0, <0.2.0"; import std.text; const OWNER: String = "gamma_walls"; fn main() -> Result<Unit, Error> { let chart = workspace.active_chart().expect("no chart is open"); let asset = if text.starts_with(chart.symbol, "ETH") { "ETH" } else { "BTC" }; let now = event.current().time; let gamma = options.gamma_at(asset, now)?; // Whatever this drew before is taken down first: if the chain is unknown now, yesterday's walls must not stay on the chart. plot.clear(chart.chart, OWNER)?; match gamma.unknown { Some(why) => { print("no walls drawn: " + why); return Ok(()); } None => {} } if gamma.unpriced > 0 { print(to_string(gamma.unpriced) + " listed options had no implied volatility: the walls are worked out without them"); } match gamma.put_wall { Some(wall) => { plot.level(chart.chart, OWNER, price(wall.amount(), USDT), "put wall", "green")?; } None => {} } if gamma.call_wall.is_none() { print("the chain has no call wall"); return Ok(()); } let wall = gamma.call_wall.expect("checked above"); plot.level(chart.chart, OWNER, price(wall.amount(), USDT), "call wall", "red")?; // The last closed five-minute bar: what traded in the band that holds the wall. let band = price(50.0, USDT); let fp = flow.footprint(chart.symbol, "5m", now - 10min, now, band)?; if fp.bars.is_empty() { print("call wall " + to_string(wall) + ": no five-minute bar has closed yet"); return Ok(()); } let bar = fp.bars.last().expect("checked above"); if !bar.known { print("call wall " + to_string(wall) + ": the last bar was not recorded by the tape, so there is no verdict on it"); return Ok(()); } let mut verdict = "nothing traded at the wall in the last bar"; for cell in bar.cells { let floor = to_float(cell.price.amount()); let level = to_float(wall.amount()); if level >= floor && level < floor + 50.0 { let lifted = to_float(cell.buy.value()); let hit = to_float(cell.sell.value()); if lifted >= hit * 3.0 && lifted > 0.0 { plot.marker(chart.chart, OWNER, bar.open_time, cell.price, "absorbed: " + to_string(lifted) + " lifted", "red")?; alert.notify("Absorption at the call wall", chart.symbol + ": " + to_string(lifted) + " bought into " + to_string(wall) + " and it held")?; verdict = "ABSORBED at the wall"; } else { verdict = "traded at the wall without absorption"; } } } print("call wall " + to_string(wall) + ": " + verdict); return Ok(()); }