Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
This is a separate guide on how to set up the environment to write your custom indicator for FTO.
To to use our custom indicator API, you need to first download indicator example. You can find some of the examples here or download the suggested example file below.
Open it with Cursor or any IDE of your choice — we suggest Cursor. Then, by clicking the icon shown in Picture #1, open the terminal and install the dependencies using the command npm install
.
After installing the dependencies, build the project using the command npm run build
.
If you get an error that goes like this:
cannot be loaded because running scripts is disabled on this system.
For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1
Then you need to enter command Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
and then trynpm install
and then npm run build
command again.
After building the project, a file my-indicator-project.js
(Indicator file name) will appear in the dist
folder.
If you want to know how to upload your indicator to FTO, you can go to upload guide.
Welcome to the documentation for creating custom indicators in Forex Tester Online (FTO).
This guide is designed to help developers and strategy testers understand the structure, lifecycle, and capabilities of custom scripts written for FTO. You’ll learn how to set up your environment, build your own indicators, and access key platform features via the available API.
Get started with setting up your development environment and creating your first indicator using a simple Moving Average example.
Understand the lifecycle of an indicator through core functions like Init
, Calculate
, Done
, and more.
Learn how to create and manage visible buffers to display your indicator’s values on the chart.
Understand how to retrieve bar data, price arrays, and time series to power your custom logic.
Customize the behavior and appearance of indicators through parameters and configuration blocks.
Use external inputs to make your indicators dynamic and easily customizable by users.
Retrieve metadata about the active instrument, such as symbol name, point size, and tick value.
Use the FTODate
structure to manage time-based logic and align calculations with bar timestamps.
Explore helper functions and additional features available to streamline development.
This documentation is for:
Developers building and debugging trading indicators
Algorithmic traders backtesting and optimizing their strategies
Power users looking to customize and extend FTO’s capabilities
Start with the guide and move on to the to see how it all works in action.
The Init
method is called once, right when your custom indicator is created or loaded onto the chart.
This is where you set everything up — like naming your indicator, creating buffers, creating parameters and registering them, and more.
public Init(): void {
// initialization logic here
}
Init
This method is like a constructor for your indicator. Here’s what usually happens inside:
Set the name and description of the indicator
Create buffers that store the calculated values
Create and register input parameters like period, color, or line style
Set the number of plots, line types, and other configurations
export default class MovingAverage extends IndicatorImplementation {
// parameters
public Period!: TOptValue_number;
public MA!: TIndexBuffer;
public Init(): void {
// Create parameters
this.Period = this.api.createTOptValue_number(8);
// Setting visible name for an indicator
this.api.IndicatorShortName("Moving Average");
// Setting output window to chart, not oscillator window
this.api.SetOutputWindow(TOutputWindow.CHART_WINDOW);
// Registerring parameter Period
this.api.RegOption("Period", TOptionType.INTEGER, this.Period);
// Setting available range for it in the menu
this.api.SetOptionRange("Period", 1, 9999);
// Creating and tuning the buffer
this.MA = this.api.CreateIndexBuffer();
this.api.IndicatorBuffers(1);
this.api.SetIndexBuffer(0, this.MA);
this.api.SetIndexLabel(0, "Moving Average");
this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#FF0000");
}
}
Without Init
, your indicator won't show anything.
It's required to tell the system how many lines you draw and what inputs you need.
Think of it as your setup stage — it only runs once when the indicator is loaded.
Avoid heavy calculations or per-bar logic here. Use Calculate()
for that.
Init
is only for defining the structure and settings of the indicator.
This page will guide you how to install Cursor IDE and how to upload your custom indicator to FTO.
Download and install the Cursor editor: https://www.cursor.com/downloads, while installing make sure to check all the checkmarks (Picture #1)
Then, you have to install Node.js if you don't already have it. Use the link below. https://nodejs.org/en
After installing node.js, download the archive with the indicator example below and extract it to a convenient location.
Open the extracted folder "Moving Average" and inside of it you should find another folder "custom_indicator", open it with Cursor (Picture #2 and #3).
If you get a pop-up like this, click "Yes, I trust the authors"
Then, by clicking the icon shown on Picture #5 you should open the terminal and install the dependencies using the command npm install
.
After installing the dependencies, you can start writing your indicator in the index.ts
file.
Once the implementation is complete, you can build the project using the command npm run build
.
If you get an error that goes like this:
cannot be loaded because running scripts is disabled on this system.
For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1
Then you need to enter command Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
and then trynpm install
and then npm run build
command again.
After building the project, a file my-indicator-project.js
(Indicator file name) will appear in the dist
folder.
Upload this file to the FTO (Picture #6 and #7).
From there, your indicator should appear in "My Indicators" dropdown menu (Picture #8).
This is a separate guide on how to upload your indicator to FTO.
If you have created an indicator that you want to upload and have run the npm run build
command in the terminal, a file named my-indicator-project.js
(indicator's file name) will appear in the dist
folder. Upload this file to FTO (see Picture #1 and #2).
From there, your indicator should appear in "My Indicators" dropdown menu (Picture #3).
This tutorial will guide you through the process of creating a new indicator using Cursor IDE.
Cursor IDE is a fork of VS Code that has powerful AI capabilities, allowing it to access your code directly and have information about your project.
Cursor can also be provided with FTO custom indicator documentation to assist in creating new indicators.
How to install Cursor and set up the project is described in guide. If you don’t yet know how to set up your environment to work with the FTO API for indicators, that is also covered in the same guide.
The feature in Cursor IDE allows users to define custom guidelines or behaviors that the AI should follow when generating code. By setting up rules that describe how indicators work in FTO, you can effectively teach Cursor the context it needs to produce accurate and consistent indicators.
To set up global rules for Cursor, click the setting icon (Picture #1)
From here, click the Rules setting (Picture #2)
In the User Rules field (Picture #3), download and paste contents of the file below called Rules.txt
You can upload the FTO indicator documentation to Cursor, and Cursor will be able to use it to help you create new indicators.
To upload the FTO indicator documentation to Cursor, you need to follow these steps:
1. Click the setting icon in the top right corner of the Cursor IDE. (Picture #4)
2. Select "Features" on the left sidebar (Picture #5).
Scroll down until you see Docs (Picture #6)
Click on the "Add new doc" button and insert link https://fto-2.gitbook.io/fto-indicators-docs to the FTO indicator documentation (Picture #7).
After some indexing, Cursor will be able to refer to the documentation to help you create new indicators.
To become more familiar with how to use this added documentation in your requests to Cursor, go to the section below.
To open Cursors AI window, you can press Ctrl+L
or click on the icon in the top right corner of the Cursor IDE (Picture #8)
This panel has a chat interface and in Cursor version 0.47.8 it has 3 modes, Agent, Ask and Edit,
each catering to different needs during development (Picture #9).
Agent Mode: This mode allows for automated code generation and completion by interacting with the AI. It helps streamline the coding process by providing intelligent suggestions and solutions. I access your project files directly and suggests code which you can accept or reject
Ask Mode: In this mode, developers can ask questions about their codebase, programming concepts, or any development-related topics. The AI will respond with helpful guidance and explanations.
Edit Mode: Edit Mode assists in making modifications to the existing code. It aids in refactoring, simplifying, or improving code sections as needed.
What makes these modes powerful is the ability to add context directly from your project or documentation
For now, select the Ask mode
Next to the "select mode menu" there is also an option to select a model of AI that we want to use, for now we should choose Auto-select (Picture#10).
Before we begin writing the indicator, it is expected that you are familiar with how to set up the environment to access the FTO Indicator API. If not, please read guide first before continuing.
For this example, we will ask Cursor to implement the On Balance Volume (OBV) indicator for us. In this guide, we will start with an empty file, but for future indicator implementations, you can use some of our indicator foundations provided in .
In the request to create the OBV indicator for us, I included the FTO documentation for and added the discussed earlier. In the screenshot, you can see the sections of the documentation it decided to use (Picture #11).
In the result, we got code below
The current logic seems correct, but it's using only the Close price, and there is currently no way for the user to specify their own price type. Let's ask it to fix that (Picture #12).
The code that Cursor wrote in his second response is below
And with the addition of this new parameter and internal method, we get a nice dropdown with price types (Picture #13).
So in the end, we got a proper indicator with just two simple requests by setting up Cursor properly and providing it with and documentation for context.
For Cursor to use the documentation that we provided in we need to do the following:
Start by selecting the Ask mode and add context to your query by typing @ and selecting Docs from the drop-down menu (Picture #14).
In the drop-down menu, select FTO Indicator documentation, which we added earlier in (Picture#15)
And provide add a file in which you want to create the indicator, you can do it by drag and dropping it from explorer window on the left onto the chat window or finding it in the @ drop-down menu under Files & folders (Picture #16)
The feature in Cursor IDE allows users to define custom guidelines or behaviors that the AI should follow when generating code. By setting up rules that describe how indicators work in FTO, you can effectively teach Cursor the context it needs to produce accurate and consistent indicators.
To set up global rules for Cursor, click the setting icon (Picture #1)
From here, click the Rules setting (Picture #2)
In the User Rules field (Picture #3), download and paste contents of the file below called Rules.txt
import { IndicatorImplementation, TDrawStyle, TPenStyle, TOutputWindow, TIndexBuffer } from "forex-tester-custom-indicator-api";
export default class OBVIndicator extends IndicatorImplementation {
// Declare the buffer as a class property
public obvBuffer!: TIndexBuffer;
Init(): void {
this.api.RecalculateMeAlways();
// Set indicator name
this.api.IndicatorShortName("On Balance Volume (OBV)");
// Configure to display in separate window since OBV is an oscillator
this.api.SetOutputWindow(TOutputWindow.SEPARATE_WINDOW);
// Register the number of buffers we'll use
this.api.IndicatorBuffers(1);
// Create and initialize the OBV buffer
this.obvBuffer = this.api.CreateIndexBuffer();
// Bind buffer to index 0
this.api.SetIndexBuffer(0, this.obvBuffer);
// Configure buffer appearance
this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#0000FF"); // Blue line
this.api.SetIndexLabel(0, "OBV");
}
Calculate(index: number): void {
// If this is the first bar (rightmost/newest), initialize OBV
if (index === this.api.Bars() - 1) {
this.obvBuffer.setValue(index, this.api.Volume(index));
return;
}
// Get current and previous close prices
const currentClose = this.api.Close(index);
const previousClose = this.api.Close(index + 1);
// Get current volume
const volume = this.api.Volume(index);
// Get previous OBV value
const previousOBV = this.obvBuffer.getValue(index + 1);
let currentOBV;
// Calculate OBV based on price movement
if (currentClose > previousClose) {
// If price increased, add volume
currentOBV = previousOBV + volume;
} else if (currentClose < previousClose) {
// If price decreased, subtract volume
currentOBV = previousOBV - volume;
} else {
// If price unchanged, OBV remains the same
currentOBV = previousOBV;
}
// Set the calculated OBV value
this.obvBuffer.setValue(index, currentOBV);
}
}
import {
IndicatorImplementation,
TDrawStyle,
TPenStyle,
TOutputWindow,
TIndexBuffer,
TOptionType,
TOptValue_number
} from "forex-tester-custom-indicator-api";
export default class OBVIndicator extends IndicatorImplementation {
// Declare the buffer as a class property
public obvBuffer!: TIndexBuffer;
// Declare price type parameter
public priceType!: TOptValue_number;
Init(): void {
this.api.RecalculateMeAlways();
// Set indicator name
this.api.IndicatorShortName("On Balance Volume (OBV)");
// Configure to display in separate window since OBV is an oscillator
this.api.SetOutputWindow(TOutputWindow.SEPARATE_WINDOW);
// Initialize price type parameter
this.priceType = this.api.createTOptValue_number(0); // Default to Close price
// Register price type parameter as an enum
this.api.RegOption(
"Price Type",
TOptionType.ENUM_TYPE,
this.priceType
);
// Add price type options
this.api.AddOptionValue("Price Type", "Close");
this.api.AddOptionValue("Price Type", "Open");
this.api.AddOptionValue("Price Type", "High");
this.api.AddOptionValue("Price Type", "Low");
this.api.AddOptionValue("Price Type", "Median ((H+L)/2)");
this.api.AddOptionValue("Price Type", "Typical ((H+L+C)/3)");
// Register the number of buffers we'll use
this.api.IndicatorBuffers(1);
// Create and initialize the OBV buffer
this.obvBuffer = this.api.CreateIndexBuffer();
// Bind buffer to index 0
this.api.SetIndexBuffer(0, this.obvBuffer);
// Configure buffer appearance
this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#0000FF"); // Blue line
this.api.SetIndexLabel(0, "OBV");
}
private getPrice(index: number): number {
switch (this.priceType.value) {
case 0: // Close
return this.api.Close(index);
case 1: // Open
return this.api.Open(index);
case 2: // High
return this.api.High(index);
case 3: // Low
return this.api.Low(index);
case 4: // Median
return (this.api.High(index) + this.api.Low(index)) / 2;
case 5: // Typical
return (this.api.High(index) + this.api.Low(index) + this.api.Close(index)) / 3;
default:
return this.api.Close(index); // Fallback to Close
}
}
Calculate(index: number): void {
// If this is the first bar (rightmost/newest), initialize OBV
if (index === this.api.Bars() - 1) {
this.obvBuffer.setValue(index, this.api.Volume(index));
return;
}
// Get current and previous prices using selected price type
const currentPrice = this.getPrice(index);
const previousPrice = this.getPrice(index + 1);
// Get current volume
const volume = this.api.Volume(index);
// Get previous OBV value
const previousOBV = this.obvBuffer.getValue(index + 1);
let currentOBV;
// Calculate OBV based on price movement
if (currentPrice > previousPrice) {
// If price increased, add volume
currentOBV = previousOBV + volume;
} else if (currentPrice < previousPrice) {
// If price decreased, subtract volume
currentOBV = previousOBV - volume;
} else {
// If price unchanged, OBV remains the same
currentOBV = previousOBV;
}
// Set the calculated OBV value
this.obvBuffer.setValue(index, currentOBV);
}
}
The OnParamsChange
method is called automatically when the user changes any parameter of your indicator — for example, the period, color, MA type, etc.
It allows you to respond to these changes and adjust your indicator's behavior or visuals accordingly.
public OnParamsChange(): void {
// logic after parameter change
}
This method is called after the user updates the settings in the indicator panel.
Use it to:
Recalculate internal values
Adjust or re-create custom chart objects
Apply shifts, styling, or any other dynamic behavior
Update dependencies between parameters
Let’s say your indicator displays a shifted line or a custom label. When the user updates the "Shift" parameter, you want the line or label to move accordingly — that logic would go inside OnParamsChange
.
public OnParamsChange(): void {
// Example: Reposition a line or label when "VShift" is changed
this.UpdateShiftedLine(this.VShift.value) // custom method UpdateShiftedLine
}
It only runs when the user changes something manually in the settings window.
If you don’t need any custom logic after parameter changes — you can leave it empty.
Think of OnParamsChange
as the method that reacts to user edits in the settings panel.
It gives you a place to respond to those changes and adjust the indicator’s behavior.
import { IndicatorImplementation } from "forex-tester-custom-indicator-api";
export default class IndicatorName extends IndicatorImplementation {
// parameters
public Init(): void {
// initialization logic
}
public Calculate(index: number): void {
// calculation logic
}
public OnParamsChange(): void {
// logic after parameters change
}
public Done(): void {
// logic after finishing the calculation
}
public OnHide(): void {
// logic after hiding the indicator
}
public OnShow(): void {
// logic after showing the indicator
}
}
Main methods of each indicator are Init and Calculate, Init is called once when the indicator is created, and Calculate is called on each tick. Other methods are optional and can be used to add additional logic to the indicator.
To get familiar with other methods, you can read the documentation for each method.
In this tutorial, we will look at an example implementation of the MovingAverage
indicator.
To get acquainted with the implementation example, download the archive with the indicator example and open it in IDE of your choice, we suggest you use Cursor IDE.
You can download the archive of Moving Average from here
A custom indicator is built by extending the IndicatorImplementation
class, provided by the forex-tester-custom-indicator-api
library.
You can find this implementation in the source code of the Moving Average example described in the Setup and Installation section.
import { IndicatorImplementation } from "forex-tester-custom-indicator-api";
export default class MovingAverage extends IndicatorImplementation {
// indicator logic
}
These parameters can be of different types, they are determined by the TOptValue class, and they will be displayed in the indicator addition/editing window
export default class MovingAverage extends IndicatorImplementation {
// Declaring class-level fields
public Period!: TOptValue_number;
public Shift!: TOptValue_number;
public MAtype!: TOptValue_number;
public ApplyToPrice!: TOptValue_number;
public VShift!: TOptValue_number;
Init(): void {
// Create parameters using factory method
this.Period = this.api.createTOptValue_number(8);
this.Shift = this.api.createTOptValue_number(0);
this.MAtype = this.api.createTOptValue_number(E_MAType.SMA);
this.ApplyToPrice = this.api.createTOptValue_number(TPriceType.CLOSE);
this.VShift = this.api.createTOptValue_number(0);
...existing code...
}
For this, they need to be registered in the Init function.
public Init(): void {
...existing code...
// Register parameter this.Period so it's shown in the indicator settings
this.api.RegOption(
'Period',
TOptionType.INTEGER,
this.Period
);
// Setting the maximum avalable range that can be used for Period value
this.api.SetOptionRange(
'Period',
1,
Number.MAX_SAFE_INTEGER
);
// Register parameter this.Shift so it's shown in the indicator settings
this.api.RegOption(
'Shift',
TOptionType.INTEGER,
this.Shift
);
// Register parameter this.VShift so it's its shown in the indicator settings
this.api.RegOption(
'VShift',
TOptionType.INTEGER,
this.VShift
);
// Register the MA type so it has a drowdown in the indicator settings
this.api.RegMATypeOption(
this.MAtype,
'MAtype'
);
// Register the price type so it has a dropdown in the indicator settings.
this.api.RegApplyToPriceOption(
this.ApplyToPrice,
'ApplyToPrice'
);
...existing code...
}
You can see the methods for registering parameters in the external parameters definition
Buffers are used to store and display indicator values on the chart.
public SSMA!: TIndexBuffer
private SMA!: TIndexBuffer
They need to be declared with all class fields and initialized in the Init function
this.SMA = this.api.CreateIndexBuffer();
this.SSMA = this.api.CreateIndexBuffer();
After their creation, you need to tell how many buffers will be displayed on the chart and bind them by index, starting from 0 (the indices must be unique) In this case, there is one buffer
this.api.IndicatorBuffers(1);
this.api.SetIndexBuffer(0, this.SSMA);
Each registered buffer can be configured
this.api.SetIndexLabel(0, "MA");
this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#FF0000");
this.api.SetIndexDrawBegin(0, this.Period.value - 1 + this.Shift.value);
Also, other methods for configuring the indicator are used in the Init function. To ensure the indicator recalculates on each tick, use the function RecalculateMeAlways. If this setting is not used, each buffer index will be calculated only once to save resources, but some indicators may be calculated inaccurately. If the calculations do not heavily load the processor, we recommend always using it.
Set the indicator name, which will be displayed in the indicator settings window and in the context menu: IndicatorShortName.
We want the Moving Average indicator to be displayed on the main chart, so we use SetOutputWindow.
Using this call, specify that values equal to 0 will not be drawn on the chart: SetEmptyValue.
The main function of the indicator is the Calculate function, where the indicator values are calculated on each tick.
public Calculate(index: number): void {
// check if the index is in the valid range
if (index + this.Period.value >= this.api.Bars()) {
return
}
// calculate the SMA value
const calculatedSMA = this.api.GetMA(
index,
0,
this.Period.value,
this.MAtype.value,
this.ApplyToPrice.value,
// here we get the value of the previous bar
this.SMA.getValue(index + 1)
)
this.SMA.setValue(index, calculatedSMA)
// set the value which is going to be displayed on the chart
this.SSMA.setValue(index, calculatedSMA + this.VShift.value * this.api.Point())
}
To add custom logic after changing the indicator parameters, we use the OnParamsChange method. In Moving average, it is applied to the horizontal shift of the indicator. This method is often used to work with custom objects or to shift the indicator.
public OnParamsChange(): void {
this.api.SetBufferShift(0, this.Shift.value)
}
This is documentation for different types of TOptValue classes which are used to create parameters for indicators.
The Calculate
method is one of the core functions used in a custom indicator. It’s responsible for calculating the logic of your indicator for each bar (candle) on the chart.
This function runs automatically on each price update (tick) and recalculates values for the given bar.
index
— This parameter tells you which bar you’re working with.
index = 0
→ the latest bar (rightmost on the chart).
index = 1
→ the previous bar, and so on.
The method runs once per tick (price change) and calculates the indicator value only for the specified bar.
Checks if there are enough bars to calculate the moving average.
(We need Period
number of candles; otherwise, we skip.)
Calculates a Moving Average value using GetMA()
.
Stores the result in the SMA
buffer, which is used for drawing on the chart.
Applies a vertical shift (VShift
) and stores the result in a second buffer (SSMA
).
This method is where you put your main logic.
It runs automatically for each bar.
You should use it to calculate and store indicator values.
Buffers like SMA
and SSMA
are how your indicator shows up visually on the chart.
Indicator parameters are configurable settings that allow users to customize how an indicator behaves and looks. They appear in the indicator’s settings panel and can be modified without changing the code.
To make a parameter configurable, it must be created using one of the TOptValue
types , created and registered inside the Init()
method.
Any variable that does not extend TOptValue
is considered internal and will not be visible or editable in the user interface.
Here are some of the commonly used TOptValue
types:
TOptValue_number
— numeric values (e.g., period, shift)
TOptValue_bool
— true/false switches
TOptValue_string
— string input
Only -based parameters are configurable
You must register each parameter inside the method using
Parameters control how the indicator works and looks — use them for anything the user might want to tweak
The OnShow
method is called when the indicator is made visible on the chart.
This includes the moment it’s re-enabled after being hidden.
Use OnShow
when you need to:
Re-create or re-draw custom chart objects
Restore visual elements that were removed or hidden earlier
Trigger any logic that should happen only when the indicator is visible
This method is helpful when your indicator includes dynamic elements (like shapes, labels, or highlights) that should appear only when the indicator is active.
This method is not called during every tick or calculation — only when visibility changes.
If your indicator does not rely on custom objects or UI elements, you may not need to implement OnShow
.
public Calculate(index: number): void {
// Skip if not enough bars to calculate moving average
if (index + this.Period.value >= this.api.Bars()) {
return
}
// Get the calculated value of the Moving Average
const calculatedSMA = this.api.GetMA(
index,
0, // Shift (usually 0)
this.Period.value, // Period for MA
this.MAtype.value, // Type of MA (SMA, EMA, etc.)
this.ApplyToPrice.value, // Price type (Close, Open, etc.)
this.SMA.getValue(index + 1) // Previous value for smoothing (optional)
)
// Save the value to the SMA buffer
this.SMA.setValue(index, calculatedSMA)
// Save a shifted version to another buffer
this.SSMA.setValue(index, calculatedSMA + this.VShift.value * this.api.Point())
}
this.SSMA.setValue(index, calculatedSMA + this.VShift.value * this.api.Point())
public OnShow(): void {
// logic after showing the indicator
}
public OnShow(): void {
// Custom method to re-draw label when the indicator is shown
this.CreateTextLabel("InfoLabel", 0, this.api.High(0), "SMA Active", "blue")
}
export default class CustomIndicator extends IndicatorImplementation {
// Configurable parameters
public Period!: TOptValue_number;
public ShowLabels!: TOptValue_bool;
public ApplyToPrice!: TOptValue_number;
// Internal parameter (not configurable)
public internalParameter: number = 0;
public Init(): void {
// Create parameters
this.Period = this.api.createTOptValue_number(8);
this.ShowLabels = this.api.createTOptValue_bool(true);
this.ApplyToPrice = this.api.createTOptValue_number(TPriceType.CLOSE);
// Register parameters so they show up in the UI
this.api.RegOption("Period", TOptionType.INTEGER, this.Period);
this.api.RegOption("ShowLabels", TOptionType.BOOLEAN, this.ShowLabels);
this.api.RegOption("ApplyToPrice", TOptionType.INTEGER, this.ApplyToPrice);
}
}
The OnHide
method is called automatically when the indicator is hidden from the chart — for example, when the user disables its visibility.
This gives you a place to clean up any visual elements or perform other logic when the indicator is no longer visible.
public OnHide(): void {
// logic after hiding the indicator
}
Use OnHide
when you want to:
Remove custom chart objects (labels, lines, shapes) added by the indicator
Free resources or stop background logic tied to visualization
Prepare for a clean re-render when the indicator is shown again
public OnHide(): void {
// Custom method to remove a label created when the indicator was shown
this.DeleteObject("InfoLabel")
}
OnHide
only runs when the indicator becomes hidden — not when it is removed completely.
It pairs naturally with OnShow
, helping you manage custom visual elements.
These are indicator examples you can download
The Done
method is called once, after the indicator has finished calculating all bars.
It marks the end of the calculation cycle and is typically used for final steps or cleanup.
public Done(): void {
// logic after finishing the calculation
}
Use Done
when you need to:
Perform post-processing after all Calculate()
calls are complete
Draw or update custom chart objects that rely on full data
Clean up temporary data or buffers
Log or store final values
This method is especially useful if your indicator logic depends on seeing the entire dataset.
public Done(): void {
// Draw a horizontal line based on final SMA value
const lastIndex = 0
const finalValue = this.SMA.getValue(lastIndex)
// custom method CreateHorizontalLine
this.api.CreateHorizontalLine("FinalSMA", finalValue, "red")
}
Done
is called after all bars have been processed in Calculate()
.
It runs once per full calculation cycle — not on every tick.
It’s safe to use this method to add chart decorations, logs, or summary calculations.
To display indicator values on the chart in Forex Tester Online, you need to use buffers. Buffers store the calculated values and define how they should be visualized (e.g., lines, histograms, dots).
Each buffer is created as a TIndexBuffer
and configured through API calls.
All buffers must be declared as class fields using the TIndexBuffer
type.
public SSMA!: TIndexBuffer;
Init()
Create the buffer instance using the CreateIndexBuffer()
method.
this.SSMA = this.api.CreateIndexBuffer();
Tell the API how many buffers you plan to use. In this case — one:
this.api.IndicatorBuffers(1);
This must be called before setting buffer styles or assignments.
Each buffer must be assigned a unique index:
this.api.SetIndexBuffer(0, this.SSMA);
You can now customize how the buffer will appear on the chart:
this.api.SetIndexLabel(0, "SSMA"); // Label shown in the legend
this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#FF0000"); // Style
this.api.SetIndexDrawBegin(0, this.Period.value - 1 + this.Shift.value); // Starting bar
import { TIndexBuffer } from "forex-tester-custom-indicator-api";
export default class MovingAverage extends IndicatorImplementation {
// Declare parameters as class fields
public Period!: TOptValue_number;
public Shift!: TOptValue_number;
public SSMA!: TIndexBuffer;
public Init(): void {
// Create parameters
this.Period = this.api.createTOptValue_number(8);
this.Shift = this.api.createTOptValue_number(0);
// Create and configure the buffer
this.SSMA = this.api.CreateIndexBuffer();
this.api.IndicatorBuffers(1);
this.api.SetIndexBuffer(0, this.SSMA);
this.api.SetIndexLabel(0, "SSMA");
this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#FF0000");
this.api.SetIndexDrawBegin(0, this.Period.value - 1 + this.Shift.value);
}
}
Each buffer must be declared, created, and registered properly to be visible on the chart.
Indices must be unique and zero-based (0
, 1
, 2
, etc.).
You can use multiple buffers to display several lines or visual elements.
TOptValue_number
is a class used to define numeric parameters for custom indicators.
These parameters appear in the indicator settings panel and allow the user to input or adjust numbers such as periods, shifts, price types, and more.
You must use the createTOptValue_number()
method of the api
object inside Init()
method to create an instance.
Use TOptValue_number
when you need a configurable parameter of type number
, such as:
Period length for moving averages
Shift values
Enum values (e.g., MA type, price type)
Any numeric input from the user
// Declare the parameter in the class fields
public MyParameter!: TOptValue_number;
public Init(): void {
// Create the parameter
this.MyParameter = this.api.createTOptValue_number(defaultValue);
// Register the parameter
this.api.RegOption("MyParameter", TOptionType.INTEGER, this.MyParameter);
}
export default class MovingAverage extends IndicatorImplementation {
public Period!: TOptValue_number;
public Shift!: TOptValue_number;
public MAtype!: TOptValue_number;
public ApplyToPrice!: TOptValue_number;
public VShift!: TOptValue_number;
public Init(): void {
// Create the parameter
this.Period = this.api.createTOptValue_number(8);
this.Shift = this.api.createTOptValue_number(0);
this.MAtype = this.api.createTOptValue_number(E_MAType.SMA);
this.ApplyToPrice = this.api.createTOptValue_number(TPriceType.CLOSE);
this.VShift = this.api.createTOptValue_number(0);
// Register the parameter
this.api.RegOption("Period", TOptionType.INTEGER, this.Period);
this.api.RegOption("Shift", TOptionType.INTEGER, this.Shift);
this.api.RegOption("MAtype", TOptionType.INTEGER, this.MAtype);
this.api.RegOption("ApplyToPrice", TOptionType.INTEGER, this.ApplyToPrice);
this.api.RegOption("VShift", TOptionType.INTEGER, this.VShift);
}
}
In this example:
Period
controls how many bars are used in the moving average calculation.
Shift
can offset the indicator horizontally.
MAtype
selects the type of moving average (e.g., SMA, EMA).
ApplyToPrice
defines which price (close, open, high, low) the MA should use.
VShift
applies a vertical offset to the line.
After creating a parameter, don’t forget to register it using this.RegOption
in the Init
method.
You can access the value using this.MyParameter.value
.
Returns the opening time of a bar in the specified symbol's price history.
iTime(Symbol: string, TimeFrame: number, index: number): FTODate
Symbol
: The symbol to get data for
TimeFrame
: The timeframe of the data (in minutes)
index
: The index of the bar (0 is current/last bar, 1 is previous bar, etc.)
Returns an FTODate object representing the opening time of the specified bar.
The iTime
method retrieves the opening time of a bar at the specified index from the price history of a given symbol and timeframe. The index parameter uses zero-based indexing where 0 represents the current (most recent) bar. The returned time is in UTC timezone.
// Get the time of the current bar for EURUSD on H1 timeframe
const currentTime = this.api.iTime("EURUSD", 60, 0);
// Get the time from 5 bars ago
const pastTime = this.api.iTime("EURUSD", 60, 5);
// Calculate time difference between bars
const timeDiff =
this.api.iTime("EURUSD", 60, 0).toMilliseconds() -
this.api.iTime("EURUSD", 60, 1).toMilliseconds();
// Check if bar is from today
const now = this.api.createFTODate(Date.now());
const barTime = this.api.iTime("EURUSD", 60, 0);
const isToday =
barTime.getUTCDate() === now.getUTCDate() &&
barTime.getUTCMonth() === now.getUTCMonth() &&
barTime.getUTCFullYear() === now.getUTCFullYear();
// Get bar times for the last 3 bars
const barTimes = [];
for (let i = 0; i < 3; i++) {
barTimes.push(this.api.iTime("EURUSD", 60, i));
}
Returns the volume for a specific bar.
Volume(shift: number): number
shift
: A number representing the shift from the current bar
Returns a number
representing the trading volume during the specified bar.
The Volume
method returns the trading volume for a bar at the specified shift from the current bar. Volume represents the total amount of trading activity during the bar's timeframe. The shift parameter determines which bar's volume to return:
0: Current bar
1: Previous bar
2: Two bars ago
And so on
// Get current bar's volume
const currentVolume = this.api.Volume(0);
// Get previous bar's volume
const previousVolume = this.api.Volume(1);
// Calculate average volume over last 3 bars
let totalVolume = 0;
for (let i = 0; i < 3; i++) {
totalVolume += this.api.Volume(i);
}
const averageVolume = totalVolume / 3;
console.log(`Average volume over last 3 bars: ${averageVolume}`);
// Check for volume spike
if (this.api.Volume(0) > this.api.Volume(1) * 2) {
console.log("Volume spike detected on current bar");
}
Returns the tick volume of a bar in the specified symbol's price history.
iVolume(Symbol: string, TimeFrame: number, index: number): number
Symbol
: The symbol to get data for
TimeFrame
: The timeframe of the data (in minutes)
index
: The index of the bar (0 is current/last bar, 1 is previous bar, etc.)
Returns a number
representing the tick volume of the specified bar.
The iVolume
method retrieves the tick volume of a bar at the specified index from the price history of a given symbol and timeframe. The index parameter uses zero-based indexing where 0 represents the current (most recent) bar. The volume represents the number of price changes (ticks) that occurred during the bar period.
// Get the volume of the current bar for EURUSD on H1 timeframe
const currentVolume = this.api.iVolume("EURUSD", 60, 0);
// Get the volume from 5 bars ago
const pastVolume = this.api.iVolume("EURUSD", 60, 5);
// Calculate the total volume over the last 3 bars
const totalVolume =
this.api.iVolume("EURUSD", 60, 0) +
this.api.iVolume("EURUSD", 60, 1) +
this.api.iVolume("EURUSD", 60, 2);
// Calculate average volume over last 3 bars
const avgVolume = totalVolume / 3;
// Check if current volume is higher than previous bar
if (this.api.iVolume("EURUSD", 60, 0) > this.api.iVolume("EURUSD", 60, 1)) {
console.log("Volume is increasing");
}
// Check for volume spike (2x average)
const isVolumeSpiking = this.api.iVolume("EURUSD", 60, 0) > avgVolume * 2;
TOptValue_bool
is a class used to define boolean (true/false) parameters in custom indicators.
It allows users to enable or disable certain features through the indicator settings panel.
Use the createTOptValue_bool()
method from the api
object inside Init()
method to create an instance.
Use TOptValue_bool
when you want to let the user:
Toggle a feature on or off
Show or hide additional elements
Enable conditional behavior in your indicator
public MyFlag!: TOptValue_bool;
public Init(): void {
// Create the parameter
this.MyFlag = this.api.createTOptValue_bool(defaultValue);
// Register the parameter
this.api.RegOption("MyFlag", TOptionType.BOOLEAN, this.MyFlag);
}
export default class CustomIndicator extends IndicatorImplementation {
public IsEnabled!: TOptValue_bool;
public Init(): void {
this.IsEnabled = this.api.createTOptValue_bool(true);
this.api.RegOption("IsEnabled", TOptionType.BOOLEAN, this.IsEnabled);
}
public Calculate(index: number): void {
if (!this.IsEnabled.value) {
return;
}
// Perform calculations only if enabled
}
}
In this example:
IsEnabled
allows the user to toggle indicator logic on or off.
Inside Calculate()
, the logic runs only if the toggle is true
.
Don't forget to register string parameters using this.RegOption
inside the Init
method.
Access the value with this.MyFlag.value
.
Returns the open price of a bar in the specified symbol's price history.
iOpen(Symbol: string, TimeFrame: number, index: number): number
Symbol
: The symbol to get data for
TimeFrame
: The timeframe of the data (in minutes)
index
: The index of the bar (0 is current/last bar, 1 is previous bar, etc.)
Returns a number
representing the open price of the specified bar.
The iOpen
method retrieves the opening price of a bar at the specified index from the price history of a given symbol and timeframe. The index parameter uses zero-based indexing where 0 represents the current (most recent) bar.
// Get the open price of the current bar for EURUSD on H1 timeframe
const currentOpen = this.api.iOpen("EURUSD", 60, 0);
// Get the open price from 5 bars ago
const pastOpen = this.api.iOpen("EURUSD", 60, 5);
// Calculate the difference between current and previous bar's open prices
const openDiff =
this.api.iOpen("EURUSD", 60, 0) - this.api.iOpen("EURUSD", 60, 1);
// Check if current bar opened higher than previous bar
if (this.api.iOpen("EURUSD", 60, 0) > this.api.iOpen("EURUSD", 60, 1)) {
console.log("Current bar opened higher");
}
TOptValue_str
is a class used to define string parameters in custom indicators.
It allows users to enter or modify text values in the indicator settings panel.
Use the createTOptValue_str()
method from the api
object inside Init()
method to create an instance.
Use TOptValue_str
when you want to let the user:
Input custom labels or names
Define identifiers or tags
Set any free-form text value
// Declare the parameter in the class fields
public MyText!: TOptValue_str;
public Init(): void {
// Create the parameter
this.MyText = this.api.createTOptValue_str("default text");
// Register the parameter
this.api.RegOption("MyText", TOptionType.STRING, this.MyText);
}
export default class CustomIndicator extends IndicatorImplementation {
public Name!: TOptValue_str;
public Init(): void {
this.Name = this.api.createTOptValue_str("Custom Indicator");
this.api.RegOption("Name", TOptionType.STRING, this.Name);
}
}
In this example:
Name
is a string parameter that can be changed by the user.
The value can be accessed via this.Name.value
.
Don't forget to register string parameters using this.RegOption
inside the Init
method.
You can use the value directly in Calculate
, OnShow
, or other methods as needed.
Returns the index of the bar with the lowest value over a specified range.
symbol
: The symbol to get data for
timeFrame
: The timeframe of the data (in minutes)
type
: The price type to compare (0=OPEN, 1=HIGH, 2=LOW, 3=CLOSE, 4=VOLUME)
count
: Number of bars to search through
index
: The starting bar index (0 is current/last bar, 1 is previous bar, etc.)
Returns a number
representing the index of the bar with the lowest value. Returns -1 if no valid bar is found.
The iLowest
method searches for the bar with the lowest value of the specified price type (open, high, low, close, or volume) within a range of bars. The search starts from the specified index and looks back for the specified number of bars. The method is useful for finding local minima and implementing various technical analysis strategies.
This section provides functions to access historical bar data such as open, high, low, close, volume, and time. These functions are essential for building logic in custom indicators.
: Gets the volume value of the current bar.
: Retrieves volume value from a specific bar index.
: Retrieves the timestamp of a specific bar.
: Retrieves the open price of a specific bar.
: Finds the lowest value over a range of bars.
: Gets the low price of a specific bar.
: Finds the highest value over a range of bars.
: Gets the high price of a specific bar.
: Retrieves the close price of a specific bar.
: Finds the index of a bar by time.
: Returns the number of bars between two dates.
: Gets the close price of the current bar.
: Gets the high price of the current bar.
: Gets the low price of the current bar.
: Gets the open price of the current bar.
: Returns the total number of bars.
: Gets the time of the current bar.
Click on any function name to view its detailed documentation.
Returns the lowest price of a bar in the specified symbol's price history.
Symbol
: The symbol to get data for
TimeFrame
: The timeframe of the data (in minutes)
index
: The index of the bar (0 is current/last bar, 1 is previous bar, etc.)
Returns a number
representing the lowest price of the specified bar.
The iLow
method retrieves the lowest price reached during a bar at the specified index from the price history of a given symbol and timeframe. The index parameter uses zero-based indexing where 0 represents the current (most recent) bar.
Returns the close price of a bar in the specified symbol's price history.
Symbol
: The symbol to get data for
TimeFrame
: The timeframe of the data (in minutes)
index
: The index of the bar (0 is current/last bar, 1 is previous bar, etc.)
Returns a number
representing the close price of the specified bar.
The iClose
method retrieves the closing price of a bar at the specified index from the price history of a given symbol and timeframe. The index parameter uses zero-based indexing where 0 represents the current (most recent) bar.
Returns the bar index for a specified time in the symbol's price history.
symbol
: The symbol to get data for
timeframe
: The timeframe of the data (in minutes)
time
: The time to search for
exact
: Whether to require an exact match
Returns a number
representing the index of the bar corresponding to the specified time. Returns -1 if no matching bar is found.
The iBarShift
method searches for a bar with a specific opening time and returns its index. If exact
is true, only bars with exactly matching times will be considered. If exact
is false, the method will return the index of the nearest bar that opened before the specified time.
Returns the closing price for a specific bar.
shift
: A number representing the shift from the current bar
Returns a number
representing the closing price of the specified bar.
The Close
method returns the closing price of a bar at the specified shift from the current bar. The shift parameter determines which bar's closing price to return:
0: Current bar
1: Previous bar
2: Two bars ago
And so on
iLowest(symbol: string, timeFrame: number, type: number, count: number, index: number): number
// Find lowest low price in last 10 bars
const lowestIndex = this.api.iLowest("EURUSD", 60, 2, 10, 0);
if (lowestIndex !== -1) {
const lowestPrice = this.api.iLow("EURUSD", 60, lowestIndex);
console.log(`Lowest price: ${lowestPrice} at index ${lowestIndex}`);
}
// Find lowest close in last 20 bars
const lowestCloseIndex = this.api.iLowest("EURUSD", 60, 3, 20, 0);
// Find lowest volume in last 5 bars
const lowestVolumeIndex = this.api.iLowest("EURUSD", 60, 4, 5, 0);
// Check if current bar is lowest in last 50 bars
const isNewLow = this.api.iLowest("EURUSD", 60, 2, 50, 0) === 0;
// Find lowest low starting from a specific bar
const startIndex = 10;
const lookback = 5;
const lowIndex = this.api.iLowest("EURUSD", 60, 2, lookback, startIndex);
// Get lowest price values for different types
const types = [0, 1, 2, 3]; // OPEN, HIGH, LOW, CLOSE
const lowestValues = types.map((type) => {
const idx = this.api.iLowest("EURUSD", 60, type, 10, 0);
return idx !== -1 ? this.api.iLow("EURUSD", 60, idx) : null;
});
// Find price channel
const highestHigh = this.api.iHigh(
"EURUSD",
60,
this.api.iHighest("EURUSD", 60, 1, 20, 0)
);
const lowestLow = this.api.iLow(
"EURUSD",
60,
this.api.iLowest("EURUSD", 60, 2, 20, 0)
);
const channelHeight = highestHigh - lowestLow;
iLow(Symbol: string, TimeFrame: number, index: number): number
// Get the low price of the current bar for EURUSD on H1 timeframe
const currentLow = this.api.iLow("EURUSD", 60, 0);
// Get the low price from 5 bars ago
const pastLow = this.api.iLow("EURUSD", 60, 5);
// Calculate the lowest price over the last 3 bars
const lowest = Math.min(
this.api.iLow("EURUSD", 60, 0),
this.api.iLow("EURUSD", 60, 1),
this.api.iLow("EURUSD", 60, 2)
);
// Check if current bar's low is a new local low
if (this.api.iLow("EURUSD", 60, 0) < this.api.iLow("EURUSD", 60, 1)) {
console.log("New local low formed");
}
// Calculate the average low price of last 3 bars
const avgLow =
(this.api.iLow("EURUSD", 60, 0) +
this.api.iLow("EURUSD", 60, 1) +
this.api.iLow("EURUSD", 60, 2)) /
3;
// Calculate bar range
const barRange =
this.api.iHigh("EURUSD", 60, 0) - this.api.iLow("EURUSD", 60, 0);
iClose(Symbol: string, TimeFrame: number, index: number): number
// Get the close price of the current bar for EURUSD on H1 timeframe
const currentClose = this.api.iClose("EURUSD", 60, 0);
// Get the close price from 5 bars ago
const pastClose = this.api.iClose("EURUSD", 60, 5);
// Calculate the difference between current and previous bar's close prices
const closeDiff =
this.api.iClose("EURUSD", 60, 0) - this.api.iClose("EURUSD", 60, 1);
// Check if current bar closed higher than previous bar
if (this.api.iClose("EURUSD", 60, 0) > this.api.iClose("EURUSD", 60, 1)) {
console.log("Current bar closed higher");
}
// Calculate average closing price of last 3 bars
const avgClose =
(this.api.iClose("EURUSD", 60, 0) +
this.api.iClose("EURUSD", 60, 1) +
this.api.iClose("EURUSD", 60, 2)) /
3;
Close(shift: number): number
// Get current bar's closing price
const currentClose = this.api.Close(0);
// Get previous bar's closing price
const previousClose = this.api.Close(1);
// Calculate price change
const priceChange = this.api.Close(0) - this.api.Close(1);
console.log(`Price changed by ${priceChange} points`);
// Get closing prices for last 3 bars
for (let i = 0; i < 3; i++) {
const closePrice = this.api.Close(i);
console.log(`Bar -${i} close price: ${closePrice}`);
}
iBarShift(symbol: string, timeframe: number, time: FTODate, exact: boolean): number
// Find bar index for a specific time
const searchTime = this.api.createFTODate("2023-01-01T10:00:00Z");
const barIndex = this.api.iBarShift("EURUSD", 60, searchTime, true);
// Check if specific time exists in history
if (this.api.iBarShift("EURUSD", 60, searchTime, true) !== -1) {
console.log("Bar found for the specified time");
}
// Find nearest bar before a time
const approxIndex = this.api.iBarShift("EURUSD", 60, searchTime, false);
// Get price at specific historical time
const historicalTime = this.api.createFTODate("2023-06-01T14:30:00Z");
const index = this.api.iBarShift("EURUSD", 60, historicalTime, false);
if (index !== -1) {
const price = this.api.iClose("EURUSD", 60, index);
console.log(`Price at ${historicalTime}: ${price}`);
}
// Find bar index for current time
const now = this.api.createFTODate(Date.now());
const currentIndex = this.api.iBarShift("EURUSD", 60, now, false);
Returns the highest price for a specific bar.
High(shift: number): number
shift
: A number representing the shift from the current bar
Returns a number
representing the highest price reached during the specified bar.
The High
method returns the highest price reached during a bar at the specified shift from the current bar. The shift parameter determines which bar's high price to return:
0: Current bar
1: Previous bar
2: Two bars ago
And so on
// Get current bar's high price
const currentHigh = this.api.High(0);
// Get previous bar's high price
const previousHigh = this.api.High(1);
// Find highest price over last 3 bars
let highestPrice = this.api.High(0);
for (let i = 1; i < 3; i++) {
const high = this.api.High(i);
if (high > highestPrice) {
highestPrice = high;
}
}
console.log(`Highest price in last 3 bars: ${highestPrice}`);
// Check if current bar made new high
if (this.api.High(0) > this.api.High(1)) {
console.log("New high formed on current bar");
}
Returns the total number of bars.
Bars(): number
Returns a number
representing the total count of available bars.
The Bars
method returns the total number of price bars available in the current symbol's history. This count includes all bars from the earliest available data point up to and including the current bar.
// Get total number of bars
const totalBars = this.api.Bars();
console.log(`Total available bars: ${totalBars}`);
// Check if enough history for analysis
const requiredBars = 20;
if (this.api.Bars() >= requiredBars) {
// Perform analysis requiring 20 bars of history
}
// Process last 10 bars (if available)
const barsToProcess = Math.min(10, this.api.Bars());
for (let i = 0; i < barsToProcess; i++) {
const close = this.api.Close(i);
console.log(`Bar -${i} close price: ${close}`);
}
// Calculate valid shift range
const maxShift = this.api.Bars() - 1;
console.log(`Valid shift range: 0 to ${maxShift}`);
Returns the index of the bar with the highest value over a specified range.
iHighest(symbol: string, timeFrame: number, type: number, count: number, index: number): number
symbol
: The symbol to get data for
timeFrame
: The timeframe of the data (in minutes)
type
: The price type to compare (0=OPEN, 1=HIGH, 2=LOW, 3=CLOSE, 4=VOLUME)
count
: Number of bars to search through
index
: The starting bar index (0 is current/last bar, 1 is previous bar, etc.)
Returns a number
representing the index of the bar with the highest value. Returns -1 if no valid bar is found.
The iHighest
method searches for the bar with the highest value of the specified price type (open, high, low, close, or volume) within a range of bars. The search starts from the specified index and looks back for the specified number of bars. The method is useful for finding local maxima and implementing various technical analysis strategies.
// Find highest high price in last 10 bars
const highestIndex = this.api.iHighest("EURUSD", 60, 1, 10, 0);
if (highestIndex !== -1) {
const highestPrice = this.api.iHigh("EURUSD", 60, highestIndex);
console.log(`Highest price: ${highestPrice} at index ${highestIndex}`);
}
// Find highest close in last 20 bars
const highestCloseIndex = this.api.iHighest("EURUSD", 60, 3, 20, 0);
// Find highest volume in last 5 bars
const highestVolumeIndex = this.api.iHighest("EURUSD", 60, 4, 5, 0);
// Check if current bar is highest in last 50 bars
const isNewHigh = this.api.iHighest("EURUSD", 60, 1, 50, 0) === 0;
// Find highest high starting from a specific bar
const startIndex = 10;
const lookback = 5;
const highIndex = this.api.iHighest("EURUSD", 60, 1, lookback, startIndex);
// Get highest price values for different types
const types = [0, 1, 2, 3]; // OPEN, HIGH, LOW, CLOSE
const highestValues = types.map((type) => {
const idx = this.api.iHighest("EURUSD", 60, type, 10, 0);
return idx !== -1 ? this.api.iHigh("EURUSD", 60, idx) : null;
});
Returns the total number of bars available in the specified symbol's price history.
iBars(Symbol: string, TimeFrame: number): number
Symbol
: The symbol to get data for
TimeFrame
: The timeframe of the data (in minutes)
Returns a number
representing the total count of available bars.
The iBars
method returns the total number of bars available in the price history for a given symbol and timeframe. This count includes all bars from the oldest available bar up to the current (most recent) bar. The method is useful for determining the size of the historical data and for implementing lookback periods in technical analysis.
// Get total number of bars for EURUSD on H1 timeframe
const totalBars = this.api.iBars("EURUSD", 60);
// Check if enough historical data is available
const requiredBars = 100;
if (this.api.iBars("EURUSD", 60) >= requiredBars) {
console.log("Sufficient historical data available");
}
// Calculate average over all available bars
let sum = 0;
const bars = this.api.iBars("EURUSD", 60);
for (let i = 0; i < bars; i++) {
sum += this.api.iClose("EURUSD", 60, i);
}
const average = sum / bars;
// Find the oldest available bar's time
const oldestBarIndex = this.api.iBars("EURUSD", 60) - 1;
const oldestTime = this.api.iTime("EURUSD", 60, oldestBarIndex);
// Check data availability across timeframes
const m1Bars = this.api.iBars("EURUSD", 1);
const h1Bars = this.api.iBars("EURUSD", 60);
const d1Bars = this.api.iBars("EURUSD", 1440);
Returns the lowest price for a specific bar.
Low(shift: number): number
shift
: A number representing the shift from the current bar
Returns a number
representing the lowest price reached during the specified bar.
The Low
method returns the lowest price reached during a bar at the specified shift from the current bar. The shift parameter determines which bar's low price to return:
0: Current bar
1: Previous bar
2: Two bars ago
And so on
// Get current bar's low price
const currentLow = this.api.Low(0);
// Get previous bar's low price
const previousLow = this.api.Low(1);
// Find lowest price over last 3 bars
let lowestPrice = this.api.Low(0);
for (let i = 1; i < 3; i++) {
const low = this.api.Low(i);
if (low < lowestPrice) {
lowestPrice = low;
}
}
console.log(`Lowest price in last 3 bars: ${lowestPrice}`);
// Check if current bar made new low
if (this.api.Low(0) < this.api.Low(1)) {
console.log("New low formed on current bar");
}
Returns the highest price of a bar in the specified symbol's price history.
iHigh(Symbol: string, TimeFrame: number, index: number): number
Symbol
: The symbol to get data for
TimeFrame
: The timeframe of the data (in minutes)
index
: The index of the bar (0 is current/last bar, 1 is previous bar, etc.)
Returns a number
representing the highest price of the specified bar.
The iHigh
method retrieves the highest price reached during a bar at the specified index from the price history of a given symbol and timeframe. The index parameter uses zero-based indexing where 0 represents the current (most recent) bar.
// Get the high price of the current bar for EURUSD on H1 timeframe
const currentHigh = this.api.iHigh("EURUSD", 60, 0);
// Get the high price from 5 bars ago
const pastHigh = this.api.iHigh("EURUSD", 60, 5);
// Calculate the highest price over the last 3 bars
const highest = Math.max(
this.api.iHigh("EURUSD", 60, 0),
this.api.iHigh("EURUSD", 60, 1),
this.api.iHigh("EURUSD", 60, 2)
);
// Check if current bar's high is a new local high
if (this.api.iHigh("EURUSD", 60, 0) > this.api.iHigh("EURUSD", 60, 1)) {
console.log("New local high formed");
}
// Calculate the average high price of last 3 bars
const avgHigh =
(this.api.iHigh("EURUSD", 60, 0) +
this.api.iHigh("EURUSD", 60, 1) +
this.api.iHigh("EURUSD", 60, 2)) /
3;
Returns the opening price for a specific bar.
Open(shift: number): number
shift
: A number representing the shift from the current bar
Returns a number
representing the opening price of the specified bar.
The Open
method returns the opening price of a bar at the specified shift from the current bar. The shift parameter determines which bar's opening price to return:
0: Current bar
1: Previous bar
2: Two bars ago
And so on
// Get current bar's opening price
const currentOpen = this.api.Open(0);
// Get previous bar's opening price
const previousOpen = this.api.Open(1);
// Compare current and previous opening prices
const openDiff = this.api.Open(0) - this.api.Open(1);
console.log(
`Price opened ${openDiff > 0 ? "higher" : "lower"} than previous bar`
);
// Get opening prices for last 3 bars
for (let i = 0; i < 3; i++) {
const openPrice = this.api.Open(i);
console.log(`Bar -${i} open price: ${openPrice}`);
}
Returns the time for a specific bar.
Time(shift: number, timeZoneMode?: TimeZoneMode): FTODate
shift
: A number representing the shift from the current bar
timeZoneMode
: Optional. Default value is project timezone. A TimeZoneMode
enum value representing the timezone mode to use for the returned date
Returns an FTODate object representing the bar's opening time.
The Time
method returns the opening time of a bar at the specified shift from the current bar. The time is returned as an FTODate
object, which provides various date/time manipulation capabilities. The shift parameter determines which bar's time to return:
0: Current bar
1: Previous bar
2: Two bars ago
And so on
The timeZoneMode
parameter allows you to specify how the time should be interpreted:
TimeZoneMode.PROJECT
: Returns time in the project's timezone (default)
TimeZoneMode.UTC
: Returns time in UTC
// Get current bar's time in project timezone
const currentTime = this.api.Time(0);
console.log(`Current bar time: ${currentTime.toString()}`);
// Get current bar's time in UTC
const currentTimeUTC = this.api.Time(0, TimeZoneMode.UTC);
console.log(`Current bar UTC time: ${currentTimeUTC.toString()}`);
// Get previous bar's time
const previousTime = this.api.Time(1);
// Calculate time difference between bars
const timeDiff = currentTime.getTime() - previousTime.getTime();
console.log(`Time between bars: ${timeDiff} milliseconds`);
// Get opening times for last 3 bars
for (let i = 0; i < 3; i++) {
const time = this.api.Time(i);
console.log(`Bar -${i} opened at: ${time.toString()}`);
}
Returns the type of a chart object.
GetObjectType(name: string, isStatic: boolean = false): TObjectType
name
string
The name of the object
isStatic
boolean
Optional. Whether to look in static objects (default: false)
Returns a TObjectType enum value representing the object's type.
The GetObjectType
method retrieves the type of a specified chart object. The type is returned as a TObjectType
enumeration value.
// Get type of a specific object
const type = this.api.GetObjectType("MyTrendLine");
console.log(`Object type: ${type}`);
// Check object type
if (this.api.GetObjectType("MyLine") === TObjectType.TREND_LINE) {
console.log("Object is a trend line");
}
// List all objects with their types
const count = this.api.GetObjectCount();
for (let i = 0; i < count; i++) {
const name = this.api.GetObjectName(i);
const type = this.api.GetObjectType(name);
console.log(`Object ${name} is of type ${type}`);
}
// Check static object type
const staticType = this.api.GetObjectType("MyStaticLine", true);
if (staticType === TObjectType.V_LINE) {
console.log("Static object is a vertical line");
}
Returns the text content of a chart object.
GetObjectText(name: string, isStatic: boolean = false): string
name
string
The name of the object
isStatic
boolean
Optional. Whether to look in static objects (default: false)
Returns a string
containing the object's text content.
The GetObjectText
method retrieves the text content of a specified chart object. This is primarily used with text-based objects like labels, but can also be used with other objects that have text properties.
// Get text from a text label
const labelText = this.api.GetObjectText('MyLabel')
console.log(`Label text: ${labelText}`)
// Get text from a static label
const staticText = this.api.GetObjectText('MyStaticLabel', true)
console.log(`Static label text: ${staticText}`)
// List all text objects with their content
const count = this.api.GetObjectCount()
for (let i = 0; i < count; i++) {
const name = this.api.GetObjectName(i)
if (this.api.GetObjectType(name) === TObjectType.TEXT) {
const text = this.api.GetObjectText(name)
console.log(`Text object ${name}: "${text}"`)
}
}
// Error handling example
try {
const text = this.api.GetObjectText('NonExistentObject')
} catch (error) {
console.log('Error getting object text:', error.message)
}
Creates a new chart object with specified parameters.
СreateChartObject(
name: string,
objType: TObjectType,
window: number,
ftoDate1: FTODate,
price1: number,
ftoDate2?: FTODate,
price2?: number,
ftoDate3?: FTODate,
price3?: number,
isStatic?: boolean
): boolean
name
string
Unique identifier for the object
objType
Type of object to create (e.g., trend line, rectangle)
window
number
Chart window number where the object will be placed
ftoDate1
First time coordinate
price1
number
First price coordinate
ftoDate2
Optional. Second time coordinate (required for some objects)
price2
number
Optional. Second price coordinate (required for some objects)
ftoDate3
Optional. Third time coordinate (required for triangles)
price3
number
Optional. Third price coordinate (required for triangles)
isStatic
boolean
Optional. Whether the object is static (persists across timeframes)
Returns boolean
- true
if the object was created successfully, false
otherwise.
The СreateChartObject
method creates a new chart object with the specified parameters. Different object types require different sets of coordinates
// Create a trend line
const trendLine = this.api.СreateChartObject(
"MyTrendLine",
TObjectType.TREND_LINE,
0,
this.api.createFTODate(1641024000000), // Jan 1, 2022
1.2,
this.api.createFTODate(1641110400000), // Jan 2, 2022
1.21
);
// Create a text label
const textLabel = this.api.СreateChartObject(
"MyLabel",
TObjectType.TEXT,
0,
this.api.createFTODate(1641024000000),
1.2
);
// Create a triangle
const triangle = this.api.СreateChartObject(
"MyTriangle",
TObjectType.TRIANGLE,
0,
this.api.createFTODate(1641024000000),
1.2,
this.api.createFTODate(1641110400000),
1.21,
this.api.createFTODate(1641196800000),
1.205
);
Removes all chart objects of a specified type.
RemoveAllObjects(objType: TObjectType, isStatic: boolean = false): void
objType
The type of objects to remove
isStatic
boolean
Optional. Whether to remove static objects (default: false)
The RemoveAllObjects
method removes all chart objects of a specified type from the chart. This is useful for cleaning up multiple objects at once. The method can remove either regular objects or static objects, depending on the isStatic
parameter.
// Remove all trend lines
this.api.RemoveAllObjects(TObjectType.TREND_LINE);
// Remove all static text labels
this.api.RemoveAllObjects(TObjectType.TEXT, true);
// Clean up all drawing objects
const objectTypes = [
TObjectType.TREND_LINE,
TObjectType.RECTANGLE,
TObjectType.TRIANGLE,
TObjectType.TEXT,
];
for (const type of objectTypes) {
this.api.RemoveAllObjects(type);
}
// Remove objects and log count
const beforeCount = this.api.GetObjectCount();
this.api.RemoveAllObjects(TObjectType.RECTANGLE);
const afterCount = this.api.GetObjectCount();
console.log(`Removed ${beforeCount - afterCount} rectangle objects`);
This section provides functions to manage and interact with chart objects. These functions allow you to create, remove, and modify objects on a chart.
: Creates a new chart object.
: Removes all objects from a chart.
: Checks if a chart object exists.
: Retrieves the text of a chart object.
: Retrieves the type of a chart object.
: Retrieves the name of a chart object.
: Retrieves the count of objects on a chart.
: Removes a specific chart object.
: Sets the text of a chart object.
: Retrieves a property of a chart object.
: Sets a property of a chart object.
Click on any function name to view its detailed documentation.
This section provides functions to configure and customize indicators. These functions allow you to set styles, buffers, and other properties of indicators.
: Adds a level to an indicator.
: Sets the style of an indicator index.
: Creates an index buffer with arguments.
: Sets the output window for an indicator.
: Sets the number of digits for an indicator.
: Retrieves the number of counted bars.
: Sets the buffer shift for an indicator.
: Retrieves information about a buffer.
: Sets the draw begin index for an indicator.
: Retrieves the minimum value of a buffer.
: Retrieves the count of a buffer.
: Retrieves the maximum value of a buffer.
: Sets a value in a buffer.
: Retrieves a value from a buffer.
: Sets the label for an indicator index.
: Sets the symbol for an indicator index.
: Sets the visibility of an indicator index.
: Sets the buffer for an indicator index.
: Creates an index buffer.
: Manages indicator buffers.
: Sets the value of a level.
: Sets the indicator to always recalculate.
: Sets the back offset for calculation.
: Sets fixed min and max values for an indicator.
: Sets the ID key for an indicator.
: Sets the empty value for an indicator.
: Sets the short name for an indicator.
Click on any function name to view its detailed documentation.
Adds a horizontal level line to the indicator.
value
- A number representing the Y-value where the level should be drawn.
style
- A value from the enum specifying the line style.
width
- A number representing the line width in pixels.
color
- A string hex color value for the level line.
opacity
- A number between 0 and 1 representing the opacity of the line.
This method does not return a value.
The AddLevel
method adds a horizontal level line to the indicator window. This is commonly used for indicators like RSI or Stochastic to mark overbought and oversold levels.
See for available line styles
Removes a chart object with the specified name.
The RemoveChartObject
method removes a specified chart object from the chart. The object is identified by its unique name. If the object is static (persists across all timeframes), set the isStatic
parameter to true.
Returns the total number of chart objects.
Returns a number
representing the total count of chart objects.
The GetObjectCount
method returns the total number of objects in the chart. It can count either regular objects or static objects, depending on the isStatic
parameter.
Checks if a chart object with the specified name exists.
Returns a boolean
indicating whether the object exists (true
) or not (false
).
The DoesChartObjectExist
method checks for the existence of a chart object with the specified name. It can check for both regular and static objects, depending on the isStatic
parameter.
Retrieves a property value from a chart object.
Returns either a number
or string
depending on the property type.
The GetObjectProperty
method retrieves a property value from a specified chart object. It can return either numeric or string properties depending on the property identifier provided.
See for a complete list of available object properties.
Sets a property value for a chart object.
Returns boolean
- true
if the property was set successfully, false
otherwise.
The SetObjectProperty
method sets a property value for a specified chart object. It can handle both numeric and string properties, and automatically converts time values from FTODate to the internal format.
Sets the text content and formatting for a chart object.
Returns boolean
- true
if the text was set successfully, false
otherwise.
The SetObjectText
method sets the text content and formatting properties for a specified chart object. This method is primarily used with text-based objects like labels, but can also be used with other objects that support text properties.
Returns the name of a chart object by its index.
Returns a string
representing the object's name.
The GetObjectName
method retrieves the name of a chart object based on its index in the list of objects. Objects are indexed from 0 to GetObjectCount() - 1
. This method is useful for iterating through all objects on a chart.
Sets the visual style for a buffer.
bufferIndex
- A number representing the index of the buffer to style.
type
- A value from the enum specifying how to draw the buffer.
style
- A value from the enum specifying the line style.
width
- A number representing the line width in pixels.
clr
- A string hex color value for the buffer.
isVisible
- (Optional) A boolean indicating whether the buffer should be visible.
This method does not return a value.
The SetIndexStyle
method sets the visual appearance of a buffer on the chart. This includes the drawing style (line, histogram, etc.), line style (solid, dashed, etc.), width, color, and visibility.
See for available drawing styles, for line styles
Creates a new buffer with specified display properties.
index
- A number representing the buffer index.
aLabel
- A string containing the label for the buffer.
drawStyle
- A value from the enum specifying how to draw the buffer.
style
- A value from the enum specifying the line style.
width
- A number representing the line width in pixels.
color
- A string hex color value for the buffer.
Returns a TIndexBuffer
object that can be used to store indicator values.
The CreateIndexBufferWithArgs
method creates a new buffer with specified display properties and assigns it to the given index. This is a convenient way to create and configure a buffer in a single call.
Sets the starting bar for drawing a buffer.
bufferIndex
- A number representing the index of the buffer.
paintFrom
- A number representing the bar index to start drawing from.
This method does not return a value.
The SetIndexDrawBegin
method sets the starting bar for drawing a buffer. This is useful for indicators that require a certain number of bars to initialize before they can produce meaningful values. By setting the draw begin point, you can prevent the indicator from displaying potentially misleading values during its initialization period.
Sets the window where the indicator will be displayed.
outputWindow
- A value from the enum specifying where the indicator should be displayed.
This method does not return a value.
The SetOutputWindow
method determines where the indicator will be displayed on the chart. Indicators can be displayed either in the main chart window or in a separate window below the main chart.
See for the complete list of available window types.
Finds the minimum value in a buffer within a specified range.
buffer
- A number representing the buffer index.
index1
- A number representing the start of the range.
index2
- A number representing the end of the range.
Returns a number
representing the minimum value found in the specified range of the buffer.
The GetBufferMin
method finds the minimum value in a buffer within the range specified by index1 and index2. This can be useful for scaling or normalizing indicator values.
Retrieves information about a buffer.
index
- A number representing the buffer index.
Returns a object containing information about the buffer.
The GetBufferInfo
method retrieves information about a buffer, such as its label, drawing style, line style, width, color, and visibility. This can be useful for dynamically adjusting buffer properties based on the current state.
See for more information about the buffer information structure.
Sets the number of decimal places for indicator values.
digits
- A number representing the number of decimal digits to display for indicator values.
This method does not return a value.
The IndicatorDigits
method sets the number of decimal places that will be used when displaying indicator values. This affects how values are formatted in tooltips, indicator configuration panels, and other UI elements.
Setting the appropriate number of decimal places is important for readability and precision. For example, oscillators that range between 0 and 100 might use 1 or 2 decimal places, while price-based indicators might need 4 or 5 decimal places for currency pairs.
Sets the horizontal shift for a buffer.
bufferIndex
- A number representing the index of the buffer.
shift
- A number representing the number of bars to shift the buffer.
This method does not return a value.
The SetBufferShift
method sets the horizontal shift for a buffer. This allows you to offset the display of the buffer by a specified number of bars. Positive values shift the buffer to the right (into the future), while negative values shift it to the left (into the past).
Finds the maximum value in a buffer within a specified range.
buffer
- A number representing the buffer index.
index1
- A number representing the start of the range.
index2
- A number representing the end of the range.
Returns a number
representing the maximum value found in the specified range of the buffer.
The GetBufferMax
method finds the maximum value in a buffer within the range specified by index1 and index2. This can be useful for scaling or normalizing indicator values.
Sets the visibility of a buffer.
index
- A number representing the index of the buffer.
isVisible
- A boolean indicating whether the buffer should be visible.
This method does not return a value.
The SetIndexVisibility
method sets whether a buffer should be visible on the chart. This can be used to hide buffers that are used for calculations but should not be displayed to the user.
RemoveChartObject(uniqueObjectName: string, isStatic: boolean = false): void
uniqueObjectName
string
The unique name of the object to remove
isStatic
boolean
Optional. Whether the object is static (default: false)
// Remove a regular chart object
this.api.RemoveChartObject('MyTrendLine')
// Remove a static chart object
this.api.RemoveChartObject('MyStaticLabel', true)
// Remove object after checking existence
if (this.api.DoesChartObjectExist('MyObject')) {
this.api.RemoveChartObject('MyObject')
console.log('Object removed successfully')
}
// Remove multiple related objects
const objectPrefix = 'Signal_'
for (let i = 0; i < this.api.GetObjectCount(); i++) {
const name = this.api.GetObjectName(i)
if (name.startsWith(objectPrefix)) {
this.api.RemoveChartObject(name)
}
}
GetObjectCount(isStatic: boolean = false): number
isStatic
boolean
Optional. Whether to count static objects (default: false)
// Get count of regular objects
const regularCount = this.api.GetObjectCount();
console.log(`Regular objects: ${regularCount}`);
// Get count of static objects
const staticCount = this.api.GetObjectCount(true);
console.log(`Static objects: ${staticCount}`);
// Use counts in a loop
for (let i = 0; i < this.api.GetObjectCount(); i++) {
const objectName = this.api.GetObjectName(i);
console.log(`Object ${i}: ${objectName}`);
}
DoesChartObjectExist(uniqueObjectName: string, isStatic: boolean = false): boolean
uniqueObjectName
string
The unique name of the object to check
isStatic
boolean
Optional. Whether to check static objects (default: false)
// Check if object exists before using it
if (this.api.DoesChartObjectExist("MyTrendLine")) {
// Object exists, safe to use
this.api.SetObjectProperty("MyTrendLine", ObjProp.OBJPROP_COLOR, 0xff0000);
} else {
console.log("Object not found");
}
// Check static object
const staticExists = this.api.DoesChartObjectExist("MyStaticLabel", true);
console.log(`Static object exists: ${staticExists}`);
// Create object only if it doesn't exist
const objectName = "UniqueObject";
if (!this.api.DoesChartObjectExist(objectName)) {
this.api.СreateChartObject(
objectName,
TObjectType.TEXT,
0,
this.api.createFTODate(Date.now()),
1.2345
);
}
// Remove object if it exists
if (this.api.DoesChartObjectExist("OldObject")) {
this.api.RemoveChartObject("OldObject");
}
SetObjectProperty(
name: string,
index: number,
value: any,
isStatic: boolean = false
): boolean
name
string
The name of the object
index
number
The property identifier
value
any
The value to set
isStatic
boolean
Optional. Whether the object is static (default: false)
// Set object coordinates
const success1 = this.api.SetObjectProperty(
"MyTrendLine",
ObjProp.OBJPROP_TIME1,
this.api.createFTODate(1641024000000)
);
const success2 = this.api.SetObjectProperty(
"MyTrendLine",
ObjProp.OBJPROP_PRICE1,
1.2
);
// Set visual properties
this.api.SetObjectProperty("MyTrendLine", ObjProp.OBJPROP_COLOR, 0xff0000); // Red color
this.api.SetObjectProperty("MyTrendLine", ObjProp.OBJPROP_STYLE, 1); // Solid line
this.api.SetObjectProperty("MyTrendLine", ObjProp.OBJPROP_WIDTH, 2); // Line width
// Set text properties
this.api.SetObjectProperty("MyLabel", ObjProp.OBJPROP_TEXT, "New Label Text");
this.api.SetObjectProperty("MyLabel", ObjProp.OBJPROP_FONTSIZE, 12);
// Set object state
this.api.SetObjectProperty("MyTrendLine", ObjProp.OBJPROP_HIDDEN, true);
SetObjectText(
name: string,
text: string,
fontSize: number = 14,
fontName: string = Roboto Flex,
fontColor: string = '#000000',
isStatic: boolean = false
): boolean
name
string
The name of the object
text
string
The text content to set
fontSize
number
Optional. The font size (default: 14)
fontName
string
Optional. The font name (default: Roboto Flex)
fontColor
string
Optional. The font color in hex value (default: '#000000')
isStatic
boolean
Optional. Whether the object is static (default: false)
// Set basic text
const success1 = this.api.SetObjectText("MyLabel", "Hello World");
console.log(`Text set: ${success1}`);
// Set text with custom formatting
const success2 = this.api.SetObjectText(
"MyLabel",
"Custom Text",
14, // font size
"Arial",
0xff0000 // red color
);
console.log(`Formatted text set: ${success2}`);
GetObjectName(index: number, isStatic: boolean = false): string
index
number
The index of the object
isStatic
boolean
Optional. Whether to look in static objects (default: false)
// Get name of first object
const firstName = this.api.GetObjectName(0)
console.log(`First object name: ${firstName}`)
// Get name of first static object
const firstStaticName = this.api.GetObjectName(0, true)
console.log(`First static object name: ${firstStaticName}`)
// List all objects
const count = this.api.GetObjectCount()
for (let i = 0; i < count; i++) {
const name = this.api.GetObjectName(i)
const type = this.api.GetObjectType(name)
console.log(`Object ${i}: Name=${name}, Type=${type}`)
}
// List all static objects
const staticCount = this.api.GetObjectCount(true)
for (let i = 0; i < staticCount; i++) {
const name = this.api.GetObjectName(i, true)
const type = this.api.GetObjectType(name, true)
console.log(`Static object ${i}: Name=${name}, Type=${type}`)
}
SetIndexDrawBegin(bufferIndex: number, paintFrom: number): void
// For a 14-period moving average, don't draw the first 13 bars
this.api.SetIndexDrawBegin(0, 13);
// For a 26-period EMA, don't draw until we have enough data
this.api.SetIndexDrawBegin(0, 25);
// For MACD with 12 and 26 periods, don't draw until we have enough data for both
this.api.SetIndexDrawBegin(0, 25); // MACD line
this.api.SetIndexDrawBegin(1, 33); // Signal line (26 + 9 - 1)
GetBufferMin(buffer: number, index1: number, index2: number): number
// Create buffer
public someBuffer = this.api.CreateIndexBuffer();
// Assign the buffer to index 0
this.api.SetIndexBuffer(0, this.someBuffer)
// Find the minimum value in buffer 0 over the last 20 bars
const min = this.api.GetBufferMin(0, 0, 19)
// Find the minimum value in buffer 1 over a custom range
const startIndex = 10
const endIndex = 50
const minInRange = this.api.GetBufferMin(1, startIndex, endIndex)
// Use the minimum value for normalization
const range = this.api.GetBufferMax(0, 0, 19) - min
for (let i = 0; i < 20; i++) {
const normalizedValue = (this.someBuffer.getValue(i) - min) / range
this.someBuffer.setValue(i, normalizedValue)
}
IndicatorDigits(digits: number): void
// Set indicator to display 2 decimal places
this.api.IndicatorDigits(2)
// For a price-based indicator on EURUSD (which typically has 5 decimal places)
this.api.IndicatorDigits(5)
// For an RSI indicator (values between 0-100)
this.api.IndicatorDigits(1)
SetBufferShift(bufferIndex: number, shift: number): void
// Shift buffer 0 forward by 5 bars (into the future)
this.api.SetBufferShift(0, 5)
// Shift buffer 1 backward by 3 bars (into the past)
this.api.SetBufferShift(1, -3)
// Use shifting to create a predictive indicator
const predictionPeriod = 10
this.api.SetBufferShift(0, predictionPeriod)
GetBufferMax(buffer: number, index1: number, index2: number): number
// Create buffer
public someBuffer = this.api.CreateIndexBuffer();
// Assign the buffer to index 0
this.api.SetIndexBuffer(0, this.someBuffer)
// Find the maximum value in buffer 0 over the last 20 bars
const max = this.api.GetBufferMax(0, 0, 19)
// Find the maximum value in buffer 1 over a custom range
const startIndex = 10
const endIndex = 50
const maxInRange = this.api.GetBufferMax(1, startIndex, endIndex)
// Use the maximum value for scaling
const scaleFactor = 100 / max
for (let i = 0; i < 20; i++) {
const scaledValue = this.someBuffer(0, i) * scaleFactor
this.someBuffer.setValue(i, scaledValue)
}
SetIndexVisibility(index: number, isVisible: boolean): void
// Make buffer 0 visible
this.api.SetIndexVisibility(0, true);
// Hide buffer 1 (used for calculations only)
this.api.SetIndexVisibility(1, false);
// Conditionally show buffer based on user option
const showSignalLine = true; // This could be a user option
this.api.SetIndexVisibility(2, showSignalLine);
AddLevel(value: number, style: TPenStyle, width: number, color: string, opacity: number): void
// Add an overbought level at 70 (red line)
this.api.AddLevel(70, TPenStyle.SOLID, 1, "#ff0000", 1);
// Add an oversold level at 30 (green line)
this.api.AddLevel(30, TPenStyle.SOLID, 1, "#00ff00", 1);
// Add a middle level with a dashed line (gray line)
this.api.AddLevel(50, TPenStyle.DASH, 1, "#808080", 0.7);
GetObjectProperty(
name: string,
index: ObjProp | number,
isStatic: boolean = false
): number | string
name
string
The name of the object
index
ObjProp | number
The property identifier
isStatic
boolean
Optional. Whether the object is static (default: false)
// Get object coordinates
const time1 = this.api.GetObjectProperty("MyTrendLine", ObjProp.OBJPROP_TIME1);
const price1 = this.api.GetObjectProperty(
"MyTrendLine",
ObjProp.OBJPROP_PRICE1
);
console.log(`First point: Time=${time1}, Price=${price1}`);
// Get object color
const color = this.api.GetObjectProperty("MyTrendLine", ObjProp.OBJPROP_COLOR);
console.log(`Object color: ${color}`);
// Get text content
const text = this.api.GetObjectProperty("MyLabel", ObjProp.OBJPROP_TEXT);
console.log(`Label text: ${text}`);
SetIndexStyle(
bufferIndex: number,
type: TDrawStyle,
style: TPenStyle,
width: number,
clr: string,
isVisible?: boolean
): void
// Style buffer 0 as a solid blue line with width 2
this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 2, "#0000ff");
// Style buffer 1 as a dashed red line with width 1
this.api.SetIndexStyle(1, TDrawStyle.LINE, TPenStyle.DASH, 1, "#ff0000");
// Style buffer 2 as a histogram with green bars of width 3
this.api.SetIndexStyle(2, TDrawStyle.HISTOGRAM, TPenStyle.SOLID, 3, "#00ff00");
// Style buffer 3 as invisible (for calculation purposes only)
this.api.SetIndexStyle(
3,
TDrawStyle.NONE,
TPenStyle.SOLID,
1,
"#000000",
false
);
CreateIndexBufferWithArgs(
index: number,
aLabel: string,
drawStyle: TDrawStyle,
style: TPenStyle,
width: number,
color: string
): TIndexBuffer
// Create a buffer for a moving average with display properties
const maBuffer = this.api.CreateIndexBufferWithArgs(
0, // Index
"Moving Average", // Label
TDrawStyle.LINE, // Draw as a line
TPenStyle.SOLID, // Solid line
2, // Width of 2 pixels
"#0000ff" // Blue color
);
// Calculate and store values in the buffer
for (let i = period; i < this.api.Bars(); i++) {
maBuffer[i] = calculateMA(i, period);
}
SetOutputWindow(outputWindow: TOutputWindow): void
// Display indicator in the main chart window (like Moving Averages, Bollinger Bands)
this.api.SetOutputWindow(TOutputWindow.CHART_WINDOW);
// Display indicator in a separate window (like RSI, MACD, Stochastic)
this.api.SetOutputWindow(TOutputWindow.SEPARATE_WINDOW);
GetBufferInfo(index: number): TVisibleBufferInfo
// Get information about buffer 0
const bufferInfo = this.api.GetBufferInfo(0);
// Log buffer properties
console.log(`Buffer Name: ${bufferInfo.name}`);
console.log(`Paint From: ${bufferInfo.paintFrom}`);
// Modify buffer visibility based on a condition
if (bufferInfo.paintFrom > 0) {
this.api.SetIndexVisibility(0, true);
} else {
this.api.SetIndexVisibility(0, false);
}
Creates a new buffer for storing indicator values.
CreateIndexBuffer(): TIndexBuffer
This method does not take any parameters.
Returns a TIndexBuffer object that can be used to store indicator values.
The CreateIndexBuffer
method creates a new buffer for storing indicator values. This buffer can then be assigned to a specific index using the SetIndexBuffer method. Each buffer represents a series of values that can be displayed on the chart.
See TIndexBuffer for more information about working with indicator buffers.
// Create a buffer for a simple moving average
const maBuffer = this.api.CreateIndexBuffer();
// Assign the buffer to index 0
this.api.SetIndexBuffer(0, maBuffer);
// get value from some index
this.maBuffer.getValue(0);
// set value for some index
this.maBuffer.setValue(0, 100.15);
Sets a label for a buffer.
SetIndexLabel(bufferIndex: number, bufferName: string): void
bufferIndex
- A number representing the index of the buffer.
bufferName
- A string containing the label for the buffer.
This method does not return a value.
The SetIndexLabel
method sets a descriptive label for a buffer. This label is displayed in the indicator's legend and in tooltips when hovering over the indicator on the chart.
// Set labels for Bollinger Bands buffers
this.api.SetIndexLabel(0, 'Upper Band')
this.api.SetIndexLabel(1, 'Middle Band')
this.api.SetIndexLabel(2, 'Lower Band')
// Set labels for MACD buffers
this.api.SetIndexLabel(0, 'MACD Line')
this.api.SetIndexLabel(1, 'Signal Line')
this.api.SetIndexLabel(2, 'Histogram')
Sets a value in a specific buffer at a given index.
this.bufferName.setValue(index, value);
index
- A number representing the position in the buffer to set the value at.
value
- A number representing the value to store.
This method does not return a value.
The setValue
method of a buffer object sets a value in a specific buffer at a given index. This is used to store calculated indicator values in the buffer for display on the chart.
// Calculate a simple moving average
let sum = 0;
for (let i = 0; i < period; i++) {
sum += this.api.Close(i);
}
const average = sum / period;
// Store the calculated value in buffer 0 at the current bar
this.someBuffer.setValue(0, average);
// Store values for multiple bars
for (let i = 0; i < this.api.Bars(); i++) {
const value = calculateIndicatorValue(i);
this.someBuffer.setValue(i, value);
}
Returns the number of values stored in a buffer.
GetBufferCount(buffer: number): number
buffer
- A number representing the buffer index.
Returns a number
representing the count of values stored in the specified buffer.
The GetBufferCount
method returns the number of values that have been stored in a specific buffer. This can be useful for determining how many bars have valid indicator values.
// Get the count of values in buffer 0
const count = this.api.GetBufferCount(0);
// Use the count to iterate through all values in the buffer
for (let i = 0; i < count; i++) {
const value = this.someBuffer.getValue(i);
// Process the value
}
// Check if there are enough values for calculations
if (this.api.GetBufferCount(0) >= period) {
// Perform calculations that require at least 'period' values
}
Retrieves a value from a specific buffer at a given index.
this.someBuffer.getValue(index);
index
- A number representing the position in the buffer to retrieve the value from.
Returns a number
representing the value stored at the specified position in the buffer.
The getValue
method of a buffer object retrieves a value from a specific buffer at a given index. This is useful for accessing previously calculated values or values from other buffers during indicator calculations.
// Get the value from buffer 0 at the current bar
const currentValue = this.someBuffer.getValue(0);
// Get the value from buffer 0 at the previous bar
const previousValue = this.someBuffer.getValue(1);
// Get a value from another buffer
const signalValue = this.someBuffer.getValue(0);
// Use values in calculations
const difference = currentValue - signalValue;
Sets a symbol to be used for drawing points in a buffer.
SetIndexSymbol(bufferIndex: number, symbol: number, xoffs: number, yoffs: number): void
bufferIndex
- A number representing the index of the buffer.
symbol
- A number representing the symbol code to use.
xoffs
- A number representing the X-offset for the symbol.
yoffs
- A number representing the Y-offset for the symbol.
This method does not return a value.
The SetIndexSymbol
method sets a symbol to be used for drawing points in a buffer.
// Set buffer 0 to use symbol 217 (arrow up) with no offset
this.api.SetIndexSymbol(0, 217, 0, 0);
// Set buffer 1 to use symbol 218 (arrow down) with a slight offset
this.api.SetIndexSymbol(1, 218, 2, -2);
Sets the indicator to be recalculated on every tick.
RecalculateMeAlways(): void
This method does not take any parameters.
This method does not return a value.
The RecalculateMeAlways
method configures the indicator to be recalculated on every tick, rather than only when a new bar forms. This is useful for indicators that need to update their values continuously, such as those that depend on the current price.
If this setting is not used, each buffer index will be calculated only once for resource saving, but some indicators may be calculated inaccurately.
If calculations do not significantly load the processor, we recommend using it always.
// Set the indicator to recalculate on every tick
this.api.RecalculateMeAlways();
Sets fixed minimum and maximum values for the indicator's scale.
SetFixedMinMaxValues(aMin: number, aMax: number): void
aMin
- A number representing the minimum value for the indicator's scale.
aMax
- A number representing the maximum value for the indicator's scale.
This method does not return a value.
The SetFixedMinMaxValues
method sets fixed minimum and maximum values for the indicator's scale. This is particularly useful for oscillators and other indicators that should be displayed within a specific range.
// Set fixed scale for RSI (0-100)
this.api.SetFixedMinMaxValues(0, 100)
// Set fixed scale for Stochastic (0-100)
this.api.SetFixedMinMaxValues(0, 100)
// Set custom range for an oscillator (-50 to 50)
this.api.SetFixedMinMaxValues(-50, 50)
Assigns a buffer to a specific index.
SetIndexBuffer(bufferIndex: number, buffer: TIndexBuffer): void
bufferIndex
- A number representing the index to assign the buffer to.
buffer
- A TIndexBuffer object to be assigned to the specified index.
This method does not return a value.
The SetIndexBuffer
method assigns a buffer to a specific index. This is necessary after creating a buffer with CreateIndexBuffer to specify which index the buffer should be associated with. The index must be less than the number of buffers specified with IndicatorBuffers.
// Specify that the indicator uses 3 buffers
this.api.IndicatorBuffers(3);
// Create buffers
const upperBuffer = this.api.CreateIndexBuffer();
const middleBuffer = this.api.CreateIndexBuffer();
const lowerBuffer = this.api.CreateIndexBuffer();
// Assign buffers to indices
this.api.SetIndexBuffer(0, upperBuffer);
this.api.SetIndexBuffer(1, middleBuffer);
this.api.SetIndexBuffer(2, lowerBuffer);
// Now the buffers can be used to store indicator values
Sets a unique identifier key for the indicator.
SetIndicatorIdKey(key: string): void
key
- A string containing a unique identifier for the indicator.
This method does not return a value.
The SetIndicatorIdKey
method assigns a unique identifier key to the indicator. This key can be used for internal reference, persistence, or to identify the indicator in various operations.
// Set a simple key
this.api.SetIndicatorIdKey('RSI_14')
// Use a more complex key with parameters
this.api.SetIndicatorIdKey(`MA_${period}_${method}_${price}`)
// Generate a unique key
this.api.SetIndicatorIdKey(`CustomIndicator_${Date.now()}`)
Sets the number of additional bars to include in calculations.
SetBackOffsetForCalculation(offset: number): void
offset
- A number representing the additional bars to include in calculations.
This method does not return a value.
The SetBackOffsetForCalculation
method sets the number of additional historical bars that should be included when calculating the indicator. This is useful for indicators that require more historical data than just the visible range to calculate correctly.
// Include 50 additional bars in calculations
this.api.SetBackOffsetForCalculation(50)
// For indicators that need a lot of historical data
this.api.SetBackOffsetForCalculation(200)
Changes the value of an existing level line.
SetLevelValue(index: number, value: number): void
index
- A number representing the index of the level to modify.
value
- A number representing the new Y-value for the level.
This method does not return a value.
The SetLevelValue
method changes the Y-value of an existing level line. This can be used to dynamically adjust level positions based on market conditions or user preferences.
// Change the first level (index 0) to value 75
this.api.SetLevelValue(0, 75)
// Change the second level (index 1) to value 25
this.api.SetLevelValue(1, 25)
// Dynamically adjust levels based on volatility
const volatility = this.api.iATR('EURUSD', 14, 0)
this.api.SetLevelValue(0, 50 + volatility * 2)
this.api.SetLevelValue(1, 50 - volatility * 2)
Sets the number of data buffers used by the indicator.
IndicatorBuffers(bufferCount: number): void
bufferCount
- A number representing the count of data buffers needed by the indicator.
This method does not return a value.
The IndicatorBuffers
method specifies how many data buffers the indicator will use. Each buffer represents a series of values that can be displayed on the chart. For example, a simple moving average uses one buffer, while Bollinger Bands use three buffers (middle line, upper band, lower band).
// For a simple indicator with one line
this.api.IndicatorBuffers(1)
// For Bollinger Bands (middle, upper, lower)
this.api.IndicatorBuffers(3)
// For MACD (MACD line, signal line, histogram)
this.api.IndicatorBuffers(3)
Sets the value to be used for empty or undefined indicator values.
SetEmptyValue(emptyValue: number): void
emptyValue
- A number representing the value to use for empty or undefined indicator values.
This method does not return a value.
The SetEmptyValue
method defines what value should be used when an indicator value is empty, undefined, or cannot be calculated. This is commonly used to prevent drawing lines or markers when there is insufficient data to calculate the indicator.
// Set empty values to zero
this.api.SetEmptyValue(0)
// Use a negative value to clearly identify missing data points
this.api.SetEmptyValue(-1)
// Common practice is to use a very large negative number
this.api.SetEmptyValue(-999999)
Sets the number of decimal digits for a numeric option.
SetOptionDigits(name: string, digits: number): void
name
- A string containing the name of the option to set the digits for.
digits
- A number representing the number of decimal digits to display.
This method does not return a value.
The SetOptionDigits
method sets the number of decimal digits for a numeric option. This is used to define how many decimal places should be displayed and used for a numeric option in an indicator or strategy.
// Register a level option
this.api.RegOption("Overbought Level", TOptionType.DOUBLE, 70.0);
// Set to display 1 decimal digit
this.api.SetOptionDigits("Overbought Level", 1);
// Register a multiplier option
this.api.RegOption("Multiplier", TOptionType.DOUBLE, 2.618);
// Set to display 3 decimal digits
this.api.SetOptionDigits("Multiplier", 3);
Returns the number of bars that have already been calculated in previous calls.
Counted_bars(): number
This method does not take any parameters.
Returns a number
representing the count of bars that have already been calculated.
The Counted_bars
method returns the number of bars that have already been processed in previous calls to the indicator's calculation function. This is useful for optimization, as it allows the indicator to only calculate values for new bars rather than recalculating all bars.
// Get the number of already calculated bars
const counted = this.api.Counted_bars()
// Use it to optimize calculations
const total = this.api.Bars()
const limit = counted > 0 ? total - counted : total - 1
// Only calculate for new bars
for (let i = limit; i >= 0; i--) {
// Perform indicator calculations for bar at index i
}
Adds a possible value for an enum-type option.
AddOptionValue(name: string, value: string): void
name
- A string containing the name of the option to add a value to.
value
- A string containing the value to add to the option.
This method does not return a value.
The AddOptionValue
method adds a possible value for an enum-type option. This is used to define the possible values that users can select for an enum option in an indicator or strategy.
// Register an MA Type option
this.api.RegOption("MA Type", TOptionType.ENUM_TYPE, 0);
// Add possible values for the MA Type option
this.api.AddOptionValue("MA Type", "Simple");
this.api.AddOptionValue("MA Type", "Exponential");
this.api.AddOptionValue("MA Type", "Smoothed");
this.api.AddOptionValue("MA Type", "Weighted");
Returns the minimum price change (point) value.
Point(): number
Returns a number
representing the minimum price change value.
The Point
method returns the minimum price change value for the symbol. This is the smallest price movement possible and is used as a base for various calculations.
// Get point value
const point = this.api.Point();
console.log(`Point value: ${point}`);
// Calculate spread in points
const spreadPoints = (this.api.Ask() - this.api.Bid()) / this.api.Point();
console.log(`Spread in points: ${spreadPoints}`);
// Calculate price movement
const priceChange = (currentPrice - previousPrice) / this.api.Point();
console.log(`Price moved ${priceChange} points`);
Returns the current ask price.
Ask(): number
Returns a number
representing the current ask price.
The Ask
method returns the current ask price for the symbol. The ask price is the price at which the market is willing to sell the base currency (in forex) or the asset (in other markets).
// Get current ask price
const currentAsk = this.api.Ask();
console.log(`Current ask price: ${currentAsk}`);
// Calculate spread in points
const spreadInPoints = (this.api.Ask() - this.api.Bid()) / this.api.Point();
console.log(`Current spread in points: ${spreadInPoints}`);
// Use in trading decisions
if (this.api.Ask() < resistanceLevel) {
// Price is below resistance
// Consider long position
}
Sets the short name for the indicator.
IndicatorShortName(shortName: string): void
shortName
- A string containing the short name for the indicator.
This method does not return a value.
The IndicatorShortName
method sets the short name that will be displayed for the indicator in the chart legend, indicator list, and other UI elements. This name helps users identify the indicator on the chart.
// Set a simple name
this.api.IndicatorShortName('RSI(14)')
// Include parameter values in the name
const period = 14
const price = 'Close'
this.api.IndicatorShortName(`MA(${period}, ${price})`)
// For a custom indicator with multiple parameters
this.api.IndicatorShortName(`Custom Oscillator(${fast}, ${slow}, ${signal})`)
This section provides functions to define and manage external parameters for indicators. These functions allow you to add options, set ranges, and configure parameters.
RegOption
: Registers an option for an indicator.
AddOptionValue
: Adds a value to an option.
SetOptionDigits
: Sets the number of digits for an option.
SetOptionRange
: Sets the range for an option.
Click on any function name to view its detailed documentation.
Registers a new option parameter for an indicator or strategy.
RegOption(name: string, type: TOptionType, optPtrOrValue?: string | number | boolean | TOptValue, inv = true, useInNameWithParams = true): void
name
- A string containing the name of the option.
type
- The type of the option (from TOptionType enum).
optPtrOrValue
- (Optional) The default value for the option.
inv
- (Optional) Visibility flag, defaults to true.
useInNameWithParams
- (Optional) Whether to include this option in the name with parameters, defaults to true.
This method does not return a value.
The RegOption
method registers a new option parameter for an indicator or strategy. This is used to define the configurable parameters that users can adjust when applying the indicator or strategy.
See TOptionType for a complete list of option types.
// Declare parameters as class fields
public Period!: TOptValue_number;
public Color!: TOptValue_number;
public Deviation!: TOptValue_number;
public ShowLabels!: TOptValue_bool;
public FillPriceType!: TOptValue_number;
Init(): void {
// Create parameters
this.Period = this.api.createTOptValue_number(8);
this.Color = this.api.createTOptValue_number(0);
this.Deviation = this.api.createTOptValue_number(0);
this.ShowLabels = this.api.createTOptValue_bool(true);
this.FillPriceType = this.api.createTOptValue_number(0);
// Register a period option
this.api.RegOption("Period", TOptionType.INTEGER, this.Period);
// Register a color option
this.api.RegOption("Deviation", TOptionType.DOUBLE, this.Deviation);
// Register a boolean option
this.api.RegOption("Show Labels", TOptionType.BOOLEAN, this.ShowLabels);
// Register an enum option
this.api.RegOption('Fill Price Type',TOptionType.ENUM_TYPE,this.FillPriceType)
this.api.AddOptionValue('Fill Price Type','Close')
this.api.AddOptionValue('Fill Price Type','HighLow')
}
Returns the current bid price.
Returns a number
representing the current bid price.
The Bid
method returns the current bid price for the symbol. The bid price is the price at which the market is willing to buy the base currency (in forex) or the asset (in other markets).
This section provides functions to retrieve information about currency pairs. These functions allow you to get details such as bid, ask, and point values.
: Retrieves the current ask price.
: Retrieves the current bid price.
: Retrieves the number of digits for a currency.
: Retrieves the point value for a currency.
: Retrieves the symbol name.
Click on any function name to view its detailed documentation.
Sets the valid range for a numeric option.
name
- A string containing the name of the option to set the range for.
lowValue
- A number representing the minimum allowed value.
highValue
- A number representing the maximum allowed value.
This method does not return a value.
The SetOptionRange
method sets the valid range for a numeric option. This is used to define the minimum and maximum values that users can input for a numeric option in an indicator or strategy.
Returns the number of decimal places in the symbol's price.
Returns a number
representing the count of decimal places.
The Digits
method returns the number of decimal places used in the symbol's price quotation. This value is important for proper price formatting and calculations.
Outputs a message to the console with the current UTC time in testing.
message
- A string containing the message to be printed.
This method does not return a value.
The Print
method outputs a message to the console, prefixed with the current UTC time in testing. This is useful for debugging and logging information during strategy development and testing.
The timestamp format is "YYYY.MM.DD HH:nn:ss" and represents the last processed tick time in the testing environment.
This section provides miscellaneous functions that do not fit into other categories. These functions include utility and time-related operations.
: Prints a message to the console.
: Retrieves the current time.
: Retrieves the current timeframe.
Click on any function name to view its detailed documentation.
This section provides documentation for various types used in indicators. These types define the structure and behavior of indicator options and chart objects.
: Defines the type of an option parameter.
: Defines the types of chart objects that can be created.
: Defines where an indicator should be displayed on the chart.
: Defines the style of lines used in indicators and chart objects.
: Defines how indicator values should be visually represented on the chart.
: Defines the properties that can be accessed for chart objects.
: Represents a buffer for storing indicator values.
: Represents the visual properties and information about an indicator buffer.
: Represents a date and time value in the format of the trading platform.
Click on the type name to view its detailed documentation.
Returns the current time.
Returns an object representing the current time.
The TimeCurrent
method returns the current time as an object. This time represents the timestamp of the last processed tick in the project. The returned object provides various methods for date and time manipulation.
Symbol(): string
// Get the current symbol name
const symbolName = this.api.Symbol();
console.log(`Current symbol: ${symbolName}`); // e.g., "EURUSD"
// Use symbol name in conditions
if (this.api.Symbol() === "EURUSD") {
// EURUSD specific logic
}
LONGWORD
Represents an unsigned 32-bit integer
INTEGER
Represents a signed integer value
DOUBLE
Represents a floating-point number
STRING
Represents a text string
BOOLEAN
Represents a true/false value
ENUM_TYPE
Represents a selection from a list of predefined values
TIMEFRAME
Represents a chart timeframe
CURRENCY
Represents a currency selection
LINE_STYLE
Represents a line style for drawing
SEPARATOR
Represents a visual separator in the options dialog
INDICATOR
Represents an indicator selection
COLOR
Represents a color selection
DATE_TIME
Represents a date and time value
LEVELS
Represents level settings
SESSION
Represents a trading session
SESSIONS_ARRAY
Represents an array of trading sessions
// Register an integer option
this.api.RegOption("Period", TOptionType.INTEGER, 14);
// Register a color option
this.api.RegOption("Line Color", TOptionType.COLOR, "#0000FF");
// Register a boolean option
this.api.RegOption("Show Labels", TOptionType.BOOLEAN, true);
// Register an enum option
this.api.RegOption("MA Type", TOptionType.ENUM_TYPE, 0);
// Add a separator
this.api.AddSeparator("Visual Settings");
Bid(): number
// Get current bid price
const currentBid = this.api.Bid();
console.log(`Current bid price: ${currentBid}`);
// Calculate spread
const spread = this.api.Ask() - this.api.Bid();
console.log(`Current spread: ${spread}`);
// Use in trading decisions
if (this.api.Bid() > previousPrice) {
// Price has increased
// Implement trading logic
}
SetOptionRange(name: string, lowValue: number, highValue: number): void
// Register a period option
this.api.RegOption("Period", TOptionType.INTEGER, 14);
// Set the valid range for the period option (1 to 200)
this.api.SetOptionRange("Period", 1, 200);
// Register a level option
this.api.RegOption("Overbought Level", TOptionType.DOUBLE, 70);
// Set the valid range for the level option (50 to 100)
this.api.SetOptionRange("Overbought Level", 50, 100);
Digits(): number
// Get number of decimal places
const digits = this.api.Digits();
console.log(`Price decimal places: ${digits}`);
// Format price with correct precision
const price = 1.23456;
const formattedPrice = price.toFixed(this.api.Digits());
console.log(`Formatted price: ${formattedPrice}`);
// Use in calculations
const point = Math.pow(10, -this.api.Digits());
console.log(`One point value: ${point}`);
Timeframe(): number
// Get the current timeframe
const timeframe = this.api.Timeframe();
console.log(`Current timeframe: ${timeframe}`);
// Check for specific timeframes
if (this.api.Timeframe() === 60) {
// H1 specific logic
} else if (this.api.Timeframe() === 1440) {
// Daily chart logic
}
Print(message: string): void
// Print a simple message
this.api.Print('Hello, world!')
// Print a variable value
const rsi = this.api.iRSI('EURUSD', 14, 0)
this.api.Print(`Current RSI value: ${rsi}`)
// Print information during strategy execution
if (this.api.iRSI('EURUSD', 14, 0) < 30) {
this.api.Print('Oversold condition detected')
}
SOLID
A solid line
DASH
A dashed line (- - -)
DOT
A dotted line (. . .)
DASHDOT
A line with alternating dashes and dots (- . - .)
DASHDOTDOT
A line with dashes and double dots (- . . - . .)
// Create a solid line level
this.api.AddLevel(70, TPenStyle.SOLID, 1, "#FF0000", 1);
// Create a dashed line level
this.api.AddLevel(30, TPenStyle.DASH, 1, "#00FF00", 1);
// Create a dotted middle line
this.api.AddLevel(50, TPenStyle.DOT, 1, "#808080", 0.7);
ANY_OBJECT
Represents any type of chart object
V_LINE
A vertical line on the chart
H_LINE
A horizontal line on the chart
TREND_LINE
A trend line connecting two points
RAY
A ray extending from one point in a direction
POLYLINE
A line consisting of multiple connected segments
FIBO_RETRACEMENT
Fibonacci retracement levels
FIBO_TIME_ZONES
Fibonacci time zones
FIBO_ARC
Fibonacci arcs
FIBO_FAN
Fibonacci fan lines
ANDREWS_PITCHFORK
Andrews' Pitchfork technical analysis tool
TEXT
Simple text object
TEXT_LABEL
Text label with additional formatting options
RECTANGLE
A rectangular shape
ELLIPSE
An elliptical shape
TRIANGLE
A triangular shape
FIBO_CHANNEL
Fibonacci channel
LR_CHANNEL
Linear regression channel
FIBO_EXTENSION
Fibonacci extension levels
GANN_BOX
Gann box analysis tool
// Create a trend line object
const trendLine = this.api.CreateChartObject(
"MyTrendLine",
TObjectType.TREND_LINE,
0,
startDate,
startPrice,
endDate,
endPrice
);
// Create a text label
const label = this.api.CreateChartObject(
"MyLabel",
TObjectType.TEXT_LABEL,
0,
date,
price
);
CHART_WINDOW
Display the indicator in the main chart window overlaid on price
SEPARATE_WINDOW
Display the indicator in a separate window below the main chart
// Display indicator in the main chart window (like Moving Averages)
this.api.SetOutputWindow(TOutputWindow.CHART_WINDOW);
// Display indicator in a separate window (like RSI)
this.api.SetOutputWindow(TOutputWindow.SEPARATE_WINDOW);
TimeCurrent(): FTODate
// Get current time
const currentTime = this.api.TimeCurrent();
// Display current time components
console.log(
`Date: ${currentTime.yearOf()}.${currentTime.monthOf()}.${currentTime.dayOfMonth()}`
);
console.log(
`Time: ${currentTime.hour()}:${currentTime.minute()}:${currentTime.second()}`
);
// Get timestamp in milliseconds
const timestamp = currentTime.getTime();
console.log(`Timestamp: ${timestamp}`);
// Format the date
console.log(`Formatted date: ${currentTime.toString()}`);
// Check if it's weekend
const dayOfWeek = currentTime.dayOfWeek();
const isWeekend = dayOfWeek === 0 || dayOfWeek === 6;
console.log(`Is weekend: ${isWeekend}`);