What's New in cTrader Automate API 3.01

Created at 23 Jul 2018, 15:11
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
SP Spotware's avatar

Spotware

Joined 23.09.2013

What's New in cTrader Automate API 3.01
23 Jul 2018, 15:11


cTrader Automate (former cAlgo) implemented a new set of API in the version 3.01.
Using the new API you can configure the chart, where a cBot or an Indicator is running: get or set the chart settings, chart colors, scroll the chart positions, subscribe to the chart changes events, etc.
Also, we have added a new API to work with the objects that you can draw on the chart, like Trend Lines, Fibonacci Retracement, and others. Now you can draw all the chart objects available in cTrader, get existing objects from the chart and set their properties, receive events when the objects are added, removed, updated, hovered, or selected.

Here is the list of all the changes.

Chart Settings

  • Chart.DisplaySettings - contains settings for the items you see on the chart (Positions, Order, Grid, Deal map etc).
  • Chart.ColorSettings - contains the chart colors settings, like Candlesticks filling and background colors, etc.
  • Chart.Zoom - gets or sets the zoom level of the chart.
  • Chart.MarketSeries - access bar series used on the chart, like Open, High, Low, or Close.
  • Chart.TimeFrame - gets the timeframe of the chart.
  • Chart.Symbol - gets the symbol of the chart.
  • Chart.ChartType - gets the type of the chart (Bars, Candlesticks, Lines or Dots).
  • ChartArea.IsAlive - indicates if the indicator area is still on the chart.

Bars on the chart

  • Chart.BarsTotal - gets the number of the bars on the chart.
  • Chart.FirstVisibleBarIndex - gets the bar index of the first visible bar on the chart.
  • Chart.LastVisibleBarIndex - get the bar index of the last visible bar on the chart.
  • Chart.MaxVisibleBars - gets the maximum number of bars that can be shown on the chart with the current size and zoom level.

Size and scroll position

  • ChartArea.Width - gets the chart area width in pixels.
  • ChartArea.Height - gets the chart area height in pixels.
  • ChartArea.TopY - gets the highest value of the Y-axis in the visible area. For the main chart area, it is the top price that you see on the chart.
  • ChartArea.BottomY - gets the lowest value of the Y-axis in the visible area. For the main area, it is the lowest price you see on the chart.
  • Chart.ScrollXBy(int bars) - scrolls the chart for the specified number of bars to the right with a positive value, and to the left with a negative value.
  • Chart.ScrollXTo(int barIndex) - scrolls the chart to specified bar index, so that the first bar in the visible area will be the specified bar.
  • Chart.ScrollXTo(DateTime time) - scrolls the chart to the specified time, so that the specified time value will be in the time range of the first bar in the visible area.
  • ChartArea.SetYRange(double bottomY, double topY) - move or stretch the chart area upon the Y-axis.
  • Chart.IsScrollingEnabled - disable or enable the chart scrolling from the UI.

Chart events

  • Chart.DisplaySettingsChanged - occurs when one or multiple changes were made to the chart display settings.
  • Chart.ColorsChanged - occurs when one or multiple changes were made to chart color settings.
  • Chart.ChartTypeChanged - occurs when the type of the chart was changed.
  • Chart.ZoomChanged - occurs when the chart zoom level was changed.
  • Chart.IndicatorAreaAdded - occurs when an indicator was added to the chart that is drawn in its own chart area.
  • Chart.IndicatorAreaRemoved - occurs when an indicator was removed from the chart that is drawn in its own chart area.
  • ChartArea.SizeChanged - occurs when the size of the chart area was changed.
  • ChartArea.ScrollChanged - occurs when the first bar index or topY/bottomY has changed on the chart area.
  • ChartArea.MouseEnter - occurs when the mouse cursor enters the chart area.
  • ChartArea.MouseLeave - occurs when the mouse cursor leaves the chart area.
  • ChartArea.MouseMove - occurs when the mouse coordinates have changed in the chart area.
  • ChartArea.MouseDown - occurs when the left mouse button is pressed inside the chart area.
  • ChartArea.MouseUp - occurs when the left mouse button is released inside the chart area.
  • ChartArea.MouseWheel - occurs when the mouse wheel is scrolled.
  • ChartArea.DragStart - occurs when the chart area dragging was started using a mouse.
  • ChartArea.DragEnd - occurs when chart area dragging was stopped due to the left mouse button release or mouse capture was lost.
  • ChartArea.Drag - occurs when the mouse moves while the chart area is dragged.

Chart Objects

There are 14 chart objects available via the new cAlgo API:

  • ChartHorizontalLine
  • ChartVerticalLine
  • ChartTrendLine
  • ChartText
  • ChartStaticText
  • ChartIcon
  • ChartFibonacciRetracement
  • ChartFibonacciExpansion
  • ChartFibonacciFan
  • ChartAndrewsPitchfork
  • ChartEquidistantChannel
  • ChartRectangle
  • ChartEllipse
  • ChartTriangle

For each object, there is a corresponding method of drawing this particular object on a specific chart area.
Here is how to draw a horizontal line and make it interactive for a user:

var line = Chart.DrawHorizontalLine("my line", Symbol.Ask, Color.Red);
line.IsInteractive = true;

Calculate price of trend line

Now you can calculate a price value or indicator value of a trend line for a specific bar index or DateTime:

var line = Chart.DrawTrendLine("myLine", MarketSeries.OpenTime.Last(10), MarketSeries.High.Last(10), MarketSeries.OpenTime.LastValue, MarketSeries.High.LastValue, Color.Red);
line.ExtendToInfinity = true;
var price = line.CalculateY(MarketSeries.OpenTime.LastValue.AddHours(1));
Print("Next bar price is {0}", price);

Interactivity of ChartObject

The IsInteractive property has been introduced to the Chart objects. It allows creating interactive and non-interactive objects.
Non-interactive objects can't be changed by a user and are not visible by other cBots or Indicators. Only a cBot or an Indicator that owns non-interactive object can see it.
Interactive objects, on the other hand, can be seen and changed by a user or other cBots or Indicators that are working on the same chart.
When a cBot is stopped, or an Indicator is removed from the chart, all the non-interactive objects that belong to that cBot or Indicator will be removed from the chart automatically.

Chart API support in Optimization

Note that the Chart API is not supported in Optimization. If you call any methods from the Chart interface, the optimization will be stopped with the 'Not Supported' error.
If you plan to use a cBot or an Indicator in the Optimization, then you should avoid using the Chart interface in this mode. The mode can be checked using the new RunningMode property:

if (RunningMode != RunningMode.Optimization)
{
    Chart.DrawTrendLine...
}

New Color class

The new Color class replaces the old Colors enumeration. Now you can specify the custom colors for indicators, chart objects, and chart color settings.
Color values can be set using RGB, ARGB, Hex string or using a color name.

Indicator line color

For the Indicator lines, we have implemented a new LineColor property in OutputAttribute. Before, only colors from the Colors enum were supported and the line color could be set like this:

[Output("Main", Color = Colors.Red)] 


The new LineColor property can be specified using the Hex value:

[Output("Main", LineColor = "#FF0000")] 


Or color name:

[Output("Main", LineColor = "Red")] 

Trading API shortcuts

For the Position and PendingOrders, we have added the shortcuts for modification and close/cancel methods. Now, most of the modification or close/cancel actions can be done by calling the methods directly on the Position and PendingOrder instance. Find the full list of the new methods below.

For Position:

  • Position.ModifyVolume
  • Position.ModifyStopLossPips
  • Position.ModifyStopLossPrice
  • Position.ModifyTakeProfitPips
  • Position.ModifyTakeProfitPrice
  • Position.ModifyTrailingStop
  • Position.Reverse
  • Position.Close


For PendingOrder:

  • PendingOrder.ModifyVolume
  • PendingOrder.ModifyExpirationTime
  • PendingOrder.ModifyTargetPrice
  • PendingOrder.ModifyStopLossPips
  • PendingOrder.ModifyTakeProfitPips
  • PendingOrder.ModifyStopLimitRange
  • PendingOrder.Cancel

Deprecated API

  • Colors enumeration (replaced with Color).
  • Color property for OutputAttribute (replaced with the LineColor property).
  • ChartObjects interface (replace with the ChartArea interface).

@Spotware
Replies

afhacker
23 Jul 2018, 16:39

Finally some real improvement!

Please add the platform time zone as a property in form of a TimeZoneInfo object so the developer will be able to know what's the user platform time zone setting, I don't know why you haven't added it yet.


@afhacker

ClickAlgo
23 Jul 2018, 17:28 ( Updated at: 21 Dec 2023, 09:20 )

Thank you Spotware, this will allow vendors to create even more tools for the platform to help traders.

Do you have the API documented off-line in the form of a PDF document?

Paul Hayes
Sales & Marketing
Emailcontact@clickalgo.com
Phone: (44) 203 289 6573
Websitehttps://clickalgo.com


@ClickAlgo

ctrader.guru
23 Jul 2018, 18:44

great work, thanks ...


@ctrader.guru

Waxy
23 Jul 2018, 22:01

Hello Spotware,

This looks great and will help us develop better tools for trades.

I have two requests I haven't seen but been asking for it.

  1. Opacity for objects, this is important because chart data is sometimes blocked by these objects.
  2. Have an option to have objects drawn on backtests, but interactivity disabled.

Thanks for your continuous work.


@Waxy

PanagiotisCharalampous
26 Jul 2018, 09:50

Hi Waxy,

Transparency has already been added. We have a new Colors.FromArgb() function that allows you to set the alpha channel. Regarding interactivity, all chart objects have an IsInteractive property which is set to false by default.

Best Regards,

Panagiotis


@PanagiotisCharalampous

AxiomQuant
27 Jul 2018, 12:00

A great improvements coming with v.3.00 and especially now with v3.01! It's been a long time of waiting for some of these recently introduced functionality and I'm very happy seeing them now available!

Please also focus on the mobile version now - the recent upgrade (though I understend the reasons behind) actually removed a lot of functionality and unlike on the desktop platform it represents a big move backwards (at least for me). Bring those functions back please and you're going to have a very powerful multi-platform system set


@AxiomQuant

deanmikan@gmail.com
29 Jul 2018, 04:33

Beautiful

Thank you so much devs!!!! This is the best update in a LONG time. I've been manually drawing rectangles for too long... And the visual mode looks and feels great.

Whilst I might have your attention, I would like to point out a massive bug in the backtest feature:
The ModifyPosition method is bugged in the fact that if you modify the volume to be less than that of the current position, it calculates the profit incorrectly. 

An example would be this code:

protected override void OnBar()
       {
            if (Positions.Count == 0)
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, Symbol.NormalizeVolumeInUnits(Account.Balance*5), "temp", 50, 50);
            }
            else
            {
                if (Positions[0].NetProfit > 5)
                    ModifyPosition(Positions[0], Symbol.NormalizeVolumeInUnits(Positions[0].VolumeInUnits - 1000));

            }
        }

This will give you a profit in the billions of % due to it calculating every profit when modified as the original volume, despite only taking 1000 units in volume. Test on EURUSD for example.

Also it would be awesome if in future updates the devs could work on making the backtest feature less hell to use. When making over 2000 or 3000 trades the lag I experience, even ona a good computer, is atleast 20-30 wait times till I can even use the software without it not responding. And i'm quite sure there are many memory leaks in the software as using it for a long period of time it gets slower and slower.

 

Cheers Devs!


@deanmikan@gmail.com

PanagiotisCharalampous
30 Jul 2018, 09:42

Hi deanmikan@gmail.com,

Thanks for posting this issue. We will have a look at it and come back to you.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
23 Aug 2018, 15:04

Hi deanmikan@gmail.com,

We have released an update today that should have fixed this issue.

Best Regards,

Panagiotis


@PanagiotisCharalampous

.ics
25 Aug 2018, 02:40

Automate API 3.01 is nice!


@.ics

thongbaogiaodich
31 Aug 2018, 18:41

Hi,

I have this code

ChartObjects.DrawText("pipsaway", PipsAway, StaticPosition.TopRight);


When I compile in cTrader beta, it show error:

Error CS0612: 'cAlgo.API.StaticPosition' is obsolete
Error CS1501: No overload for method 'DrawText' takes 3 arguments

How can I modify my code to new API?

Thanks!


@thongbaogiaodich

PanagiotisCharalampous
03 Sep 2018, 11:02

Hi thongbaogiaodich,

Here it is

Chart.DrawStaticText("pipsaway", PipsAway, VerticalAlignment.Top, HorizontalAlignment.Right, Color.Red);

Best Regards,

Panagiotis


@PanagiotisCharalampous

AxiomQuant
03 Sep 2018, 17:12

Hi Panagiotis,

could you provide any insight into when the v3.01 could be released to production for brokers? Would be great having the new API available on my life accounts, too

Thank you


@AxiomQuant

PanagiotisCharalampous
04 Sep 2018, 09:59

Hi Vitore,

There is no ETA for release yet but we are in the final stages of beta testing so it should be soon.

Best Regards,

Panagiotis


@PanagiotisCharalampous

daniele84ct
26 Sep 2018, 14:26

Hello, thanks to this new set of API can a programmer create new custom tick charts?

@daniele84ct

PanagiotisCharalampous
26 Sep 2018, 14:32

Hi daniele84ct,

Thanks for posting in our forum. It is possible to create your custom tick charts in cAlgo. You can use this indicator as a guide.

Best Regards,

Panagiotis


@PanagiotisCharalampous

thriscio
26 Sep 2018, 18:23

RE:

Hi ! I have a probleme with new classes for drawing

I get a crash using the new DrawText, Color, DrawHorizontalLine etc..

 

If use the exemple you mentionned

     var line = Chart.DrawHorizontalLine("my line", Symbol.Ask, Color.Red);

 

26/09/2018 15:15:18.000 | Crashed in OnStart with TypeLoadException: Impossible de charger le type 'cAlgo.API.ChartHorizontalLine' à partir de l'assembly 'cAlgo.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3499da3018340880'.

 

Is there anything to do to fix it ? It looks like my reference to cAlgo.API is junk.


@thriscio

Shares4UsDevelopment
12 Nov 2018, 09:57

Spaces in ObjectNames

Hi thriscio

Change 

var line = Chart.DrawHorizontalLine("my line", Symbol.Ask, Color.Red);

to

var line = Chart.DrawHorizontalLine("my_line", Symbol.Ask, Color.Red);

Dont use spaces in ObjectNames


@Shares4UsDevelopment

VertoTrading
23 Nov 2018, 07:38

Draw EMA Trends in cBot

Hey Guys,

Great Update! Been waiting for this for a while.

Just wondering if it is possible to draw an Exponential Moving Average Line in the cBots now?


@VertoTrading

PanagiotisCharalampous
23 Nov 2018, 11:18

Hi sean.n.long,

Thanks for the nice comments. I am not sure what you mean with Exponential Moving Average Line. How is this different from the EMA indicator?

Best Regards,

Panagiotis


@PanagiotisCharalampous

VertoTrading
01 Dec 2018, 10:28

RE:

Panagiotis Charalampous said:

Hi sean.n.long,

Thanks for the nice comments. I am not sure what you mean with Exponential Moving Average Line. How is this different from the EMA indicator?

Best Regards,

Panagiotis

Just wondering if can now draw the indicator in the chart without having a separate indicator running.For example, i am wanting to draw 4 different ema indicators, but i am wanting my cbot to draw them, not manually put them in myself.


@VertoTrading

PanagiotisCharalampous
03 Dec 2018, 10:37

Hi sean.n.long, 

This is not possible at the moment.

Best Regards,

Panagiotis

 


@PanagiotisCharalampous

Vitali Gajdabrus
11 Dec 2018, 23:55 ( Updated at: 21 Dec 2023, 09:21 )

RE:

Panagiotis

How to programmatically read and change (get, set) the state of the cursor?

thank...


@Vitali Gajdabrus

Vitali Gajdabrus
12 Dec 2018, 00:03 ( Updated at: 21 Dec 2023, 09:21 )

RE:

 

Panagiotis

Can I programmatically drawTrendLine in the indicator window?


@Vitali Gajdabrus

PanagiotisCharalampous
12 Dec 2018, 11:47

Hi Vitaly,

Yes you can. See an example below

            Chart.DrawTrendLine("test", Server.Time.AddHours(-24), 1.14, Server.Time, 1.13, Color.Red);
            Chart.IndicatorAreas[0].DrawTrendLine("test", Server.Time.AddHours(-24), 0, Server.Time, 100, Color.Red);

Best Regards,

Panagiotis


@PanagiotisCharalampous

Vitali Gajdabrus
12 Dec 2018, 21:03

RE:

 

Panagiotis

You are the best.
Thank. :)


@Vitali Gajdabrus

Vitali Gajdabrus
25 Dec 2018, 07:54

RE:

Panagiotis Charalampous said:

Hi Vitaly,

Yes you can. See an example below

            Chart.DrawTrendLine("test", Server.Time.AddHours(-24), 1.14, Server.Time, 1.13, Color.Red);
            Chart.IndicatorAreas[0].DrawTrendLine("test", Server.Time.AddHours(-24), 0, Server.Time, 100, Color.Red);

Best Regards,

Panagiotis

How to do it?

[Output("Result_1", Color = Colors.Orange)]
public Chart.IndicatorAreas[0].IndicatorDataSeries Result_1 { get; set; }

[Output("Result_2", Color = Colors.Orange)]
public Chart.IndicatorAreas[1].IndicatorDataSeries Result_2 { get; set; }

 


@Vitali Gajdabrus

PanagiotisCharalampous
27 Dec 2018, 09:54

Hi Vitali,

What do you want to do? It is not clear to me.

Best Regards,

Panagiotis


@PanagiotisCharalampous

Vitali Gajdabrus
27 Dec 2018, 10:15 ( Updated at: 21 Dec 2023, 09:21 )

RE:

 

What do you want to do? It is not clear to me.

I solved my problem.
Many thanks for your attention.
Sorry for my English. 

 


@Vitali Gajdabrus

matt92
10 Jun 2019, 02:29

What does this mean? under Bars on the chart ... Chart.BarsTotal - gets the number of the bars on the chart.

Can this be used to minus 1 live bar off a chart, for instance the new live renko bar, i would love to be able to remove the live bar.


@matt92

PanagiotisCharalampous
10 Jun 2019, 10:21

Hi Matt, 

This property tells you how many bars are on the chart. You cannot use it to dictate which bars will be shown. 

Best Regards,

Panagiotis


@PanagiotisCharalampous

... Deleted by UFO ...

RayAdam
10 Nov 2019, 08:27

ChartObject property access

Hi Support,

Is there a way to update object name which is drawn manually on chart like a trendline. if yes could you please provide an example.

Thanks in advance

 


@RayAdam

PanagiotisCharalampous
11 Nov 2019, 08:53

RE: ChartObject property access

RayAdam said:

Hi Support,

Is there a way to update object name which is drawn manually on chart like a trendline. if yes could you please provide an example.

Thanks in advance

 

Hi RayAdam,

At the moment names are read-only therefore you cannot change a name of an object drawn on the chart.  

Best Regards,

Panagiotis


@PanagiotisCharalampous

... Deleted by UFO ...

... Deleted by UFO ...

... Deleted by UFO ...

prlozc
15 Aug 2024, 19:50

please don't remove Colors enumeration because we can't use Color as a default parameter!!!


@prlozc

PanagiotisCharalampous
16 Aug 2024, 05:08

RE: What's New in cTrader Automate API 3.01

prlozc said: 

please don't remove Colors enumeration because we can't use Color as a default parameter!!!

You can pass the default color as a string


@PanagiotisCharalampous