forex-tester-custom-indicator-api
v3.0.1
Published
TypeScript types and runtime API for custom indicators in [Forex Tester Online](https://forextester.com/).
Readme
forex-tester-custom-indicator-api
TypeScript types and runtime API for custom indicators in Forex Tester Online.
Install this package in a custom indicator project, extend Indicator, then build and upload the result to FTO.
Install
npm install forex-tester-custom-indicator-apiWrite an indicator
Export a default class that extends Indicator. Implement OnInit and OnCalculate. The platform injects this.api before OnInit runs.
import {
Indicator,
IndexBuffer,
InputNumber,
InputEnum,
MovingAverageType,
OutputWindow,
PenStyle,
PlotType,
PriceType,
} from 'forex-tester-custom-indicator-api'
export default class SimpleMovingAverage extends Indicator {
private period!: InputNumber
private maType!: InputEnum<MovingAverageType>
private applyToPrice!: InputEnum<PriceType>
private buffer!: IndexBuffer
public OnInit(): void {
this.api.SetIndicatorShortName('SMA')
this.api.SetIndicatorOutputWindow(OutputWindow.CHART)
this.period = this.api.CreateIntegerInput('Period', 14, 1, 500, 1)
this.maType = this.api.CreateMATypeInput()
this.applyToPrice = this.api.CreateApplyToPriceInput()
this.buffer = this.api.CreateBuffer()
this.api.SetPlotCount(1)
this.api.CreatePlot(0, this.buffer, 'SMA', PlotType.LINE, PenStyle.SOLID, 1, '#2196F3')
}
public OnCalculate(index: number): void {
if (index + this.period.value >= this.api.Bars()) {
return
}
const value = this.api.GetMA(
index,
0,
this.period.value,
this.maType.value,
this.applyToPrice.value,
this.buffer.getValue(index + 1)
)
this.buffer.setValue(index, value)
}
}Lifecycle
| Method | Required | When it runs |
| --- | --- | --- |
| OnInit() | yes | Once, when the indicator is created |
| OnCalculate(index) | yes | For each bar that needs a value. 0 is the current bar |
| OnParamsChange() | no | After the user changes inputs |
| OnHide() / OnShow() | no | When the indicator is hidden or shown |
| OnDeinit() | no | When the indicator is removed |
| OnToolButtonClick(toolName) | no | When an indicator tool button is clicked |
What this.api covers
- Plots and buffers —
CreateBuffer,SetPlotCount,CreatePlot, and related style helpers - Inputs —
CreateIntegerInput,CreateDoubleInput,CreateEnumInput,CreateMATypeInput,CreateApplyToPriceInput, and other typed input helpers - Chart data —
Open,High,Low,Close,Volume,Time,Bars,Symbol,Timeframe - Built-in indicators —
GetMA,iRSI,iMACD, and otheri*helpers - 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 indicators docs.
