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

FTO Indicators Docs

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

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

Step 1: Install Cursor and set up the project

Get your tools ready — install Cursor IDE and prepare your project so you’re set to start building indicators.

First things first — you’ll need Cursor IDE.

If you don’t have it yet, go ahead and install it (full setup guide is right here).

Once Cursor is ready, set up your project.

If you’re new to the FTO Indicator API, don’t worry — that same guide also covers how to prep your environment so you’re good to go.

Tutorial: Create indicator with Cursor IDE

Introduction

Want to build your own indicator from scratch? You’re in the right place.

This tutorial walks you through creating a custom indicator using Cursor IDE.

Don’t worry if it sounds complicated — we’ll go step by step, with screenshots and examples. By the end, you’ll have your very own indicator running in FTO, powered by Cursor’s AI.

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 2: Apply Cursor Rules

Teach Cursor your custom rules so it knows how to handle indicators smarter and faster.

Cursor has a Rules feature — basically a way to teach the AI how you want it to behave when generating code.

Think of it as house rules for a guest: “shoes off, fridge is fair game, don’t touch the cat.”

By setting up rules that explain how indicators work in FTO, you’re giving Cursor the context it needs to create consistent, accurate code. No more random guesses — just well-informed suggestions.

To set global rules:

  1. Click the Settings icon (see Picture #1)

Picture 1
  1. From the Settings menu, click on Rules (see Picture #2).

This is where you’ll drop in the custom guidelines that will teach Cursor how to behave when working with your indicators.

Think of this as setting the ground rules before starting a board game — once everyone knows the rules, things run smoother (and there’s less arguing).\

  1. In the User Rules field (see Picture #3), paste in the contents of the file called Rules.txt.

That’s your playbook — the set of instructions that teaches Cursor how to “think” when working with indicators in FTO.

Pro tip: It’s like giving your AI a cheat sheet before the test. The more detail you put in here, the less Cursor will bother you later with questions.

10KB
Rules.txt
Open
Picture #2
Picture #3

Indicators: your trading super-vision

A quick introduction: what they do, why traders use them, and how they can help you spot market trends and signals.

If strategies are the brain and hands of trading, indicators are the eyes.They don’t open or close trades for you, but they help you see the market more clearly — drawing lines, showing averages, or highlighting trends. Think of them as your personal set of night-vision goggles: they light up what’s happening on the chart so you can decide what to do next (or let your strategy decide).In short:

  • Strategies = decision-makers (they trade)

  • Indicators = signal-givers (they show the picture)

With indicators, you can track momentum, spot entry points, or just make your charts look way cooler. Ready to add some trading super-vision? Let’s dive in!\

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

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


👨‍💻 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?

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

Upload indicator to FTO

This guide shows you how to take your freshly built indicator and bring it into Forex Tester Online.

f you’ve already run the npm run build command and everything went smoothly, you should now have a file called my-indicator-project.js sitting inside your dist folder. That’s the one we’re going to upload.

Open FTO, head over to your project, and in the Indicators tab hit Upload Indicator. Then just drag-and-drop your .js file into the upload area or select it manually (see Picture #1 and Picture #2).

Pro tip: Treat this file like your golden ticket — once it’s in FTO, you’ll finally get to see your indicator in action.

Picture #1
Picture #2

After uploading, your indicator will show up in the “My Indicators” dropdown menu (see Picture #3).

From here, just pick it, hit Apply, and watch it come alive on your chart.

Pro tip: If you don’t see it right away, double-check that you uploaded the .js file from your dist folder — that’s the only one FTO recognizes.

Picture #3

Accessing Chart Data Understand how to retrieve bar data, price arrays, and time series to power your custom logic.

  • Indicator Configuration Customize the behavior and appearance of indicators through parameters and configuration blocks.

  • External Parameters Use external inputs to make your indicators dynamic and easily customizable by users.

  • Getting Currency Information Retrieve metadata about the active instrument, such as symbol name, point size, and tick value.

  • Working with Dates and Time Use the FTODate structure to manage time-based logic and align calculations with bar timestamps.

  • Other Utilities Explore helper functions and additional features available to streamline development.

  • Quick Guide
    Indicator Structure
    Working with Buffers
    Setup and Installation
    Moving Average Tutorial

    Recommendations

    Some quick tips to get the most out of Cursor and your docs

    Remember the documentation we uploaded back in Step 3? Now it’s time to make Cursor use it like a pro.

    Here’s how:

    • Switch Cursor to Ask Mode (it’s the one for questions and answers).

    • In your request, type @ and choose Docs from the drop-down menu (see Picture #1).

    This tells Cursor, “Hey, use the official FTO indicator docs for this answer.”

    It’s like giving your AI a quick shot of espresso before it writes code — smarter, faster, and right on point.

    From that drop-down menu, choose FTO Indicator documentation — the same one we uploaded back in Step 3 (see Picture #2).

    This basically tells Cursor, “Hey, use the official playbook for this answer.” It’s like handing your AI the cheat sheet before an exam — fewer mistakes, better results.

    Cursor needs to know which file to use for your indicator. You can simply drag and drop it straight from the Explorer panel (on the left) into the chat window, or use the @ menu, scroll down to Files & Folders, and select it from the list (see Picture #3). It’s like pointing Cursor to the right canvas before asking it to paint — now it knows exactly where to put the code.

    Once you’ve selected the docs and the right file, Cursor has everything it needs to work its magic. From here, it’s just you, the AI, and some clean indicator-building fun. Time to let the code flow!

    Set up indicator

    This page shows you how to set up your environment for writing custom indicators in FTO. Think of it as laying out your pencils before sketching.

    This guide shows you how to prepare your environment so you can start writing your own custom indicator for FTO.

    To use the custom indicator API, you’ll first need an example to work from. Don’t worry, we’ve got you covered — you can either browse a few ready-made examples here, or just grab the suggested starter file below. Think of it as your “Hello World” for indicators.

    19MB
    Moving Average.zip
    archive
    Open

    Why start with an example?

    Jumping into custom indicators from scratch can feel like walking into a movie halfway through — you’ll miss the setup.

    That’s why we suggest starting with a ready-made example:

    • You see the basic structure in action

    • You avoid silly mistakes on the first steps

    • You can tweak and play instead of reinventing the wheel

    It’s faster, safer, and way more fun. Once you’re comfortable, you can always build your own indicator logic from scratch.

    Open and Set Things Up

    Open the example project in Cursor (or any IDE you like — but honestly, Cursor makes life easier).

    Next, click the little terminal icon (see Picture #1) — it’s that black box where all the behind-the-scenes magic happens.

    Now run:

    Once the dependencies are in place, it’s time to build your project.

    Pop open your terminal (still in that same black box of magic) and run:

    This will compile your indicator into a nice, ready-to-use .js file.

    Think of it as baking the dough you just mixed — after this step, you’ll actually have bread instead of just flour and water.

    If everything goes well, you should see a fresh build appear in your dist folder. That’s your indicator, ready for action!

    Sometimes Windows likes to be extra careful and won’t let you run scripts right away.

    If you see an error like this:

    Don’t panic — it’s just a security setting. You need to enter command Set-ExecutionPolicy RemoteSigned -Scope CurrentUser and then trynpm install and then npm run build command again.

    After building, you’ll see a fresh file named my-indicator-project.js appear in your dist folder. That’s your ready-to-use indicator, hot and shiny.

    Curious about the next step? Head over to the to learn how to bring your indicator into FTO and watch it in action on a chart.

    Upload Guide
    Picture #1
    Picture 1
    Picture 2
    Picture #3
    npm install
    npm run build
    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

    Set up indicator

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

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

    Open it with Cursor or any IDE of your choice — we suggest Cursor. Then, by clicking the icon shown in Picture #1, open the terminal and install the dependencies using the command npm install.

    Picture #1

    After installing the dependencies, 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.

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

    Tutorial: Open and upload indicator

    Ready to see your hard work come alive? This tutorial shows you how to open your indicator project and upload it into Forex Tester Online so you can test it in action.

    1. Download and Install Cursor

    First, grab the Cursor editor from cursor.com/downloads.

    Run the installer and, when it asks about options, tick all the checkboxes — trust us, you’ll want those extras (see Picture #1).

    Think of it like ordering pizza with all the toppings. The more boxes you check, the more powerful Cursor becomes.

    Picture #1

    2. Install Node.js and Get the Example Project

    Next up, you’ll need Node.js. If you don’t already have it, grab it here: .

    Run the installer and follow the steps — nothing fancy.

    Once Node.js is ready, download the indicator example archive we’ve provided below and extract it to a convenient spot. Desktop, Downloads — anywhere you’ll remember.

    Tip: Keep it somewhere easy to find — we’ll open it in Cursor soon.

    3. Open the Project in Cursor

    Once you’ve unzipped the archive, open the Moving Average folder.

    Inside, you’ll find another folder called custom_indicator — that’s where the action is.

    Open it with Cursor (see Picture #2 and #3).

    Tip: If you see those folders exactly as described, you’re in the right place. Cursor is now ready to load your project.

    4. Trust the Authors

    If a pop-up appears saying something like “Do you trust the authors?”, don’t panic. It’s just Cursor being cautious.

    Click “Yes, I trust the authors” — this simply lets the IDE know it’s safe to open the files.

    Tip: This is a normal step whenever you open a project for the first time. Cursor just wants to make sure you’re cool with the code you’re about to run.

    5. Open the Terminal and Install Dependencies

    Next, click the little terminal icon (see Picture #5) — it’s your gateway to the behind-the-scenes magic. Once it’s open, type this command and hit Enter:

    This will download and set up everything your indicator needs to run. Think of it as unpacking your toolbox before you start building.

    Tip: If your screen starts showing a bunch of green and white text, you’re doing great — Cursor is fetching all the right pieces.

    6. Start Writing and Build Your Indicator

    Once the dependencies are installed, it’s showtime — open the index.ts file and start coding your indicator. This is your playground: add logic, tweak parameters, and let your creativity flow. When you’re happy with your code, it’s time to turn it into something FTO can actually use.

    Open the terminal again and run:

    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.

    7. Find Your Finished Indicator

    Once the build is complete, you’ll see a shiny new file appear in your dist folder called my-indicator-project.js (or whatever name you gave it). This is your ready-to-use indicator — the one you’ll upload into Forex Tester Online.

    Tip: Don’t move or rename it yet; FTO expects it just like this when you upload.

    Upload this file to the FTO (Picture #6 and #7).

    Once you’ve uploaded the file, your indicator will appear in the “My Indicators” dropdown menu (see Picture #8).

    From here, it’s just a click away: pick your indicator, apply it, and watch it show up on your chart.

    That’s a wrap!

    You’ve gone from setting up Cursor to building, uploading, and running your own custom indicator in Forex Tester Online. Now you know how to prepare your environment, guide the AI, and see your work come to life on a chart. Keep experimenting, keep refining, and if you ever get stuck, teams like are there to help. Build more, debug less, and enjoy the process!

    Tutorial: Moving Average

    Learn how to create and run a simple Moving Average indicator in FTO — perfect for getting started with custom indicators.

    Ready to create your first custom indicator? Let’s start with a classic: the Moving Average.

    In this tutorial, we’ll walk step by step through building, coding, and running this popular indicator in FTO.

    Don’t worry — even if you’re new to indicators, this one’s a great warm-up. By the end, you’ll have a working Moving Average ready to test and tweak on your charts.

    To see how things work in practice, start by downloading the archive with the indicator example.

    Once it’s on your computer, open it in any IDE you like — but we highly recommend Cursor IDE for the smoothest experience.

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

    You can download the archive of Moving Average from here

    How Custom Indicators Are Built

    Every custom indicator in FTO starts with a simple but powerful idea: extend the IndicatorImplementation class from the forex-tester-custom-indicator-api library.

    This class gives you all the building blocks you need — methods, structures, and tools — so you can focus on your logic instead of reinventing the wheel.

    You can see a working version of this in action in the Moving Average example, which we described earlier in the section. It’s a great place to peek at the code and understand how everything fits together.

    Indicator Parameters

    Every custom indicator can have its own set of adjustable parameters — things like periods, colors, or calculation methods.

    These parameters are defined using the class, which handles different types (numbers, booleans, lists, etc.) and makes them easy to edit.

    When you add or edit your indicator in FTO, these parameters will appear in a user-friendly window where you (or your users) can tweak the settings to get just the right behavior.

    Think of it as the dashboard for your indicator — all the knobs and switches in one place.

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

    Registering Parameters

    Defining parameters is only half the story — to actually use them in your indicator, they need to be registered inside the function. This is where you “introduce” your parameters to FTO so they’ll show up in the indicator settings window.

    Without registration, your parameters will just sit quietly in the code, never making it to the user interface.

    Think of Init as the guest list at a party — if you don’t put your parameter on the list, it won’t get through the door.

    You can see the methods for registering parameters in the

    Where to Find Registration Methods

    All the methods you’ll need to register your parameters live in the section of the API.

    That’s the place where FTO tells you: “Here’s how to make your parameters visible in the UI and ready for users to tweak.”

    So whenever you’re setting up parameters in the Init function, just look back at those definitions — they’re your cheat sheet for getting everything hooked up the right way.

    Tip: Without registration, parameters stay hidden in the code. With registration, they become clickable, adjustable settings in the indicator window.

    Buffers setup

    are the backstage crew of your indicator.

    They’re used to store all those calculated values and then display them as lines, histograms, or other visuals right on your chart.

    Think of them as the buckets where your indicator keeps its data before painting it onto the screen.

    No buffers = no output. With buffers, your calculations finally become visible magic on the chart.

    Buffers need to be both declared as class fields and initialized inside the function.

    Connecting Buffers to the Chart

    Creating buffers is just the start — now you need to tell FTO how many buffers will actually show up on the chart, and then bind each one by its index (starting from 0).

    Each index must be unique, like seat numbers in a cinema.

    In this example, we only need one buffer, so the setup looks like this:

    • IndicatorBuffers(1) → tells FTO, “I’ve got one buffer to draw.”

    • SetIndexBuffer(0, this.SSMA) → assigns our buffer SSMA to slot #0 on the chart.

    Tip: If you ever add more buffers later (say, for multiple lines), just increase the number in IndicatorBuffers() and assign each one to its own index.

    Configuring Buffers

    Each registered buffer isn’t just a data bucket — you can also how it’s displayed on the chart.

    For example:

    • SetIndexLabel(0, "MA") → gives your buffer a friendly name (“MA”) so it shows up in the legend.

    • SetIndexStyle(...) → sets how it looks: here it’s a solid red line with thickness 1.

    • SetIndexDrawBegin(...) → defines the point on the chart where drawing should start (usually after enough data has been collected).

    Tip: Don’t be afraid to play with colors, line styles, and labels. It’s your indicator — make it not only useful but also easy to read at a glance.

    Other settings

    Always Recalculate (or Not?)

    Inside the function, you can use a handy setting called . By default, FTO calculates each buffer index only once to save resources. That’s efficient, but sometimes it means your indicator won’t be as accurate as you’d like.

    If your calculations aren’t too heavy for the processor, we recommend always enabling this option. It ensures your indicator updates on every tick, keeping results fresh and reliable.

    Tip: Think of it as “live mode” for your indicator — better accuracy in exchange for a tiny bit more CPU work.

    Give Your Indicator a Name

    Every indicator deserves an identity. With ., you set the name that will show up in the indicator settings window and the context menu.

    Think of it as the little nametag your indicator wears — something short, clear, and easy to recognize when you’re scrolling through the list.

    Tip: Keep it simple (like “Moving Average” or “OBV”) so you instantly know what it is at a glance.

    Choose Where to Draw

    By default, some indicators want to open their own little subwindow under the main chart. But for a Moving Average, it makes much more sense to see it directly on the main chart, hugging the price candles where it belongs.

    That’s where comes in — it tells FTO exactly where to draw your indicator. In this case, we point it to the main chart so the Moving Average is right there in the action.

    Tip: If you’re building other indicators (like oscillators), you can send them to their own window instead. For Moving Average, keep it on the main chart for the clearest view.

    Skip the Zeroes

    Sometimes indicators calculate values that are just 0 — and honestly, those don’t tell us much. With , you can tell FTO not to draw these points at all.

    That way, the chart stays clean, without random flat lines cluttering your view.

    Tip: Think of it like editing out background noise from a song — you only keep the meaningful parts, so the final output looks and sounds better.

    Indicator's main function

    At the heart of every custom indicator is the function. This is where the real action happens — all the math, logic, and updates take place here on each tick.

    Changing parameters

    Sometimes you want your indicator to react when the user changes its settings — that’s where the method comes in.

    This method lets you add custom logic that runs right after parameters are updated. For example, in the Moving Average indicator it’s used to handle the horizontal shift, so the line moves correctly on the chart when the shift value changes.

    OnParamsChange is especially handy if your indicator uses custom objects or needs to redraw elements whenever a parameter is tweaked.

    Tip: Think of it as your indicator’s “refresh button” — it makes sure the chart always reflects the latest settings the user has chosen.

    Wrapping Up

    And there you have it — you’ve just built and understood your first custom indicator: the Moving Average.

    From setting up parameters and buffers to configuring styles and handling recalculations, you now know the essential steps behind making an indicator come alive in FTO.

    This is a solid foundation — once you’ve mastered the Moving Average, you’re ready to experiment, tweak, and create even more powerful custom tools for your trading.

    Download indicator examples

    These are indicator examples you can download

    3KB
    Moving Average.zip
    archive
    Open
    4KB
    Indicator Skeleton with one buffer and parameter.zip
    archive
    Open
    3KB
    Empty indicator.zip
    archive
    Open

    Download indicator examples

    Not sure where to start? No worries — we’ve prepared a few ready-made indicator examples for you. Think of them as training wheels: you can try them out are indicator examples you can download

    Below you’ll find three example files — grab them, test them in FTO, and use them as a base for your custom indicators.

    19MB
    Moving Average.zip
    archive
    Open
    19MB
    Indicator Skeleton with one buffer and parameter.zip
    archive
    Open
    23KB
    Empty indicator.zip
    archive
    Open
    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
    upload guide
    nodejs.org
    19MB
    Moving Average.zip
    archive
    Open
    4xdev.com
    Picture #2
    Picture #3
    Picture #4
    Picture #5
    Picture #6
    Picture #7
    Picture #8
    19MB
    Moving Average.zip
    archive
    Open
    Setup and Installation
    TOptValue
    Init
    Init
    external parameters definition
    external parameters definition
    Buffers
    Init
    configure
    Init
    RecalculateMeAlways
    IndicatorShortName
    SetOutputWindow
    SetEmptyValue
    Calculate
    OnParamsChange
    npm install
    npm run build
    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
    import { IndicatorImplementation } from "forex-tester-custom-indicator-api";
    
    export default class MovingAverage extends IndicatorImplementation {
      // indicator logic
    }
    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...
    }
    public SSMA!: TIndexBuffer
    private SMA!: TIndexBuffer
    this.SMA = this.api.CreateIndexBuffer();
    this.SSMA = this.api.CreateIndexBuffer();
    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);
    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())
    }
    public OnParamsChange(): void {
        this.api.SetBufferShift(0, this.Shift.value)
    }

    Step 4: Getting familiar with Cursor

    Get to know the Cursor AI panel — the control room for your indicator magic. We’ll guide you through its modes, buttons, and little tricks to speed up your workflow (and keep things fun).

    To open the Cursor AI panel, press Ctrl+L or click the icon in the top right corner of the Cursor IDE (see Picture #1).

    Picture 1

    This will open the chat interface — your command center for talking to the AI (yes, it listens — and it’s surprisingly helpful). In Cursor version 1.3.9, there are three available modes: Agent, Ask, and Background (see Picture #2).

    Picture 2

    Choosing Your AI Mode

    Each one plays a different role in your coding adventure.

    Agent Mode

    Think of it as your AI pair programmer. It sees your project, suggests edits, and you can thumbs-up or thumbs-down its ideas like a benevolent overlord.

    Ask Mode

    Your Q&A corner. Need to know how a moving average works? Why your code screams in red? Ask away.

    Background Mode

    This one works behind the scenes. Cursor quietly watches your code and offers suggestions only when relevant. It won’t interrupt you — unless it has something genuinely useful to say. The real magic? You can feed Cursor extra context from your files or docs — like giving it caffeine for smarter replies.

    For now, select Agent Mode.

    Choosing the Right Brain for the Job

    Next to the mode selector, you’ll also see an AI model dropdown. Just leave it on Auto for now — let Cursor pick the right brain for the job (see Picture #3).

    Quick warning:

    Skip Gemini. Cursor and Gemini aren’t exactly BFFs — context issues, buggy behavior, you name it. If you do want to pick a model manually, stick to Claude or OpenAI. Cursor was trained to jam with them, and the experience is smooth.

    Once you’ve taken this quick tour, you’re all set to dive into building your first custom indicator. Next step — sleeves up (real or metaphorical) and let’s create something awesome for FTO.\

    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

    Main methods of each indicator are Init and Calculate, Init is called once when the indicator is created, and Calculate is called on each tick. Other methods are optional and can be used to add additional logic to the indicator.

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

    • OnParamsChange

    Step 5: Start building

    Alright, the warm-up is done — now it’s time to get your hands dirty (figuratively).

    This is where we actually start writing code for your custom indicator.

    Before we dive into coding, make sure your setup is ready to roll. You’ll need access to the FTO Indicator API to make things work smoothly.

    Not there yet? No problem — check out the setup guide first, get your environment prepped, and then come back here. It’s a quick read and will save you a ton of head-scratching later.

    For this example, we’ll let Cursor do some of the heavy lifting: we’ll ask it to create the On Balance Volume (OBV) indicator for us. We’ll start simple — with a completely empty file — so you can see the process from scratch. Later, when you’re more comfortable, you can speed things up by using some of our pre-built indicator foundations (you’ll find them in this section).

    Think of this as baking your first cake from flour and sugar — once you’ve got the hang of it, you can use ready-made mixes to save time.

    When we asked Cursor to create the OBV indicator, we didn’t just say “do it.” We gave it some context — included the FTO Indicator documentation and the Rules we set up earlier. In the screenshot (Picture #1), you can see exactly which parts of the documentation Cursor decided to use. It’s like watching your AI buddy flip through the manual before giving you the best answer.

    In the result, we got code below

    Time for a Quick Fix

    The current logic looks solid so far, but there’s a catch: it’s locked to using the Close price only. That’s a bit limiting, right? What if someone wants to use the High, Low, or Open price instead?

    No worries — let’s get Cursor to step up its game. We’ll ask it to tweak the code so users can pick their preferred price type. (See Picture #2 to follow along.)

    Cursor’s Updated Code

    After we asked Cursor to improve the OBV indicator, here’s what it came up with in its second response.

    This version lets users choose the price type instead of being stuck with the Close price — nice upgrade! (See below.)

    A Little Upgrade Goes a Long Way

    With that new parameter and internal method added, Cursor gives us a neat bonus: a dropdown menu for choosing the price type.

    No more hardcoded Close price — now you can pick what you need right from the list. (See Picture #3 — that’s your shiny new option selector!)

    Wrapping Up

    And that’s it — with just two simple requests, Cursor delivered a fully working OBV indicator.

    All it took was a proper setup, some clear , and a bit of documentation magic to give it the right context.

    Not bad for a few clicks, right? Less typing, more building.

    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 run build command in the terminal, a file named my-indicator-project.js (indicator's file name) will appear in the dist folder. Upload this file to FTO (see Picture #1 and #2).

    Picture #1
    Picture #2

    From there, your indicator should appear in "My Indicators" dropdown menu (Picture #3).

    Picture #3

    Tutorial: Open and upload indicator

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

    Download and install the Cursor editor: https://www.cursor.com/downloads, while installing make sure to check all the checkmarks (Picture #1)

    Picture #1

    Then, you have to install Node.js if you don't already have it. Use the link below. https://nodejs.org/en

    After installing node.js, download the archive with the indicator example below and extract it to a convenient location.

    19MB
    Moving Average.zip
    archive
    Open

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

    Picture #2
    Picture #3

    If you get a pop-up like this, click "Yes, I trust the authors"

    Picture #4

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

    Done
    OnHide
    OnShow
    Rules
    Picture 1
    Picture 2
    Picture 3
    Picture #5
    Picture #6
    Picture #7
    Picture #8
    Picture 3
    import { IndicatorImplementation, TDrawStyle, TPenStyle, TOutputWindow, TIndexBuffer } from "forex-tester-custom-indicator-api";
    
    export default class OBVIndicator extends IndicatorImplementation {
        // Declare the buffer as a class property
        public obvBuffer!: TIndexBuffer;
    
        Init(): void {
            this.api.RecalculateMeAlways();
            
            // Set indicator name
            this.api.IndicatorShortName("On Balance Volume (OBV)");
            
            // Configure to display in separate window since OBV is an oscillator
            this.api.SetOutputWindow(TOutputWindow.SEPARATE_WINDOW);
            
            // Register the number of buffers we'll use
            this.api.IndicatorBuffers(1);
            
            // Create and initialize the OBV buffer
            this.obvBuffer = this.api.CreateIndexBuffer();
            
            // Bind buffer to index 0
            this.api.SetIndexBuffer(0, this.obvBuffer);
            
            // Configure buffer appearance
            this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#0000FF"); // Blue line
            this.api.SetIndexLabel(0, "OBV");
        }
    
        Calculate(index: number): void {
            // If this is the first bar (rightmost/newest), initialize OBV
            if (index === this.api.Bars() - 1) {
                this.obvBuffer.setValue(index, this.api.Volume(index));
                return;
            }
    
            // Get current and previous close prices
            const currentClose = this.api.Close(index);
            const previousClose = this.api.Close(index + 1);
            
            // Get current volume
            const volume = this.api.Volume(index);
            
            // Get previous OBV value
            const previousOBV = this.obvBuffer.getValue(index + 1);
            
            let currentOBV;
            
            // Calculate OBV based on price movement
            if (currentClose > previousClose) {
                // If price increased, add volume
                currentOBV = previousOBV + volume;
            } else if (currentClose < previousClose) {
                // If price decreased, subtract volume
                currentOBV = previousOBV - volume;
            } else {
                // If price unchanged, OBV remains the same
                currentOBV = previousOBV;
            }
            
            // Set the calculated OBV value
            this.obvBuffer.setValue(index, currentOBV);
        }
    }
    import { 
        IndicatorImplementation, 
        TDrawStyle, 
        TPenStyle, 
        TOutputWindow, 
        TIndexBuffer,
        TOptionType,
        TOptValue_number
    } from "forex-tester-custom-indicator-api";
    
    export default class OBVIndicator extends IndicatorImplementation {
        // Declare the buffer as a class property
        public obvBuffer!: TIndexBuffer;
        
        // Declare price type parameter
        public priceType!: TOptValue_number;
    
        Init(): void {
            this.api.RecalculateMeAlways();
            
            // Set indicator name
            this.api.IndicatorShortName("On Balance Volume (OBV)");
            
            // Configure to display in separate window since OBV is an oscillator
            this.api.SetOutputWindow(TOutputWindow.SEPARATE_WINDOW);
            
            // Initialize price type parameter
            this.priceType = this.api.createTOptValue_number(0); // Default to Close price
            
            // Register price type parameter as an enum
            this.api.RegOption(
                "Price Type",
                TOptionType.ENUM_TYPE,
                this.priceType
            );
            
            // Add price type options
            this.api.AddOptionValue("Price Type", "Close");
            this.api.AddOptionValue("Price Type", "Open");
            this.api.AddOptionValue("Price Type", "High");
            this.api.AddOptionValue("Price Type", "Low");
            this.api.AddOptionValue("Price Type", "Median ((H+L)/2)");
            this.api.AddOptionValue("Price Type", "Typical ((H+L+C)/3)");
            
            // Register the number of buffers we'll use
            this.api.IndicatorBuffers(1);
            
            // Create and initialize the OBV buffer
            this.obvBuffer = this.api.CreateIndexBuffer();
            
            // Bind buffer to index 0
            this.api.SetIndexBuffer(0, this.obvBuffer);
            
            // Configure buffer appearance
            this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#0000FF"); // Blue line
            this.api.SetIndexLabel(0, "OBV");
        }
    
        private getPrice(index: number): number {
            switch (this.priceType.value) {
                case 0: // Close
                    return this.api.Close(index);
                case 1: // Open
                    return this.api.Open(index);
                case 2: // High
                    return this.api.High(index);
                case 3: // Low
                    return this.api.Low(index);
                case 4: // Median
                    return (this.api.High(index) + this.api.Low(index)) / 2;
                case 5: // Typical
                    return (this.api.High(index) + this.api.Low(index) + this.api.Close(index)) / 3;
                default:
                    return this.api.Close(index); // Fallback to Close
            }
        }
    
        Calculate(index: number): void {
            // If this is the first bar (rightmost/newest), initialize OBV
            if (index === this.api.Bars() - 1) {
                this.obvBuffer.setValue(index, this.api.Volume(index));
                return;
            }
    
            // Get current and previous prices using selected price type
            const currentPrice = this.getPrice(index);
            const previousPrice = this.getPrice(index + 1);
            
            // Get current volume
            const volume = this.api.Volume(index);
            
            // Get previous OBV value
            const previousOBV = this.obvBuffer.getValue(index + 1);
            
            let currentOBV;
            
            // Calculate OBV based on price movement
            if (currentPrice > previousPrice) {
                // If price increased, add volume
                currentOBV = previousOBV + volume;
            } else if (currentPrice < previousPrice) {
                // If price decreased, subtract volume
                currentOBV = previousOBV - volume;
            } else {
                // If price unchanged, OBV remains the same
                currentOBV = previousOBV;
            }
            
            // Set the calculated OBV value
            this.obvBuffer.setValue(index, currentOBV);
        }
    }
    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

    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

    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.

    Step 2: Apply Cursor Rules

    The feature in Cursor IDE allows users to define custom guidelines or behaviors that the AI should follow when generating code. By setting up rules that describe how indicators work in FTO, you can effectively teach Cursor the context it needs to produce accurate and consistent indicators.

    To set up global rules for Cursor, click the setting icon (Picture #1)

    From here, click the Rules setting (Picture #2)\

    In the User Rules field (Picture #3), download and paste contents of the file below called Rules.txt

    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.

    To become more familiar with how to use this added documentation in your requests to Cursor, go to the section below.

    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

    Before we begin writing the indicator, it is expected that you are familiar with how to set up the environment to access the FTO Indicator API. If not, please read guide first before continuing.

    For this example, we will ask Cursor to implement the On Balance Volume (OBV) indicator for us. In this guide, we will start with an empty file, but for future indicator implementations, you can use some of our indicator foundations provided in .

    In the request to create the OBV indicator for us, I included the FTO documentation for and added the discussed earlier. In the screenshot, you can see the sections of the documentation it decided to use (Picture #11).

    In the result, we got code below

    The current logic seems correct, but it's using only the Close price, and there is currently no way for the user to specify their own price type. Let's ask it to fix that (Picture #12).

    The code that Cursor wrote in his second response is below

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

    So in the end, we got a proper indicator with just two simple requests by setting up Cursor properly and providing it with and documentation for context.

    Recommendations

    For Cursor to use the documentation that we provided in we need to do the following:

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

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

    And provide add a file in which you want to create the indicator, you can do it by drag and dropping it from explorer window on the left onto the chat window or finding it in the @ drop-down menu under Files & folders (Picture #16)

    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


    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


    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.

    Set up Cursor Rules

    The Rules feature in Cursor IDE allows users to define custom guidelines or behaviors that the AI should follow when generating code. By setting up rules that describe how indicators work in FTO, you can effectively teach Cursor the context it needs to produce accurate and consistent indicators.

    To set up global rules for Cursor, click the setting icon (Picture #1)

    Picture #1

    From here, click the Rules setting (Picture #2)

    Picture #2

    In the User Rules field (Picture #3), download and paste contents of the file below called Rules.txt

    10KB
    Rules.txt
    Open
    Picture #3

    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 implement custom logic that should happen when parameters are modified.

    Important: This method is NOT used for the actual parameter values to change — that happens internally. This method is only for custom logic that needs to be executed when parameters are changed.


    Syntax


    When and Why to Use It

    This method is called after the user updates the settings in the indicator panel, but before the indicator is recalculated.

    Use OnParamsChange() When You Need To:

    • Recalculate internal values based on new parameter values

    • Adjust or re-create custom chart objects (lines, labels, etc.)

    • Update dependencies between parameters

    • Perform validation or parameter-based setup

    Don't Use OnParamsChange() If:

    • You only need basic parameter changes (values update automatically)

    • You don't have any custom logic dependent on parameter changes

    • Your indicator works fine with just and


    What CAN Be Done in OnParamsChange

    Buffer and Display Updates

    • Modify buffer properties (styles, labels, visibility)

    • Update buffer configuration based on parameter changes

    • Reconfigure drawing styles and colors

    • Adjust buffer drawing ranges with

    Chart Object Management

    • Create, modify, or remove custom chart objects

    • Update object positions based on parameter changes

    • Reconfigure object properties (colors, styles, positions)

    • Manage dynamic visual elements

    Internal State Management

    • Reset calculation counters or accumulators

    • Update lookup tables or cached calculations

    • Reconfigure internal algorithms based on parameters

    • Initialize parameter-dependent variables


    What CANNOT Be Done in OnParamsChange

    ❌ Forbidden Operations

    • Heavy calculations or complex mathematical operations

    • Per-bar data processing (this should be in )

    • Modifying the actual parameter values (handled internally)

    • Creating new parameters (must be done in )

    ❌ Wrong Approach

    ✅ Correct Approach


    Practical Examples

    Example 1: Dynamic Buffer Styling

    Example 2: Parameter Validation and Dependencies

    Example 3: Chart Object Management


    Best Practices

    ✅ Do This

    • Keep it lightweight - only essential parameter-dependent logic

    • Use it for setup/configuration that depends on parameters

    • Reset internal state when parameters change

    • Update visual properties based on parameter values

    ❌ Avoid This

    • Heavy computational work (belongs in Calculate())

    • Complex loops or data processing

    • Modifying parameter values

    • Creating new parameters or buffers (belongs in Init()


    When NOT to Implement OnParamsChange()

    You can skip implementing this method if:

    • Your indicator only uses basic parameters for calculations

    • No custom logic is needed when parameters change

    • All parameter-dependent behavior happens in Calculate()

    • You don't have dynamic visual elements or chart objects


    Key Rules Summary

    1. OnParamsChange() is optional - only implement if you need custom logic

    2. Keep it lightweight - no heavy calculations or data processing

    3. Parameter values update automatically - this method is for additional logic only

    4. Use it for configuration and setup that depends on parameter values


    Pro Tip

    Think of OnParamsChange() as your "parameter change reaction" method. It's the perfect place to update anything that depends on parameter values but doesn't belong in the per-bar Calculate() method. Keep it fast and focused on configuration rather than calculation.

    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.

    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.


    Example Explained


    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.


    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.

    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


    What MUST Be Done in Init

    This method is like a constructor for your indicator. Here's what must happen inside:

    1. Create and Register Parameters

    All user-configurable parameters must be:

    • Declared as class-level fields using the ! syntax

    • Created in Init() using appropriate factory methods

    • Registered using to appear in the UI

    2. Create and Configure Buffers

    Buffers determine visualization and must be properly set up:

    3. Set Indicator Properties

    • Name: this.api.IndicatorShortName("Your Indicator Name")

    • Output Window: this.api.SetOutputWindow(TOutputWindow.CHART_WINDOW) or TOutputWindow.SEPARATE_WINDOW


    What CAN Be Done in Init

    Core Setup Methods

    • this.api.IndicatorShortName(name) - Set indicator display name

    • this.api.IndicatorBuffers(count) - Register number of buffers

    • this.api.CreateIndexBuffer() - Create buffer instances

    Buffer Configuration Methods

    • this.api.SetIndexLabel(index, label) - Set buffer legend label

    • this.api.SetIndexStyle(index, drawStyle, penStyle, width, color) - Set visual style

    • this.api.SetIndexDrawBegin(index, startBar) - Set drawing start point

    Parameter Configuration Methods

    • this.api.SetOptionRange(name, min, max) - Set parameter limits

    • this.api.SetOptionDigits(name, digits) - Set decimal places

    • this.api.AddOptionValue(name, value) - Add dropdown options

    Recommended Methods

    • this.api.RecalculateMeAlways() - Improves calculation accuracy but could slow down the performance of the indicator

    • this.api.SetOutputWindow(window) - Configure chart vs oscillator window

    Advanced Configuration Methods

    • this.api.AddLevel(value) - Add horizontal reference lines

    • this.api.SetLevelValue(index, value) - Set level values

    • this.api.SetFixedMinMaxValues(min, max) - Set fixed scale range


    What CANNOT Be Done in Init

    ❌ Forbidden Operations

    • Heavy calculations or complex mathematical operations

    • Per-bar data processing (use Calculate() instead)

    • Accessing bar data like this.api.Close(index), this.api.High(index), etc.

    ❌ Wrong Approach

    ✅ Correct Approach


    Complete Example


    Key Rules Summary

    1. Init() is for setup only - no calculations or data processing

    2. All parameters must be created AND registered in Init()

    3. All buffers must be declared, created, and configured in Init()

    4. Use factory methods for parameter creation (, etc.)


    Pro Tip

    Remember: Init() runs once when the indicator loads. It defines the structure, settings, and appearance. All dynamic calculations and data processing must happen in which runs once per bar.

    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


    Example

    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

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

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

    TOptValue

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

    • TOptValue_str

    • TOptValue_number

    • TOptValue_bool

    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


    Example

    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

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

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

    • Access the value with this.MyFlag.value.

    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.

    TOptValue_LineStyle

    What Is It?

    TOptValue_LineStyle is a class used to define line style parameters for custom indicators. It allows users to configure line appearance (visibility, color, style, width) through the indicator settings panel.

    Use the createTOptValue_LineStyle() method from the api object inside Init() method to create an instance.


    When to Use

    Use TOptValue_LineStyle when you want to let the user configure line appearance for:

    • Support/resistance levels

    • Trend lines

    • Other visual elements on charts


    Syntax


    Example

    In this example:

    • LineStyle allows the user to configure line appearance

    • Inside Calculate(), a horizontal line is created with the configured style

    • The line is positioned at the current bar's close price


    Notes

    • Don't forget to register line style parameters using inside the method.

    • Use TOptionType.LINE when registering TOptValue_LineStyle parameters.

    • Access properties with this.MyLineStyle.isVisible, this.MyLineStyle.color, this.MyLineStyle.style

    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


    Key Rules

    • Only -based parameters are configurable

    • You must register each parameter inside the method using

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

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


    Notes

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

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

    TOptValue_LineStyle
    TOptValue_DateTime
    TOptValue_DateOnly
    TOptValue_TimeOnly
    this
    Rules
    10KB
    Rules.txt
    Open
    Recommendations
    this
    this section
    context
    Rules
    Rules
    Step 3
    Step 3
    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

    Reset internal state that depends on parameters

  • Apply dynamic styling or configuration changes

  • Changing buffer count with IndicatorBuffers() (must be in Init())

  • Loops through large datasets or historical data processing

  • Validate parameter combinations if needed

    )

    Cannot create new parameters or buffers - only modify existing ones

  • Runs before recalculation - perfect for resetting internal state

  • Great for dynamic visuals - updating styles, objects, and display properties

  • Init()
    Calculate()
    SetIndexDrawBegin()
    Calculate()
    Init()

    The method runs once per tick (price change) and calculates the indicator value only for the specified bar.

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

    this.api.SetIndexBuffer(index, buffer) - Bind buffers to indexes
  • this.api.RegOption(name, type, parameter) - Register parameters

  • this.api.SetIndexVisibility(index, visible) - Control buffer visibility

    Setting buffer values using buffer.setValue(index, value)

  • Time-based calculations or market data analysis

  • Loops through historical data

  • Register buffer count first with IndicatorBuffers() before configuring buffers

  • Try including RecalculateMeAlways() for better accuracy

  • Use Calculate() for all data processing and calculations

  • this.api.RegOption()
    createTOptValue_number
    Calculate()
    this.RegOption
    Init
    this.RegOption
    Init
    Calculate
    OnShow
    ,
    this.MyLineStyle.width
    .
    this.RegOption
    Init
    TOptValue
    Init
    this.api.RegOption
    ApplyToPrice defines which price (close, open, high, low) the MA should use.
  • VShift applies a vertical offset to the line.

  • this.RegOption
    Init
    import { IndicatorImplementation, TDrawStyle, TPenStyle, TOutputWindow, TIndexBuffer } from "forex-tester-custom-indicator-api";
    
    export default class OBVIndicator extends IndicatorImplementation {
        // Declare the buffer as a class property
        public obvBuffer!: TIndexBuffer;
    
        Init(): void {
            this.api.RecalculateMeAlways();
            
            // Set indicator name
            this.api.IndicatorShortName("On Balance Volume (OBV)");
            
            // Configure to display in separate window since OBV is an oscillator
            this.api.SetOutputWindow(TOutputWindow.SEPARATE_WINDOW);
            
            // Register the number of buffers we'll use
            this.api.IndicatorBuffers(1);
            
            // Create and initialize the OBV buffer
            this.obvBuffer = this.api.CreateIndexBuffer();
            
            // Bind buffer to index 0
            this.api.SetIndexBuffer(0, this.obvBuffer);
            
            // Configure buffer appearance
            this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#0000FF"); // Blue line
            this.api.SetIndexLabel(0, "OBV");
        }
    
        Calculate(index: number): void {
            // If this is the first bar (rightmost/newest), initialize OBV
            if (index === this.api.Bars() - 1) {
                this.obvBuffer.setValue(index, this.api.Volume(index));
                return;
            }
    
            // Get current and previous close prices
            const currentClose = this.api.Close(index);
            const previousClose = this.api.Close(index + 1);
            
            // Get current volume
            const volume = this.api.Volume(index);
            
            // Get previous OBV value
            const previousOBV = this.obvBuffer.getValue(index + 1);
            
            let currentOBV;
            
            // Calculate OBV based on price movement
            if (currentClose > previousClose) {
                // If price increased, add volume
                currentOBV = previousOBV + volume;
            } else if (currentClose < previousClose) {
                // If price decreased, subtract volume
                currentOBV = previousOBV - volume;
            } else {
                // If price unchanged, OBV remains the same
                currentOBV = previousOBV;
            }
            
            // Set the calculated OBV value
            this.obvBuffer.setValue(index, currentOBV);
        }
    }
    import { 
        IndicatorImplementation, 
        TDrawStyle, 
        TPenStyle, 
        TOutputWindow, 
        TIndexBuffer,
        TOptionType,
        TOptValue_number
    } from "forex-tester-custom-indicator-api";
    
    export default class OBVIndicator extends IndicatorImplementation {
        // Declare the buffer as a class property
        public obvBuffer!: TIndexBuffer;
        
        // Declare price type parameter
        public priceType!: TOptValue_number;
    
        Init(): void {
            this.api.RecalculateMeAlways();
            
            // Set indicator name
            this.api.IndicatorShortName("On Balance Volume (OBV)");
            
            // Configure to display in separate window since OBV is an oscillator
            this.api.SetOutputWindow(TOutputWindow.SEPARATE_WINDOW);
            
            // Initialize price type parameter
            this.priceType = this.api.createTOptValue_number(0); // Default to Close price
            
            // Register price type parameter as an enum
            this.api.RegOption(
                "Price Type",
                TOptionType.ENUM_TYPE,
                this.priceType
            );
            
            // Add price type options
            this.api.AddOptionValue("Price Type", "Close");
            this.api.AddOptionValue("Price Type", "Open");
            this.api.AddOptionValue("Price Type", "High");
            this.api.AddOptionValue("Price Type", "Low");
            this.api.AddOptionValue("Price Type", "Median ((H+L)/2)");
            this.api.AddOptionValue("Price Type", "Typical ((H+L+C)/3)");
            
            // Register the number of buffers we'll use
            this.api.IndicatorBuffers(1);
            
            // Create and initialize the OBV buffer
            this.obvBuffer = this.api.CreateIndexBuffer();
            
            // Bind buffer to index 0
            this.api.SetIndexBuffer(0, this.obvBuffer);
            
            // Configure buffer appearance
            this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#0000FF"); // Blue line
            this.api.SetIndexLabel(0, "OBV");
        }
    
        private getPrice(index: number): number {
            switch (this.priceType.value) {
                case 0: // Close
                    return this.api.Close(index);
                case 1: // Open
                    return this.api.Open(index);
                case 2: // High
                    return this.api.High(index);
                case 3: // Low
                    return this.api.Low(index);
                case 4: // Median
                    return (this.api.High(index) + this.api.Low(index)) / 2;
                case 5: // Typical
                    return (this.api.High(index) + this.api.Low(index) + this.api.Close(index)) / 3;
                default:
                    return this.api.Close(index); // Fallback to Close
            }
        }
    
        Calculate(index: number): void {
            // If this is the first bar (rightmost/newest), initialize OBV
            if (index === this.api.Bars() - 1) {
                this.obvBuffer.setValue(index, this.api.Volume(index));
                return;
            }
    
            // Get current and previous prices using selected price type
            const currentPrice = this.getPrice(index);
            const previousPrice = this.getPrice(index + 1);
            
            // Get current volume
            const volume = this.api.Volume(index);
            
            // Get previous OBV value
            const previousOBV = this.obvBuffer.getValue(index + 1);
            
            let currentOBV;
            
            // Calculate OBV based on price movement
            if (currentPrice > previousPrice) {
                // If price increased, add volume
                currentOBV = previousOBV + volume;
            } else if (currentPrice < previousPrice) {
                // If price decreased, subtract volume
                currentOBV = previousOBV - volume;
            } else {
                // If price unchanged, OBV remains the same
                currentOBV = previousOBV;
            }
            
            // Set the calculated OBV value
            this.obvBuffer.setValue(index, currentOBV);
        }
    }
    public OnHide(): void {
        // logic after hiding the indicator
    }
    public OnHide(): void {
        // Custom method to remove a label created when the indicator was shown
        this.DeleteObject("InfoLabel")
    }
    public OnParamsChange(): void {
        // custom logic after parameter change
    }
    public OnParamsChange(): void {
        // DON'T DO THIS - heavy calculations
        for (let i = 0; i < 1000; i++) {
            let value = this.api.Close(i) * this.period.value; // ❌ Wrong!
            this.mainBuffer.setValue(i, value); // ❌ Wrong!
        }
    
        // DON'T DO THIS - creating new parameters
        this.newParam = this.api.createTOptValue_number(10); // ❌ Wrong!
        this.api.RegOption("New Param", TOptionType.INTEGER, this.newParam); // ❌ Wrong!
    }
    public OnParamsChange(): void {
        // ✅ Correct - lightweight parameter-dependent logic
        this.internalMultiplier = this.period.value * 2;
    
        // ✅ Correct - update buffer styling based on parameters
        if (this.showLine.value) {
            this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, this.lineColor.value);
        } else {
            this.api.SetIndexVisibility(0, false);
        }
    
        // ✅ Correct - reset internal state
        this.calculationCounter = 0;
    }
    export default class CustomIndicator extends IndicatorImplementation {
      public period!: TOptValue_number;
      public lineColor!: TOptValue_str;
      public showLine!: TOptValue_bool;
      public mainBuffer!: TIndexBuffer;
    
      public OnParamsChange(): void {
        // Update line color when user changes it
        this.api.SetIndexStyle(
          0,
          TDrawStyle.LINE,
          TPenStyle.SOLID,
          1,
          this.lineColor.value
        );
    
        // Show/hide line based on boolean parameter
        this.api.SetIndexVisibility(0, this.showLine.value);
    
        // Adjust drawing start based on period
        this.api.SetIndexDrawBegin(0, this.period.value);
      }
    }
    export default class AdvancedIndicator extends IndicatorImplementation {
      public fastPeriod!: TOptValue_number;
      public slowPeriod!: TOptValue_number;
      public validConfiguration: boolean = true;
    
      public OnParamsChange(): void {
        // Validate parameter relationship
        if (this.fastPeriod.value >= this.slowPeriod.value) {
          this.validConfiguration = false;
          // Could log warning or set visual indicator
        } else {
          this.validConfiguration = true;
        }
    
        // Update internal calculation variables
        this.periodDifference = this.slowPeriod.value - this.fastPeriod.value;
      }
    
      private periodDifference: number = 0;
    }
    export default class LevelIndicator extends IndicatorImplementation {
      public levelValue!: TOptValue_number;
      public showLevel!: TOptValue_bool;
    
      public OnParamsChange(): void {
        // Remove existing level line
        this.api.RemoveAllObjects();
    
        // Create new level line if enabled
        if (this.showLevel.value) {
          // Create horizontal line at new level value
          this.CreateLevelLine(this.levelValue.value);
        }
      }
    
      private CreateLevelLine(value: number): void {
        // Custom method to create chart objects
        // Implementation depends on your specific needs
      }
    }
    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")
    }
    public Calculate(index: number): void {
        // Skip if not enough bars to calculate moving average
        if (index + this.Period.value >= this.api.Bars()) {
            return
        }
    
        // Get the calculated value of the Moving Average
        const calculatedSMA = this.api.GetMA(
            index,
            0,                              // Shift (usually 0)
            this.Period.value,              // Period for MA
            this.MAtype.value,              // Type of MA (SMA, EMA, etc.)
            this.ApplyToPrice.value,        // Price type (Close, Open, etc.)
            this.SMA.getValue(index + 1)    // Previous value for smoothing (optional)
        )
    
        // Save the value to the SMA buffer
        this.SMA.setValue(index, calculatedSMA)
    
        // Save a shifted version to another buffer
        this.SSMA.setValue(index, calculatedSMA + this.VShift.value * this.api.Point())
    }
    this.SSMA.setValue(index, calculatedSMA + this.VShift.value * this.api.Point())
    public Init(): void {
        // initialization logic here
    }
    // Declare as class-level field
    public period!: TOptValue_number;
    public showLine!: TOptValue_bool;
    public mode!: TOptValue_str;
    
    public Init(): void {
        // Create parameters with factory methods
        this.period = this.api.createTOptValue_number(14);
        this.showLine = this.api.createTOptValue_bool(true);
        this.mode = this.api.createTOptValue_str("Simple");
    
        // Register parameters (required for UI visibility)
        this.api.RegOption("Period", TOptionType.INTEGER, this.period);
        this.api.RegOption("Show Line", TOptionType.BOOLEAN, this.showLine);
        this.api.RegOption("Mode", TOptionType.STRING, this.mode);
    
        // Optional: Set parameter constraints
        this.api.SetOptionRange("Period", 1, 200);
        this.api.SetOptionDigits("Period", 0);
    }
    // Declare as class-level field
    public mainBuffer!: TIndexBuffer;
    
    public Init(): void {
        // 1. Register total number of buffers (MUST be called first)
        this.api.IndicatorBuffers(1);
    
        // 2. Create the buffer
        this.mainBuffer = this.api.CreateIndexBuffer();
    
        // 3. Bind buffer to index
        this.api.SetIndexBuffer(0, this.mainBuffer);
    
        // 4. Configure buffer appearance
        this.api.SetIndexLabel(0, "Main Line");
        this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, '#FF0000');
    
        // 5. Optional: Set drawing start point
        this.api.SetIndexDrawBegin(0, 10);
    }
    public Init(): void {
        // DON'T DO THIS - heavy calculations
        for (let i = 0; i < 1000; i++) {
            let value = this.api.Close(i) * 2; // ❌ Wrong!
            this.mainBuffer.setValue(i, value); // ❌ Wrong!
        }
    }
    public Init(): void {
        // ✅ Correct - only setup and configuration
        this.api.IndicatorShortName("My Indicator");
        this.api.IndicatorBuffers(1);
        this.mainBuffer = this.api.CreateIndexBuffer();
        // ... other setup code
    }
    
    public Calculate(index: number): void {
        // ✅ Correct - calculations go here
        let value = this.api.Close(index) * 2;
        this.mainBuffer.setValue(index, value);
    }
    export default class MovingAverage extends IndicatorImplementation {
      // Parameters - declared as class-level fields
      public Period!: TOptValue_number;
      public ShowLine!: TOptValue_bool;
    
      // Buffers - declared as class-level fields
      public MA!: TIndexBuffer;
    
      public Init(): void {
        // 1. Create and register parameters
        this.Period = this.api.createTOptValue_number(14);
        this.ShowLine = this.api.createTOptValue_bool(true);
    
        this.api.RegOption("Period", TOptionType.INTEGER, this.Period);
        this.api.RegOption("Show Line", TOptionType.BOOLEAN, this.ShowLine);
        this.api.SetOptionRange("Period", 1, 9999);
    
        // 2. Set indicator properties
        this.api.IndicatorShortName("Moving Average");
        this.api.SetOutputWindow(TOutputWindow.CHART_WINDOW);
        this.api.RecalculateMeAlways(); // Recommended
    
        // 3. Create and configure buffers
        this.api.IndicatorBuffers(1);
        this.MA = this.api.CreateIndexBuffer();
        this.api.SetIndexBuffer(0, this.MA);
        this.api.SetIndexLabel(0, "Moving Average");
        this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#FF0000");
      }
    
      public Calculate(index: number): void {
        // Actual calculations happen here, not in Init()
        const periodValue = this.Period.value; // Access parameter value
        // ... calculation logic
      }
    }
    // Declare the parameter in the class fields
    public MyText!: TOptValue_str;
    
    public Init(): void {
        // Create the parameter
        this.MyText = this.api.createTOptValue_str("default text");
    
        // Register the parameter
        this.api.RegOption("MyText", TOptionType.STRING, this.MyText);
    }
    export default class CustomIndicator extends IndicatorImplementation {
      public Name!: TOptValue_str;
    
      public Init(): void {
        this.Name = this.api.createTOptValue_str("Custom Indicator");
    
        this.api.RegOption("Name", TOptionType.STRING, this.Name);
      }
    }
    public MyFlag!: TOptValue_bool;
    
    public Init(): void {
        // Create the parameter
        this.MyFlag = this.api.createTOptValue_bool(defaultValue);
    
        // Register the parameter
        this.api.RegOption("MyFlag", TOptionType.BOOLEAN, this.MyFlag);
    }
    export default class CustomIndicator extends IndicatorImplementation {
      public IsEnabled!: TOptValue_bool;
    
      public Init(): void {
        this.IsEnabled = this.api.createTOptValue_bool(true);
    
        this.api.RegOption("IsEnabled", TOptionType.BOOLEAN, this.IsEnabled);
      }
    
      public Calculate(index: number): void {
        if (!this.IsEnabled.value) {
          return;
        }
    
        // Perform calculations only if enabled
      }
    }
    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 MyLineStyle!: TOptValue_LineStyle;
    
    public Init(): void {
        // Create the parameter
        this.MyLineStyle = this.api.createTOptValue_LineStyle(isVisible, color, style, width, ignoreColor);
    
        // Register the parameter
        this.api.RegOption("MyLineStyle", TOptionType.LINE, this.MyLineStyle);
    }
    export default class CustomIndicator extends IndicatorImplementation {
      public LineStyle!: TOptValue_LineStyle;
    
      public Init(): void {
        this.LineStyle = this.api.createTOptValue_LineStyle(true, '#FF0000', TPenStyle.SOLID, 2, false);
    
        this.api.RegOption("LineStyle", TOptionType.LINE, this.LineStyle);
      }
    
      public Calculate(index: number): void {
        if (this.LineStyle.isVisible) {
          const objName = "MyHorizontalLine";
          
          // Remove existing object if it exists
          if (this.api.DoesChartObjectExist(objName)) {
            this.api.RemoveChartObject(objName);
          }
    
          // Create horizontal line object
          this.api.CreateChartObject(objName, TObjectType.H_LINE, 0, undefined, this.api.Close(index));
    
          // Apply line style properties
          this.api.SetObjectProperty(objName, ObjProp.OBJPROP_COLOR, this.LineStyle.color);
          this.api.SetObjectProperty(objName, ObjProp.OBJPROP_STYLE, this.LineStyle.style);
          this.api.SetObjectProperty(objName, ObjProp.OBJPROP_WIDTH, this.LineStyle.width);
        }
      }
    }
    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);
      }
    }
    // 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);
      }
    }

    iOpen

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

    Syntax

    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

    iVolume

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

    Syntax

    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

    TOptValue_DateOnly

    What Is It?

    TOptValue_DateOnly is a class used to define date-only parameters for custom indicators. These parameters appear in the indicator settings panel and allow the user to input or adjust date values without time information, such as specific trading days, start dates, or end dates.

    You must use the createTOptValue_DateOnly() method of the api object inside Init() method to create an instance.


    When to Use

    Use TOptValue_DateOnly when you need a configurable parameter of date only, such as:

    • Start date for calculations (without specific time)

    • End date for a period (without specific time)

    • Specific trading day to highlight or filter

    • Date-based filters that don't require time precision


    Syntax


    Example

    In this example:

    • StartDate defines the beginning of the analysis period.

    • EndDate defines the end of the analysis period.


    Notes

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

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

    • Use TOptionType.DATE_ONLY when registering this parameter type.

    iLow

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

    Syntax

    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

    iHighest

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

    Syntax

    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

    iHigh

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

    Syntax

    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

    iLowest

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

    Syntax

    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

    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

    • Volume : Gets the volume value of the current bar.

    • : Retrieves volume value from a specific bar index.

    • : Retrieves the timestamp of a specific bar.

    • : Retrieves the open price of a specific bar.

    • : Finds the lowest value over a range of bars.

    • : Gets the low price of a specific bar.

    • : Finds the highest value over a range of bars.

    • : Gets the high price of a specific bar.

    • : Retrieves the close price of a specific bar.

    • : Finds the index of a bar by time.

    • : Returns the number of bars between two dates.

    • : Gets the close price of the current bar.

    • : Gets the high price of the current bar.

    • : Gets the low price of the current bar.

    • : Gets the open price of the current bar.

    • : Returns the total number of bars.

    • : Gets the time of the current bar.


    Click on any function name to view its detailed documentation.

    iTime

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

    Syntax

    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 an object representing the opening time of the specified bar.

    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

    TOptValue_DateTime

    What Is It?

    TOptValue_DateTime is a class used to define date and time parameters for custom indicators. These parameters appear in the indicator settings panel and allow the user to input or adjust date and time values such as start times, end times, or specific moments in trading history.

    You must use the createTOptValue_DateTime() method of the api object inside Init() method to create an instance.


    When to Use

    Use TOptValue_DateTime when you need a configurable parameter of date and time, such as:

    • Start date and time for calculations

    • End date and time for a period

    • Specific moment to trigger indicator behavior

    • Time-based filters for trading sessions


    Syntax

    Notes

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

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

    • Use TOptionType.DATE_TIME when registering this parameter type.

    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.

    iOpen(Symbol: string, TimeFrame: number, index: number): number
    iVolume(Symbol: string, TimeFrame: number, index: number): number
    iLow(Symbol: string, TimeFrame: number, index: number): number
    iHighest(symbol: string, timeFrame: number, type: number, count: number, index: number): number
    iHigh(Symbol: string, TimeFrame: number, index: number): number
    iLowest(symbol: string, timeFrame: number, type: number, count: number, index: number): number
    iTime(Symbol: string, TimeFrame: number, index: number): FTODate
    iVolume
    iTime
    iOpen
    iLowest
    iLow
    iHighest
    iHigh
    iClose
    iBarShift
    iBars
    Close
    High
    Low
    Open
    Bars
    Time
    This is useful when you only care about the date and not the specific time of day.
    this.RegOption
    Init
    FTODate
    this.RegOption
    Init
    // 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");
    }
    // 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;
    // Declare the parameter in the class fields
    public MyDateParameter!: TOptValue_DateOnly;
    
    public Init(): void {
    // Create the parameter
    this.MyDateParameter = this.api.createTOptValue_DateOnly(defaultValue);
    
    // Register the parameter
    this.api.RegOption("MyDateParameter", TOptionType.DATE_ONLY, this.MyDateParameter);
    
    }
    export default class DateRangeIndicator extends IndicatorImplementation {
        public StartDate!: TOptValue_DateOnly
        public EndDate!: TOptValue_DateOnly
    
        public Init(): void {
            // Create the parameters
            const startDate = this.api.createFTODate('2024-01-01')
            const endDate = this.api.createFTODate('2024-12-31'')
            this.StartDate = this.api.createTOptValue_DateOnly(startDate)
            this.EndDate = this.api.createTOptValue_DateOnly(endDate)
    
            // Register the parameters
            this.api.RegOption('StartDate', TOptionType.DATE_ONLY, this.StartDate)
            this.api.RegOption('EndDate', TOptionType.DATE_ONLY, this.EndDate)
        }
    }
    // 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);
    // 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;
    });
    // 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;
    // 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;
    // 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));
    }
    // Declare the parameter in the class fields
    public MyDateTimeParameter!: TOptValue_DateTime;
    
    public Init(): void {
    // Create the parameter
    this.MyDateTimeParameter = this.api.createTOptValue_DateTime(defaultValue);
    
    // Register the parameter
    this.api.RegOption("MyDateTimeParameter", TOptionType.DATE_TIME, this.MyDateTimeParameter);
    
    }
    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);
      }
    }

    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

    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

    Returns an object representing the bar's opening time.

    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

    GetObjectCount

    Returns the total number of chart objects.

    Syntax

    GetObjectCount(isStatic: boolean = false): number

    Parameters

    Parameter
    Type
    Description

    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

    iBarShift

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

    Syntax

    Parameters

    • symbol: The symbol to get data for

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

    • time: The time to search for

    • exact: Whether to require an exact match

    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

    High

    Returns the highest price for a specific bar.

    Syntax

    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

    Low

    Returns the lowest price for a specific bar.

    Syntax

    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

    Open

    Returns the opening price for a specific bar.

    Syntax

    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

    Close

    Returns the closing price for a specific bar.

    Syntax

    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

    RemoveAllObjects

    Removes all chart objects of a specified type.

    Syntax

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

    Parameters

    Parameter
    Type
    Description

    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

    GetObjectType

    Returns the type of a chart object.

    Syntax

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

    Parameters

    Parameter
    Type
    Description

    Return Value

    Returns a enum value representing the object's type.

    Description

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

    Example

    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

    • CreateChartObject: Creates a new chart object.

    • : Removes all objects from a chart.

    • : Checks if a chart object exists.

    • : Retrieves the text of a chart object.

    • : Retrieves the type of a chart object.

    • : Retrieves the name of a chart object.

    • : Retrieves the count of objects on a chart.

    • : Removes a specific chart object.

    • : Sets the text of a chart object.

    • : Retrieves a property of a chart object.

    • : Sets a property of a chart object.


    Click on any function name to view its detailed documentation.

    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

    Time(shift: number, timeZoneMode?: TimeZoneMode): FTODate
    iBarShift(symbol: string, timeframe: number, time: FTODate, exact: boolean): number
    High(shift: number): number
    Low(shift: number): number
    Open(shift: number): number
    Close(shift: number): number
    RemoveAllObjects
    DoesChartObjectExist
    GetObjectText
    GetObjectType
    GetObjectName
    GetObjectCount
    RemoveChartObject
    SetObjectText
    GetObjectProperty
    SetObjectProperty
    FTODate

    isStatic

    boolean

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

    FTODate

    objType

    TObjectType

    The type of objects to remove

    isStatic

    boolean

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

    name

    string

    The name of the object

    isStatic

    boolean

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

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

    SetObjectProperty

    Sets a property value for a chart object.

    Syntax

    Parameters

    Parameter
    Type
    Description

    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

    RemoveChartObject

    Removes a chart object with the specified name.

    Syntax

    RemoveChartObject(uniqueObjectName: string, isStatic: boolean = false): void

    Parameters

    Parameter
    Type
    Description

    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

    DoesChartObjectExist

    Checks if a chart object with the specified name exists.

    Syntax

    Parameters

    Parameter
    Type
    Description

    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

    GetObjectName

    Returns the name of a chart object by its index.

    Syntax

    Parameters

    Parameter
    Type
    Description

    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

    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

    CreateIndexBufferWithArgs

    Creates a new buffer with specified display properties.

    Syntax

    Parameters

    • index - A number representing the buffer index.

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

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

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

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

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

    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

    GetObjectText

    Returns the text content of a chart object.

    Syntax

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

    Parameters

    Parameter
    Type
    Description

    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

    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

    • AddLevel: Adds a level to an indicator.

    • : Sets the style of an indicator index.

    • : Creates an index buffer with arguments.

    • : Sets the output window for an indicator.

    • : Sets the number of digits for an indicator.

    • : Retrieves the number of counted bars.

    • : Sets the buffer shift for an indicator.

    • : Retrieves information about a buffer.

    • : Sets the draw begin index for an indicator.

    • : Retrieves the minimum value of a buffer.

    • : Retrieves the count of a buffer.

    • : Retrieves the maximum value of a buffer.

    • : Sets a value in a buffer.

    • : Retrieves a value from a buffer.

    • : Sets the label for an indicator index.

    • : Sets the symbol for an indicator index.

    • : Sets the visibility of an indicator index.

    • : Sets the buffer for an indicator index.

    • : Creates an index buffer.

    • : Manages indicator buffers.

    • : Sets the value of a level.

    • : Sets the indicator to always recalculate.

    • : Sets the back offset for calculation.

    • : Sets fixed min and max values for an indicator.

    • : Sets the ID key for an indicator.

    • : Sets the empty value for an indicator.

    • : Sets the short name for an indicator.


    Click on any function name to view its detailed documentation.

    AddLevel

    Adds a horizontal level line to the indicator.

    Syntax

    Parameters

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

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

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

    • color - A string hex color value for the level line.

    • opacity - A number between 0 and 1 representing the opacity of the line.

    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.

    See for available line styles

    Example

    SetObjectProperty(
      name: string,
      index: number,
      value: any,
      isStatic: boolean = false
      ): boolean
    DoesChartObjectExist(uniqueObjectName: string, isStatic: boolean = false): boolean
    GetObjectName(index: number, isStatic: boolean = false): string
    CreateIndexBufferWithArgs(
        index: number,
        aLabel: string,
        drawStyle: TDrawStyle,
        style: TPenStyle,
        width: number,
        color: string
    ): TIndexBuffer
    AddLevel(value: number, style: TPenStyle, width: number, color: string, opacity: number): void
    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

    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)

    uniqueObjectName

    string

    The unique name of the object to remove

    isStatic

    boolean

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

    uniqueObjectName

    string

    The unique name of the object to check

    isStatic

    boolean

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

    index

    number

    The index of the object

    isStatic

    boolean

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

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

    name

    string

    The name of the object

    isStatic

    boolean

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

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

    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

    GetObjectProperty

    Retrieves a property value from a chart object.

    Syntax

    Parameters

    Parameter
    Type
    Description

    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.

    See for a complete list of available object properties.

    Example

    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

    SetOutputWindow

    Sets the window where the indicator will be displayed.

    Syntax

    SetOutputWindow(outputWindow: TOutputWindow): void

    Parameters

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

    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.

    See for the complete list of available window types.

    Example

    GetBufferMax

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

    Syntax

    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

    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

    SetObjectText

    Sets the text content and formatting for a chart object.

    Syntax

    Parameters

    Parameter
    Type
    Description

    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

    SetIndexStyle

    Sets the visual style for a buffer.

    Important: This method should only be used inside the Init() method for initial buffer configuration.

    Syntax

    Parameters

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

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

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

    Return Value

    This method does not return a value.

    Description

    The SetIndexStyle method sets the visual appearance of a buffer on the chart during indicator initialization. This includes the drawing style (line, histogram, etc.), line style (solid, dashed, etc.), width, color, and initial visibility.

    Usage Guidelines:

    • Use in only - for setting up buffer appearance during indicator creation

    • For algorithmic visibility control - use in based on conditions/calculations

    See for available drawing styles, for line styles

    Visibility Parameter vs SetIndexVisibility

    Initial Setup (in Init())

    Use the isVisible parameter in SetIndexStyle for setting the initial visibility state:

    Dynamic Changes (in OnParamsChange() or Calculate())

    Use SetIndexVisibility for algorithmic visibility control:

    Example

    Key Rules

    1. SetIndexStyle = Initial setup in only

    2. SetIndexVisibility = Dynamic changes in or

    3. Both methods control visibility, but serve different purposes in the indicator lifecycle

    GetBufferMin

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

    Syntax

    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

    GetBufferInfo

    Retrieves information about a buffer.

    Syntax

    GetBufferInfo(index: number): TVisibleBufferInfo

    Parameters

    • index - A number representing the buffer index.

    Return Value

    Returns a object containing information about the buffer.

    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.

    See for more information about the buffer information structure.

    Example

    Set buffer value

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

    Syntax

    this.bufferName.setValue(index, value);

    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

    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

    GetObjectProperty(
      name: string,
      index: ObjProp | number,
      isStatic: boolean = false
      ): number | string
    GetBufferMax(buffer: number, index1: number, index2: number): number
    SetObjectText(
        name: string,
        text: string,
        fontSize: number = 14,
        fontName: string = Roboto Flex,
        fontColor: string = '#000000',
        isStatic: boolean = false
    ): boolean
    SetIndexStyle(
        bufferIndex: number,
        type: TDrawStyle,
        style: TPenStyle,
        width: number,
        clr: string,
        isVisible?: boolean
    ): void
    GetBufferMin(buffer: number, index1: number, index2: number): number
    // 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
    }

    name

    string

    The name of the object

    index

    ObjProp | number

    The property identifier

    isStatic

    boolean

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

    ObjProp
    TOutputWindow
    TOutputWindow

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

    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

    width - A number representing the line width in pixels.

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

  • isVisible - (Optional) A boolean for initial visibility setup only. For algorithmic visibility control, use SetIndexVisibility instead.

  • TDrawStyle
    TPenStyle
    Init()
    SetIndexVisibility
    Calculate()
    TDrawStyle
    TPenStyle
    Init()
    OnParamsChange()
    Calculate()
    TVisibleBufferInfo
    TVisibleBufferInfo
    // 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}`);
    // 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)
    // 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);
    // 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)
    }
    // 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
    }
    // 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}`);
    public Init(): void {
        // Set initial style with visibility
        this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 2, "#0000ff", true);  // Initially visible
        this.api.SetIndexStyle(1, TDrawStyle.NONE, TPenStyle.SOLID, 1, "#000000", false); // Initially hidden
    }
    public Calculate(index: number): void {
        // Show different buffers based on market state
        if (this.isInTrendingMarket(index)) {
            this.api.SetIndexVisibility(0, true);  // Trend buffer
            this.api.SetIndexVisibility(1, false); // Range buffer
        } else {
            this.api.SetIndexVisibility(0, false); // Trend buffer
            this.api.SetIndexVisibility(1, true);  // Range buffer
        }
    }
    public Init(): void {
        // Initial buffer setup with visibility
    
        // Buffer 0: Always visible main line
        this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 2, "#0000ff", true);
    
        // Buffer 1: Initially hidden calculation buffer
        this.api.SetIndexStyle(1, TDrawStyle.NONE, TPenStyle.SOLID, 1, "#000000", false);
    
        // Buffer 2: Initially hidden, will be shown conditionally
        this.api.SetIndexStyle(2, TDrawStyle.HISTOGRAM, TPenStyle.SOLID, 3, "#00ff00", false);
    }
    
    public Calculate(index: number): void {
        // Algorithmic visibility control - use SetIndexVisibility
        const signalStrength = this.calculateSignalStrength(index);
        if (signalStrength > 0.8) {
            this.api.SetIndexVisibility(2, true);  // Show strong signals only
        } else {
            this.api.SetIndexVisibility(2, false); // Hide weak signals
        }
    
        // DON'T do this in Calculate() or any method thats not Init():
        // this.api.SetIndexStyle(2, TDrawStyle.HISTOGRAM, TPenStyle.SOLID, 3, "#00ff00", true); // ❌ Wrong!
    }
    // 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)
    }
    // 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);
    }
    // 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 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;

    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

    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

    SetIndexSymbol

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

    Syntax

    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

    CreateIndexBuffer

    Creates a new buffer for storing indicator values.

    Important: This method should only be used inside the Init() method during indicator initialization.

    Syntax

    Parameters

    This method does not take any parameters.

    Return Value

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

    Description

    The CreateIndexBuffer method creates a new buffer for storing indicator values. Buffers are essential for displaying data on charts and must be properly declared, created, and configured during indicator setup.

    Buffer Management Rules:

    • Declare all buffers as class-level fields using the ! syntax

    • Create buffers in Init() using CreateIndexBuffer()

    • Register buffer count with IndicatorBuffers()

    See for more information about working with indicator buffers.

    Proper Buffer Declaration

    All buffers must be declared as class-level fields with the non-null assertion operator (!):

    Complete Buffer Setup Workflow

    Step 1: Declare Buffers (Class Level)

    Step 2: Create and Configure in Init()

    Step 3: Use Buffers in Calculate()

    Buffer Creation Rules

    ✅ Must Be Done in Init()

    • Create all buffers with CreateIndexBuffer()

    • Register buffer count with IndicatorBuffers()

    • Assign buffers to indexes with SetIndexBuffer()

    ❌ Cannot Be Done Outside Init()

    • Creating new buffers in Calculate() or other methods

    • Changing buffer count after initialization

    • Reassigning buffer indexes during runtime

    Complete Example

    Key Rules Summary

    1. Declare buffers as class-level fields with ! syntax

    2. Create buffers only in Init() using CreateIndexBuffer()

    3. Assign buffers to indexes with SetIndexBuffer()

    SetIndexVisibility

    Sets the visibility of a buffer programmatically based on custom indicator logic.

    Syntax

    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 allows your indicator to programmatically control buffer visibility based on custom logic, calculations, or indicator states. This is NOT for basic user preferences (users already have built-in checkboxes for that), but for algorithmic decisions where the indicator itself determines what should be displayed.

    When to Use SetIndexVisibility

    ✅ Use SetIndexVisibility For:

    • State-based indicators - show different buffers for different market states

    • Conditional logic - only show certain buffers when specific conditions are met

    • Mutually exclusive displays - show one buffer OR another, never both

    • Data-driven visibility - hide buffers when data is invalid or insufficient

    ❌ Don't Use SetIndexVisibility For:

    • Basic user preferences - users have built-in checkboxes for this

    • Simple on/off toggles - the built-in visibility controls handle this

    • Initial visibility setup in (use instead)

    SetIndexVisibility vs Built-in Controls

    Built-in User Controls (Checkboxes)

    Users can already control basic visibility:

    • ✅ "Show/Hide Main Line"

    • ✅ "Show/Hide Signal Line"

    • ✅ Basic on/off toggles

    SetIndexVisibility (Custom Logic)

    Use for intelligent, condition-based visibility:

    • ✅ Show uptrend buffer OR downtrend buffer (never both)

    • ✅ Hide signal when market is ranging

    • ✅ Show different buffers for different timeframes

    • ✅ Display warning buffer only when conditions are dangerous

    Practical Examples

    Example 1: State-Based Indicator (Trend vs Range)

    Example 2: Conditional Signal Display

    Example 3: Timeframe-Dependent Display

    Example 4: Data Quality Control

    Common Use Cases

    1. Mutually Exclusive States: Show buffer A OR buffer B, never both

    2. Conditional Signals: Only display signals when market conditions are suitable

    3. Quality Control: Hide unreliable data, show only when confidence is high

    4. Mode Switching: Different displays for different market modes (trend/range/volatile)

    Key Rules

    1. SetIndexVisibility = Algorithmic decisions by the indicator

    2. Built-in checkboxes = User preferences and basic on/off controls

    3. Use for intelligent logic, not simple user toggles

    4. Perfect for state machines and conditional displays

    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

    SetIndexSymbol(bufferIndex: number, symbol: number, xoffs: number, yoffs: number): void
    CreateIndexBuffer(): TIndexBuffer
    SetIndexVisibility(index: number, isVisible: boolean): void
    // 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)

    Assign buffers to indexes with SetIndexBuffer()

  • Configure buffer appearance with SetIndexStyle()

  • Configure initial styles with SetIndexStyle()

    Configure appearance with SetIndexStyle()

  • Use buffers in Calculate() for data storage and retrieval

  • Never create buffers outside Init() - this will cause errors

  • TIndexBuffer
    TIndexBuffer

    Dynamic switching - change what's visible based on calculations

    Error Handling: Hide buffers when calculations are invalid or insufficient data

  • Performance Optimization: Hide complex buffers during high-frequency updates

  • Great for data quality control and error handling

    Init()
    SetIndexStyle
    // 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)
    // 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);
    // ✅ Correct - declare as class-level fields
    export default class MyIndicator extends IndicatorImplementation {
      public mainBuffer!: TIndexBuffer;
      public signalBuffer!: TIndexBuffer;
      public helperBuffer!: TIndexBuffer;
    
      public Init(): void {
        this.mainBuffer = this.api.CreateIndexBuffer();
        this.signalBuffer = this.api.CreateIndexBuffer();
        this.helperBuffer = this.api.CreateIndexBuffer();
      }
    }
    // ❌ Wrong - don't use api methods (any api methods, including CreateIndexBuffer) in class level fields
    export default class MyIndicator extends IndicatorImplementation {
      public mainBuffer = this.api.CreateIndexBuffer();
      public signalBuffer = this.api.CreateIndexBuffer();
      public helperBuffer = this.api.CreateIndexBuffer();
    
      public Init(): void {}
    }
    export default class MovingAverageIndicator extends IndicatorImplementation {
        // Declare all buffers as class properties
        public maBuffer!: TIndexBuffer;
        public signalBuffer!: TIndexBuffer;
        public Init(): void {
            // 1. Register total number of buffers FIRST
            this.api.IndicatorBuffers(2);
    
            // 2. Create buffer instances
            this.maBuffer = this.api.CreateIndexBuffer();
            this.signalBuffer = this.api.CreateIndexBuffer();
    
            // 3. Assign buffers to indexes
            this.api.SetIndexBuffer(0, this.maBuffer);
            this.api.SetIndexBuffer(1, this.signalBuffer);
    
            // 4. Configure buffer appearance
            this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 2, "#0000ff");
            this.api.SetIndexStyle(1, TDrawStyle.LINE, TPenStyle.DASH, 1, "#ff0000");
    
            // 5. Set buffer labels
            this.api.SetIndexLabel(0, "Moving Average");
            this.api.SetIndexLabel(1, "Signal Line");
        }
        public Calculate(index: number): void {
            // Use buffers to store and retrieve values
            const closePrice = this.api.Close(index);
            const maValue = this.calculateMA(index);
    
            // Set buffer values
            this.maBuffer.setValue(index, maValue);
            this.signalBuffer.setValue(index, maValue * 1.1);
    
            // Get buffer values (from previous bars)
            const previousMA = this.maBuffer.getValue(index + 1);
        }
    }
    export default class AdvancedIndicator extends IndicatorImplementation {
      // 1. Declare all buffers as class-level fields
      public fastMA!: TIndexBuffer;
      public slowMA!: TIndexBuffer;
      public signalBuffer!: TIndexBuffer;
      public helperBuffer!: TIndexBuffer;
    
      public Init(): void {
        // 2. Register total buffer count
        this.api.IndicatorBuffers(4);
    
        // 3. Create buffer instances
        this.fastMA = this.api.CreateIndexBuffer();
        this.slowMA = this.api.CreateIndexBuffer();
        this.signalBuffer = this.api.CreateIndexBuffer();
        this.helperBuffer = this.api.CreateIndexBuffer();
    
        // 4. Assign to indexes
        this.api.SetIndexBuffer(0, this.fastMA);
        this.api.SetIndexBuffer(1, this.slowMA);
        this.api.SetIndexBuffer(2, this.signalBuffer);
        this.api.SetIndexBuffer(3, this.helperBuffer);
    
        // 5. Configure styles
        this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#0000ff");
        this.api.SetIndexStyle(1, TDrawStyle.LINE, TPenStyle.SOLID, 1, "#ff0000");
        this.api.SetIndexStyle(
          2,
          TDrawStyle.HISTOGRAM,
          TPenStyle.SOLID,
          2,
          "#00ff00"
        );
        this.api.SetIndexStyle(3, TDrawStyle.NONE, TPenStyle.SOLID, 1, "#000000"); // Hidden
    
        // 6. Set labels
        this.api.SetIndexLabel(0, "Fast MA");
        this.api.SetIndexLabel(1, "Slow MA");
        this.api.SetIndexLabel(2, "Signal");
      }
    
      public Calculate(index: number): void {
        // Use buffers for calculations and display
        const fastValue = this.calculateFastMA(index);
        const slowValue = this.calculateSlowMA(index);
    
        this.fastMA.setValue(index, fastValue);
        this.slowMA.setValue(index, slowValue);
        this.helperBuffer.setValue(index, fastValue - slowValue);
    
        // Conditional signal display
        if (Math.abs(fastValue - slowValue) > 0.01) {
          this.signalBuffer.setValue(index, fastValue);
        }
      }
    }
    export default class TrendRangeIndicator extends IndicatorImplementation {
      public trendBuffer!: TIndexBuffer;
      public rangeBuffer!: TIndexBuffer;
      private isInTrend: boolean = false;
    
      public Calculate(index: number): void {
        // Determine market state
        this.isInTrend = this.calculateTrendState(index);
    
        if (this.isInTrend) {
          // Show trend buffer, hide range buffer
          this.api.SetIndexVisibility(0, true); // Trend buffer
          this.api.SetIndexVisibility(1, false); // Range buffer
    
          this.trendBuffer.setValue(index, this.calculateTrendValue(index));
        } else {
          // Show range buffer, hide trend buffer
          this.api.SetIndexVisibility(0, false); // Trend buffer
          this.api.SetIndexVisibility(1, true); // Range buffer
    
          this.rangeBuffer.setValue(index, this.calculateRangeValue(index));
        }
      }
    }
    export default class SmartSignalIndicator extends IndicatorImplementation {
      public mainBuffer!: TIndexBuffer;
      public warningBuffer!: TIndexBuffer;
      public signalBuffer!: TIndexBuffer;
    
      public Calculate(index: number): void {
        const mainValue = this.calculateMainValue(index);
        this.mainBuffer.setValue(index, mainValue);
    
        // Only show warning when market is volatile
        const volatility = this.calculateVolatility(index);
        if (volatility > 2.0) {
          this.api.SetIndexVisibility(1, true); // Show warning
          this.warningBuffer.setValue(index, mainValue);
        } else {
          this.api.SetIndexVisibility(1, false); // Hide warning
        }
    
        // Only show signals when conditions are optimal
        const signalStrength = this.calculateSignalStrength(index);
        if (signalStrength > 0.8 && volatility < 1.5) {
          this.api.SetIndexVisibility(2, true); // Show signal
          this.signalBuffer.setValue(index, this.generateSignal(index));
        } else {
          this.api.SetIndexVisibility(2, false); // Hide signal
        }
      }
    }
    export default class MultiTimeframeIndicator extends IndicatorImplementation {
      public shortTermBuffer!: TIndexBuffer;
      public longTermBuffer!: TIndexBuffer;
    
      public OnParamsChange(): void {
        const currentTimeframe = this.api.Timeframe();
    
        if (currentTimeframe <= 60) {
          // 1 hour or less
          // Show short-term analysis
          this.api.SetIndexVisibility(0, true); // Short-term buffer
          this.api.SetIndexVisibility(1, false); // Long-term buffer
        } else {
          // Show long-term analysis
          this.api.SetIndexVisibility(0, false); // Short-term buffer
          this.api.SetIndexVisibility(1, true); // Long-term buffer
        }
      }
    }
    export default class QualityControlIndicator extends IndicatorImplementation {
      public reliableBuffer!: TIndexBuffer;
      public unreliableBuffer!: TIndexBuffer;
    
      public Calculate(index: number): void {
        const dataQuality = this.assessDataQuality(index);
        const calculatedValue = this.performCalculation(index);
    
        if (dataQuality > 0.9) {
          // High quality data - show reliable buffer
          this.api.SetIndexVisibility(0, true); // Reliable buffer
          this.api.SetIndexVisibility(1, false); // Unreliable buffer
          this.reliableBuffer.setValue(index, calculatedValue);
        } else {
          // Low quality data - show unreliable buffer with warning style
          this.api.SetIndexVisibility(0, false); // Reliable buffer
          this.api.SetIndexVisibility(1, true); // Unreliable buffer
          this.unreliableBuffer.setValue(index, calculatedValue);
        }
      }
    }
    // 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)

    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

    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

    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

    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.

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

    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

    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

    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

    RegOption

    Registers a new option parameter for an indicator or strategy.

    Syntax

    Parameters

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

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

    • optPtrOrValue - (Optional) The default value for the option.

    • inv - (Optional) Visibility flag, defaults to true.

    • useInNameWithParams - (Optional) Whether to include this option in the name with parameters, defaults to true.

    • tab - (Optional) The tab to display the option in (from enum), defaults to TOptionTab.INPUTS.

    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.

    See for a complete list of option types.

    Example

    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

    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

    Step 3: Upload FTO indicator documentation to Cursor

    In this step, we’ll give Cursor its “textbook” — the official FTO indicator documentation.

    Now that Cursor knows the rules, let’s give it the actual manual.

    By uploading the official FTO indicator documentation, Cursor will have a knowledge base it can use to generate better code for you. No more guessing, no more “hmm, what does this method do?” — Cursor will actually know.

    Here’s how to do it:

    1. Click the Settings icon in the top right corner of Cursor IDE (see Picture #1).

      Think of this step as handing Cursor the instruction booklet — without it, it’s like trying to build IKEA furniture without the tiny hex key.

    Picture 1

    2. Next stop: Features.

    Think of it as the secret drawer where all the cool settings live. Click on Features in the left sidebar — that’s where you’ll find everything you need to feed Cursor the right docs. (See Picture #2.)

    1. Almost there! Scroll down the Features page until you spot the Docs section — that’s your gateway to feeding Cursor some serious brain food. (See Picture #3.)

    1. Time to feed Cursor some serious knowledge! Hit the “Add new doc” button and paste this link: https://fto-2.gitbook.io/fto-indicators-docs.

      This tells Cursor, “Here’s everything you need to know about indicators in FTO — study up!” (See Picture #4.)

    Once you add the link, Cursor will take a moment to index the docs. Grab a coffee (or stretch your fingers) while it works.

    After that, Cursor will have all the smarts it needs to reference the documentation and help you craft your shiny new indicators like a pro.

    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

    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

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


    Click on any function name to view its detailed documentation.

    RegOption(name: string, type: TOptionType, optPtrOrValue?: string | number | boolean | TOptValue, inv = true, useInNameWithParams = true, tab = TOptionTab.INPUTS): void
    AddOptionValue
    SetOptionDigits
    SetOptionRange
    Picture 2
    Picture 3
    Picture #4
    // 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)
    // Include 50 additional bars in calculations
    this.api.SetBackOffsetForCalculation(50)
    
    // For indicators that need a lot of historical data
    this.api.SetBackOffsetForCalculation(200)
    // 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()}`)
    TIndexBuffer
    // Set the indicator to recalculate on every tick
    this.api.RecalculateMeAlways();
    TOptionType
    TOptionTab
    TOptionType
    // 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})`)
    // 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
    // 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')
    
    
    // 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')
    }
    // 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");
    // 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)

    CreateChartObject

    Creates a new chart object with specified parameters.

    Syntax

    Parameters

    Parameter
    Type
    Description

    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

    Examples

    Text Object

    Rectangle Object

    Fixed Object (Screen Coordinates)

    Volume

    Returns the volume for a specific bar.

    Syntax

    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

    iClose

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

    Syntax

    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

    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.

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

    You can download the archive of Moving Average from here

    Indicator structure

    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.

    Indicator parameters

    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

    Buffers setup

    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

    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

    Each registered buffer can be

    Other settings

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

    Indicator's main function

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

    Changing parameters

    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.

    TOptValue_TimeOnly

    What Is It?

    TOptValue_TimeOnly is a class used to define time-only parameters for custom indicators. These parameters appear in the indicator settings panel and allow the user to input or adjust time values without date information, such as daily trading session times, specific hours of the day, or recurring time-based events.

    You must use the createTOptValue_TimeOnly() method of the api object inside Init() method to create an instance.

    The UI for this parameter type uses the enum, which provides predefined time values in 15-minute intervals from 00:00 to 23:59.


    When to Use

    Use TOptValue_TimeOnly when you need a configurable parameter for time selection, such as:

    • Trading session start/end times

    • Market open/close times

    • Recurring time-based events

    • Any time input from the user (without date)


    Syntax


    Example

    In this example:

    • SessionStart defines when the trading session begins.

    • SessionEnd defines when the trading session ends.


    Notes

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

    • Use TOptionType.TIME_ONLY when registering this parameter type.

    • Default values should use the enum.

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

    СreateChartObject(
        name: string,
        objType: TObjectType,
        window: number,
        ftoDate1: FTODate,
        price1: number,
        ftoDate2?: FTODate,
        price2?: number,
        ftoDate3?: FTODate,
        price3?: number,
        isStatic?: boolean
    ): boolean
    Volume(shift: number): number
    iClose(Symbol: string, TimeFrame: number, index: number): number
    Setup and Installation
    TOptValue
    Init
    external parameters definition
    Buffers
    Init
    configured
    Init
    RecalculateMeAlways
    IndicatorShortName
    SetOutputWindow
    SetEmptyValue
    Calculate
    OnParamsChange
    .
  • The UI presents users with a dropdown of time values in 15-minute intervals.

  • This is useful for recurring daily events or session-based filtering.

  • TimeValue
    this.RegOption
    Init
    TimeValue
    // 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");
    }
    // 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;
    import { IndicatorImplementation } from "forex-tester-custom-indicator-api";
    
    export default class MovingAverage extends IndicatorImplementation {
      // indicator logic
    }
    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...
    }
    public SSMA!: TIndexBuffer
    private SMA!: TIndexBuffer
    this.SMA = this.api.CreateIndexBuffer();
    this.SSMA = this.api.CreateIndexBuffer();
    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);
    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())
    }
    public OnParamsChange(): void {
        this.api.SetBufferShift(0, this.Shift.value)
    }
    // Declare the parameter in the class fields
    public MyTimeParameter!: TOptValue_TimeOnly;
    
    public Init(): void {
        // Create the parameter
        this.MyTimeParameter = this.api.createTOptValue_TimeOnly(defaultTimeValue);
    
        // Register the parameter
        this.api.RegOption("MyTimeParameter", TOptionType.TIME_ONLY, this.MyTimeParameter);
    }
    export default class SessionIndicator extends IndicatorImplementation {
        public SessionStart!: TOptValue_TimeOnly
        public SessionEnd!: TOptValue_TimeOnly
    
        public Init(): void {
            // Create the parameters
            this.SessionStart = this.api.createTOptValue_TimeOnly(TimeValue['09:00'])
            this.SessionEnd = this.api.createTOptValue_TimeOnly(TimeValue['17:00'])
    
            // Register the parameters
            this.api.RegOption('SessionStart', TOptionType.TIME_ONLY, this.SessionStart)
            this.api.RegOption('SessionEnd', TOptionType.TIME_ONLY, this.SessionEnd)
        }
    }

    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)

    name

    string

    Unique identifier for the object

    objType

    TObjectType

    Type of object to create (e.g., trend line, rectangle)

    window

    number

    Chart window number where the object will be placed

    ftoDate1

    FTODate

    First time coordinate

    price1

    number

    First price coordinate

    ftoDate2

    // Create text object
    this.api.CreateChartObject('MyLabel', TObjectType.TEXT, 0, this.api.Time(0), this.api.Close(0))
    
    // Set text content and styling
    this.api.SetObjectProperty('MyLabel', ObjProp.OBJPROP_TEXT, 'Support Level')
    this.api.SetObjectProperty('MyLabel', ObjProp.OBJPROP_FONTNAME, 'Arial')
    this.api.SetObjectProperty('MyLabel', ObjProp.OBJPROP_FONTSIZE, 12)
    this.api.SetObjectProperty('MyLabel', ObjProp.OBJPROP_COLOR, '#0000FF')
    this.api.SetObjectProperty('MyLabel', ObjProp.OBJPROP_ANCHOR_POINT, AnchorPoint.CENTER)
    // Create rectangle
    this.api.CreateChartObject(
        'MyRectangle',
        TObjectType.RECTANGLE,
        0,
        this.api.Time(10),
        this.api.Close(10),
        this.api.Time(0),
        this.api.Close(0)
    )
    
    // Set rectangle styling
    this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_COLOR, '#00FF00')
    this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_FILLCOLOR, '#00FF0020')
    this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_FILLINSIDE, true)
    this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_WIDTH, 1)
    this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_BACK, true)
    this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_MIDDLE_LINE, true)
    
    // Set text content and styling for rectangle
    this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_TEXT, 'Text')
    this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_FONTNAME, 'Arial')
    this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_FONTSIZE, 12)
    // Create a text object with screen coordinates
    this.api.CreateChartObject('FixedLabel', TObjectType.TEXT, 0, 0, 0)
    
    // Enable screen coordinates mode
    this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_SCREENCOORDS, true)
    
    // Set fixed position relative to chart corner (top-left)
    this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_XDISTANCE, 50) // 50 pixels from left
    this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_YDISTANCE, 30) // 30 pixels from top
    
    // Set fixed size
    this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_XSIZE, 200) // 200 pixels wide
    this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_YSIZE, 40) // 40 pixels tall
    
    // Configure text properties
    this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_TEXT, 'Fixed Position Label')
    this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_FONTNAME, 'Arial')
    this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_FONTSIZE, 14)
    this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_COLOR, '#333333')
    this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_ANCHOR_POINT, AnchorPoint.LEFT_TOP)
    FTODate
    FTODate