New Features in cTrader Automate API 3.7

jani's avatar

jani since: 05 Apr 2019;

  13 Feb 2020, 00:28
New Features in cTrader Automate API 3.7

I think it is great that Spotware keeps updating and improving cTrader, and the new additions on 3.7. look very nice!

However, for someone like me with very limited understanding of programming, it is sometimes hard to keep up...

I have also difficulty understanding the API reference syntax, and I really only understand code by seeing examples of it in a code snippet, indicator or cBot.

Would it be possible to get some examples of how to use these new Ticks API data?

Ticks

Automate API adds Ticks to work with tick data.
Ticks is a collection of Tick objects with following properties

Tick.Bid
Tick.Ask
Tick.Time

Note, in the previous versions tick data was accessible only if cBot or indicator was running on Tick1 chart and only for bid prices using old MarketSeries. With the new API you can access tick data from any timeframe and use bid and ask prices

“Markets can remain irrational longer than you can remain solvent.” ― John Maynard Keynes // https://www.youtube.com/watch?v=8GP87dgTqF8
jani's avatar

jani since: 05 Apr 2019;

  20 Feb 2020, 13:09
OpenTime.GetIndexByTime replaced by what?

It's quite frustrating to run into warnings and error messages due to thwe 3,7 changes and there is no instructions on how to replace the old code!

for example, I have:

public Bars hour;

 hour = MarketData.GetBars(TimeFrame.Hour);

public override void Calculate(int index)
        {
              int i_hour = hour.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
          //  int i_hour = hour.OpenTime.GetIndexByTime(Bars.OpenTimes[index]);

....

I cannot find anywhere how to replace

hour.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);

I tried just adding

Bars.OpenTimes[index]

instead of

MarketSeries.OpenTime[index]

but still getting an error message, and the problem is the 

OpenTime

I just cannot find anywhere what to replace it with?

I also have:

_hour[index] = hour.Open[i_hour];

What to replace "Open" with?

API reference is a nightmare to try to find anything (expecially since I do not even know what I'm looking for as old API definitions are removed and new ones I'm not familiar with) and if I do find syntax I usually do not understand it because there are no or only a few short examples... 

Spotware , when you make large changes like 3.7. updates to you API code, please help us less professional programmers to translate the code, that is if you want to keep people like me here...  Would it be totally impossible to have the error message tell what to replace old code with?

“Markets can remain irrational longer than you can remain solvent.” ― John Maynard Keynes // https://www.youtube.com/watch?v=8GP87dgTqF8
PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  20 Feb 2020, 14:19

Hi Jan,

I am not sure how clearer we can make the messages. You get three messages explaining to you exactly what do you need to do.

So as per the messages above

 int i_hour = hour.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);

should become

int i_hour = hour.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);

Is it not understood from the message 

Error CS0618: 'cAlgo.API.Internals.MarketSeries.OpenTime' is obsolete: 'Use Bars.OpenTimes instead'

that MarketSeries.OpenTime should become Bars.OpenTimes?

Also if you use 

  var i = MarketSeries.Open[0];

You will get

 

which I think it describes clearly that it should be changed to

var i = Bars.OpenPrices[0];

as a result

_hour[index] = hour.Open[i_hour]

should become

_hour[index] = hour.OpenPrices[i_hour]

Best Regards,

Panagiotis 

Join us on Telegram

Head of Community Management at cTrader

kerrifox19 since: 11 Dec 2019;

  05 Mar 2020, 16:07

Thanks for sharing this useful info with us.

jani's avatar

jani since: 05 Apr 2019;

  09 Mar 2020, 00:05
Problems with substitutions

I'm still having issues with substituting new API definitions. I tried to do exactly as the warning messages direct, but still unable to find the correct format and getting error messages.

I have:

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;


namespace cAlgo.Indicators
{

    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class HighestHighLowestLow2 : Indicator
    {

        [Parameter(" Period", DefaultValue = 10, MinValue = 1)]
        public int Period { get; set; }

        [Parameter(" Timeframe")]
        public TimeFrame AnotherTimeFrame { get; set; }

        [Output("Close Up", LineColor = "Red")]
        public IndicatorDataSeries CloseUp { get; set; }

        [Output("High", LineColor = "Pink")]
        public IndicatorDataSeries High { get; set; }

        [Output("Close Down", LineColor = "Blue")]
        public IndicatorDataSeries CloseDown { get; set; }

        [Output("Low", LineColor = "Aqua")]
        public IndicatorDataSeries Low { get; set; }

        public MarketSeries dataseries;
        // public Bars dataseries;

        protected override void Initialize()
        {

            dataseries = MarketData.GetSeries(Symbol, AnotherTimeFrame);
            // dataseries = MarketData.GetBars(Symbol, AnotherTimeFrame);
        }

        public override void Calculate(int index)
        {
            // Top[index] = MarketSeries.High.Maximum(PeriodsHigh);
            //Bottom[index] = MarketSeries.Low.Minimum(PeriodsLow);

            High[index] = dataseries.High.Maximum(Period);
            //High[index] = dataseries.Bars.HighPrices.Maximum(Period);

            CloseUp[index] = dataseries.Close.Maximum(Period);
            CloseDown[index] = dataseries.Close.Minimum(Period);
            Low[index] = dataseries.Low.Minimum(Period);
        }
    }
}

I'm getting warnings:

For example if I change 

public MarketSeries dataseries;

to

 public Bars dataseries;

as the instruction says, I get an error:

Sorry to trouble with a similar issue, but I believe I'm not alone here with these 3.7 API substitution troubles...?

“Markets can remain irrational longer than you can remain solvent.” ― John Maynard Keynes // https://www.youtube.com/watch?v=8GP87dgTqF8
PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  09 Mar 2020, 09:16

Hi Jani,

You do the substitution but you do not change the line below to

 dataseries = MarketData.GetSeries(Symbol, AnotherTimeFrame);

to 

dataseries = MarketData.GetBars(AnotherTimeFrame, Symbol.Name);

Here is the updated code

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;


namespace cAlgo.Indicators
{

    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class HighestHighLowestLow2 : Indicator
    {

        [Parameter(" Period", DefaultValue = 10, MinValue = 1)]
        public int Period { get; set; }

        [Parameter(" Timeframe")]
        public TimeFrame AnotherTimeFrame { get; set; }

        [Output("Close Up", LineColor = "Red")]
        public IndicatorDataSeries CloseUp { get; set; }

        [Output("High", LineColor = "Pink")]
        public IndicatorDataSeries High { get; set; }

        [Output("Close Down", LineColor = "Blue")]
        public IndicatorDataSeries CloseDown { get; set; }

        [Output("Low", LineColor = "Aqua")]
        public IndicatorDataSeries Low { get; set; }

        public Bars dataseries;
        // public Bars dataseries;

        protected override void Initialize()
        {

            dataseries = MarketData.GetBars(AnotherTimeFrame, Symbol.Name);
            // dataseries = MarketData.GetBars(Symbol, AnotherTimeFrame);
        }

        public override void Calculate(int index)
        {
            // Top[index] = MarketSeries.High.Maximum(PeriodsHigh);
            //Bottom[index] = MarketSeries.Low.Minimum(PeriodsLow);

            High[index] = dataseries.HighPrices.Maximum(Period);
            //High[index] = dataseries.Bars.HighPrices.Maximum(Period);

            CloseUp[index] = dataseries.ClosePrices.Maximum(Period);
            CloseDown[index] = dataseries.ClosePrices.Minimum(Period);
            Low[index] = dataseries.LowPrices.Minimum(Period);
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram

Head of Community Management at cTrader
jani's avatar

jani since: 05 Apr 2019;

  09 Mar 2020, 10:54
RE:

Thank you Panagiotis,

This was very helpful!

“Markets can remain irrational longer than you can remain solvent.” ― John Maynard Keynes // https://www.youtube.com/watch?v=8GP87dgTqF8

kerrifox19 since: 11 Dec 2019;

  12 Mar 2020, 15:40

All is good as I see.

justinpor119 since: 28 May 2020;

  28 May 2020, 13:31

One can now add custom UI elements and modify chart controls in Automate API for cBots and indicators. Available panels with different layouts and controls feature a variety of options upsers portal

alfredwilliam0809 since: 24 May 2020;

  28 May 2020, 15:34
  • FXStreet Economic Calendar.
  • Multi-Symbol Backtesting for cBots.
  • New Chart Zoom.
  • Freehand Drawing Tool.
  • Detached Chart Containers.
  • Hide Sensitive Information.
  • New Historical Data API.
  • Clouds Between Indicator Lines.
<a href=https://vidmateapp.win/>VidMate</a>[url=https://teatvapk.win/]TeaTV[/url] https://shareitapp.me