PanagiotisCharalampous's avatar
PanagiotisCharalampous
26 follower(s) 0 following 1006 subscription(s)
Replies

PanagiotisCharalampous
10 Oct 2019, 12:22

Hi social.trading

The below seems to work fine for me

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.FileSystem)]
    public class LvAMaCross : Indicator
    {
        [Parameter("MA Type", DefaultValue = MovingAverageType.TimeSeries)]
        public MovingAverageType maType { get; set; }

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

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

        [Parameter("Time Frame MA", DefaultValue = "Hour")]
        public TimeFrame timeFrame { get; set; }


        [Output("Sell Point", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 15)]
        public IndicatorDataSeries SellSeries { get; set; }

        [Output("Buy Point", Color = Colors.Blue, PlotType = PlotType.Points, Thickness = 15)]
        public IndicatorDataSeries BuySeries { get; set; }

        public bool alreadyPlayed = false;

        public IndicatorDataSeries FastDataSeries { get; set; }

        public IndicatorDataSeries SlowDataSeries { get; set; }


        //market series cho timeframe cần tính
        public MarketSeries selectedSeries;

        public MovingAverage fastMA;
        public MovingAverage slowMA;
        int _previousIndex;
        protected override void Initialize()
        {
            FastDataSeries = CreateDataSeries();
            SlowDataSeries = CreateDataSeries();

            if (timeFrame == MarketSeries.TimeFrame)
            {
                selectedSeries = MarketSeries;
                fastMA = Indicators.MovingAverage(MarketSeries.Close, fastPeriod, maType);
                slowMA = Indicators.MovingAverage(MarketSeries.Close, slowPeriod, maType);
            }
            else
            {
                selectedSeries = MarketData.GetSeries(timeFrame);
                fastMA = Indicators.MovingAverage(selectedSeries.Close, fastPeriod, maType);
                slowMA = Indicators.MovingAverage(selectedSeries.Close, slowPeriod, maType);
            }

        }

        public override void Calculate(int index)
        {
            var selectedIndex = selectedSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);

            if (selectedIndex == -1)
            {
                return;
            }
            if (selectedIndex != _previousIndex)
            {
                _previousIndex = selectedIndex;
                alreadyPlayed = false;
            }
            FastDataSeries[index] = fastMA.Result[selectedIndex];
            SlowDataSeries[index] = slowMA.Result[selectedIndex];

            if (isCrossBelow())
            {

                // sell
                SellSeries[index] = MarketSeries.High[index];

                if (IsLastBar)
                {
                    ChartObjects.DrawText("text1", "SELL", StaticPosition.Center, Colors.White);
                    if (!alreadyPlayed)
                    {
                        ChartObjects.DrawText("", "" + alreadyPlayed, StaticPosition.BottomRight, Colors.White);
                        Notifications.PlaySound("C:\\Windows\\Media\\notify.wav");
                        Print("Play Sell Sound");
                        alreadyPlayed = true;

                    }
                }
            }


            else if (isCrossAbove())
            {
                // buy 
                BuySeries[index] = MarketSeries.Low[index];
                if (IsLastBar)
                {
                    ChartObjects.DrawText("text1", "BUY", StaticPosition.Center, Colors.White);
                    if (!alreadyPlayed)
                    {
                        ChartObjects.DrawText("", "" + alreadyPlayed, StaticPosition.TopRight, Colors.White);
                        Notifications.PlaySound("C:\\Windows\\Media\\notify.wav");
                        Print("Play Buy Sound");
                        alreadyPlayed = true;
                    }
                }
            }
        }

        #region Predicate
        public bool isCrossAbove()
        {
            return FastDataSeries.HasCrossedAbove(SlowDataSeries, 0);
        }
        public bool isCrossBelow()
        {
            return FastDataSeries.HasCrossedBelow(SlowDataSeries, 0);
        }
        #endregion
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
10 Oct 2019, 11:56

Hi Xavier R,

This is a bug. We will fix it in an update.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
10 Oct 2019, 11:46

Hi enam3074,

There are no limitations for the number of symbols at the moment.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
10 Oct 2019, 11:12

Hi social.trading,

Did you check if the specific part of the code is executed? If no, you should investigate the reason. If yes, please make sure that the sound file is in the correct location. It would be better to start with an empty indicator and try to make the sound play on each bar change. After that works successfully, add the functionality to the existing indicator.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
10 Oct 2019, 10:45

Hi social.trading,

The way you have programmed it, it will play the sound only once and then it will stop working. You will need to reset the alreadyPlayed on the change of each bar. 

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
10 Oct 2019, 09:55

Hi social.trading,

First of all it would be better if you could post the complete cBot code. It is not clear what is the code supposed to do. Then give us a clear explanation of what do you expect the cBot to be doing. Why do you have a loop? Also why do you need to have the sound playing inside the loop?

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
10 Oct 2019, 09:02

Hi ctid712216,

As explained above, new orders can be placed automatically to restore the equity to equity ratio between the two accounts. For the specific trade you reported, there was a change in the strategy provider's balance that caused automatic trades to be executed on copying accounts to restore the equity to equity ratio.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
10 Oct 2019, 08:50

Hi social.trading,

The easiest solution to this would be to use a sound file that repeats the sound as many times as you want and just play it from the cBot once.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
10 Oct 2019, 08:45

Hi RayAdam,

There is no option to disable updates for cTrader. 

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
10 Oct 2019, 08:41

Hi Aiki1000,

It would be easier for somebody to help you if you posted the relevant source codes as well as some screenshots showing what you are describing.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
10 Oct 2019, 08:36

Hi GlenHendriks,

Either post a link here or send it at community@spotware.com

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
09 Oct 2019, 16:54

Hi ctid1566965,

Yes you need to select the trendline tool for each line you want to draw.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
09 Oct 2019, 16:32

Hi GlenHendriks,

Is it possible to record a short video demonstrating this behavior so that we can have a look?

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
09 Oct 2019, 15:31

Hi Be Rich,

There is a fully working example using Open API 2.0 here.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
09 Oct 2019, 12:48

Hi davewilson347,

If you are always getting an exception in these cases, you can always use a try catch statement to handle them.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
09 Oct 2019, 12:31

Hi FireMyst,

First of all if you want to see any results at all you need to change

            double tsiDivisor = _divisor.Result[altIndex];
            double tsiDividend = _dividend.Result[altIndex];

to

            double tsiDivisor = _divisor.Result[index];
            double tsiDividend = _dividend.Result[index];

But then there is a major logical issue with your indicator. You are trying to do calculations for indicators using a different timeframe on the main indicator. This will result to wrong results due to different resolution of the available data.  

Example

            if (MarketSeries.TimeFrame != _marketSeries.TimeFrame)
            {
                altIndex = _marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
            }

If MarketSeries.TimeFrame is h1 and _marketSeries.TimeFrame is m30 then when executing the following

_dataSeries[index] = _marketSeries.Close[altIndex] - _marketSeries.Close[altIndex - 1];

The last x values (let's say 14) of _dataSeries will contain sample data from the last 28 values of the _marketSeries.Close, since for every change of the index for h1, the index for m30 increases by 2 (print altIndex to understand what i man). Therefore this average

_longDividend = Indicators.MovingAverage(_dataSeries, 14, MaType);

will not be an average of the last 14 periods but the last 28 since it will average the last 14 sample values collected in _dataSeries.

Since you are using moving averages which are simple to code, it would be easier to do the calculations yourself rather than relying on cTrader indicators. Just loop through the custom timeframe data and calculate the MAs

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
09 Oct 2019, 10:06

Ηι drayzen,

cTrader is a platform for CFD contracts which is a different market in many ways than exchanges. We already have an exchange product called cExchange which has a similar interface to cTrader and it is targeted to cryptocurrency exchanges.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
09 Oct 2019, 08:35

Hi yahuimns,

cTrader Desktop is not available on Mac OS.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
09 Oct 2019, 08:34

Hi FireMyst,

As explained above, data series are not "attached" to any timeframe. It is just a series of doubles. If you want to feed them with data from a lower timeframe, you can do it. There is no time property on anything else that relates an item of the data series to a timeframe.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
09 Oct 2019, 08:20

Hi Stephen,

Thanks for posting in our forum. We do not have a timeframe at the moment.

Best Regards,

Panagiotis


@PanagiotisCharalampous