Log in

Try QTScript in the browser

Three QTScript strategies you can run here, in your browser, on sample series, and change their parameters to see what each one does.

The strategies on this page run in your browser. The code of each block is compiled by the QTScript compiler of the Laboratory and run by the TypeScript engine on a sample series, the same series the indicator pages draw. Move a parameter or pick another series and it runs again: the chart shows the strategy’s own indicators and the signals it acted on, and below it are the figures of the run.

No account and no request to the platform are involved. The figures are those of this run, on these bars: a backtest on the platform runs the Java engine over the market data you prepare, and can give other numbers.

Bollinger bounce

It buys when the close falls under the lower band and sells when it comes back above the middle one. The period of the bands is a parameter; the body is on the bands themselves, so $indicator is their name and value($indicator + "Lower") reads the lower band whatever the period.

strategy "Bollinger bounce" kline

param period = 20 "Bollinger period"

setup:
  bollinger(period, 2) window m1 {
    if (close < value($indicator + "Lower") && !store.is("long")) {
      store.set("long");
      emitBuy(close);
    }
    if (close > value($indicator) && store.is("long")) {
      store.unset("long");
      emitSell(close);
    }
  }

EMA cross

It is long while the fast EMA is above the slow one. The two periods are parameters, and the names of the two indicators follow them ("ema" + fast), so a run with other periods reads the right lines.

strategy "EMA cross" kline

param fast = 9  "Fast EMA"
param slow = 21 "Slow EMA"

setup:
  ema(fast)
  ema(slow)
  window close m1 {
    double f = value("ema" + fast);
    double s = value("ema" + slow);
    if (f > s && !store.is("long")) {
      store.set("long");
      emitBuy(close);
    }
    if (f < s && store.is("long")) {
      store.unset("long");
      emitSell(close);
    }
  }

RSI coming back from an extreme

It buys when the RSI comes back above rsiLow after being under it, and sells when it comes back below rsiHigh after being over it. A window gives prev and actual, so the crossing is a comparison of the two; the "long" mark keeps it from buying twice.

rsi(14, false) is the RSI with Wilder’s smoothing, which moves on every bar. A plain rsi(14) is built on simple averages over blocks of 14 updates, the builder’s default, so its value holds for a block and moves in steps.

strategy "RSI re-entry" kline

param rsiLow  = 30  "Oversold"
param rsiHigh = 70  "Overbought"

setup:
  rsi(14, false) window m1 {
    if (prev < rsiLow && actual >= rsiLow && !store.is("long")) {
      store.set("long");
      emitBuy(close);
    }
    if (prev > rsiHigh && actual <= rsiHigh && store.is("long")) {
      store.unset("long");
      emitSell(close);
    }
  }

Going further