Skip to content
Open RaamTrade

RC2_TRAILING_TWO_NUMBERS

self.trailing_stop() takes two numbers: how far the trade must be up before trailing starts, and how far behind the best price to trail.

What it means

A trailing stop has two numbers:

  • the activation, which is how far the trade must be up before trailing starts;
  • the distance, which is how far behind the best price the stop follows.

The old one-number spelling, self.trailing_stop(1.5), only said the distance. It never let you choose when trailing starts, so it always trailed from the entry.

New code must write both numbers. self.trailing_stop(0, 1.5) is exactly what self.trailing_stop(1.5) always did: activation 0, which trails from the entry, with a distance of 1.5% of the peak.

Strategies already saved with the one-number spelling keep working unchanged. When the platform rebuilds them, it reads the one number as activation 0 and adds a warning. Only a new build is refused, whether from the editor, the API or the assistant.

Why it happens

The one-number spelling, positional or percent=. Both only say the distance:

class OneNumber(Strategy):
trade = Symbol()
sizing = FixedCapital()
def execute(self):
self.stop_loss(2.0)
self.trailing_stop(1.5)
if self.trade.is_flat:
self.buy(self.trade)
class OneNamedNumber(Strategy):
trade = Symbol()
sizing = FixedCapital()
def execute(self):
self.trailing_stop(percent=1.5)
if self.trade.is_flat:
self.buy(self.trade)

How to fix it

To keep today’s behaviour and trail from the entry, put a 0 in front:

class TrailFromEntry(Strategy):
trade = Symbol()
sizing = FixedCapital()
def execute(self):
self.trailing_stop(0, 1.5)
if self.trade.is_flat:
self.buy(self.trade)

To start trailing only once the trade is up, give a real activation. Two positional numbers are both percent. To use points, name the numbers, and give each one its own unit:

class TrailOnceUp(Strategy):
activate_pct = Param(1.0, min=0.0, max=5.0)
trail_pct = Param(0.5, min=0.1, max=3.0)
trade = Symbol()
sizing = FixedCapital()
def execute(self):
self.trailing_stop(self.activate_pct, self.trail_pct) # start at +1%, trail 0.5% of the peak
if self.trade.is_flat:
self.buy(self.trade)
class TrailInPoints(Strategy):
trade = Symbol()
sizing = FixedCapital()
def execute(self):
self.trailing_stop(activate_points=20, trail_points=10) # start at +20 points, trail 10 points
if self.trade.is_flat:
self.buy(self.trade)
  • Exit Rules
  • RC2_EXIT_ARG: no numbers at all, only one of the two named numbers, or named and positional mixed.
  • RC2_EXIT_UNIT: points= or price= on trailing_stop, or two units for the same number.