Overview

Primitives

Primitives are the building blocks of Stoqey. you can think of them as actions / functions that can be used to create more complex strategies.

Primitives

followStopLoss (position)

Input parameters:

PropTypeDefault
percent
number
0.3
ticks
number
3
invisible
boolean
No default value
transmit
boolean

Follow Stop Loss with a stop loss percentage or ticks and some options to make it invisible(not visible to the broker), it follows the the position price and modifies the stop loss order to trail the position.

e.g SQL

POS calculatePosition size=100, entryPrice=50.25 > 51.00 THEN followStopLoss SET ticks=10, invisible=false

takeProfit (position)

Input parameters:

PropTypeDefault
percent
number
0
ticks
number
0
transmit
boolean
true

TakeProfitAlgo is a model that takes profit at a given percentage or ticks.

e.g SQL

IF takeProfit ticks=10 transmit=false
POS pnlTicks > 10 THEN takeProfit SET ticks=10, transmit=true

tickFlow (tick)

Input parameters:

PropTypeDefault
minutes
number
3
transmit
boolean
true
capital
number
No default value

TickFlowAlgo is a model that uses the tick flow to determine the direction of the market.

e.g SQL

IF tickFlow capital=1000 minutes=3 transmit=false
TICK volume WITH minutes=3 > 10000 THEN tickFlow SET transmit=true

timeAction (tick)

Input parameters:

PropTypeDefault
from
string
No default value
to
string
No default value
direction
string
No default value
minutes
number
No default value
capital
number
No default value
transmit
boolean
No default value

TimeActionAlgo is an algorithm that allows you to enter and exit a position during a specific time

e.g SQL

IF timeAction from=09:00:00 to=15:00:00 direction=long minutes=3 capital=1000 transmit=false
TICK volume WITH minutes=3 > 10000 THEN timeAction SET transmit=true

session (all)

Input parameters:

PropTypeDefault
start
string
No default value
end
string
No default value
transmit
boolean

SessionAlgo limits your strategy to precise windows — NYSE open, London close, or any custom range

e.g SQL

IF session from=09:00:00 to=15:00:00 transmit=false
TICK time > "09:00:00" THEN session SET transmit=true
or
IF session from=09:00:00 to=15:00:00 (transmit=true by default)

trailingProfit (position)

Input parameters:

PropTypeDefault
percent
number
0.5
percentBelow
number
0.1
ticks
number
1
ticksBelow
number
1
transmit
boolean

Trailing profit algorithm, close position when profit is above or below a certain percentage or ticks, with below options, you can set a trailing stop to close position when profit is below a certain percentage or ticks

e.g SQL

-- transmit=false manually
IF POS trailingProfit ticks=15 ticksBelow=5 transmit=false
TICK profitTicks > 10 THEN trailingProfit SET transmit=true
-- or transmit=true by default
IF POS trailingProfit ticks=15 ticksBelow=5

breakEven (tick)

Input parameters:

PropTypeDefault
ticks*
number
No default value

Position management algorithm that moves the stop loss to the entry price (break-even) once the position has moved in profit by a specified number of ticks. This helps protect profits while letting winning trades run.

e.g SQL

POS calculatePosition size=100, entryPrice=50.25 > 51.00 THEN breakEven SET ticks=5

cancelOrder (tick)

Input parameters:

PropTypeDefault
afterSeconds*
number
No default value

Cancels all pending orders after a specified time period. This helps manage risk by ensuring orders don't stay open indefinitely.

e.g SQL

TICK price WITH minutes=1 > 0 THEN cancelOrder SET afterSeconds=300

coolDown (tick)

Input parameters:

PropTypeDefault
minutes
number
No default value
transmit
boolean
No default value

Enforces a minimum time period between trades to prevent over-trading. This helps manage risk by ensuring sufficient time between trading decisions.

e.g SQL

IF coolDown minutes=3 transmit=false
TICK volume WITH minutes=3 > 10000 THEN coolDown SET transmit=true

closeOrder (position)

Input parameters:

PropTypeDefault
transmit
boolean
true

Position management algorithm that closes positions based on transmit.

e.g SQL

POS calculatePosition size=100, entryPrice=50.25 > 51.00 THEN closeOrder SET transmit=true

flatten (tick)

Input parameters:

PropTypeDefault
transmit
boolean

Closes all open positions immediately. This is typically used as an emergency exit or to reset the trading state.

e.g SQL

POS calculatePosition size=100, entryPrice=50.25 > 0 THEN flatten SET transmit=true

hedge (tick)

Input parameters:

PropTypeDefault
side*
string
No default value
size*
number
No default value
transmit
boolean
false

Places a hedge order in the opposite direction of the current position to reduce risk. This helps protect against adverse market movements.

e.g SQL

TICK price WITH minutes=1 > 0 THEN hedge SET side=long, size=50, transmit=true

order (tick)

Input parameters:

PropTypeDefault
action*
string
No default value
quantity*
number
No default value
limitPrice
number
No default value
transmit
boolean
false

Basic order placement algorithm that allows placing market or limit orders with specified quantity and action (buy/sell).

e.g SQL

TICK volume WITH minutes=3 > 50 THEN order SET size=100, price=51.25, transmit=true

scaleIn (position)

Input parameters:

PropTypeDefault
increments*
number
No default value
size*
number
No default value
transmit
boolean
false

Scales into a position by placing additional orders when price moves by a specified increment. This helps build a position gradually while managing risk.

e.g SQL

TICK price WITH minutes=1 > 50.25 THEN scaleIn SET increments=0.25, size=50, transmit=true

scaleOut (tick)

Input parameters:

PropTypeDefault
steps*
number
No default value
size*
number
No default value
transmit
boolean
false

Scales out of a position by selling portions of the position at predetermined price levels. This helps lock in profits while letting the remaining position run.

e.g SQL

POS calculatePosition size=100, entryPrice=50.25 > 51.00 THEN scaleOut SET steps=0.25, size=25

timeExit (tick)

Input parameters:

PropTypeDefault
seconds*
number
No default value
transmit
boolean
true

Exits a position after a specified time period has elapsed. This helps manage risk by ensuring positions don't stay open longer than intended.

e.g SQL

POS calculatePosition size=100, entryPrice=50.25 > 0 THEN timeExit SET seconds=1800

riskCap (tick)

Input parameters:

PropTypeDefault
percent*
number
No default value

Limits the risk per trade to a specified percentage of the account. This helps manage overall portfolio risk by controlling position sizes.

e.g SQL

TICK price WITH minutes=1 > 0 THEN riskCap SET percent=2