Topics

Forum Topics not found

Replies

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

amusleh
20 Jun 2022, 09:24

Hi,

You can use synchronized crosshair indicator: Synchronized Crosshair Indicator | Algorithmic Forex Trading | cTrader Community


@amusleh

amusleh
20 Jun 2022, 09:22 ( Updated at: 20 Jun 2022, 09:23 )

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.


@amusleh

amusleh
20 Jun 2022, 09:20

Hi,

Please post a sample cBot code with optimization settings that can reproduce this issue.


@amusleh

amusleh
20 Jun 2022, 09:20

Hi,

The historical data for sentiment is not available on any of cTrader APIs so there is no indicator for showing the historical sentiment data.


@amusleh

amusleh
20 Jun 2022, 09:18

Hi,

You have to check your account smarginLevelThreshold , and you can change the threshold.

Here you can find more detail: Messages - cTrader Open API

 


@amusleh

amusleh
20 Jun 2022, 09:14

Hi,

I just tested, I created a new demo account and then I got a new token and the newly created demo account was returned by ProtoOAGetAccountListByAccessTokenReq request.


@amusleh

amusleh
20 Jun 2022, 08:48

Hi,

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


@amusleh

amusleh
17 Jun 2022, 11:00

Hi,

Historical price data are created from live price data, they are not different at all.

The issue you faced is a bug, it's not because the historical data is generated from different price data.

We were able to reproduce this issue and it will be fixed on next release of cTrader web.


@amusleh

amusleh
17 Jun 2022, 10:58

RE: RE: RE: Any Australian brokers yet?

ctid4797769 said:

amusleh said:

ctid2514471 said:

Are any Australian brokers offering Desktop 4.2 as yet?
The Australian brokers just say "We offer cTrader" - But they don't specify which version.

The improvements here sound awesome, as a few of the improvements address issues that made me give up on my algorithmic trading ideas.

Hi,

All cTrader brokers will be updated to latest version eventually, we are rolling out version 4.2 slowly for all brokers.

 

Do we know who will be the first and a more specific when? There are key features we have been waiting for so I think everybody want to move :-)

Hi,

We can't give you any ETA, we already released version 4.2 for some brokers, it will be released for other brokers in near future.


@amusleh

amusleh
17 Jun 2022, 10:56

Hi,

All technical indicators last value will keep changing until it closes, so for tow hour stochastic you have to wait two hours for the last value to close and then use it, otherwise it can keep changing based on bar price changes.

It's not a bug nor a problem of cTrader, it's same across all platforms and it's how technical indicators work, and yes they are lagging.


@amusleh

amusleh
17 Jun 2022, 10:53

Hi,

You can pass another time frame Bars to ADX indicator:

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class ADXOtherTimeFrame : Robot
    {
        private DirectionalMovementSystem _adx;
        private Bars _otherTimeFrameBars;

        [Parameter("Other Time Frame")]
        public TimeFrame OtherTimeFrame { get; set; }

        [Parameter("Periods")]
        public int Periods { get; set; }

        protected override void OnStart()
        {
            _otherTimeFrameBars = MarketData.GetBars(OtherTimeFrame);

            _adx = Indicators.DirectionalMovementSystem(_otherTimeFrameBars, Periods)
        }
    }
}

 


@amusleh

amusleh
17 Jun 2022, 10:47

Hi,

A position comment or label can be null, so you have to check them before dereferencing them otherwise you will get null reference exception.

You should your code to:

        private void Positions_Opened(PositionOpenedEventArgs obj)
        {
            BeginInvokeOnMainThread(() =>
            {
                var psn = obj.Position;
                Print(GlobalSymbolName + "::Event Positions Opened....");
                if (psn.SymbolName.Equals(GlobalSymbolName, StringComparison.Ordinal) && psn.TradeType == TradeType.Buy && !string.IsNullOrWhiteSpace(psn.Comment) && psn.Comment.Contains("AO", StringComparison.Ordinal))
                {
                    Print(GlobalSymbolName + "Buy Opened Position opened id====" + psn.Id);
                    // GlobalBuyPositionsIds.Add(obj.Position.Id);
                    // GlobalBuyPositionsIds.TrimExcess();
                    //   Print(SymbolName + "GlobalBuyPositionsidList=" + GlobalBuyPositionsIds[0]);
                }

                if (psn.SymbolName.Equals(GlobalSymbolName, StringComparison.Ordinal) && psn.TradeType == TradeType.Sell && !string.IsNullOrWhiteSpace(psn.Comment) && psn.Comment.Contains("AO", StringComparison.Ordinal))
                {
                    Print(GlobalSymbolName + "Sell Opened Position opened id====" + psn.Id);
                    // GlobalSellPositionsIds.Add(obj.Position.Id);
                    // GlobalSellPositionsIds.TrimExcess();
                    //   Print(SymbolName + "GlobalSellPositionsidList=" + GlobalSellPositionsIds[0]);
                }
            }
            );
        }

 


@amusleh

amusleh
17 Jun 2022, 10:25

Hi,

Can you tell what do you mean by overall Pips? cTrader Pips column shows the amount of Pips for your Position which you can get via Pips property of a Position.

To calculate it programmatically you can subtract the current price from Position entry price:

        private double GetPositionPips(Position position)
        {
            var symbol = Symbols.GetSymbol(position.SymbolName);

            return Math.Round((position.TradeType == TradeType.Buy ? symbol.Bid - position.EntryPrice : position.EntryPrice - symbol.Ask) / symbol.PipSize, 1);
        }

 


@amusleh

amusleh
17 Jun 2022, 09:44

Hi,

I checked your video, it looks like your broker lost connection to their price feed provider, please contact your broker and they should help you.


@amusleh

amusleh
16 Jun 2022, 10:17 ( Updated at: 19 Mar 2025, 08:57 )

Hi,

Please record a video from your screen and send a troubleshoot report with forum thread link.

To send a troubleshoot report press Ctrl+Alt+Shift+T.

Post the video here or send it to our email: support@ctrader.com


@amusleh

amusleh
16 Jun 2022, 10:08

Hi,

Your indicator code has a bug, you access the Last(1) which means there should be at least two bars inside Bars collection two access the last second one, and if it's the first bar then it throws argument out of range exception.

You should check IsLastBar of Index == 0, try 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 DailyPriceLines : Indicator
    {
        private Bars _bars;
        
        [Parameter("High", DefaultValue = true)]
        public bool High { get; set; }

        [Parameter("Low", DefaultValue = true)]
        public bool Low { get; set; }

        [Parameter("Open", DefaultValue = true)]
        public bool Open { get; set; }

        [Parameter("Close", DefaultValue = true)]
        public bool Close { get; set; }

        [Parameter("High Color", DefaultValue = "Red")]
        public string HighColor { get; set; }

        [Parameter("Low Color", DefaultValue = "Lime")]
        public string LowColor { get; set; }

        [Parameter("Open Color", DefaultValue = "Transparent")]
        public string OpenColor { get; set; }

        [Parameter("Close Color", DefaultValue = "Transparent")]
        public string CloseColor { get; set; }



        protected override void Initialize()
        {
            _bars = MarketData.GetBars(TimeFrame.Daily);
        }

        public override void Calculate(int index)
        {
            // This or index == 0 will fix the issue
            if (!IsLastBar) return;
            
            if (High)
                Chart.DrawHorizontalLine("Daily Heigh", _bars.HighPrices.Last(1), HighColor, 1, LineStyle.Dots);

            if (Low)
                Chart.DrawHorizontalLine("Daily Low", _bars.LowPrices.Last(1), LowColor, 1, LineStyle.Dots);

            if (Open)
                Chart.DrawHorizontalLine("Daily Open", _bars.OpenPrices.Last(1), OpenColor, 1, LineStyle.Dots);

            if (Close)
                Chart.DrawHorizontalLine("Daily Close", _bars.ClosePrices.Last(1), CloseColor, 1, LineStyle.Dots);
        }
    }
}

 


@amusleh