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
IF POS followStopLoss invisible=false transmit=false
POS pnlTicks > 5 THEN followStopLoss SET ticks=10 transmit=true
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"
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:
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
Input parameters:
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
Input parameters:
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"
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
IF POS breakEven ticks=2
POS pnlTicks > 5 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
IF cancelOrder afterSeconds=300
TICK price > 100 THEN cancelOrder SET transmit=true
POS pnlTicks > 5 THEN cancelOrder SET transmit=true
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
IF POS closeOrder
POS pnlTicks > 5 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
IF POS flatten
POS pnlTicks > 5 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 pnlTicks > 5 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
IF timeExit seconds=1800
POS pnlTicks > 5 THEN timeExit SET seconds=1800 transmit=true
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