npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

forex-tester-custom-robot-api

v2.0.3

Published

TypeScript types and runtime API for custom strategies in [Forex Tester Online](https://forextester.com/).

Downloads

361

Readme

forex-tester-custom-robot-api

TypeScript types and runtime API for custom strategies in Forex Tester Online.

Install this package in a custom strategy project, extend Robot, then build and upload the result to FTO.

Install

npm install forex-tester-custom-robot-api

Write a strategy

Export a default class that extends Robot. Implement OnInit and OnTick. The platform injects this.api before OnInit runs.

import {
  Robot,
  InputNumber,
  MovingAverageType,
  OrderSelectMode,
  OrderType,
  PriceType,
} from 'forex-tester-custom-robot-api'

export default class MaCrossover extends Robot {
  private fastPeriod!: InputNumber
  private slowPeriod!: InputNumber
  private lotSize!: InputNumber

  public OnInit(): void {
    this.api.SetRobotShortName('MA Crossover')
    this.api.SetRobotDescription('Buys when the fast MA crosses above the slow MA.')

    this.fastPeriod = this.api.CreateIntegerInput('Fast Period', 10, 1, 500, 1)
    this.slowPeriod = this.api.CreateIntegerInput('Slow Period', 20, 1, 500, 1)
    this.lotSize = this.api.CreateDoubleInput('Lot Size', 0.1, 0.01, 100, 0.01, 2)
  }

  public OnTick(): void {
    const fast = this.api.GetMA(1, 0, this.fastPeriod.value, MovingAverageType.SMA, PriceType.CLOSE)
    const slow = this.api.GetMA(1, 0, this.slowPeriod.value, MovingAverageType.SMA, PriceType.CLOSE)
    const prevFast = this.api.GetMA(2, 0, this.fastPeriod.value, MovingAverageType.SMA, PriceType.CLOSE)
    const prevSlow = this.api.GetMA(2, 0, this.slowPeriod.value, MovingAverageType.SMA, PriceType.CLOSE)

    const crossedUp = prevFast <= prevSlow && fast > slow
    const crossedDown = prevFast >= prevSlow && fast < slow

    if (crossedUp) {
      this.closeOpposite(OrderType.SELL)
      this.openIfFlat(OrderType.BUY)
    } else if (crossedDown) {
      this.closeOpposite(OrderType.BUY)
      this.openIfFlat(OrderType.SELL)
    }
  }

  private openIfFlat(orderType: OrderType): void {
    if (this.hasOrder(orderType)) {
      return
    }

    this.api.PlaceOrder(
      this.api.Symbol(),
      orderType,
      0,
      this.lotSize.value,
      0,
      0,
      'MA Crossover',
      0
    )
  }

  private closeOpposite(orderType: OrderType): void {
    for (let i = this.api.GetActiveOrderCount() - 1; i >= 0; i--) {
      if (!this.api.SelectOrder(i, OrderSelectMode.POSITION)) {
        continue
      }

      if (this.api.GetOrderSymbol() === this.api.Symbol() && this.api.GetOrderType() === orderType) {
        this.api.CloseOrder(this.api.GetOrderTicket())
      }
    }
  }

  private hasOrder(orderType: OrderType): boolean {
    for (let i = 0; i < this.api.GetActiveOrderCount(); i++) {
      if (!this.api.SelectOrder(i, OrderSelectMode.POSITION)) {
        continue
      }

      if (this.api.GetOrderSymbol() === this.api.Symbol() && this.api.GetOrderType() === orderType) {
        return true
      }
    }

    return false
  }
}

0 is the current forming bar. Use index 1 when you need a confirmed closed bar.

Lifecycle

| Method | Required | When it runs | | --- | --- | --- | | OnInit() | yes | Once, when the strategy is created | | OnTick() | yes | On each price update | | OnParamsChange() | no | After the user changes inputs | | OnStart() | no | When the strategy starts running | | OnStop() | no | When the strategy is stopped |

What this.api covers

  • OrdersPlaceOrder, ModifyOrder, CloseOrder, ClosePartial, CancelOrder, SelectOrder, GetOrderInfo
  • InputsCreateIntegerInput, CreateDoubleInput, CreateEnumInput, CreateMATypeInput, CreateApplyToPriceInput, and other typed input helpers
  • Chart dataOpen, High, Low, Close, Volume, Time, Bars, Symbol, Timeframe
  • Built-in indicatorsGetMA, iMA, iRSI, iMACD, and other i* helpers
  • Custom indicatorsCreateIndicator, GetIndicatorValue
  • Objects, dates, and account info — chart objects, FTODate, and account/testing helpers

TypeScript types in this package are the source of truth: use autocomplete on this.api and the exported enums.

Documentation

Full authoring guides, setup, and upload steps: FTO custom strategies docs.