Only this pageAll pages
Powered by GitBook
Couldn't generate the PDF for 105 pages, generation stopped at 100.
Extend with 50 more pages.
1 of 100

FTO Indicators Docs

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Indicators

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...

Overview

Overview

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.


📌 What You’ll Find Here


👨‍💻 Who is This For?

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


🚀 Ready to Begin?

Upload indicator to FTO

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 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).

Set up Cursor Rules

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

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.

Start with the guide and move on to the to see how it all works in action.

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.

Quick Guide
Indicator Structure
Working with Buffers
Accessing Chart Data
Indicator Configuration
External Parameters
Getting Currency Information
Working with Dates and Time
Other Utilities
Setup and Installation
Moving Average Tutorial
Rules

Indicator structure

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
  }
}

Description of the structure

To get familiar with other methods, you can read the documentation for each method.

Main methods of each indicator are and , 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.

Init
Calculate
OnParamsChange
Done
OnHide
OnShow

Tutorial: Moving Average

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

Indicator structure

import { IndicatorImplementation } from "forex-tester-custom-indicator-api";

export default class MovingAverage extends IndicatorImplementation {
  // indicator logic
}

Indicator parameters

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...
    }

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...
}

Buffers setup

public SSMA!: TIndexBuffer
private SMA!: TIndexBuffer
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);
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);

Other settings

Indicator's main function

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())
}

Changing parameters

public OnParamsChange(): void {
    this.api.SetBufferShift(0, this.Shift.value)
}

OnParamsChange

What is it?

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.


Syntax


When and Why to Use It

  • 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


Example Use Case

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.


Important Notes

  • 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.


In Simple Terms

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.

For more details on how to open it in Cursor IDE, you can refer to this .

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 section.

These parameters can be of different types, they are determined by the class, and they will be displayed in the indicator addition/editing window

For this, they need to be registered in the function.

You can see the methods for registering parameters in the

are used to store and display indicator values on the chart.

They need to be declared with all class fields and initialized in the function

Each registered buffer can be

Also, other methods for configuring the indicator are used in the function. To ensure the indicator recalculates on each tick, use the function . 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: .

We want the Moving Average indicator to be displayed on the main chart, so we use .

Using this call, specify that values equal to 0 will not be drawn on the chart: .

The main function of the indicator is the function, where the indicator values are calculated on each tick.

To add custom logic after changing the indicator parameters, we use the 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.

section
Setup and Installation
TOptValue
Init
external parameters definition
Buffers
Init
configured
Init
RecalculateMeAlways
IndicatorShortName
SetOutputWindow
SetEmptyValue
Calculate
OnParamsChange
public OnParamsChange(): void {
    // logic after parameter change
}
public OnParamsChange(): void {
    // Example: Reposition a line or label when "VShift" is changed
    
    this.UpdateShiftedLine(this.VShift.value) // custom method UpdateShiftedLine
}

Set up indicator

This is a separate guide on how to set up the environment to write your custom indicator for FTO.

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.

Download indicator examples

These are indicator examples you can download

To to use our custom indicator API, you need to first download indicator example. You can find some of the examples or download the suggested example file below.

If you want to know how to upload your indicator to FTO, you can go to .

here
upload guide

OnHide

What is it?

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.


Syntax

public OnHide(): void {
    // logic after hiding the indicator
}

When and Why to Use It

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


Example

public OnHide(): void {
    // Custom method to remove a label created when the indicator was shown
    this.DeleteObject("InfoLabel")
}

Important Notes

  • 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.

Parameters

What Are Parameters?

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.


How It Works

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.


Common Parameter Types

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


Example

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);
  }
}

Key Rules

  • Parameters control how the indicator works and looks — use them for anything the user might want to tweak

Only -based parameters are configurable

You must register each parameter inside the method using

TOptValue
Init
this.api.RegOption

Tutorial: Create indicator with Cursor IDE

This tutorial will guide you through the process of creating a new indicator using Cursor IDE.

Introduction

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.

Please note that Cursor is a paid IDE, but it has a free version, the free version is limited to 50 requests and 2000 completions total.

Step 1: Install Cursor and set up the project

Step 2: Apply Cursor Rules

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

Step 3: Upload FTO indicator documentation to Cursor

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).

  1. Scroll down until you see Docs (Picture #6)

  1. 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.

Step 4: Getting familiar with Cursor

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).

Step 5: Start building

In the result, we got code below

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);
    }
}

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

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);
    }
}

And with the addition of this new parameter and internal method, we get a nice dropdown with price types (Picture #13).

Recommendations

Start by selecting the Ask mode and add context to your query by typing @ and selecting Docs from the drop-down menu (Picture #14).

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)

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 become more familiar with how to use this added documentation in your requests to Cursor, go to the section below.

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).

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:

In the drop-down menu, select FTO Indicator documentation, which we added earlier in (Picture#15)

this
Rules
this
this section
Recommendations
context
Rules
Rules
Step 3
Step 3

Calculate

What is it?

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.


How It Works

  • 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.


Example Explained

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())
}

What This Code Does

  1. Checks if there are enough bars to calculate the moving average. (We need Period number of candles; otherwise, we skip.)

  2. Calculates a Moving Average value using GetMA().

  3. Stores the result in the SMA buffer, which is used for drawing on the chart.

  4. Applies a vertical shift (VShift) and stores the result in a second buffer (SSMA).


In Short

  • 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.

this.SSMA.setValue(index, calculatedSMA + this.VShift.value * this.api.Point())

Init

What is it?

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.


Syntax

public Init(): void {
    // initialization logic here
}

What Happens in 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


Example

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");
  }
}

Why It Matters

  • 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.


Pro Tip

Avoid heavy calculations or per-bar logic here. Use Calculate() for that. Init is only for defining the structure and settings of the indicator.

Done

What is it?

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.


Syntax


When and Why to Use It

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.


Example


Important Notes

  • 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.

OnShow

What is it?

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.


Syntax


When and Why to Use It

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.


Example


Important Notes

  • 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.

Tutorial: Open and upload indicator

This page will guide you how to install Cursor IDE and how to upload your custom indicator to FTO.

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:

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).

Download and install the Cursor editor: , 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.

public Done(): void {
    // logic after finishing the calculation
}
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") 
}
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")
}
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
https://www.cursor.com/downloads
https://nodejs.org/en

TOptValue

This is documentation for different types of TOptValue classes which are used to create parameters for indicators.

TOptValue_number

What Is It?

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.


When to Use

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


Syntax


Example

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.


Notes

  • You can access the value using this.MyParameter.value.

After creating a parameter, don’t forget to register it using in the method.

TOptValue_str
TOptValue_number
TOptValue_bool
// 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);
  }
}
this.RegOption
Init

TOptValue_bool

What Is It?

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.


When to Use

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


Syntax

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);
}

Example

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.


Notes

  • Access the value with this.MyFlag.value.

Visible buffers

Overview

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.


Step-by-Step Guide

1. Declare the Buffer

All buffers must be declared as class fields using the TIndexBuffer type.


2. Create the Buffer in Init()

Create the buffer instance using the CreateIndexBuffer() method.


3. Register the Number of Buffers

Tell the API how many buffers you plan to use. In this case — one:

This must be called before setting buffer styles or assignments.


4. Bind the Buffer to an Index

Each buffer must be assigned a unique index:


5. Configure the Buffer

You can now customize how the buffer will appear on the chart:


Full Example


Notes

  • 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.

Don't forget to register string parameters using inside the method.

You can use the value directly in , , or other methods as needed.

this.RegOption
Init
Calculate
OnShow
public SSMA!: TIndexBuffer;
this.SSMA = this.api.CreateIndexBuffer();
this.api.IndicatorBuffers(1);
this.api.SetIndexBuffer(0, this.SSMA);
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);
  }
}

Volume

Returns the volume for a specific bar.

Syntax

Volume(shift: number): number

Parameters

  • shift: A number representing the shift from the current bar

Return Value

Returns a number representing the trading volume during the specified bar.

Description

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

Example

// 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");
}

iTime

Returns the opening time of a bar in the specified symbol's price history.

Syntax

iTime(Symbol: string, TimeFrame: number, index: number): FTODate

Parameters

  • 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.)

Return Value

Description

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.

Example

// 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));
}

TOptValue_str

What Is It?

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.


When to Use

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


Syntax

// 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);
}

Example

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.


Notes

  • You can use the value directly in Calculate, OnShow, or other methods as needed.

Returns an object representing the opening time of the specified bar.

Don't forget to register string parameters using inside the method.

FTODate
this.RegOption
Init

iLow

Returns the lowest price of a bar in the specified symbol's price history.

Syntax

iLow(Symbol: string, TimeFrame: number, index: number): number

Parameters

  • 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.)

Return Value

Returns a number representing the lowest price of the specified bar.

Description

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.

Example

// 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);

iVolume

Returns the tick volume of a bar in the specified symbol's price history.

Syntax

iVolume(Symbol: string, TimeFrame: number, index: number): number

Parameters

  • 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.)

Return Value

Returns a number representing the tick volume of the specified bar.

Description

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.

Example

// 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;

iClose

Returns the close price of a bar in the specified symbol's price history.

Syntax

iClose(Symbol: string, TimeFrame: number, index: number): number

Parameters

  • 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.)

Return Value

Returns a number representing the close price of the specified bar.

Description

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.

Example

// 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;

iOpen

Returns the open price of a bar in the specified symbol's price history.

Syntax

iOpen(Symbol: string, TimeFrame: number, index: number): number

Parameters

  • 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.)

Return Value

Returns a number representing the open price of the specified bar.

Description

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.

Example

// 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");
}

iBars

Returns the total number of bars available in the specified symbol's price history.

Syntax

iBars(Symbol: string, TimeFrame: number): number

Parameters

  • Symbol: The symbol to get data for

  • TimeFrame: The timeframe of the data (in minutes)

Return Value

Returns a number representing the total count of available bars.

Description

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.

Example

// 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);

Low

Returns the lowest price for a specific bar.

Syntax

Low(shift: number): number

Parameters

  • shift: A number representing the shift from the current bar

Return Value

Returns a number representing the lowest price reached during the specified bar.

Description

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

Example

// 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");
}

iHighest

Returns the index of the bar with the highest value over a specified range.

Syntax

iHighest(symbol: string, timeFrame: number, type: number, count: number, index: number): number

Parameters

  • 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.)

Return Value

Returns a number representing the index of the bar with the highest value. Returns -1 if no valid bar is found.

Description

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.

Example

// 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;
});

iHigh

Returns the highest price of a bar in the specified symbol's price history.

Syntax

iHigh(Symbol: string, TimeFrame: number, index: number): number

Parameters

  • 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.)

Return Value

Returns a number representing the highest price of the specified bar.

Description

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.

Example

// 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;

iBarShift

Returns the bar index for a specified time in the symbol's price history.

Syntax

iBarShift(symbol: string, timeframe: number, time: FTODate, exact: boolean): number

Parameters

  • symbol: The symbol to get data for

  • timeframe: The timeframe of the data (in minutes)

  • exact: Whether to require an exact match

Return Value

Returns a number representing the index of the bar corresponding to the specified time. Returns -1 if no matching bar is found.

Description

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.

Example

// 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);

time: The time to search for

FTODate

iLowest

Returns the index of the bar with the lowest value over a specified range.

Syntax

iLowest(symbol: string, timeFrame: number, type: number, count: number, index: number): number

Parameters

  • 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.)

Return Value

Returns a number representing the index of the bar with the lowest value. Returns -1 if no valid bar is found.

Description

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.

Example

// 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;

High

Returns the highest price for a specific bar.

Syntax

High(shift: number): number

Parameters

  • shift: A number representing the shift from the current bar

Return Value

Returns a number representing the highest price reached during the specified bar.

Description

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

Example

// 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");
}

Access to Bar Arrays

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.


Available Functions


Click on any function name to view its detailed documentation.

: 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.

Volume
iVolume
iTime
iOpen
iLowest
iLow
iHighest
iHigh
iClose
iBarShift
iBars
Close
High
Low
Open
Bars
Time

RemoveAllObjects

Removes all chart objects of a specified type.

Syntax

RemoveAllObjects(objType: TObjectType, isStatic: boolean = false): void

Parameters

Parameter
Type
Description

objType

The type of objects to remove

isStatic

boolean

Optional. Whether to remove static objects (default: false)

Description

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.

Example

// 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`);

TObjectType

Bars

Returns the total number of bars.

Syntax

Bars(): number

Return Value

Returns a number representing the total count of available bars.

Description

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.

Example

// 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}`);

Open

Returns the opening price for a specific bar.

Syntax

Open(shift: number): number

Parameters

  • shift: A number representing the shift from the current bar

Return Value

Returns a number representing the opening price of the specified bar.

Description

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

Example

// 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}`);
}

GetObjectText

Returns the text content of a chart object.

Syntax

GetObjectText(name: string, isStatic: boolean = false): string

Parameters

Parameter
Type
Description

name

string

The name of the object

isStatic

boolean

Optional. Whether to look in static objects (default: false)

Return Value

Returns a string containing the object's text content.

Description

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.

Example

// 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)
}

Close

Returns the closing price for a specific bar.

Syntax

Close(shift: number): number

Parameters

  • shift: A number representing the shift from the current bar

Return Value

Returns a number representing the closing price of the specified bar.

Description

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

Example

// 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}`);
}

DoesChartObjectExist

Checks if a chart object with the specified name exists.

Syntax

DoesChartObjectExist(uniqueObjectName: string, isStatic: boolean = false): boolean

Parameters

Parameter
Type
Description

uniqueObjectName

string

The unique name of the object to check

isStatic

boolean

Optional. Whether to check static objects (default: false)

Return Value

Returns a boolean indicating whether the object exists (true) or not (false).

Description

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.

Example

// 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");
}

Access to 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.


Available Functions


Click on any function name to view its detailed documentation.

: 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.

CreateChartObject
RemoveAllObjects
DoesChartObjectExist
GetObjectText
GetObjectType
GetObjectName
GetObjectCount
RemoveChartObject
SetObjectText
GetObjectProperty
SetObjectProperty

GetObjectCount

Returns the total number of chart objects.

Syntax

GetObjectCount(isStatic: boolean = false): number

Parameters

Parameter
Type
Description

isStatic

boolean

Optional. Whether to count static objects (default: false)

Return Value

Returns a number representing the total count of chart objects.

Description

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.

Example

// 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}`);
}

CreateChartObject

Creates a new chart object with specified parameters.

Syntax

СreateChartObject(
    name: string,
    objType: TObjectType,
    window: number,
    ftoDate1: FTODate,
    price1: number,
    ftoDate2?: FTODate,
    price2?: number,
    ftoDate3?: FTODate,
    price3?: number,
    isStatic?: boolean
): boolean

Parameters

Parameter
Type
Description

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)

Return Value

Returns boolean - true if the object was created successfully, false otherwise.

Description

The СreateChartObject method creates a new chart object with the specified parameters. Different object types require different sets of coordinates

Example

// 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
);

RemoveChartObject

Removes a chart object with the specified name.

Syntax

Parameters

Description

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.

Example

Time

Returns the time for a specific bar.

Syntax

Parameters

  • 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

Return Value

Description

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

Example

Parameter
Type
Description

Returns an object representing the bar's opening time.

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)
    }
}
Time(shift: number, timeZoneMode?: TimeZoneMode): FTODate
// 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()}`);
}
TObjectType
FTODate
FTODate
FTODate
FTODate

GetObjectName

Returns the name of a chart object by its index.

Syntax

GetObjectName(index: number, isStatic: boolean = false): string

Parameters

Parameter
Type
Description

index

number

The index of the object

isStatic

boolean

Optional. Whether to look in static objects (default: false)

Return Value

Returns a string representing the object's name.

Description

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.

Example

// 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}`)
}

GetObjectType

Returns the type of a chart object.

Syntax

GetObjectType(name: string, isStatic: boolean = false): TObjectType

Parameters

Parameter
Type
Description

name

string

The name of the object

isStatic

boolean

Optional. Whether to look in static objects (default: false)

Return Value

Description

The GetObjectType method retrieves the type of a specified chart object. The type is returned as a TObjectType enumeration value.

Example

// 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 a enum value representing the object's type.

TObjectType

SetIndexStyle

Sets the visual style for a buffer.

Syntax

SetIndexStyle(
    bufferIndex: number,
    type: TDrawStyle,
    style: TPenStyle,
    width: number,
    clr: string,
    isVisible?: boolean
): void

Parameters

  • bufferIndex - A number representing the index of the buffer to 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.

Return Value

This method does not return a value.

Description

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.

Example

// 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
);

type - A value from the enum specifying how to draw the buffer.

style - A value from the enum specifying the line style.

See for available drawing styles, for line styles

TDrawStyle
TPenStyle
TDrawStyle
TPenStyle

GetObjectProperty

Retrieves a property value from a chart object.

Syntax

GetObjectProperty(
  name: string,
  index: ObjProp | number,
  isStatic: boolean = false
  ): number | string

Parameters

Parameter
Type
Description

name

string

The name of the object

index

The property identifier

isStatic

boolean

Optional. Whether the object is static (default: false)

Return Value

Returns either a number or string depending on the property type.

Description

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.

Example

// 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}`);

| number

See for a complete list of available object properties.

ObjProp

SetObjectProperty

Sets a property value for a chart object.

Syntax

SetObjectProperty(
  name: string,
  index: number,
  value: any,
  isStatic: boolean = false
  ): boolean

Parameters

Parameter
Type
Description

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)

Return Value

Returns boolean - true if the property was set successfully, false otherwise.

Description

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.

Example

// 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);
ObjProp

Configure Indicator

This section provides functions to configure and customize indicators. These functions allow you to set styles, buffers, and other properties of indicators.


Available Functions


Click on any function name to view its detailed documentation.

: 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.

AddLevel
SetIndexStyle
CreateIndexBufferWithArgs
SetOutputWindow
IndicatorDigits
CountedBars
SetBufferShift
GetBufferInfo
SetIndexDrawBegin
GetBufferMin
GetBufferCount
GetBufferMax
Set buffer value
Get buffer value
SetIndexLabel
SetIndexSymbol
SetIndexVisibility
SetIndexBuffer
CreateIndexBuffer
IndicatorBuffers
SetLevelValue
RecalculateMeAlways
SetBackOffsetForCalculation
SetFixedMinMaxValues
SetIndicatorIdKey
SetEmptyValue
IndicatorShortName

AddLevel

Adds a horizontal level line to the indicator.

Syntax

AddLevel(value: number, style: TPenStyle, width: number, color: string, opacity: number): void

Parameters

  • value - A number representing the Y-value where the level should be drawn.

  • 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.

Return Value

This method does not return a value.

Description

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.

Example

// 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);

style - A value from the enum specifying the line style.

See for available line styles

TPenStyle
TPenStyle

IndicatorDigits

Sets the number of decimal places for indicator values.

Syntax

IndicatorDigits(digits: number): void

Parameters

  • digits - A number representing the number of decimal digits to display for indicator values.

Return Value

This method does not return a value.

Description

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.

Example

// 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)

SetObjectText

Sets the text content and formatting for a chart object.

Syntax

SetObjectText(
    name: string,
    text: string,
    fontSize: number = 14,
    fontName: string = Roboto Flex,
    fontColor: string = '#000000',
    isStatic: boolean = false
): boolean

Parameters

Parameter
Type
Description

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)

Return Value

Returns boolean - true if the text was set successfully, false otherwise.

Description

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.

Example

// 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}`);

SetOutputWindow

Sets the window where the indicator will be displayed.

Syntax

SetOutputWindow(outputWindow: TOutputWindow): void

Parameters

Return Value

This method does not return a value.

Description

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.

Example

// 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);

outputWindow - A value from the enum specifying where the indicator should be displayed.

See for the complete list of available window types.

TOutputWindow
TOutputWindow

SetBufferShift

Sets the horizontal shift for a buffer.

Syntax

SetBufferShift(bufferIndex: number, shift: number): void

Parameters

  • bufferIndex - A number representing the index of the buffer.

  • shift - A number representing the number of bars to shift the buffer.

Return Value

This method does not return a value.

Description

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).

Example

// 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)

CountedBars

Returns the number of bars that have already been calculated in previous calls.

Syntax

Counted_bars(): number

Parameters

This method does not take any parameters.

Return Value

Returns a number representing the count of bars that have already been calculated.

Description

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.

Example

// 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
}

CreateIndexBufferWithArgs

Creates a new buffer with specified display properties.

Syntax

CreateIndexBufferWithArgs(
    index: number,
    aLabel: string,
    drawStyle: TDrawStyle,
    style: TPenStyle,
    width: number,
    color: string
): TIndexBuffer

Parameters

  • index - A number representing the buffer index.

  • aLabel - A string containing the label for the buffer.

  • width - A number representing the line width in pixels.

  • color - A string hex color value for the buffer.

Return Value

Returns a TIndexBuffer object that can be used to store indicator values.

Description

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.

Example

// 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);
}

drawStyle - A value from the enum specifying how to draw the buffer.

style - A value from the enum specifying the line style.

TDrawStyle
TPenStyle

SetIndexDrawBegin

Sets the starting bar for drawing a buffer.

Syntax

SetIndexDrawBegin(bufferIndex: number, paintFrom: number): void

Parameters

  • bufferIndex - A number representing the index of the buffer.

  • paintFrom - A number representing the bar index to start drawing from.

Return Value

This method does not return a value.

Description

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.

Example

// 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)

GetBufferCount

Returns the number of values stored in a buffer.

Syntax

GetBufferCount(buffer: number): number

Parameters

  • buffer - A number representing the buffer index.

Return Value

Returns a number representing the count of values stored in the specified buffer.

Description

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.

Example

// 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
}

GetBufferMin

Finds the minimum value in a buffer within a specified range.

Syntax

GetBufferMin(buffer: number, index1: number, index2: number): number

Parameters

  • 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.

Return Value

Returns a number representing the minimum value found in the specified range of the buffer.

Description

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.

Example

// 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)
}

GetBufferMax

Finds the maximum value in a buffer within a specified range.

Syntax

GetBufferMax(buffer: number, index1: number, index2: number): number

Parameters

  • 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.

Return Value

Returns a number representing the maximum value found in the specified range of the buffer.

Description

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.

Example

// 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)
}

GetBufferInfo

Retrieves information about a buffer.

Syntax

GetBufferInfo(index: number): TVisibleBufferInfo

Parameters

  • index - A number representing the buffer index.

Return Value

Description

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.

Example

// 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);
}

Set buffer value

Sets a value in a specific buffer at a given index.

Syntax

Parameters

  • index - A number representing the position in the buffer to set the value at.

  • value - A number representing the value to store.

Return Value

This method does not return a value.

Description

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.

Example

Returns a object containing information about the buffer.

See for more information about the buffer information structure.

TVisibleBufferInfo
TVisibleBufferInfo
this.bufferName.setValue(index, value);
// 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);
}

Get buffer value

Retrieves a value from a specific buffer at a given index.

Syntax

this.someBuffer.getValue(index);

Parameters

  • index - A number representing the position in the buffer to retrieve the value from.

Return Value

Returns a number representing the value stored at the specified position in the buffer.

Description

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.

Example

// 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;

SetIndexSymbol

Sets a symbol to be used for drawing points in a buffer.

Syntax

SetIndexSymbol(bufferIndex: number, symbol: number, xoffs: number, yoffs: number): void

Parameters

  • 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.

Return Value

This method does not return a value.

Description

The SetIndexSymbol method sets a symbol to be used for drawing points in a buffer.

Example

// 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);

CreateIndexBuffer

Creates a new buffer for storing indicator values.

Syntax

CreateIndexBuffer(): TIndexBuffer

Parameters

This method does not take any parameters.

Return Value

Description

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.

Example

// 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);

Returns a object that can be used to store indicator values.

See for more information about working with indicator buffers.

TIndexBuffer
TIndexBuffer

SetIndexVisibility

Sets the visibility of a buffer.

Syntax

SetIndexVisibility(index: number, isVisible: boolean): void

Parameters

  • index - A number representing the index of the buffer.

  • isVisible - A boolean indicating whether the buffer should be visible.

Return Value

This method does not return a value.

Description

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.

Example

// 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);

SetIndexLabel

Sets a label for a buffer.

Syntax

SetIndexLabel(bufferIndex: number, bufferName: string): void

Parameters

  • bufferIndex - A number representing the index of the buffer.

  • bufferName - A string containing the label for the buffer.

Return Value

This method does not return a value.

Description

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.

Example

// 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')

SetLevelValue

Changes the value of an existing level line.

Syntax

SetLevelValue(index: number, value: number): void

Parameters

  • index - A number representing the index of the level to modify.

  • value - A number representing the new Y-value for the level.

Return Value

This method does not return a value.

Description

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.

Example

// 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)

RecalculateMeAlways

Sets the indicator to be recalculated on every tick.

Syntax

RecalculateMeAlways(): void

Parameters

This method does not take any parameters.

Return Value

This method does not return a value.

Description

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.

Example

// Set the indicator to recalculate on every tick
this.api.RecalculateMeAlways();

SetIndexBuffer

Assigns a buffer to a specific index.

Syntax

SetIndexBuffer(bufferIndex: number, buffer: TIndexBuffer): void

Parameters

  • bufferIndex - A number representing the index to assign the buffer to.

Return Value

This method does not return a value.

Description

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.

Example

// 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

buffer - A object to be assigned to the specified index.

TIndexBuffer

SetEmptyValue

Sets the value to be used for empty or undefined indicator values.

Syntax

SetEmptyValue(emptyValue: number): void

Parameters

  • emptyValue - A number representing the value to use for empty or undefined indicator values.

Return Value

This method does not return a value.

Description

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.

Example

// 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)

SetIndicatorIdKey

Sets a unique identifier key for the indicator.

Syntax

SetIndicatorIdKey(key: string): void

Parameters

  • key - A string containing a unique identifier for the indicator.

Return Value

This method does not return a value.

Description

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.

Example

// 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()}`)

IndicatorShortName

Sets the short name for the indicator.

Syntax

IndicatorShortName(shortName: string): void

Parameters

  • shortName - A string containing the short name for the indicator.

Return Value

This method does not return a value.

Description

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.

Example

// 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})`)

SetFixedMinMaxValues

Sets fixed minimum and maximum values for the indicator's scale.

Syntax

SetFixedMinMaxValues(aMin: number, aMax: number): void

Parameters

  • aMin - A number representing the minimum value for the indicator's scale.

  • aMax - A number representing the maximum value for the indicator's scale.

Return Value

This method does not return a value.

Description

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.

Example

// 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)

IndicatorBuffers

Sets the number of data buffers used by the indicator.

Syntax

IndicatorBuffers(bufferCount: number): void

Parameters

  • bufferCount - A number representing the count of data buffers needed by the indicator.

Return Value

This method does not return a value.

Description

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).

Example

// 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)

External Parameters Definition

This section provides functions to define and manage external parameters for indicators. These functions allow you to add options, set ranges, and configure parameters.


Available Functions


Click on any function name to view its detailed documentation.

: Registers an option for an indicator.

: Adds a value to an option.

: Sets the number of digits for an option.

: Sets the range for an option.

RegOption
AddOptionValue
SetOptionDigits
SetOptionRange

SetOptionRange

Sets the valid range for a numeric option.

Syntax

SetOptionRange(name: string, lowValue: number, highValue: number): void

Parameters

  • 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.

Return Value

This method does not return a value.

Description

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.

Example

// 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);

SetBackOffsetForCalculation

Sets the number of additional bars to include in calculations.

Syntax

SetBackOffsetForCalculation(offset: number): void

Parameters

  • offset - A number representing the additional bars to include in calculations.

Return Value

This method does not return a value.

Description

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.

Example

// Include 50 additional bars in calculations
this.api.SetBackOffsetForCalculation(50)

// For indicators that need a lot of historical data
this.api.SetBackOffsetForCalculation(200)

RegOption

Registers a new option parameter for an indicator or strategy.

Syntax

RegOption(name: string, type: TOptionType, optPtrOrValue?: string | number | boolean | TOptValue, inv = true, useInNameWithParams = true): void

Parameters

  • name - A string containing the name of the option.

  • 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.

Return Value

This method does not return a value.

Description

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.

Example



// 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')
}

type - The type of the option (from enum).

See for a complete list of option types.

TOptionType
TOptionType

SetOptionDigits

Sets the number of decimal digits for a numeric option.

Syntax

SetOptionDigits(name: string, digits: number): void

Parameters

  • 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.

Return Value

This method does not return a value.

Description

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.

Example

// 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);

AddOptionValue

Adds a possible value for an enum-type option.

Syntax

AddOptionValue(name: string, value: string): void

Parameters

  • 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.

Return Value

This method does not return a value.

Description

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.

Example

// 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");

Getting Information About Currency

This section provides functions to retrieve information about currency pairs. These functions allow you to get details such as bid, ask, and point values.


Available Functions


Click on any function name to view its detailed documentation.

: 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.

Ask
Bid
Digits
Point
Symbol

Ask

Returns the current ask price.

Syntax

Ask(): number

Return Value

Returns a number representing the current ask price.

Description

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).

Example

// 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
}

Digits

Returns the number of decimal places in the symbol's price.

Syntax

Digits(): number

Return Value

Returns a number representing the count of decimal places.

Description

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.

Example

// 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}`);

Bid

Returns the current bid price.

Syntax

Bid(): number

Return Value

Returns a number representing the current bid price.

Description

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).

Example

// 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
}

Point

Returns the minimum price change (point) value.

Syntax

Point(): number

Return Value

Returns a number representing the minimum price change value.

Description

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.

Example

// 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`);

Symbol

Returns the name of the current trading symbol.

Syntax

Symbol(): string

Return Value

Returns a string representing the current symbol name.

Description

The Symbol method returns the name of the currently selected trading symbol. This is the identifier used for the financial instrument being traded or analyzed.

Example

// 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
}

TimeCurrent

Returns the current time.

Syntax

TimeCurrent(): FTODate

Return Value

Description

Example

// 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}`);

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.

FTODate
FTODate
FTODate

Print

Outputs a message to the console with the current UTC time in testing.

Syntax

Print(message: string): void

Parameters

  • message - A string containing the message to be printed.

Return Value

This method does not return a value.

Description

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.

Example

// 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')
}

Timeframe

Returns the current chart timeframe.

Syntax

Timeframe(): number

Return Value

Returns a number representing the current timeframe in seconds.

Description

The Timeframe method returns the timeframe of the current chart. The timeframe is represented in seconds, with special values for longer periods.

Example

// 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
}

Types

This section provides documentation for various types used in indicators. These types define the structure and behavior of indicator options and chart objects.


Available Types


Click on the type name to view its detailed documentation.

: 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.

TOptionType
TObjectType
TOutputWindow
TPenStyle
TDrawStyle
ObjProp
TIndexBuffer
TVisibleBufferInfo
FTODate

TOptionType

An enumeration of option types used for indicator and strategy parameters.

Values

Value
Description

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

Example Usage

// 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");

TObjectType

An enumeration that defines the different types of chart objects that can be created in the trading platform.

Values

Value
Description

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

Example Usage

// 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
);

TOutputWindow

An enumeration that defines where an indicator should be displayed on the chart.

Values

Value
Description

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

Example Usage

// 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);

TPenStyle

An enumeration that defines the style of lines used in indicators and chart objects.

Values

Value
Description

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 (- . . - . .)

Example Usage

// 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);

Other

This section provides miscellaneous functions that do not fit into other categories. These functions include utility and time-related operations.


Available Functions


Click on any function name to view its detailed documentation.

: Prints a message to the console.

: Retrieves the current time.

: Retrieves the current timeframe.

Print
TimeCurrent
Timeframe
19MB
Moving Average.zip
archive
19MB
Moving Average.zip
archive
19MB
Moving Average.zip
archive
57MB
Empty indicator.zip
archive
19MB
Indicator Skeleton with one buffer and parameter.zip
archive
10KB
Rules.txt
19MB
Moving Average.zip
archive
10KB
Rules.txt
Picture #1
Picture #1
Picture #2
Picture #3
Picture #4
Picture #5
Picture #6
Picture #7
Picture #8
Picture #9
Picture #10
Picture #11
Picture #12
Picture #13
Picture #14
Picture #15
Picture #16
Picture #1
Picture #2
Picture #3
Picture #4
Picture #5
Picture #6
Picture #7
Picture #8
Picture #1
Picture #2
Picture #3
Picture #1
Picture #2
Picture #3