Skip to content

AlphaScriptIndicators and strategies for subnet alpha markets

JavaScript that runs on the block clock, trades through the AMM pool and backtests exactly the way it trades.

The AlphaForge terminal with the AlphaScript editor open and a strategy running on the chart

A strategy in 20 lines ​

js
strategy({ name: "EMA cross", version: "0.1", market: "ALPHA:61", resolution: "15m",
           capital: { tao: 100 }, risk: { maxPriceImpactPct: 0.5, maxPositionTao: 50 } });

const fast = ta.ema(candle.close, input.int("Fast EMA", 9, { min: 2 }));
const slow = ta.ema(candle.close, input.int("Slow EMA", 21, { min: 2 }));
const goLong = ta.crossover(fast, slow);
const goFlat = ta.crossunder(fast, slow);

plot(fast, { title: "EMA fast", color: "#2bb889" });
plot(slow, { title: "EMA slow", color: "#f2b544" });

event.onCandle(() => {
  const size = account.equity() * 0.25;
  if (goLong.value && pool.impact(size) < 0.0025)
    trade.buy({ tao: size, maxPrice: pool.price() * 1.01, ttlBlocks: 3 });
  if (goFlat.value && account.position().alpha > 0) trade.closePosition();
});

Series such as fast and goLong are declared once at the top level and advance on every bar. Handlers read their current value with .value and decide what to trade. Getting started walks through it.

AlphaScript language v0.1 · runtime 0.2.0