Skip to main content

10.1. Primitives

A rule tests something about a position: how far it has gained, how long it has been held, where its price stands against a moving average. Each such measure is a primitive. Open Plan → Primitives to see them all, in three tabs.

Thresholds​

Thresholds are your own numbers: the figures your method is built on. They include your capital, the stop-loss percentage you work to (sl_pct) and the largest share of your capital you will put in one position (max_position_pct).

A rule can name a threshold in place of a number. That way the number lives in one place: change your stop-loss percentage here, and every rule that uses sl_pct follows.

For this chapter, our example portfolio's thresholds are a stop-loss of 8% and a maximum position of 6% of its ₹50 lakh capital.

Position Fields​

Position fields are facts Tradestory works out for every position, every day. Some that the examples in this chapter use:

FieldWhat it measures
gain_pctThe position's gain or loss, in per cent of its cost
cmpThe current market price
tranche_countHow many tranches the position has
days_heldDays since the first tranche
drawdown_from_peak_pctHow far the price has fallen from its highest close since entry, in per cent
gain_from_last_tranche_pctHow far the price has moved since the latest tranche, in per cent
total_investedThe amount invested in the position

The Position fields tab lists every one, with a search box.

Indicators​

Indicators are measures worked out from a stock's prices and volumes. Tradestory offers several families of them:

  • trend, such as the exponential moving average (EMA) we met in Chapter 8, and the average directional index,
  • momentum, such as the relative strength index (RSI), which runs from 0 to 100 and rises with strong, steady gains,
  • volatility, such as the average true range (ATR),
  • volume, such as relative volume: a period's volume against the usual, so that 2 means twice the normal amount traded,
  • and delivery, from NSE's records of how much of each day's traded volume was delivered into demat accounts.

An indicator in a rule carries its timeframe and settings in its name: the first letter is the timeframe (daily, weekly or monthly), then the indicator, then its settings. So w_ema_21 is the 21-week EMA, w_rsi_14 the 14-week RSI, w_rvol_20 this week's volume against the usual of the past 20 weeks, and w_deliv_pct the share of this week's volume that was delivered.

The Indicators tab lists every indicator with a description, and lets you add a variant with your own settings. You rarely need to: when a rule names an indicator, Tradestory sets it up for you. A change to an indicator's settings takes effect after the next price update.

Next, let's put primitives to work in rules.