Skip to content
API status
Automatic trading

KAS desktop strategies

Create, run, and manage Koneth Automated Strategies in the macOS and Windows terminals.

KAS stands for Koneth Automated Strategies. A KAS runs locally in the native Koneth Terminal and reacts to market events while the app is open and connected.

  1. Open the KAS manager

    Select KAS in the left toolbar of the macOS or Windows terminal. The Koneth Automated Strategies manager opens.

  2. Add a KAS

    Select Add KAS, then choose New KAS to open the KS editor or Import to open an existing .ks strategy file.

  3. Check and save the strategy

    In the KS editor, enter a KAS name and strategy source. Select Check to validate the source, then select Save KAS.

  4. Review the inputs

    Start the KAS from the manager and review its inputs. Select the symbol, timeframe, and volume when the strategy does not define them.

  5. Allow trading and start

    Turn on the terminal-wide Auto Trading switch. In the start dialog, select Allow automated trading, then select Start KAS.

Control What it does
Auto Trading Allows all eligible KAS strategies in the terminal to send trade instructions. When it is off, running strategies can continue calculating and writing logs, but their trade instructions are rejected.
Allow automated trading Gives one KAS permission to send its trade instructions through normal Koneth order execution. You must enable it before starting that KAS.
KAS power switch Starts or stops one saved KAS. Stopping it does not close positions that it already opened.
Auto Start Starts the KAS after a terminal restart when the trading account, market data, and saved strategy ownership are ready.

Koneth Script is a bounded, JavaScript-compatible language. A KAS can declare inputs, read market and account data, calculate indicators, react to events, and submit trade instructions through the functions below.

Every .ks file must contain exactly one strategy() declaration with a quoted name.

strategy("My KAS", { permissions: ["marketData", "trade"] });
Argument Description
name Name shown in the KAS manager.
permissions Capabilities used by the strategy. Declare marketData for market data and trade when the strategy submits trade instructions.

Declaring trade does not enable trading by itself. The terminal-wide Auto Trading switch and the KAS-specific Allow automated trading permission must also be enabled.

Register an event with one arrow callback. You can register each event at most once.

Function When it runs
onStart(() => { ... }) After the KAS starts and its historical bar data is ready.
onTick(() => { ... }) When the subscribed symbol receives a live price update.
onBar(() => { ... }) Once after a new bar closes on the selected timeframe.
onPositionOpened((position) => { ... }) When a position opened by this KAS appears in the account snapshot.
onPositionClosed((position) => { ... }) When a position owned by this KAS closes.
onStop(() => { ... }) When the running KAS stops.

The position passed to a position event has these read-only fields: id, symbol, side, volume, openPrice, currentPrice, stopLoss, takeProfit, and profit.

onPositionOpened((position) => {
log("Opened position " + position.id);
});

Inputs appear in the KAS start and settings dialogs. Each input takes a label followed by its default value.

Function Returns Example
input.int(label, default) Integer input.int("Fast EMA", 20)
input.float(label, default) Number input.float("Volume", 0.10)
input.bool(label, default) Boolean input.bool("Use stops", true)
input.symbol(label, default) Symbol string input.symbol("Symbol", "XAUUSD")
input.timeframe(label, default) Timeframe string input.timeframe("Timeframe", "M5")

Supported timeframe values are M1, M5, M15, M30, H1, H4, and D1. The selected symbol must be available on the connected trading account.

The runtime provides the following bar series for the KAS symbol and timeframe:

Series Value for each bar
open Opening price
high Highest price
low Lowest price
close Closing price
volume Bar volume
time Bar opening time in Unix milliseconds

Use a calculation function with these series:

Function Result
sma(series, period) Simple moving-average series
ema(series, period) Exponential moving-average series
rsi(series, period) Relative Strength Index series
atr(period) Average True Range series calculated from high, low, and close
highest(series, period) Rolling highest-value series
lowest(series, period) Rolling lowest-value series
cross(first, second) Boolean series that is true when either series crosses the other
crossover(first, second) Boolean series that is true when first crosses above second
crossunder(first, second) Boolean series that is true when first crosses below second
last(series) Most recent available value in a series
at(series, barsAgo) Value at the requested number of bars before the latest bar
Math.sqrt(value) Square root of a number

Periods must be between 1 and the number of available bars, up to 5000.

const fast = ema(close, input.int("Fast EMA", 20));
const previousClose = at(close, 1);
const currentAtr = last(atr(14));

The read-only account object exposes current account values:

Property Description
account.balance Account balance
account.equity Current equity
account.margin Margin in use
account.freeMargin Available margin
account.marginLevel Current margin level

Use log(value) to write a value to the KAS journal.

onStart(() => {
log("Starting equity: " + account.equity);
});
Function Returns
positions.all() All open positions on the trading account
positions.mine() Open positions owned by this KAS
positions.count() Number of open positions owned by this KAS
positions.forSymbol(symbol) First account position matching the symbol, or no value when none exists
orders.all() All pending orders on the trading account
orders.mine() Pending orders owned by this KAS
orders.count() Number of pending orders owned by this KAS

A position contains id, symbol, side, volume, openPrice, currentPrice, stopLoss, takeProfit, and profit. A pending order contains id, symbol, side, orderType, volume, price, stopLoss, takeProfit, and status.

Every trading function accepts one options object. Market and pending-order functions use the KAS symbol and volume configured in the start dialog when you omit those fields.

Function Required options Purpose
trade.buy(options) Positive volume or configured volume Submit a market buy
trade.sell(options) Positive volume or configured volume Submit a market sell
trade.buyLimit(options) Positive volume and price Place a buy limit order
trade.sellLimit(options) Positive volume and price Place a sell limit order
trade.buyStop(options) Positive volume and price Place a buy stop order
trade.sellStop(options) Positive volume and price Place a sell stop order
trade.close({ positionId }) Owned positionId Close a position owned by this KAS
trade.modify(options) Owned positionId Change the position’s stop-loss or take-profit
trade.cancel({ orderId }) Owned orderId Cancel a pending order owned by this KAS

Opening-order options are:

Option Description
symbol Trading symbol. Defaults to the KAS symbol.
volume Positive order volume. Defaults to the volume approved in the start dialog.
price Required trigger price for a limit or stop order.
stopLoss or sl Stop-loss price.
takeProfit or tp Take-profit price.
comment Order comment. Defaults to the KAS name.

Use positionId, plus stopLoss or takeProfit, with trade.modify(). The shorter sl and tp names are also accepted.

const mine = positions.mine();
if (mine.length > 0) {
trade.modify({
positionId: mine[0].id,
stopLoss: last(close) - last(atr(14))
});
}

The following strategy checks for a fast and slow exponential moving-average crossover on each new bar. It opens a position only when this KAS has no open positions of its own.

strategy("EMA crossover", { permissions: ["marketData", "trade"] });
onBar(() => {
const fast = ema(close, input.int("Fast EMA", 20));
const slow = ema(close, input.int("Slow EMA", 50));
if (crossover(fast, slow) && positions.count() === 0) {
log("Bullish crossover detected");
trade.buy({
symbol: input.symbol("Symbol", "XAUUSD"),
volume: input.float("Volume", 0.10),
comment: "EMA KAS"
});
}
if (crossunder(fast, slow) && positions.count() === 0) {
log("Bearish crossover detected");
trade.sell({
symbol: input.symbol("Symbol", "XAUUSD"),
volume: input.float("Volume", 0.10),
comment: "EMA KAS"
});
}
});

Save the strategy, start it on a demo trading account, and use Logs in the KAS manager to inspect its activity. Use Settings to change its inputs or enable Auto Start. You can also edit, export, stop, or delete a saved KAS from the manager.

  • KAS runs in a restricted local runtime without direct network, browser, process, or storage access.
  • Trade instructions pass through normal Koneth account authorization and order execution.
  • The runtime rejects duplicate trade instructions within the same event and limits the number of instructions a strategy can send per event.
  • Saved KAS definitions remain available after a terminal restart. A running KAS returns to a stopped state unless you enable Auto Start.

Keep Koneth Terminal open and connected while a KAS is running. If the terminal or computer stops, the KAS cannot process new market events until it starts again.