Topics

Forum Topics not found

Replies

amusleh
30 Jul 2021, 09:40

RE:

cW22Trader said:

Could you also provide a simple example with an indicator used for multiple symbols at the same time?

Is it still initialized in OnStart? Do I need one per symbol or is this handled automatically?

Kind regards

Please check the example on Market Data API references.


@amusleh

amusleh
30 Jul 2021, 09:37

RE: API Activation Request

opusensemble said:

Hi amusleh, 

My API application is not activated. The current status is "Submitted". 

To have it activated, is it enough to request it here or should I request it through a separate method?

(In case I need to use another method like Email or ticket, kindly let me know the email address or where I should place the ticket)

Looking forward to hearing back from you, 

Best Regards, 
opusensemble

Please send an email to connect@spotware.com and we will activate your app.

Before sending an activation request be sure you fill the application description filled so we will know what you will use the application for.


@amusleh

amusleh
29 Jul 2021, 17:17

Hi,

No, it's not possible, you can use a cBot instead.


@amusleh

amusleh
29 Jul 2021, 14:45

RE: RE:

victor.major said:

amusleh said:

Hi,

Can you send us the troubleshoot report by adding this forum thread URL to your reference description?

You can explain what actions you did that caused cTrader to become unresponsive?

If possible can you send us the code of cBots you used before cTrader became unresponsive?

 

Done.

I can cause even the new version 4.1 to become unresponsive when I switch views from Trade to cBot instance view. In v4.0 cTrader would go unresponsive when I try to scroll through the cBot list on the left of the window. It appears that every time cTrader went unresponsive I was trying to interact with its display, clicking, dragging, selecting, etc.

Hi,

Our team checked your troubleshoot report and they found that the issue is your cBots, in order to reproduce the issue we need your cBot code and a video that shows how to reproduce the issue.


@amusleh

amusleh
29 Jul 2021, 12:52

Hi,

Try this:

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.FullAccess)]
    public class RiskonSL : Robot
    {
        [Parameter("Label", DefaultValue = "")]
        public string _Label { get; set; }

        [Parameter("Risk %", DefaultValue = 1.0, MaxValue = 100.0, MinValue = 0.01, Step = 0.1)]
        public double _RiskPercent { get; set; }

        [Parameter("Max Allowed Lots", DefaultValue = 10.0, MaxValue = 100.0, MinValue = 0.01, Step = 0.01)]
        public double _MaxLots { get; set; }

        [Parameter("Stop Loss", DefaultValue = 10.0, MaxValue = 50.0, MinValue = 0.1, Step = 0.1)]
        public double _SL { get; set; }

        [Parameter("Take Profit", DefaultValue = 15.0, MaxValue = 50.0, MinValue = 0.1, Step = 0.1)]
        public double _TP { get; set; }

        private ExponentialMovingAverage _ema_12;
        private ExponentialMovingAverage _ema_26;
        private bool _ema_buy, _ema_sell;

        protected override void OnStart()
        {
            _ema_12 = Indicators.ExponentialMovingAverage(Bars.ClosePrices, 12);
            _ema_26 = Indicators.ExponentialMovingAverage(Bars.ClosePrices, 26);
        }

        protected override void OnBar()
        {
            var ActiveBuy = Positions.Find(_Label, SymbolName, TradeType.Buy);
            var ActiveSell = Positions.Find(_Label, SymbolName, TradeType.Sell);

            var volume = GetVolume();

            if (_ema_12.Result.HasCrossedAbove(_ema_26.Result.Last(1), 1))
            {
                _ema_buy = true;
                _ema_sell = false;
            }
            else if (_ema_12.Result.HasCrossedBelow(_ema_26.Result.Last(1), 1))
            {
                _ema_sell = true;
                _ema_buy = false;
            }

            if (ActiveBuy == null && _ema_buy)
            {
                if (ActiveSell != null)
                {
                    ClosePosition(ActiveSell);
                }
                ExecuteMarketOrder(TradeType.Buy, SymbolName, volume, _Label, _SL, _TP);
            }

            if (ActiveSell == null && _ema_sell)
            {
                if (ActiveBuy != null)
                {
                    ClosePosition(ActiveBuy);
                }
                ExecuteMarketOrder(TradeType.Sell, SymbolName, volume, _Label, _SL, _SL);
            }
        }

        private double GetVolume()
        {
            double costPerPip = (double)((int)(Symbol.PipValue * 10000000)) / 100;

            double baseNumber = Account.Equity;

            double sizeInLots = Math.Round((baseNumber * _RiskPercent / 100) / (_SL * costPerPip), 2);

            var result = Symbol.QuantityToVolumeInUnits(sizeInLots);

            if (result > Symbol.VolumeInUnitsMax)
            {
                result = Symbol.VolumeInUnitsMax;
            }
            else if (result < Symbol.VolumeInUnitsMin)
            {
                result = Symbol.VolumeInUnitsMin;
            }
            else if (result % Symbol.VolumeInUnitsStep != 0)
            {
                result = result - (result % Symbol.VolumeInUnitsStep);
            }

            return result;
        }
    }
}

 


@amusleh

amusleh
29 Jul 2021, 12:45

Hi,

We just want to be sure that there is such an issue, and if possible can you post a sample cBot code that can replicate this issue.


@amusleh

amusleh
29 Jul 2021, 12:44

Hi,

Can you send us the troubleshoot report by adding this forum thread URL to your reference description?

You can explain what actions you did that caused cTrader to become unresponsive?

If possible can you send us the code of cBots you used before cTrader became unresponsive?


@amusleh

amusleh
29 Jul 2021, 11:02

RE: RE:

khoshroomahdi said:

amusleh said:

Hi,

You can have one line and two outputs, that's exactly what my posted code does.

 i mean 1 output line with two color by condition.

could you please explain me why in plottype.point or dicontinueline or histogram, it's fine but plottype.line we have 2 line.

i couldn't underatnd it.

Hi,

You can't have one output with two-color, the solution is to use two outputs and show only one based on some condition like I did on my code.

The PlotType.Line is continuous, it will always be shown even if you set some values in between to NAN.


@amusleh

amusleh
29 Jul 2021, 10:15

We will investigate this and let you know the result.


@amusleh

amusleh
29 Jul 2021, 09:57

Hi,

Is your API application active? or its status is submitted?

If it's not active then you should contact us and we will activate it for you.


@amusleh

amusleh
29 Jul 2021, 09:53

Hi,

Please post a full cBot sample that uses your calculation code and then we will be able to help you.


@amusleh

amusleh
29 Jul 2021, 09:51

Hi,

Which broker cTrader you are using and which version?

Did you submit the troubleshoot report?

cTrader is not single-threaded, and it uses multiple threads when it needs.


@amusleh

amusleh
29 Jul 2021, 09:48

We have something like that on our backlog but I can't give you any ETA, for now, you can use Open API.


@amusleh

amusleh
29 Jul 2021, 09:44 ( Updated at: 29 Jul 2021, 10:37 )

Hi,

We were able to replicate this issue, we will investigate and update you as soon as possible.


@amusleh

amusleh
29 Jul 2021, 09:32

Hi,

You can have one line and two outputs, that's exactly what my posted code does.


@amusleh

amusleh
29 Jul 2021, 09:30

RE:

SmallStep said:

Hi is v4.0 and brokerage=ICMarkets

I am also getting weird data, eg, I ran VBT from 1/1/2012 to 31/12/2020, start time 0101 to 2359 (bot trading times) i cant get any 2019 or 2020 trades at all. It might be the bot settings, but when i tried with same date ranges, same other settings and time 0101 to 0459, i got some 2020 trades. It might be some bugs with the bot, but would like to know whether there might be the issue and not with ctrader VBT

 

I test but I couldn't replicate the issue, can you record a short video?


@amusleh

amusleh
28 Jul 2021, 14:48

Hi,

Can you post the cBot full code?


@amusleh

amusleh
28 Jul 2021, 14:47

Hi,

Try this:

using System;
using System.Linq;
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 AWMultiData : Indicator
    {
        private TextBlock tb = new TextBlock();

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

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

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

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

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

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

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

        protected override void Initialize()
        {
            Chart.AddControl(tb);
        }

        public override void Calculate(int index)
        {
            if (IsLastBar)
                DisplaySpreadOnChart();
        }

        public void DisplaySpreadOnChart()
        {
            // Calc Spread
            var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
            string sp = string.Format("{0}", spread);

            //Calc daily Net Profit
            double DailyNet1 = Positions.Sum(p => p.NetProfit);
            double DailyNet2 = History.Where(x => x.ClosingTime.Date == Time.Date).Sum(x => x.NetProfit);
            double DailyNet = Math.Round(DailyNet1 + DailyNet2, 2);

            var oldTrades = History.Where(x => x.ClosingTime.Date != Time.Date).OrderBy(x => x.ClosingTime).ToArray();

            // get Starting Balance
            double StartingBalance;

            if (oldTrades.Length == 0)
            {
                StartingBalance = History.Count == 0 ? Account.Balance : History.OrderBy(x => x.ClosingTime).First().Balance;
            }
            else
            {
                StartingBalance = oldTrades.Last().Balance;
            }

            //calc Daily Percent Profit

            string DailyPercent = Math.Round(DailyNet / StartingBalance * 100, 2).ToString();

            //text property
            tb.Text = Symbol.Name + ", " + TimeFrame.ShortName + "\n" + StartingBalance + "\n" + DailyPercent + " %" + "\n" + DailyNet + " $" + "\n" + sp;
            tb.FontSize = FontSize;
            tb.ForegroundColor = Color1.TrimEnd();
            tb.HorizontalAlignment = HAlignment;
            tb.VerticalAlignment = VAlignment;
            tb.TextAlignment = Alignment;
            tb.Margin = Margin;
            tb.Opacity = Opacity;
        }
    }
}

 


@amusleh

amusleh
28 Jul 2021, 14:42

Hi,

It works fine on my system, it works only if new ticks are coming and the market is open.


@amusleh

amusleh
28 Jul 2021, 14:41

Hi,

Your indicator has two outputs, and it should display two lines, not one, it's not a bug.

Even if you don't provide a value for the line it will connect the line by using previous and next values on the output series.

To solve this use DiscontinuousLine or Histogram PlotType:

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MACDHistogram : Indicator
    {

        public MacdHistogram MacdHistogram;

        [Parameter()]

        public DataSeries Source { get; set; }

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }



        [Output("Histogram Up", PlotType = PlotType.DiscontinuousLine, Color = Colors.DodgerBlue)]
        public IndicatorDataSeries HistogramPositive { get; set; }

        [Output("Histogram Down", PlotType = PlotType.DiscontinuousLine, Color = Colors.Red)]
        public IndicatorDataSeries HistogramNegative { get; set; }



        protected override void Initialize()
        {

            MacdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, 9);

        }

        public override void Calculate(int index)
        {
            HistogramPositive[index] = double.NaN;
            HistogramNegative[index] = double.NaN;


            if (MacdHistogram.Histogram[index] > 0)
            {
                HistogramPositive[index] = MacdHistogram.Histogram[index];
            }

            else if (MacdHistogram.Histogram[index] < 0)
            {
                HistogramNegative[index] = MacdHistogram.Histogram[index];
            }

        }
    }
}

 


@amusleh