Ir al contenido
← Todos los ejemplos

Ejemplo 53

Stacked imbalance stop

a footprint strategy. It buys when the last closed five-minute bar was bought hard -- positive delta, stacked buy imbalances

Categoría
Host: necesita los datos y el motor de la terminal
Permisos
orders.submit
Antes de ejecutarlo
a market whose aggregated prints the terminal has (live, replay) or a dataset holding aggTrades (Datasets window).
Qué hace
asks the terminal to run the strategy on that market; once running it places orders on the account the person chose.
Cómo ejecutarlo
Add script on the Market Replay window or the title bar's script icon; Insert strategy in the Datasets window (backtest).
Lenguaje
>=0.2.0, <0.3.0
Host
>=0.1.13, <0.2.0
Necesita
features >=0.1.8, <0.2.0trade >=0.1.0, <0.2.0

Código

// Purpose: a footprint strategy. It buys when the last closed five-minute bar was bought hard -- positive delta, stacked buy imbalances
// on the footprint rows, a close above the point of control -- and puts the stop under the value area, the target two risks away.
// The footprint figures are the chart's own: the same point of control, value area and stacked imbalances you see on the footprint.
//
//   SETUP    delta of the last closed bar > 0, a run of at least three stacked buy imbalances (diagonal ratio `ratio`), price above the POC.
//   STOP     under the bar's value-area low (`val`); TARGET `reward` times the risk away.
//   EXIT     the bar closes back under the POC.
//
// HONEST NOTE: written to the specification and checked that it compiles and hands over a strategy; its edge has not been measured.
// Backtest it on the Datasets window (aggregated prints) over several months, with fees, before trusting it.
// Category: host
// Permissions: orders.submit
// Preconditions: a market whose aggregated prints the terminal has (live, replay) or a dataset holding aggTrades (Datasets window).
// Side effects: asks the terminal to run the strategy on that market; once running it places orders on the account the person chose.
// Run: Add script on the Market Replay window or the title bar's script icon; Insert strategy in the Datasets window (backtest).

lang ">=0.2.0, <0.3.0";
host "ttt" ">=0.1.13, <0.2.0";
requires "features" ">=0.1.8, <0.2.0";
requires "trade" ">=0.1.0, <0.2.0";

strategy stacked_buyers(minutes: Int, tick: Decimal, ratio: Decimal, reward: Decimal, size: Quantity) version "1.0.0" {
    let px = features.price(features.Source.AggTrades);
    let delta = features.flow_delta(features.Source.AggTrades, minutes, tick);
    let poc = features.flow_poc(features.Source.AggTrades, minutes, tick);
    let val = features.flow_value_area_low(features.Source.AggTrades, minutes, tick);
    let stacked = features.flow_stacked_buy(features.Source.AggTrades, minutes, tick, ratio);
    let risk = px - val;
    let setup = delta > 0 && stacked >= 3 && px > poc && risk > 0;
    rule go_long when exposure_is(Exposure.Flat) && setup
        => order(Side.Buy, Intent.Open, OrderType.Market, Sizing.Fixed(size), Protect.Bracket(px + reward * risk, val));
    rule out when exposure_is(Exposure.Open) && px < poc
        => order(Side.Sell, Intent.Close, OrderType.Market, Sizing.Fixed(size));
    flatten_on_stop;
}

fn main() -> Result<Unit, Error> {
    // Five-minute bars on rows of 10 dollars; a diagonal imbalance is 3 times the other side; the target two risks away.
    let run = trade.run(stacked_buyers(5, 10.0, 3.0, 2.0, qty(0.01)))?;
    print(run.name + " on " + run.target + ": " + run.state);
    return Ok(());
}