Topics

Forum Topics not found

Replies

amusleh
31 Dec 2021, 08:48

Hi,

You can't use the bar counter on chart from Automate API, and there is no need for it.

You can easily code one, each bar has an open time and if you know the time frame you can subtract the bar open time from current time, ex:

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        private TimeSpan _barTimeLeft;

        protected override void OnStart()
        {
            Timer.Start(1);
        }
        
        protected override void OnTimer()
        {
            var previousBarTimePeriod = Bars.LastBar.OpenTime - Bars.Last(1).OpenTime;

            _barTimeLeft = previousBarTimePeriod - (Server.Time - Bars.LastBar.OpenTime);
            
            // Check logs, it should match with chart counter
            Print("{0:hh':'mm':'ss}", _barTimeLeft);

            // Close all positions if the time left is less than or equal 10 seconds
            if (_barTimeLeft.TotalSeconds <= 10)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);
                }
            }
        }
    }
}

 


@amusleh

amusleh
31 Dec 2021, 07:25

Hi,

Please follow this instruction: Creating an Indicator | cTrader Help Center


@amusleh

amusleh
30 Dec 2021, 15:45

Hi,

Try this:

using System;
using cAlgo.API;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class RoundNumbers : Indicator
    {
        [Parameter("Line Color", DefaultValue = "Gray")]
        public string LineColor { get; set; }

        [Parameter("Color", DefaultValue = 255, MinValue = 0, MaxValue = 255)]
        public int ColorAlpha { get; set; }

        [Parameter(DefaultValue = 100)]
        public int StepPips { get; set; }

        protected override void Initialize()
        {
            double max = Bars.HighPrices.Maximum(Bars.HighPrices.Count);

            double min = Bars.LowPrices.Minimum(Bars.LowPrices.Count);

            double step = Symbol.PipSize * StepPips;

            double start = Math.Floor(min / step) * step;

            var color = GetColor(LineColor, ColorAlpha);

            for (double level = start; level <= max + step; level += step)
            {
                Chart.DrawHorizontalLine("line_" + level, level, color);
            }
        }

        public override void Calculate(int index)
        {
        }

        private Color GetColor(string colorString, int alpha = 255)
        {
            var color = colorString[0] == '#' ? Color.FromHex(colorString) : Color.FromName(colorString);

            return Color.FromArgb(alpha, color);
        }
    }
}

You can use any Color name or hexadecimal color code for line color parameter, with Color alpha you can control the color transparency.


@amusleh

amusleh
30 Dec 2021, 14:57

Hi,

Please post the code of indicator and then we will be able to help you.


@amusleh

amusleh
30 Dec 2021, 08:36

Hi,

You can draw a vertical line on any time you want to, you just have to pass the time.

Use a loop and draw a line every day at 22 GMT, here is an example that might help you: 

 


@amusleh

amusleh
30 Dec 2021, 08:34

Hi,

1. Yes, it can modify any pending order or position, it doesn't matter if its created by itself or manually or by any other cBot

2. It can, you have to reference/add the indicator on your cBot

3. No, you can't, you have to do it with code


@amusleh

amusleh
29 Dec 2021, 08:58

Hi,

Do you mean something like this:

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TopYbottomYtest : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        protected override void Initialize()
        {
            if (Source == Bars.HighPrices)
            {
                Print("High Prices");
            }
        }

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

 


@amusleh

amusleh
29 Dec 2021, 08:53

Hi,

Right now this information is not available on Automate API, if you want to you can create a thread under suggestions section for it.


@amusleh

amusleh
28 Dec 2021, 08:00

Hi,

On your first post you just asked for Bollinger bands cross, you didn't mentioned any other indicator.

When you post code please use the editor "Insert Code Snippet" option.

The issue with your code is invalid indicator index, if you are using this code on a cBot try to use .Last(1) or .Last(2), you shouldn't pass the bar index which starts from beginning because the Last method uses reverse indexing.

And the LastValue property gives you the latest value inside indicator series, you should not use it because it will give non deterministic results as the last value isn't completed yet and it can change.

For more please check code examples on automate API references.


@amusleh

amusleh
27 Dec 2021, 09:10

Hola,

Publique una solicitud de trabajo o pídale ayuda a uno de nuestros consultores.

Solo brindamos asistencia en inglés; si es posible, escriba en inglés.


@amusleh

amusleh
27 Dec 2021, 09:00

Hi,

As I said it works fine on my system:

Can you tell what's you system graphics card? most probably that's the issue as it can't process fast enough that amount of data.


@amusleh

amusleh
24 Dec 2021, 11:24

Hi,

I tired with your exact code and its working fine, I replicated your actions on the video and the bottom line didn't disappeared.

Can you tell me which broker cTrader you are using or which version? I tried on Spotware Beta cTrader 4.1.


@amusleh

amusleh
24 Dec 2021, 07:57

Hi,

It works fine, try this:

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TopYbottomYtest : Indicator
    {
        private double topY, bottomY;

        protected override void Initialize()
        {
            TopBottomYtest();
            Chart.ScrollChanged += onscrollchanged;
        }

        private void onscrollchanged(ChartScrollEventArgs f)
        {
            TopBottomYtest();
        }

        private void TopBottomYtest()
        {
            topY = Math.Round(Chart.TopY, Symbol.Digits);
            bottomY = Math.Round(Chart.BottomY, Symbol.Digits);
            Chart.DrawStaticText("test", "TOP " + topY.ToString() + " Bottom " + bottomY.ToString(), VerticalAlignment.Bottom, HorizontalAlignment.Center, Color.Red);
            Chart.DrawTrendLine("trendlinetesttop", Chart.FirstVisibleBarIndex, Chart.TopY, Chart.LastVisibleBarIndex, Chart.TopY, Color.Red, 30);
            Chart.DrawTrendLine("trendlinetestbottom", Chart.FirstVisibleBarIndex, Chart.BottomY, Chart.LastVisibleBarIndex, Chart.BottomY, Color.Red, 30);
        }

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

 


@amusleh

amusleh
24 Dec 2021, 07:51

Hi,

Its possible, please post a job request or contact one of our consultants.


@amusleh

amusleh
24 Dec 2021, 07:47

Hi,

It will be released in next few weeks.


@amusleh

amusleh
23 Dec 2021, 11:25 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

firemyst said:

amusleh said:

 

The clouds uses output color which user can change, the color is not hardcoded, the output names are.

How does a user change the output color?

 

I have several indicators with "clouds" on them and cannot see anywhere in the indicator properties to change the colors of the clouds between the lines -- only the "lines" that make up the indicator.

 

Nothing in the online API reference seems to indicate how either:

https://ctrader.com/api/reference/cloudattribute

Thank you

Hi,

Did you tried the example indicator on API references?

If one output line goes above the other then the color change to that output line color. you don't have to provide the color for cloud attribute, that's optional.


@amusleh

amusleh
23 Dec 2021, 09:10

RE:

firemyst said:

While a nice feature (and finally catching up with the competition), it would be nice if the Spotware cTrader team even allowed end users to be able to select their own colors rather than what the programmer does!

The @Spotware team needs some sort of human-interface engineer (or someone) when implementing such features -- it's ridiculous that a charting feature with colors is implemented and end users have no way to change/customize it. Certainly doesn't put "traders first".

The clouds uses output color which user can change, the color is not hardcoded, the output names are.


@amusleh

amusleh
23 Dec 2021, 09:08

Hi,

What do you mean by: "i dont' know how to add signal line cross histogram to it?"

Can you show this on a chart screenshot?

Not sure about the exact size of library but if you use the newer version library the size might reduce.

You don't need that library to show a popup alert or play a sound alert.

cTrader automate API has the email and sound alert itself under Notifications: cAlgo API Reference - INotifications Interface (ctrader.com)

 


@amusleh

amusleh
22 Dec 2021, 09:28

Hi,

Please read API references and check the examples there before asking a question: cAlgo API Reference - ChartHorizontalLine Interface (ctrader.com)

Try this:

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWCPDaily : Robot
    {
        private TextBlock tb = new TextBlock();
        private ChartHorizontalLine sll;

        [Parameter("Take Profit", DefaultValue = 100)]
        public double tp { get; set; }

        [Parameter("Stop Profit", DefaultValue = 90)]
        public double sl { get; set; }

        [Parameter("FontSize", DefaultValue = 16, Group = "Text")]
        public int FontSize { get; set; }

        [Parameter("Space to Corner", DefaultValue = 10, Group = "Text")]
        public int Margin { get; set; }

        [Parameter("Horizental Alignment", DefaultValue = HorizontalAlignment.Left, Group = "Text")]
        public HorizontalAlignment HAlignment { get; set; }

        [Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top, Group = "Text")]
        public VerticalAlignment VAlignment { get; set; }

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

        [Parameter("Opacity", DefaultValue = 0.7, MinValue = 0.1, MaxValue = 1, Group = "Text")]
        public double Opacity { get; set; }

        [Parameter("Text Alignment", DefaultValue = TextAlignment.Center, Group = "Text")]
        public TextAlignment Alignment { get; set; }

        protected override void OnStart()
        {
            var y = Chart.BottomY + ((Chart.TopY - Chart.BottomY) / 2);

            sll = Chart.DrawHorizontalLine("horizontal", y, Color.Red);

            sll.IsInteractive = true;

            Chart.AddControl(tb);
            tb.Text = "sl : " + sl.ToString() + ", " + "tp : " + tp.ToString() + "\n EQ: " + Account.Equity + ", ML%: " + Account.MarginLevel + "\nVP: " + Account.Margin / Account.Balance + "V: " + sll.Y;
            tb.FontSize = FontSize;
            tb.ForegroundColor = Color1.TrimEnd();
            tb.HorizontalAlignment = HAlignment;
            tb.VerticalAlignment = VAlignment;
            tb.TextAlignment = Alignment;
            tb.Margin = Margin;
            tb.Opacity = Opacity;
        }

        protected override void OnTick()
        {
            foreach (var position in Positions)
            {
                if (Account.Equity > tp || Account.Equity < sl)
                {
                    ClosePositionAsync(position);
                }
            }

            foreach (var order in PendingOrders)
            {
                if (Account.Equity > tp || Account.Equity < sl)
                {
                    CancelPendingOrder(order);
                }
            }
        }
    }
}

You have to set a chart object IsInteractive property to true, then you will be able to change it on the chart.


@amusleh

amusleh
22 Dec 2021, 09:24

Hi,

Try this:

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        private BollingerBands _bbands;

        protected override void OnStart()
        {
            _bbands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);
        }

        protected override void OnBar()
        {
            // When a bar crossed upper band from below
            if (Bars.Last(2).High < _bbands.Top.Last(2) && Bars.Last(1).High > _bbands.Top.Last(1))
            {

            }

            // When a bar crossed upper band from above
            if (Bars.Last(2).Low > _bbands.Top.Last(2) && Bars.Last(1).Low < _bbands.Top.Last(1))
            {

            }
        }
    }
}

 


@amusleh