RealTest User Guide
RealTest User Guide

 

 

Navigation: RealTest Script Language > Syntax Element Details >

OrderSum

 

 

 

 

Category

General-Purpose Functions

Description

Evaluates an expression for each of the current bar's entry orders (non-skipped setups) and returns the sum of the values

Syntax

OrderSum(expression, symbol {0})

Notes

OrderSum sums something across the setups that became entry orders on the current bar (stocks for which an entry order is placed, as opposed to setups skipped by a position or allocation limit).

OrderSum(1) counts the current bar's orders for the current strategy.

Scope: in a strategy context the sum covers that strategy's own setups. Inside Combined(...) or Extern(@group, ...) it covers the setups of all member strategies, and inside Extern(@strategy, ...) that strategy's setups.

Which orders are counted depends on when the formula is evaluated:

During setup processing (EntrySetup, SetupSkip, SetupScore, Quantity, StrategyScore) timing follows the same rules as IsOrder: sums over strategies in an earlier EntryPhase are final, while sums over strategies in the current phase include only the selection turns completed so far. Benchmarks have their own earlier phases by default, so a strategy can follow a companion benchmark's new orders, e.g. Quantity: Extern(@bench, OrderSum(Shares, Symbol)).

During entry processing (EntrySkip, EntryTradeValue) an order drops out of the sum as soon as it has been processed, whether it filled (and became a position) or not, so OrderSum sums the orders still pending. For example PositionSum(FillValue) + OrderSum(FillValue) in EntrySkip is the value of the current positions plus the pending orders, without counting the bar's fills twice (see PositionSum). Later in the same bar (exit formulas, and the setups of ThisClose strategies) the orders of the bar's at-open entries have all been processed and are no longer counted.

After the bar (StratData, TestData and TestScan formulas, which are evaluated once the bar's entries are done) OrderSum sums all of the bar's orders, filled or not. FillValue is a filled order's fill value and an unfilled order's value at its order price, so the StratData item ordVal: OrderSum(FillValue) tracks the value of each bar's entry orders, e.g. for the exposure if all of them filled: (S.LongInv[1] + ordVal) / S.Equity[1]. TestData has no strategy context, so use Extern(@strategy, OrderSum(...)) there.

The optional symbol argument (a symbol number, default 0 = all symbols) restricts the sum to setups for that one symbol.

Use SetupSum to count or calculate something for all setups, not just the non-skipped ones.

Note that OrderSum cannot be used to refer to past setups in a strategy. It only has access to setups for the current date in the test. Therefore OrderSum(expression)[offset] will probably not have meaningful results.

 

 

 

Copyright © 2020-2026 Systematic Solutions, LLC