Primitives are the building blocks of Stoqey. you can think of them as actions / functions that can be used to create more complex strategies.
Input parameters:
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
Input parameters:
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
Input parameters:
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
Input parameters:
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
Input parameters:
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)
Input parameters:
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
Input parameters:
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
Input parameters:
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
Input parameters:
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
Input parameters:
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
Input parameters:
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
Input parameters:
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
Input parameters:
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
Input parameters:
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
Input parameters:
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
Input parameters:
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
Input parameters:
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