Skip to content

Moving-price discount ​

Buys when the pool trades below the protocol's moving price.

Kind strategy · Resolution 15m

Buys alpha when the pool trades at a discount to the protocol's moving price, and targets the moving price.

Background. The moving price is the chain's smoothed price of the subnet's alpha. When the pool price falls well below it, the gap tends to close; this strategy bets on that.

Entry. The discount (moving price over close, minus 1) is at least Min discount % and RSI is below RSI below.

Exit. Whichever comes first:

  • a take-profit at the moving price seen at entry;
  • a stop Stop below entry low % below the entry bar's low;
  • the close crossing back above the moving price.

The take-profit and stop are conditional orders, placed in onPositionOpened once the buy has filled. Placed next to the buy they would be cancelled before it fills.

Try it ​

On the chart, press /, open Strategies and choose Moving-price discount. Or copy the source below into the AlphaScript editor and click Add to chart.

Inputs ​

InputTypeDefault
Min discount %float3
RSI belowfloat40
Stop below entry low %float2
Size % of equityfloat40

Source ​

From packages/alphascript/examples/moving_price_discount.as.js.

js
strategy({ name: "Moving-price discount", version: "0.1", market: "ALPHA:61", resolution: "15m",
           capital: { tao: 100 }, actOn: "confirmed", risk: { maxPriceImpactPct: 0.4, maxOrderTao: 40 } });

const discount = input.float("Min discount %", 3, { min: 0.5, max: 30, step: 0.5 });
const rsiMax   = input.float("RSI below", 40, { min: 10, max: 60 });
const stopPct  = input.float("Stop below entry low %", 2, { min: 0.5, max: 20, step: 0.5 });
const sizePct  = input.float("Size % of equity", 40, { min: 1, max: 100 });

const mp   = candle.movingPrice;
const rsi  = ta.rsi(candle.close, 14);
const back = ta.crossover(candle.close, mp);

plot(mp,  { title: "moving price", color: "#f2b544", style: "step" });
plot(rsi, { title: "RSI", color: "#8b98a8", pane: 1 });
hline(rsiMax, { color: "#2bb889", style: "dashed", pane: 1 });
plotShape(back, { shape: "circle", location: "aboveBar", color: "#f2b544", text: "mp" });

let target = NaN, entryLow = NaN;

event.onCandle((bar) => {
  const pos = account.position();
  const disc = (mp.value / bar.close - 1) * 100;
  if (pos.alpha === 0) {
    if (disc >= discount && rsi.value < rsiMax) {
      trade.buy({ tao: account.equity() * sizePct / 100, maxPrice: pool.price() * 1.01, ttlBlocks: 3,
                  reason: `discount ${disc.toFixed(2)}%` });
      target = mp.value;
      entryLow = bar.low;
    }
  } else if (back.value) {
    trade.closePosition({ reason: "crossed moving price" });
  }
});

event.onPositionOpened(() => {
  trade.takeProfit({ price: target, reason: "at moving price" });
  trade.stop({ price: entryLow * (1 - stopPct / 100), reason: "below entry low" });
});

event.onPositionClosed((c) => log("round trip", c.realizedTao.toFixed(4), "τ"));

AlphaScript language v0.1 · runtime 0.2.0