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
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

IF POS followStopLoss invisible=false transmit=false
POS pnlTicks > 5 THEN followStopLoss SET ticks=10 transmit=true

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
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

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

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"

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

stopLoss (position)

Input parameters:

PropTypeDefault
percent
number
0
ticks
number
0
transmit
boolean

StopLossAlgo is a model that stops loss at a given percentage or ticks.

e.g SQL

IF stopLoss ticks=10 transmit=false
POS pnlTicks < -10 THEN stopLoss SET ticks=10, transmit=true

trailingStopLoss (position)

Input parameters:

PropTypeDefault
percent
number
0
ticks
number
0
transmit
boolean
No default value

TrailingStopLossAlgo is a model that follows the position and adjusts the stop loss as the price moves in favor.

e.g SQL

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

dayOfWeek (all)

Input parameters:

PropTypeDefault
exclude
string
No default value
in
string
No default value

DayOfWeekAlgo is a model that allows trading only on specific days of the week.

e.g SQL

IF dayOfWeek exclude="Sat,Sun"
IF dayOfWeek in="Mon,Tue,Wed,Thu,Fri"

breakEven (position)

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

IF POS breakEven ticks=2
POS pnlTicks > 5 THEN breakEven SET ticks=5

cancelOrder (all)

Input parameters:

PropTypeDefault
afterSeconds*
number
No default value
transmit
boolean
true

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

e.g SQL

IF cancelOrder afterSeconds=300
TICK price > 100 THEN cancelOrder SET transmit=true
POS pnlTicks > 5 THEN cancelOrder SET transmit=true

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

IF POS closeOrder
POS pnlTicks > 5 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

IF POS flatten
POS pnlTicks > 5 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
type*
string
market
action*
string
No default value
size*
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 pnlTicks > 5 THEN scaleOut SET steps=0.25, size=25

timeExit (position)

Input parameters:

PropTypeDefault
seconds*
number
No default value
transmit
boolean
No default value

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

IF timeExit seconds=1800
POS pnlTicks > 5 THEN timeExit SET seconds=1800 transmit=true

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