The trading engine provides a feedback loop to trading systems so that your strategies may leverage the information processed by the trading bot.

Trading Engine

Current

Episode

Serial Number

Identifier

Begin

End

Begin Rate

End Rate

Status

Exit Type

Head of the Market

Process Date

Episode Base Asset

Balance

Begin Balance

End Balance

Hits

Fails

Hit Ratio

Profit Loss

ROI

Annualized Rate of Return

Hit Fail

Episode Quoted Asset

Balance

Begin Balance

End Balance

Hits

Fails

Hit Ratio

Profit Loss

ROI

Annualized Rate of Return

Hit Fail

Episode Counters

Periods

Strategies

Positions

Orders

Hits

Fails

User Defined Counter

Episode Statistics

Profit Loss

ROI

Hit Fail

Hit Ratio

Days

Annualized Rate of Return

User Defined Statistic

Formula

Distance to Event

Trigger On

Trigger Off

Take Position

Close Position

Next Phase

Move to Phase

Create Order

Cancel Order

Close Order

Candle

Begin

End

Open

Close

Min

Max

Index

Cycle

Begin

End

Strategy

Serial Number

Identifier

Begin

End

Begin Rate

End Rate

Status

Exit Type

Situation Name

Index

Strategy Name

Strategy Counters

Periods

Position

Serial Number

Identifier

Begin

End

Begin Rate

End Rate

Status

Exit Type

Situation Name

Entry Target Rate

Exit Target Rate

Stop Loss

Stop Loss Phase

Stop Loss Position

Take Profit

Take Profit Phase

Take Profit Position

Position Counters

Periods

Position Statistics

Profit Loss

ROI

Hit Fail

Days

User Defined Statistic

Formula

Position Base Asset

Begin Balance

End Balance

Entry Target Size

Exit Target Size

Profit Loss

ROI

Hit Fail

Position Quoted Asset

Begin Balance

End Balance

Entry Target Size

Exit Target Size

Profit Loss

ROI

Hit Fail

Strategy Trigger Stage

Begin

End

Exit Type

Status

Begin Rate

End Rate

Strategy Open Stage

Begin

End

Exit Type

Status

Begin Rate

End Rate

Stage Defined In

Stage Base Asset

Target Size

Size Placed

Size Filled

Fees Paid

Stage Quoted Asset

Target Size

Size Placed

Size Filled

Fees Paid

Strategy Manage Stage

Begin

End

Exit Type

Status

Begin Rate

End Rate

Strategy Close Stage

Begin

End

Exit Type

Status

Begin Rate

End Rate

Stage Defined In

Stage Base Asset

Target Size

Size Placed

Size Filled

Fees Paid

Stage Quoted Asset

Target Size

Size Placed

Size Filled

Fees Paid

Last

Position

Serial Number

Identifier

Begin

End

Begin Rate

End Rate

Status

Exit Type

Situation Name

Entry Target Rate

Exit Target Rate

Stop Loss

Stop Loss Phase

Stop Loss Position

Take Profit

Take Profit Phase

Take Profit Position

Position Counters

Periods

Position Statistics

Profit Loss

ROI

Hit Fail

Days

User Defined Statistic

Formula

Position Base Asset

Begin Balance

End Balance

Entry Target Size

Exit Target Size

Profit Loss

ROI

Hit Fail

Position Quoted Asset

Begin Balance

End Balance

Entry Target Size

Exit Target Size

Profit Loss

ROI

Hit Fail

Strategy

Serial Number

Identifier

Begin

End

Begin Rate

End Rate

Status

Exit Type

Situation Name

Index

Strategy Name

Strategy Counters

Periods

Exchange Orders

Market Buy Orders

Market Order

Serial Number

Identifier

Exchange Id

Begin

End

Rate

Exit Type

Status

Order Name

Algorithm Name

Situation Name

Order Counters

Periods

Lock

Order Base Asset

Size

Size Filled

Fees Paid

Order Quoted Asset

Size

Size Filled

Fees Paid

Order Statistics

Percentage Filled

Actual Rate

Days

User Defined Statistic

Formula

Market Sell Orders

Market Order

Limit Buy Orders

Limit Order

Serial Number

Identifier

Exchange Id

Begin

End

Rate

Exit Type

Status

Order Name

Algorithm Name

Situation Name

Order Counters

Periods

Lock

Order Base Asset

Size

Size Filled

Fees Paid

Order Quoted Asset

Size

Size Filled

Fees Paid

Order Statistics

Percentage Filled

Actual Rate

Days

User Defined Statistic

Formula

Limit Sell Orders

Limit Order

Trading Engine

The trading engine hierarchy is the data structure used by the trading bot to keep runtime information highly accessible and exposed to others.

You will use this hierarchy for two main purposes:

  • To let your trading systems access the information processed by the trading bot. This allows strategies to keep track of and react to current and past events—including those involving the exchange, such as orders placed or filled—as the bot is running.

  • To keep track of the actions of the trading bot via the design space visual environment and panels over the charts. By analyzing runtime information, you may gain a detailed understanding of what happens, when, and why, throughout a trading session.

The hierarchy exposes—literally—all the information processed by the trading bot, providing a comprehensive feedback loop to trading systems and analysis capabilities to users.

Adding a Trading Engine Node

To add the trading engine node from scratch, select Add Trading Engine on the other hierarchies node menu in the Superalgos Project hierarchy.

Current

The current object refers to the context in which instances of several other objects exist—like episode, strategy, position, strategy stages, and so on—in particular, the instances that are open at the time of evaluation, hence the adjective current.

Conceptually, current is used as an adjective applied to different concepts, such as the current episode, the current strategy, the current position, or the current strategy stage, to indicate the instance that is passing at the moment.

The generation of offspring nodes under the current section of the hierarchy keeps track of information within the scope of the embodied concept: episode, strategy, position, and so on.

In other words, the episode, strategy and position nodes within the current section of the hierarchy feature information relative to the instances of the episode, strategy, and position that are currently passing, at any point in time.

Adding a Current Node

To add the current node, select Add Missing Items on the trading engine node menu.

Episode

Episode is the object that handles the information corresponding to the whole run of the trading bot—beginning to end—between the specified initial datetime and final datetime, in the time range parameter of the trading session.

In other words, episode is the context framed between the datetimes that make up the whole trading session, as per the session’s configuration. As such, an episode keeps track of—and accumulates—the results of all positions entered throughout a complete run of a trading session.

In this section of the hierarchy, you have access to:

Adding an Episode Node

To add the episode node, select Add Missing Items on the parent node menu.

Serial Number

Serial number is a sequential number assigned to the object represented by the parent node at the moment it is opened.

Serial numbers start at 1 and increment by 1 with each intance of the object that is opened.

Adding a Serial Number Node

To add the serial number node, select Add Missing Items on the parent node menu.

Identifier

Identifier is a unique alphanumeric string by which the object represented by the parent node may be unequivocally identified.

The property is what would be used to access a specific known record.

Adding an Identifier Node

To add the identifier node, select Add Missing Items on the parent node menu.

Begin

Begin is the datetime at the moment the object represented by the parent node began to exist.

In the context of a candle, it is the datetime of the open of the candle as provided by the exchange.

Adding a Begin Node

To add the begin node, select Add Missing Items on the parent node menu.

End

End is the datetime on which the object represented by the parent node ceased to exist. In case the object has not been closed yet, it is the datetime at the moment of evaluation.

In the context of a candle, it is the datetime of the close of the candle as provided by the exchange.

In every other context, the datetime is given by the datetime of the moment of evaluation. When evaluating a point in time in which the object remains open, end stores the datetime of that moment, because the object existed until that point in time when the value was last being updated. Once the object is closed, the end value is not modified again.

Adding an End Node

To add the end node, select Add Missing Items on the parent node menu.

Begin Rate

Begin rate is the close rate of the candle corresponding to the datetime of the begin property.

In the context of a strategy, it is the close rate of the last closed candle at the moment the strategy was triggered.

In the context of a position, it is the close rate of the last closed candle at the moment the take position event was triggered.

In the context of an episode, it is the close rate of the last closed candle at the moment the episode starts.

Adding a Begin Rate Node

To add the begin rate node, select Add Missing Items on the parent node menu.

End Rate

End rate is the close rate of the candle corresponding to the datetime of the end property.

In the context of a strategy, it is the close rate of the last closed candle at the moment the strategy is triggered-off.

In the context of a position, it is the close rate of the last closed candle at the moment the close stage is closed.

In the context of an episode, it is the close rate of the last closed candle at the moment the episode ends.

Adding an End Rate Node

To add the end rate node, select Add Missing Items on the parent node menu.

Status

Status refers to the state of the object represented by the parent node at the moment of evaluation.

There are three possible status:

  • Not Open: the object is not open at the current candle.

  • Open: the object is open at the current candle.

  • Closed: the object closes at the current candle.

Adding a Status Node

To add the status node, select Add Missing Items on the parent node menu.

Exit Type

Exit type refers to the reason why the object is closed.

No Exit is the default value until a new value is assigned before the object is closed. Other possible values vary with the context.

In the context of the episode object:

  • Last Candle Reached: the object was closed because the last candle was reached.

In the context of the strategy object:

  • Position Closed: the position was closed.

In the context of the position object:

  • Take Profit: the take profit target was hit.

  • Stop Loss: the stop loss target was hit.

In the context of an order:

  • Closing Stage: the current stage started closing because the Close Stage is opening.

Adding an Exit Type Node

To add the exit type node, select Add Missing Items on the parent node menu.

Episode Base Asset

The episode base asset node keeps track of the evolution of variables and metrics denominated in the base asset, throughout the episode.

Adding an Episode Base Asset Node

To add the episode base asset node, select Add Missing Items on the parent node menu.

Balance

Balance is the running balance, that is, the amount of the asset that exists at any point in time.

The balance of an asset changes every time an order involving the asset is filled. When the trading bot consults the exchange to find out the status of each order placed, the exchange answers with the size filled and actual rate for the order. That is the information used to calculate balances.

Adding a Balance Node

To add the balance node, select Add Missing Items on the parent node menu.

Begin Balance

Begin balance is the balance at the datetime of the begin property of the parent node or concept.

In the context of an episode, it is the balance at the datetime the episode started.

In the context of a position, it is the balance at the datetime the position started.

Adding a Begin Balance Node

To add the begin balance node, select Add Missing Items on the parent node menu.

End Balance

End balance is the balance at the datetime of the end property of the parent node or concept.

In the context of an episode, it is the balance at the datetime the episode ended.

In the context of a position, it is the balance at the datetime the position was closed.

Adding a End Balance Node

To add the end balance node, select Add Missing Items on the parent node menu.

Hits

Hits counts the number of positions that closed with a positive profit loss, in the context of the parent node.

In the context of the quoted asset or the base asset, hits are calculated relative to the asset in question. That is, if the base asset profit loss is positive, then a hit is counted for the base asset.

However, when the context of the asset is not specified—such as under the statistics node—then hits are calculated in a consolidated manner, converting the respective balances to perform the calculations.

Adding a Hits Node

To add the hits node, select Add Missing Items on the parent node menu.

Fails

Fails counts the number of positions that closed with a negative profit loss, in the context of the parent node.

Adding Fails Node

To add the fails node, select Add Missing Items on the parent node menu.

Hit Ratio

Hit ratio is the percentage of positions that closed with a positive profit loss, in the context of the parent node.

Hit ratio results from multiplying the number of hits by 100 and dividing it by the number of positions: hit ratio = hits * 100 / positions.

Adding a Hit Ratio Node

To add the hit ratio node, select Add Missing Items on the parent node menu.

Profit Loss

Profit loss is the difference between the balance at the end and the balance at the beginning of a certain period, given by the context.

In the context of the base asset or the quoted asset, the calculation is done by subtracting the balances in the corresponding assets, using the variable appropriate to the larger context (i.e.: episode, position, etc.).

In general terms:

  • base asset profit loss = base asset end balance - base asset begin balance

  • quoted asset profit loss = quoted asset end balance - quoted asset begin balance

In the case of the episode base asset and episode quoted asset:

tradingEngine.current.episode.episodeBaseAsset.profitLoss.value =
    tradingEngine.current.episode.episodeBaseAsset.balance.value -
    sessionParameters.sessionBaseAsset.config.initialBalance
    
tradingEngine.current.episode.episodeQuotedAsset.profitLoss.value =
    tradingEngine.current.episode.episodeQuotedAsset.balance.value -
    sessionParameters.sessionQuotedAsset.config.initialBalance

In the case of the position base asset and position quoted asset:

tradingEngine.current.position.positionBaseAsset.profitLoss.value =
    tradingEngine.current.episode.episodeBaseAsset.balance.value -
    tradingEngine.current.position.positionBaseAsset.beginBalance
    
tradingEngine.current.position.positionQuotedAsset.profitLoss.value =
    tradingEngine.current.episode.episodeQuotedAsset.balance.value -
    tradingEngine.current.position.positionQuotedAsset.beginBalance

In the context of the episode statistics or the position statistics, the calculation is done consolidating the profits of both assets.

In the context of the episode statistics:

tradingEngine.current.episode.episodeStatistics.profitLoss.value =
    tradingEngine.current.episode.episodeBaseAsset.profitLoss.value * 
    tradingEngine.current.episode.candle.close.value +
    tradingEngine.current.episode.episodeQuotedAsset.profitLoss.value

In the context of the position statistics:

tradingEngine.current.position.positionStatistics.profitLoss.value =
    tradingEngine.current.episode.episodeBaseAsset.profitLoss.value * 
    tradingEngine.current.position.endRate.value +
    tradingEngine.current.episode.episodeQuotedAsset.profitLoss.value

Adding a Profit Loss Node

To add the profit loss node, select Add Missing Items on the parent node menu.

ROI

ROI is a ratio that compares the profit loss with the cost of the investment, expressed as a percentage.

In general financial terms, ROI is equal to the Net Return on Investment divided by the Cost of Investment, expressed as a percentage.

In Superalgos, the Net Return on Investment is the profit loss, as defined elsewhere. The Cost of Investment is solely the begin balance, as the fees are subtracted from the balance to calculate the profit loss, so we don’t need to account for them in the divisor side of the ratio.

That is:

ROI = profit loss / begin balance * 100

In the context of the episode base asset and episode quoted asset, the calculation is done relative to the corresponding assets, and the overall context.

The formula:

tradingEngine.current.episode.episodeBaseAsset.ROI.value =
    tradingEngine.current.episode.episodeBaseAsset.profitLoss.value /
    tradingEngine.current.episode.episodeBaseAsset.beginBalance.value * 100 
    
tradingEngine.current.episode.episodeQuotedAsset.ROI.value =
    tradingEngine.current.episode.episodeQuotedAsset.profitLoss.value /
    tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value * 100

In the context of the position base asset and position quoted asset, the size filled is used instead of the balance, so that ROI may be properly calculated for complex execution algorithms.

The formula:


tradingEngine.current.position.positionBaseAsset.ROI.value =
    tradingEngine.current.position.positionBaseAsset.profitLoss.value * 100 /
    tradingEngine.current.strategyOpenStage.stageBaseAsset.sizeFilled.value
    
tradingEngine.current.position.positionQuotedAsset.ROI.value =
    tradingEngine.current.position.positionQuotedAsset.profitLoss.value * 100 /
    tradingEngine.current.strategyOpenStage.stageQuotedAsset.sizeFilled.value

In the context of the episode statistics, the calculation is done using the consolidated balance, as explained in the profit loss definition.

The formula:

tradingEngine.current.episode.episodeStatistics.ROI.value =
    (
        tradingEngine.current.episode.episodeBaseAsset.profitLoss.value * 
        tradingEngine.current.episode.endRate.value +
        tradingEngine.current.episode.episodeQuotedAsset.profitLoss.value
    ) / (
        tradingEngine.current.episode.episodeBaseAsset.beginBalance.value * 
        tradingEngine.current.episode.beginRate.value +
        tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value
    ) * 100

Adding a ROI Node

To add the roi node, select Add Missing Items on the parent node menu.

Annualized Rate of Return

Annualized rate of return is the equivalent ROI scaled to one year.

In other words, it is the equivalent annual return received over a given period.

The formula:

annualized rate of return = (((investment + profits) / investments) ^ (365 / days)) - 1

In the context of the episode base asset and episode quoted asset, the calculation is done relative to the corresponding assets, and the overall context.

The formulas:

tradingEngine.current.episode.episodeBaseAsset.annualizedRateOfReturn.value = 
((( tradingEngine.current.episode.episodeBaseAsset.beginBalance.value +
tradingEngine.current.episode.episodeBaseAsset.profitLoss.value ) / 
tradingEngine.current.episode.episodeBaseAsset.beginBalance.value) ^
(365 / tradingEngine.current.episode.episodeStatistics.days.value)) - 1

tradingEngine.current.episode.episodeQuotedAsset.annualizedRateOfReturn.value = 
((( tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value +
tradingEngine.current.episode.episodeQuotedAsset.profitLoss.value ) / 
tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value) ^
(365 / tradingEngine.current.episode.episodeStatistics.days.value)) - 1

The JavaScript code:

tradingEngine.current.episode.episodeBaseAsset.annualizedRateOfReturn.value = 
Math.pow(
             ( tradingEngine.current.episode.episodeBaseAsset.beginBalance.value +
             tradingEngine.current.episode.episodeBaseAsset.profitLoss.value ) / 
             tradingEngine.current.episode.episodeBaseAsset.beginBalance.value
             , 
             (365 / tradingEngine.current.episode.episodeStatistics.days.value)
        ) - 1

tradingEngine.current.episode.episodeQuotedAsset.annualizedRateOfReturn.value = 
Math.pow(
             ( tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value +
             tradingEngine.current.episode.episodeQuotedAsset.profitLoss.value ) / 
             tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value
             , 
             (365 / tradingEngine.current.episode.episodeStatistics.days.value)
        ) - 1

In the context of the episode statistics, the calculation is done using the consolidated balance, as explained in the profit loss definition.

The JavaScript code:

tradingEngine.current.episode.episodeStatistics.annualizedRateOfReturn.value =
Math.pow(
            (
                tradingEngine.current.episode.episodeBaseAsset.beginBalance.value * 
                tradingEngine.current.episode.beginRate.value +
                tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value +
                tradingEngine.current.episode.episodeBaseAsset.profitLoss.value +
                tradingEngine.current.episode.episodeQuotedAsset.profitLoss.value
            ) / 
            (
                tradingEngine.current.episode.episodeBaseAsset.beginBalance.value * 
                tradingEngine.current.episode.beginRate.value +
                tradingEngine.current.episode.episodeQuotedAsset.beginBalance.value 
            ) 
        , 
            (
                365 / tradingEngine.current.episode.episodeStatistics.days.value
            ) 
        ) - 1

Adding an Annualized Rate of Return Node

To add the annualized rate of return node, select Add Missing Items on the parent node menu.

Hit Fail

Hit fail states whether a transaction is successful or not, hit meaning it is successful and fail meaning it is not.

Superalgos marks positions and even entire episodes as hits or fails, by evaluating profit loss for the corresponding context. If profit loss is positive, then the position or episode is a hit. If profit loss is negative, it is a fail.

Adding a Hit Fail Node

To add the hit fail node, select Add Missing Items on the parent node menu.

Episode Quoted Asset

The episode quoted asset node keeps track of the evolution of variables and metrics denominated in the quoted asset, throughout the episode.

Adding an Episode Quoted Asset Node

To add the episode quoted asset node, select Add Missing Items on the parent node menu.

Episode Counters

The episode counters node features counters of instances of objects that come to exist during the duration of the episode.

Adding an Episode Counters Node

To add the episode counters node, select Add Missing Items on the parent node menu.

Periods

Periods counts the number of candles that have been evaluated, in the context of the parent node.

Adding a Periods Node

To add the periods node, select Add Missing Items on the parent node menu.

Strategies

Strategies counts the number of times strategies have been triggered-on, in the context of the parent node.

Adding a Strategies Node

To add the strategies node, select Add Missing Items on the parent node menu.

Positions

Positions counts the number of times positions have been opened, in the context of the parent node.

Adding a Positions Node

To add the positions node, select Add Missing Items on the parent node menu.

Orders

Orders counts the number of times orders have been placed, in the context of the parent node.

Adding an Orders Node

To add the orders node, select Add Missing Items on the parent node menu.

Episode Statistics

Episode statistics keeps track of several metrics in the context of the episode.

Adding an Episode Statistics Node

To add the episode statistics node, select Add Missing Items on the parent node menu.

Days

Days counts the number of days through which the trading bot has cycled since the object represented by the parent node was open.

In the context of an episode, it counts the number of days in the episode.

In the context of a position, it counts the number of days a position has been open.

Adding a Days Node

To add the days node, select Add Missing Items on the parent node menu.

Formula

A formula is a mathematical expression intended to determine a numerical value to be applied dynamically to a certain property.

In the context of the trading engine, formulas are used to create user defined statistics.

Formulas may use indicators and object properties made available by the trading engine. They must evaluate to a number.

Adding a Formula Node

To add the formula node, select Add Missing Items on the parent node menu.

Candle

The candle structure of nodes stores the properties that make up each candle in the episode, including open and close datetime, and the rates for open, min, max, and close.

Adding a Candle Node

To add the candle node, select Add Missing Items on the parent node menu.

Open

Open is the rate at the datetime of the begin property, as provided by the exchange. That is, the rate at the open of the candle.

Adding an Open Node

To add the open node, select Add Missing Items on the parent node menu.

Close

Close is the rate at the datetime of the end property, as provided by the exchange. That is, the rate at the close of the candle.

Adding a Close Node

To add the close node, select Add Missing Items on the parent node menu.

Min

Min is the minimum rate registered by the exchange during the period between the datetimes of the begin and end properties, as provided by the exchange.

Adding a Min Node

To add the min node, select Add Missing Items on the parent node menu.

Max

Max is the maximum rate registered by the exchange during the period between the datetimes of the begin and end properties, as provided by the exchange.

Adding a Max Node

To add the max node, select Add Missing Items on the parent node menu.

Index

Index is the position of the parent object in the corresponding data collection, as determined by the context.

In the context of a candle, index is the position of the current candle in the array of candles within the larger context, for example, an episode.

Trading systems may feature more than one strategy. In the context of a strategy, index is the position of the strategy within the trading system.

Adding an Index Node

To add the index node, select Add Missing Items on the parent node menu.

Cycle

The trading bot performs its duties in regards to exchange orders and accounts in two consecutive cycles for each candle.

In the first cycle, it checks the status of orders at the exchange, synchronizes the accounts, and verifies if conditions to place new orders are met.

In the second cycle, it creates the orders at the exchange, provided conditions where met on the previous cycle.

The two possible values for the cycle node are First and Second.

Adding a Cycle Node

To add the cycle node, select Add Missing Items on the parent node menu.

Distance to Event

Distance to event features counters indicating how many periods (candles) have passed since the last occurrence of certain events, in the context of the episode.

Adding a Distance to Event Node

To add the distance to event node, select Add Missing Items on the parent node menu.

Trigger On

Counts the periods since the last time a strategy was triggered on.

Adding a Trigger On Node

To add the trigger on node, select Add Missing Items on the parent node menu.

Trigger Off

Counts the periods since the last time a strategy was triggered off.

Adding a Trigger Off Node

To add the trigger off node, select Add Missing Items on the parent node menu.

Take Position

Counts the periods since the last time a position was taken.

Adding a Take Position Node

To add the take position node, select Add Missing Items on the parent node menu.

Close Position

Counts the periods since the last time a position was closed.

Adding a Close Position Node

To add the close position node, select Add Missing Items on the parent node menu.

Next Phase

Counts the periods since the last time a next phase event was triggered.

Adding a Next Phase Node

To add the next phase node, select Add Missing Items on the parent node menu.

Move to Phase

Counts the periods since the last time a move to phase event was triggered.

Adding a Move to Phase Node

To add the move to phase node, select Add Missing Items on the parent node menu.

Create Order

Counts the periods since the last time an order was created.

Adding a Create Order Node

To add the create order node, select Add Missing Items on the parent node menu.

Cancel Order

Counts the periods since the last time an order was canceled.

Adding a Cancel Order Node

To add the cancel order node, select Add Missing Items on the parent node menu.

Close Order

Counts the periods since the last time an order was closed.

Adding a Close Order Node

To add the close order node, select Add Missing Items on the parent node menu.

Strategy

The strategy section of the trading engine keeps track of information relating to the trading strategies that are triggered-on, during the time they remain open.

The strategy node is available both in the current context and the last context, that is, you may retrieve information of the strategy that was last triggered or the one currently open.

A strategy is open from the instant it is triggered-on until the instant it is triggered-off. Therefore, this section of the data structure features information spaning those periods only.

This section provides all the basic details about the strategy, which is particularly useful when the trading system features multiple strategies. It also provides information about the context, that is, what is going on with the market at the time strategies are triggered-on and off.

Most interestingly, the strategy section provides information such as which situation was responsible for triggering the strategy. This may be particularly useful in complex strategies in which the trigger on event may be defined by multiple situations.

Adding a Strategy Node

To add the strategy node, select Add Missing Items on the parent node menu.

Situation Name

Situation name features the name of the situation that triggered a certain event, which is dependent on the context.

In the context of a strategy, it is the name of the situation that triggered-on the strategy.

In the context of a position, it’s the name of the situation that triggered the take position event.

In the context of an order, it’s the situation that triggered the create order event.

Adding a Situation Name Node

To add the situation name node, select Add Missing Items on the parent node menu.

Strategy Name

Strategy name features the name of the strategy that is currently open.

Adding a Strategy Name Node

To add the strategy name node, select Add Missing Items on the parent node menu.

Strategy Counters

The strategy counters node features counters of instances of objects that come to exist while the strategy is open.

Adding a Strategy Counters Node

To add the strategy counters node, select Add Missing Items on the parent node menu.

Position

Position is the section of the data structure that keeps track of information within the scope of each position, and during the time a position is open.

The position node is available both in the current context and the last context, that is, you may retrieve information of the position that was last opened or the one currently open.

A position is open from the instant the take position event is triggered until the instant the close stage is closed. Therefore, this section of the data structure features information spaning those periods only.

In this section of the hierarchy, you have access to:

Adding a Position Node

To add the position node, select Add Missing Items on the parent node menu.

Entry Target Rate

Entry target rate is the target rate set on the initial targets definition, in the open stage of the strategy.

Refresh this concepts by reading about the initial target definitions at the trading system.

Adding a Entry Target Rate Node

To add the entry target rate node, select Add Missing Items on the parent node menu.

Exit Target Rate

Exit target rate is the target rate set on the initial targets definition, in the close stage of the strategy.

Refresh this concepts by reading about the initial target definitions at the trading system.

Adding an Exit Target Rate Node

To add the exit target rate node, select Add Missing Items on the parent node menu.

Stop Loss

Stop loss is the current stop loss target, as defined in the manage stage of the corresponding strategy.

Adding a Stop Loss Node

To add the stop loss node, select Add Missing Items on the parent node menu.

Stop Loss Phase

Stop loss phase is the numeric value of the phase that is currently open, and thus, defining the value of the stop loss.

Adding a Stop Loss Phase Node

To add the stop loss phase node, select Add Missing Items on the parent node menu.

Stop Loss Position

Stop Loss position indicates if the stop loss target is above or below the position rate.

Possible values are Above and Below.

The implications of setting the stop loss target above or below the position rate are explained on the trading system section of the documentation, in particular while describing the initial target rate definition.

Adding a Stop Loss Position Node

To add the stop loss position node, select Add Missing Items on the parent node menu.

Take Profit

Take profit is the current take profit target, as defined in the manage stage of the corresponding strategy.

Adding a Take Profit Node

To add the take profit node, select Add Missing Items on the parent node menu.

Take Profit Phase

Take profit phase is the numeric value of the phase that is currently open, and thus, defining the value of the take profit.

Adding a Take Profit Phase Node

To add the take profit phase node, select Add Missing Items on the parent node menu.

Take Profit Position

Take profit position indicates if the take profit target is above or below the position rate.

Possible values are Above and Below.

The implications of setting the take profit target above or below the position rate are explained on the trading system section of the documentation, in particular while describing the initial target rate definition.

Adding a Take Profit Position Node

To add the take profit position node, select Add Missing Items on the parent node menu.

Position Counters

The position counters node features counters of instances of objects that come to exist during the duration of the position.

Adding a Position Counters Node

To add the position counters node, select Add Missing Items on the parent node menu.

Position Statistics

Position statistics keeps track of several metrics in the context of the position.

Adding a Position Statistics Node

To add the position statistics node, select Add Missing Items on the parent node menu.

Position Base Asset

The position base asset node keeps track of the evolution of variables related to the base asset throughout the position.

Adding a Position Base Asset Node

To add the position base asset node, select Add Missing Items on the parent node menu.

Entry Target Size

Entry target size is the target size set on the initial targets definition, in the open stage of the strategy.

Refer to the explanations on the entry target size for some relevant context.

Refresh this concepts by reading about the initial target definitions at the trading system.

Adding an Entry Target Size Node

To add the entry target size node, select Add Missing Items on the parent node menu.

Exit Target Size

Exit target size is the target size set on the initial targets definition, in the close stage of the strategy.

Both entry and exit target sizes may be defined either denominated in the base asset or the quoted asset. Nevertheless, the sytem keeps track of target sizes in both assets. If the target is defined denominated in the base asset, then the target for the quoted asset is calculated using the current rate, and viceversa.

Refresh this concepts by reading about the initial target definitions at the trading system.

Adding an Exit Target Size Node

To add the exit target size node, select Add Missing Items on the parent node menu.

Position Quoted Asset

The position quoted asset node keeps track of the evolution of variables related to the quoted asset throughout the position.

Adding a Position Quoted Asset Node

To add the position quoted asset node, select Add Missing Items on the parent node menu.

Strategy Trigger Stage

Strategy trigger stage is the section of the data structure that keeps track of information specific to the scope of the trigger stage during the period the stage is open.

The trigger stage is active from the instant the trigger-on event is triggered until either the trigger-off event or the take position event gets triggered. Therefore, this section of the data structure features information spaning those periods only.

Adding a Strategy Trigger Stage Node

To add the strategy trigger stage node, select Add Missing Items on the parent node menu.

Strategy Open Stage

Strategy open stage is the section of the data structure that keeps track of information specific to the scope of the open stage during the period the stage is open.

The open stage is open from the instant the take position event gets triggered, and starts closing from the instant one of the following things happen:

  • the target size is filled,

  • the close stage event is triggered,

  • the take profit or stop loss targets are hit.

Therefore, this section of the data structure features information spaning those periods only.

Adding a Strategy Open Stage Node

To add the strategy open stage node, select Add Missing Items on the parent node menu.

Stage Base Asset

The stage base asset node keeps track of the evolution of variables related to the base asset throughout the stage.

Adding a Stage Base Asset Node

To add the stage base asset node, select Add Missing Items on the parent node menu.

Target Size

Target size is the target set on the initial targets definition which, in the context of a strategy stage, acts as a limit.

Both the close and open stages may have multiple execution algorithms, each with multiple orders defined. In this context, the target size acts as a limit, as it is defined by the user as the maximum size allowed for any given position.

Before placing an order, the system makes sure that the size limit embodied in the target size would not be breached by opening a new order.

Adding a Target Size Node

To add the target size node, select Add Missing Items on the parent node menu.

Size Placed

Size placed is the size of the order placed at the exchange.

In the context of a strategy stage, the size placed refers to the sum of the sizes placed for all orders placed on the corresponding stage.

In the context of an order, it refers to the size placed for the particular order.

Adding a Size Placed Node

To add the size placed node, select Add Missing Items on the parent node menu.

Size Filled

Size filled is the amount of the order that has been filled at the exchange.

In the context of a strategy stage, the size filled refers to the sum of the size filled for all orders placed on the corresponding stage.

In the context of an order, it refers to the size filled for the particular order.

Upon each execution of the trading bot, the system asks the exchange about the status of the orders placed, and the exchange reports back with the size filled and the actual rate at which orders are filled.

In liquid markets, market orders should usually fill immediately. However, limit orders may fill incrementally. Size filled keeps track of how much of the size placed has been filled on every execution.

Adding a Size Filled Node

To add the size filled node, select Add Missing Items on the parent node menu.

Fees Paid

Fees paid is the amount paid in fees.

The exchange does not explicitly indicate how much has been paid in fees for a given transaction. Instead, when Superalgos verifies if an order has been filled or not, the exchange reports the size filled and the actual rate only.

Exchange fees are estimated using the fee structure parameter set for the trading session. It is, therefore, important to set the correct values for that parameter.

Exchanges deduct fees from the asset you are receiving. For instance, if you are selling BTC in the BTC-USDT market, then you are receiving USDT, and the exchange will deduct the fees directly from the amount of USDT you are receiving.

Adding a Fees Paid Node

To add the fees paid node, select Add Missing Items on the parent node menu.

Stage Quoted Asset

The stage quoted asset node keeps track of the evolution of variables related to the quoted asset throughout the stage.

Adding a Stage Quoted Asset Node

To add the stage quoted asset node, select Add Missing Items on the parent node menu.

Strategy Manage Stage

Strategy manage stage is the section of the data structure that keeps track of information specific to the scope of the manage stage during the period the stage is open.

The manage stage is active from the instant the take position event is triggered until the instant either the stop or take profit targets are hit.

Therefore, this section of the data structure features information spaning those periods only.

Adding a Strategy Manage Stage Node

To add the strategy manage stage node, select Add Missing Items on the parent node menu.

Strategy Close Stage

Strategy close stage is the section of the data structure that keeps track of information specific to the scope of the close stage during the period the stage is open.

The close stage is active from the instant either the stop loss or take profit targets are hit until the instant the target size is filled or the close stage event is triggered.

Therefore, this section of the data structure features information spaning those periods only.

Adding a Strategy Close Stage Node

To add the strategy close stage node, select Add Missing Items on the parent node menu.

Last

The last object stores instances of position and strategy objects, in particular the instances that were last open at the time of evaluation, hence the adjective last.

Conceptually, last is used as an adjective applied to these concepts, such as the last position or the last strategy, providing the context on which those concepts exist.

The last context exists so that you may easily access information about the strategy that was last triggered or the position that was last opened.

This is valuable information, both for users and trading systems alike.

  • As a user, you will value being able to visually follow what happened with the last position after it closed, or the last strategy after it triggered off, and at the same time see what is going on with the current position or the current strategy.

  • From within a trading system, your strategies may make decisions factoring in what happened with the last position or strategy. For example, you may want to affect the size of the next position depending on the result of the last one.

If you can code, you may actually access any object that was open in the past at any point in time, and not just the last one.

Adding a Last Node

To add the last node, select Add Missing Items on the parent node menu.

Exchange Orders

Exchange orders is the section of the data structure that keeps track of orders of all types.

The function of this section of the trading engine is to provide the data structure to hold the information of orders as they are open and closed.

Orders are organized by type, such as market orders and limit orders, and also by the type of transaction, such as buy or sell orders.

Each section of the hierarchy must have the definition of as many orders of each type as the trading system is capable of placing concurrently. For example, if the execution algorithm may place up to three limit buy orders to open a position, then three limit orders must exist under the limit buy orders section of the hierarchy. Each order defined in the trading system must reference the data structure of a matching type of order in the trading engine.

Adding Exchange Orders Node

To add the exchange orders node, select Add Missing Items on the parent node menu.

Market Buy Orders

Market buy orders is the section of the data structure that keeps track of this specific type of order.

Adding a Market Buy Orders Node

To add the market buy orders node, select Add Missing Items on the parent node menu.

Market Order

Market order is the section of the data structure that keeps track of the properties of a specific market order, as defined in the trading system.

Each market order defined in the trading system must reference the data structure of a market order in the trading engine.

Adding a Market Order Node

To add the market order node, select Add Missing Items on the parent node menu.

Exchange Id

Exchange ID is a unique identifier the exchange assigns to the order, so that it may be unequivocally identified.

By default, it is the rate at the close of the last candle at the moment the order is placed. All market orders have the default rate value.

In the case of limit orders, it is the rate as specified by the formula under the order rate node. If no such definition exists, then limit orders use the default value as well.

Adding an Exchange Id Node

To add the exchange id node, select Add Missing Items on the parent node menu.

Rate

Rate is the rate at which the order is placed.

By default, it is the rate at the close of the last candle at the moment the order is placed. All market orders have the default rate value.

In the case of limit orders, it is the rate as specified by the formula under the order rate node. If no such definition exists, then limit orders use the default value as well.

The rate is used by the system for all internal calculations affecting the accounts kept in both assets.

Adding a Rate Node

To add the rate node, select Add Missing Items on the parent node menu.

Order Name

Order name is the name of the order as specified in the trading system.

Assigning names to orders in the definition of the trading system makes tracking the execution of orders easier.

Adding an Order Name Node

To add the order name node, select Add Missing Items on the parent node menu.

Algorithm Name

Algorithm name is the name of the execution algorithm that opened the order, as specified in the trading system.

Assigning names to execution algorithms in the definition of the trading system makes tracking the execution of orders easier.

Adding an Algorithm Name Node

To add the algorithm name node, select Add Missing Items on the parent node menu.

Order Counters

The order counters node features counters of instances of objects that come to exist while the order is open.

Adding an Order Counters Node

To add the order counters node, select Add Missing Items on the parent node menu.

Lock

Lock is an internal mechanism that blocks the data structure of the order at the trading engine when the definition of the order at the trading system disallows spawning multiple orders.

Possible values for lock are open and closed.

The moment an order is closed, the system checks the spawnMultipleOrders parameter at the order’s configuration in the trading system. If the value is false, the system sets the lock to closed so that the data structure may not be used again during the same position.

At the moment of opening an order, the system checks the spawnMultipleOrders parameter at the order’s configuration in the trading system. If the value is false, the system checks the value of the lock. If the value is open, then it may create the order; if it is closed then the order may not be created.

Adding a Lock Node

To add the lock node, select Add Missing Items on the parent node menu.

Order Base Asset

The order base asset node keeps track of the evolution of certain properties of orders, denominated in the base asset.

Adding an Order Base Asset Node

To add the order base asset node, select Add Missing Items on the parent node menu.

Size

Size is the size set for the order through a combination of formulas and configurations defined in the trading system, and is the value passed on to the exchange as the size of the order.

The system provides a flexible and robust infrastructure to control execution. The size of a single order results from the combination of multiple settings.

  • The target size in base asset or target size in quoted asset: The formulas under these nodes define the absolute maximum size allowed for the position. The implications of using one or the other are explained under the initial targets node in the open stage.

  • The configuration of the execution algorithm: The parameter percentageOfStageTargetSize determines what fraction of the target size the algorithm will attempt to execute.

  • The configuration of the order: The parameter percentageOfAlgorithmSize determines what fraction of the size handled by the algorithm the order shall be constrained to.

Adding a Size Node

To add the size node, select Add Missing Items on the parent node menu.

Order Quoted Asset

The order quoted asset node keeps track of the evolution of certain properties of orders, denominated in the quoted asset.

Adding an Order Quoted Asset Node

To add the order quoted asset node, select Add Missing Items on the parent node menu.

Order Statistics

Order statistics keeps track of several metrics in the context of the order.

Adding an Order Statistics Node

To add the order statistics node, select Add Missing Items on the parent node menu.

Percentage Filled

Percentage filled represents the portion of the order that has been filled, expressed as a percentage.

The formula:

percentage filled = size filled * 100 / size

Adding a Percentage Filled Node

To add the percentage filled node, select Add Missing Items on the parent node menu.

Actual Rate

Actual rate is the number reported by the exchange as the rate at which an order was filled.

When the system consults the status of open orders with the exchange, the exchange responds with the size filled and the actual rate for the particular order. In case an order is filled incrementally, the value is updated accordingly.

The system uses the actual rate to update the calculation of balances, which are otherwise calculated with the original rate, by default.

Adding an Actual Rate Node

To add the actual rate node, select Add Missing Items on the parent node menu.

Market Sell Orders

Market sell orders is the section of the data structure that keeps track of this specific type of order.

Adding a Market Sell Orders Node

To add the market sell orders node, select Add Missing Items on the parent node menu.

Limit Buy Orders

Limit buy orders is the section of the data structure that keeps track of this specific type of order.

Adding a Limit Buy Orders Node

To add the limit buy orders node, select Add Missing Items on the parent node menu.

Limit Order

Limit order is the section of the data structure that keeps track of the properties of a specific limit order, as defined in the trading system.

Each limit order defined in the trading system must reference the data structure of a limit order in the trading engine.

Adding a Limit Order Node

To add the limit order node, select Add Missing Items on the parent node menu.

Limit Sell Orders

Limit sell orders is the section of the data structure that keeps track of this specific type of order.

Adding a Limit Sell Orders Node

To add the limit sell orders node, select Add Missing Items on the parent node menu.