forge.signals

Forge API 1

What ``compute()`` returns: ``fg.Signals``, and named conditions built with ``fg.all_of``.

``compute(self, d)`` gives Forge whole arrays of entry and exit conditions. Forge turns them into orders without calling Python on every bar. Entry and exit fields are True/False numpy arrays the length of the strategy's bars, or condition trees whose names are kept so a bar can say which conditions were true.

NameKindSummary
AddOnclassAdd to a position that moved in its favour: ``fg.AddOn(every_pips=20, size_mult=0.5)``.
BracketfunctionAn entry order with its stop and its target: ``fg.Bracket(entry, sl, tp)``.
BreakEvenclassMove the stop to the entry price once the trade is ahead: ``fg.BreakEven(at_r=1.0)``.
CapsclassThe most a strategy may hold or risk: ``fg.Caps(max_lots=2, max_positions=3)``.
EntryclassHow entries are placed: ``fg.Entry.market``, ``limit``, ``stop`` or ``stop_limit``.
ExitclassThe ways to close trades together or by time: ``fg.Exit.basket``.
FilterclassFilters for ``fg.Signals(filters=[...])`` and the class attribute ``filters``: where not to trade.
OrderclassThe orders ``ctx.order`` takes: ``fg.Order.market``, ``limit``, ``stop`` and ``stop_limit``.
PlotclassA named series for ``fg.Signals(plots=...)`` with a style and a pane.
RegionclassA stretch of bars to shade on the chart: ``fg.Region(start, end, label="news")``.
SignalsclassWhat ``compute()`` returns: entry and exit conditions, and named series to plot or record.
SizeclassHow much each entry trades.
StopclassWhere a losing trade is closed.
TargetclassWhere a winning trade is closed.
TargetsclassSeveral targets that each close a part of the trade: ``fg.Targets([(0.5, t1), (0.5, t2)])``.
TimeStopclassClose a trade that has been open too long: ``fg.TimeStop(bars=48)`` or ``duration="2d"``.
TrailclassA stop that follows the price.
all_offunctionTrue on a bar where every named condition is true.
any_offunctionTrue on a bar where at least one named condition is true.
armedfunctionTrue from a bar where ``set_when`` is true until a bar where ``reset_when`` is, that bar excluded.
bars_sincefunctionFor each bar, how many bars ago the condition was last true: 0 on a bar where it is true, and -1 before the first time it is.
countfunctionThe number of bars among this bar and the ``over - 1`` before it where the condition is true.
count_truefunctionHow many of this bar and the ``bars - 1`` before it the condition was true on, as whole numbers.
heldfunctionTrue where the condition was true on this bar and on each of the ``bars - 1`` before it.
n_offunctionTrue on a bar where at least ``k`` of the named conditions are true.
none_offunctionTrue on a bar where none of the named conditions is true.
sincefunctionTrue where the bars since the condition was last true compare with ``bars`` by ``op`` (``"<"``, ``"<="``, ``">"``, ``">="``, ``"=="`` or ``"!="``), and False on every bar before the first time it was true, whatever the comparison: there is no count yet to compare, as a missing value compares nowhere.
thenfunctionTrue where ``second`` becomes true, if ``first`` became true 1 to ``within`` bars earlier.
votefunctionTrue from the bar the weighted share of true conditions reaches ``open_at`` percent until the bar it falls to ``close_at`` percent or below.
withinfunctionTrue where the condition was true on this bar or one of the ``bars - 1`` before it.