Topics

Forum Topics not found

Replies

amusleh
14 Sep 2023, 05:58 ( Updated at: 14 Sep 2023, 06:34 )

RE: RE: RE: RE:

andychen said: 

amusleh said: 

opusensemble said:

Hi amusleh, 

Where can the heartbeat documentation or a usage example for Open API be found?

Looking forward to hearing back from you, 
Best Regards, 

Hi,

Please read the documentation connection tutorial.

Hi amusleh,

The connection tutorial link https://spotware.github.io/open-api-docs/connection/ is broken. Could you please share again.
I'm having issue sending the heartbeat request using the python sdk.

Thanks in advance.

Regards

Andy

 

Hi,

Open API documentation is moved to cTrader help portal: Establishing a Connection - Open API (ctrader.com)


@amusleh

amusleh
21 Feb 2023, 18:04 ( Updated at: 21 Feb 2023, 18:06 )

Hi,

This works fine for me on 4.6.2 and .NET 6:

using System;
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
{
    [Indicator(AccessRights = AccessRights.None)]
    public class ComboBoxTest : Indicator
    {
        private ComboBox myDropList;

        protected override void Initialize()
        {
            myDropList = new ComboBox
            {   
                Width = 100,
                Height = 20,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                VerticalContentAlignment = VerticalAlignment.Center
            };
            
            myDropList.AddItem("Item 1");
            myDropList.AddItem("Item 2");
            myDropList.AddItem("Item 3");
            
            Chart.AddControl(myDropList);
            

            myDropList.SelectedItemChanged += myDropList_SelectedIndexChanged;

        }
        
        private void myDropList_SelectedIndexChanged(ComboBoxSelectedItemChangedEventArgs e)
        {
            if (myDropList.SelectedIndex != -1)
            {
                string selectedValue = myDropList.SelectedItem.ToString();

                switch (selectedValue)
                {
                    case "Item 1":
                        Print("Item 1 selected");
                        break;
                    case "Item 2":
                        Print("Item 2 selected");
                        break;
                    case "Item 3":
                        Print("Item 3 selected");
                        break;
                    default:
                        MessageBox.Show("The selected item was not recognized. Please contact the developer for assistance. Telegram: @DelFonseca");
                        break;
                }
            }
            else
            {
                MessageBox.Show("Please select an item from the dropdown list.");
            }
        }

        public override void Calculate(int index)
        {
            //...
        }
    }
}

 

Check event signature before using it: SelectedItemChanged Event - cTrader Automate API


@amusleh

amusleh
21 Jun 2022, 10:43

RE: RE:

m4trader4 said:

With the above approach there can be positive or negative pips at target (take profit). The same can be done through CTrader gui.

How to approach the same?

 

Hi,

Not sure what do you mean by positive / negative Pips, you can create the same cTrader advanced take profit functionality inside your cBot.

Check the number of Positions Pips on each OnTick, if it reached X pips close X% of it's volume, and record the position on a collection like a List.

It all depends on your coding skill.


@amusleh

amusleh
21 Jun 2022, 10:40

RE: RE:

Hi,

But in 4.1 it was not the behaviour what changed

Yes, this is a behavior change, we are not going to change it back to 4.1 behavior as it's not possible.

Let me know how this can be achieved with FORM or without FORM

We are going to add dialog and window to the API that mimics the looks of cTrader and uses current controls, then you don't have to use WinForms or WPF.

Is there a way to move a button within the child window

What do you mean?


@amusleh

amusleh
21 Jun 2022, 09:31

Hi,

You have to contact your broker, and if your account is from Spotware beta demo then we can do it for you.

Send us an email with your account detail: connect@spotware.com


@amusleh

amusleh
21 Jun 2022, 09:30

Hi,

You can't change the name of your strategy.


@amusleh

amusleh
21 Jun 2022, 09:26

Hi,

This indicator might help you: Chart Navigator - AlgoDeveloper


@amusleh

amusleh
21 Jun 2022, 09:25

RE:

hamijonz said:

amusleh said:

Hi,

You just have to iterate over a data series points with a loop and find the minimum or maximum values.

DateSeries itself has minimum and maximum extension methods: 

Minimum Method - cTrader Automate API

Maximum Method - cTrader Automate API

You can also use a for loop or Linq.

Hi, thank you, but I didn't mean that. I want to get it more precisely
And I don't want to get the maximum of ten previous candlesticks, for example, I just want to get the highest previous and the highest two previous ones
For example, I want to say that if the last value of RSI exceeds the previous highest point, open a buy position.
I hope you understand what I mean

Hi,

You can use the DataSeries Maximum / Minimum methods for that, just use Maximum to find the highest value of RSI on x previous bars, then compare it with current RSI value.

 


@amusleh

amusleh
21 Jun 2022, 09:23

Hi,

You can't break a position, but you can check if the position profit reached x pips and then close x% of it's volume.


@amusleh

amusleh
21 Jun 2022, 09:22

Hi,

If you open a the window from a detached chart then it will appear behind the chart, if you open the window from an attached chart then it will appear over cTrader main window.

As your indicator / cBot runs from their own process it doesn't know about the cTrader windows so it's not possible for us to change this behavior.


@amusleh

amusleh
20 Jun 2022, 14:29 ( Updated at: 20 Jun 2022, 14:34 )

RE: RE:

firemyst said:

amusleh said:

Hi,

So you are trying to calculate the Pips for positions that are partially closed or added?

If that's what you are looking to do then you can't, because the API doesn't give you the data for partially closed / added positions.

When you close part of a position or add more volume to it the history is not updated until you close the whole position, nor the positions closed / opened events are triggered.

 

 

 

But there's obviously some mathematical formula that's used because cTrader does it.

As I mentioned in my original post, I keep track of each position's volume and entry price that are added (eg, I have my own history), so I should be able to do it before the position is closed just like cTrader.

So, can't you look at cTrader's source code and tell me what formula it's using to do its live calculation? :-)

Thank you.

 

Hi,

The cTrader Pips column shows the different in Pips between position entry price and current price.

If you add new volume to the position then the entry price of position will change, and for Pips it will use the new entry price.

That's how it's calculated on cTrader, so for:

What I mean by overall pips is if my positions are:

1) 10000 units of EURCAD @ 1.3547

2) 1000 units of EURCAD @ 1.3562

3) 1000 units of EURCAD @ 1.36701

and price is currently at 1.35835

cTrader will use 1.36701 as entry price and 1.35835 as current price, the difference will be position Pips, it doesn't take into account the previous entry prices.


@amusleh

amusleh
20 Jun 2022, 11:49

Hi,

So you are trying to calculate the Pips for positions that are partially closed or added?

If that's what you are looking to do then you can't, because the API doesn't give you the data for partially closed / added positions.

When you close part of a position or add more volume to it the history is not updated until you close the whole position, nor the positions closed / opened events are triggered.

 

 

 


@amusleh

amusleh
20 Jun 2022, 11:02 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE:

firemyst said:

amusleh said:

Hi,

Can you tell me which column you are talking about? I can't find any overall Pips column in cTrader.

The "Pips" column as per the "Positions" and "History" tabs:

Thank you.

Hi,

The method I posted will give you the same value that you see on Pips columns with some fraction error due to rounding or delay.

There is no overall Pips, each position Pips is separate and it's not related to other positions.


@amusleh

amusleh
20 Jun 2022, 11:00

Hi,

10 is the maximum number of winning trades on a row combined long and short.

12 is the number of consecutive winning trades if you only consider long trades, so in between those 12 trades there were some losing short trades.

That's how it's calculated, the values are valid.


@amusleh

amusleh
20 Jun 2022, 10:06 ( Updated at: 20 Jun 2022, 10:07 )

Hi,

I just tested WinForms top most and it worked fine, I had several child windows and the WinForms window were over all of them.

The only issue I noticed was with file dialogs, they appear on the back of cTrader main window.

Check here: WinForms - cTrader Automate API

You can try the last WinForms sample and set it's top most to True before ShowDialog call.

And please post a full sample cBot code that can reproduce the issue.


@amusleh

amusleh
20 Jun 2022, 09:56 ( Updated at: 20 Jun 2022, 09:58 )

Hi,

The first request you send to server should be application authentication request not account auth request.

You can find the guide at: Connection - cTrader Open API

For sending and receiving data read: Sending/Receiving - cTrader Open API

For Python specific guide check the comments section at Sending / Receiving Messages tutorial page.

And it's not gRPC, it's just plain direct TCP client connection.


@amusleh

amusleh
20 Jun 2022, 09:53

Hi,

Try this:

using cAlgo.API;
using System.Linq;
using System;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWBoxOffline2 : Indicator
    {
        private ChartVerticalLine _vl;

        private ChartRectangle _box;
        
        private ChartTrendLine _midline;

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

        [Parameter("Line Color", DefaultValue = "Red", Group = "Line")]
        public string LineColor { get; set; }

        [Parameter("LineStyle", DefaultValue = LineStyle.Solid, Group = "Line")]
        public LineStyle ls { get; set; }

        [Parameter("Thickness", DefaultValue = 2, Group = "Line")]
        public int Thickness { get; set; }
        
        [Parameter("Mid Line", DefaultValue = true, Group = "Mid Line")]
        public bool Midline { get; set; }
        
        [Parameter("Mid Line Color", DefaultValue = "Red", Group = "Mid Line")]
        public string Color2 { get; set; }
        [Parameter("Mid Line Style", DefaultValue = LineStyle.Solid, Group = "Mid Line")]
        public LineStyle ls2 { get; set; }
        [Parameter("Mid Line Thickness", DefaultValue = 2, Group = "Mid Line")]
        public int Thickness2 { get; set; }

        protected override void Initialize()
        {
            _vl = Chart.DrawVerticalLine("scrollLine", Chart.LastVisibleBarIndex, Color.FromName(LineColor), Thickness, ls);
            _vl.IsInteractive = true;
            var verticalLineBarIndex = Bars.OpenTimes.GetIndexByTime(_vl.Time);
            
             if (Midline)
            {
                _midline = Chart.DrawTrendLine("trendLine",verticalLineBarIndex , (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2, verticalLineBarIndex-Period, (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2,Color2,Thickness2,ls2);
            }


            _box = Chart.DrawRectangle("rectangle_sample", verticalLineBarIndex, Bars.LowPrices.Minimum(Period), verticalLineBarIndex - Period, Bars.HighPrices.Maximum(Period), Color.FromArgb(100, Color.Red));
            _box.IsFilled = true;
            _box.IsInteractive = false;
            _box.IsFilled = false;
            _box.Thickness = Thickness;
            _box.Color = LineColor;
            _box.LineStyle = ls;

            Chart.ObjectsUpdated += Chart_ObjectsUpdated;
        }

        private void Chart_ObjectsUpdated(ChartObjectsUpdatedEventArgs obj)
        {
            if (!obj.ChartObjects.Contains(_vl))
                return;

            var verticalLineBarIndex = Bars.OpenTimes.GetIndexByTime(_vl.Time);

            _box.Time1 = Bars.OpenTimes[verticalLineBarIndex];
            _box.Time2 = Bars.OpenTimes[verticalLineBarIndex - Period];

            _box.Y1 = GetMinimum(Bars.LowPrices, verticalLineBarIndex, Period);
            _box.Y2 = GetMaximum(Bars.HighPrices, verticalLineBarIndex, Period);
            
            _midline.Time1= _box.Time1;
            _midline.Time2 = _box.Time2;

            _midline.Y1= _box.Y1 + ((_box.Y2 - _box.Y1) / 2);
            _midline.Y2 = _midline.Y1;
        }

        private double GetMinimum(DataSeries source, int index, int periods)
        {
            double min = double.MaxValue;

            var lastBarIndex = index - periods;

            for (int i = index; i > lastBarIndex; i--)
            {
                min = Math.Min(min, source[i]);
            }

            return min;
        }

        private double GetMaximum(DataSeries source, int index, int periods)
        {
            double max = double.MinValue;

            var lastBarIndex = index - periods;

            for (int i = index; i > lastBarIndex; i--)
            {
                max = Math.Max(max, source[i]);
            }

            return max;
        }

        public override void Calculate(int index)
        {
        }
    }
}

 


@amusleh

amusleh
20 Jun 2022, 09:49

Hi,

You have to contact the software developer and report them this issue, this error happens if the number of Open API requests per second exceeded the limitation, you can find more detail at: https://help.ctrader.com/open-api/proxies-endpoints/#limitations


@amusleh

amusleh
20 Jun 2022, 09:47

Hi,

You can access more than one symbol data on back test environment, you just have to load the symbols data, create separate instances of indicators you use for each symbol data.


@amusleh

amusleh
20 Jun 2022, 09:36

Hi,

I just tested it on Visual Back test mode, and it plays the alert sound, you have to set the Sound File Path parameter to the path of a .WAV sound file and then it will play it if two lines cross each other.


@amusleh