Skip to content

ChartShot Method

This user guide explains how to use the TakeChartshot() method when creating cTrader algorithms. If you are eager to get started, simply read our one-minute summary below.

Chartshot Methods in One Minute!

  • The TakeChartshot() method allows cTrader algos to take ChartShots of the charts on which they are running but only if this chart is visible.
  • ChartShots are a great tool to communicate with other traders and share technical analysis. With the TakeChartshot() method, this process becomes easier than ever!
  • The TakeChartshot() method returns an array of bytes, meaning that you can easily share Chartshots as .PNG files. You can also share the ChartShot on the Internet using the network access feature.
  • The TakeChartshot() method is essential if you want to make chartshots whenever your algos do something (e.g., when a cBot places an order). This feature provides a great visual aid for anyone who wants to evaluate how their solutions perform without keeping an eye on the chart 24/7.

How to Use the TakeChartshot() Method

ChartShots offer a way to quickly create screenshots of trading charts. If you create a ChartShot manually via the cTrader toolbar, the screenshot is saved on your local machine in addition to being automatically uploaded to a special portal that offers several ways via which you can share it (e.g., via embeddable HTML code).

In turn, our API allows for making ChartShots automatically. In contrast to regular ChartShots, ChartShots made by cTrader algos are not saved anywhere by default. Instead, such ChartShots are returned as byte arrays that you are free to save wherever you want by specifying an additional action in the code.

The byte[] TakeChartshot() method works as follows.

  • byte[] TakeChartshot(). Takes a ChartShot of the chart on which the algorithm is running and returns it as an array of bytes.

Note that the method only works if a chart is visible. To allow for easily checking chart visibility, the Chart interface includes the IsVisible property. It is equal to true for a visible chart and false for an invisible one.

Chartshots in Backtesting and Optimisation

  • In optimisation and non-visual backtesting, the TakeChartshot() method always returns null and invokes the OnException() handler if you have specified it.
  • In visual mode backtesting, the method works as intended.

Creating an Example cBot

To demonstrate how taking ChartShots works, we will create a simple cBot that will make a chartshot of the current chart and save it in the family system of your local machine.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.FullAccess)]
    public class ChartshotTest : Robot
    {
        protected override void OnStart()
        {
            if (Chart.IsActive)
            {
                var chartshot = Chart.TakeChartshot();

                File.WriteAllBytes(@"D://examplePath/chartshot.png", chartshot);

            }
        }
    }
}

On start, the .PNG file containing the chartshot of the chart to which we have attached the cBot instance will be added to D://examplePath/.

Summary

The TakeChartshot() method allows cTrader algos to make easily sharable ChartShots, making it essential for anyone who wants to share information with other traders or track how their automated solutions perform in response to certain conditions. This method is also usable in visual backtesting, allowing you to easily match the actions of your cBots to events occurring on charts.