Topics
14 Dec 2019, 23:09
 1
 1386
 1
14 Dec 2019, 15:02
 3
 1328
 1
14 Dec 2019, 14:57
 5
 1282
 2
29 Nov 2019, 11:59
 1
 1250
 1
17 Nov 2019, 01:49
 7
 1888
 1
17 Nov 2019, 01:46
 6
 1509
 1
17 Nov 2019, 01:43
 4
 1215
 1
Add-ons

cTrader Automate

Suggestions
17 Nov 2019, 01:34
 3
 1524
 1
17 Nov 2019, 01:32
 3
 1336
 1
17 Nov 2019, 01:31
 6
 1274
 1
17 Nov 2019, 01:29
 2
 1238
 1
20 Feb 2019, 19:23
 1387
 4
21 Jan 2018, 16:53
 0
 1780
 1
Replies

whis.gg
21 May 2017, 11:51

Why do you want to get a quote from all different timeframes at exact same time - every 60 seconds? This is going to return same price on all of them.


@whis.gg

whis.gg
10 May 2017, 03:24

Hi, I don't think I got an answer I was looking for. Anyway, here is how to assing an empty value to the IndicatorDataSeries.

series[index] = double.NaN;

 


@whis.gg

whis.gg
03 Apr 2017, 13:52

Hi, just remove or comment following lines.

if (Time.Year >= 2016 && Time.Month >= 3 && Time.Day > 2)
{
    ChartObjects.DrawText("Demo_Expired", "DEMO EXPIRED!!!\nDEMO EXPIRED!!!\nDEMO EXPIRED!!!\nDEMO EXPIRED!!!\nDEMO EXPIRED!!!\n", StaticPosition.TopLeft, Colors.Red);
    OnStop();
}
if (Time.Year >= 2016 && Time.Month >= 3 && Time.Day > 1)
    return;

 


@whis.gg

whis.gg
31 Mar 2017, 03:41

Hi, make sure the csv file isn't opened in another app. Also I had to set starting period 1 day later.


@whis.gg

whis.gg
31 Mar 2017, 03:28

Hi mate, wish you best of luck! Do you plan to become signal provider on cMirror?


@whis.gg

whis.gg
31 Mar 2017, 02:16

Sorry for late reply, I didn't notice you have replied already. :)

The code I have provided is based on daily net profit, not account balance growth. It sets daily net profit on monday and doesnt change during certain week. Onn each position closed it calculates current daily net profit and if it reached the target then it stops core logic till the next day.

Update OnPositionClosed() method to following and check the log if it's working as supposed.

private void OnPositionClosed(PositionClosedEventArgs obj)
{
    double dailyNetProfit = History.Where(x => x.ClosingTime.Date == Time.Date).Sum(x => x.NetProfit); // sums net profit of current day

    // pauses core logic if daily net target was exceeded
    if (dailyNetProfit >= dailyNetTarget)
    {
        isPausedTillNextDay = true;
        Print("Pausing core logic till {0}. Daily Net target of {1} ({2} %) reached. Current net profit is {3} ({4} %).", nextDay, dailyNetTarget, DailyTargetPercentage, dailyNetProfit, Math.Round(dailyNetProfit / dailyNetTarget, 2));
    }
}

 

P.S.: That graph is looking like a holy grail already! Feel free to contact me via email below if you need to discus anything privately.


@whis.gg

whis.gg
29 Mar 2017, 13:40

Yes or you can put both between brackets.

if (!isPausedTillNextDay)
{
    if (shortSignal)
    {
        EnterInPosition(TradeType.Sell);
    }
    else if (longSignal)
    {
        EnterInPosition(TradeType.Buy);
    }
}

One more thing that should be updated in case the cBot would be started on Sunday.

Line 19: DateTime lastMonday = Time.AddDays(1 - (Time.DayOfWeek == 0 ? 7 : (int)Time.DayOfWeek)).Date

Line 58: nextMonday = Time.AddDays(8 - (Time.DayOfWeek == 0 ? 7 : (int)Time.DayOfWeek)).Date;

Please keep in mind I haven't tested it so there might be more to fix.


@whis.gg

whis.gg
28 Mar 2017, 17:20

Updated code.

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NotTestedSample : Robot
    {
        [Parameter("Daily Target %", DefaultValue = 1)]
        public double DailyTargetPercentage { get; set; }

        private DateTime nextMonday, nextDay;
        private double weeklyStartingBalance, dailyNetTarget;
        private bool isPausedTillNextDay;

        protected override void OnStart()
        {
            DateTime lastMonday = Time.AddDays(-(int)Time.DayOfWeek + 1).Date;
            HistoricalTrade trade = History.LastOrDefault(x => x.ClosingTime <= lastMonday); // finds last historical trade before this week

            weeklyStartingBalance = trade != null ? trade.Balance : Account.Balance; // if there is historical trade it uses its balance for better accuracy
            dailyNetTarget = weeklyStartingBalance * DailyTargetPercentage / 100;

            nextMonday = Time.AddDays(8 - (int)Time.DayOfWeek).Date;
            nextDay = Time.AddDays(1).Date;

            Positions.Closed += OnPositionClosed;
        }

        private void OnPositionClosed(PositionClosedEventArgs obj)
        {
            double dailyNet = History.Where(x => x.ClosingTime.Date == Time.Date).Sum(x => x.NetProfit); // sums net profit of current day

            // pauses core logic if daily net target was exceeded
            if (dailyNet >= dailyNetTarget)
            {
                isPausedTillNextDay = true;
            }
        }

        protected override void OnTick()
        {
            // unpauses core logic if it's new day
            if (Time >= nextDay)
            {
                isPausedTillNextDay = false;

                nextDay = Time.AddDays(1).Date;
            }

            // sets new daily net target on each Monday
            if (Time >= nextMonday)
            {
                weeklyStartingBalance = Account.Balance;
                dailyNetTarget = weeklyStartingBalance * DailyTargetPercentage / 100;

                nextMonday = Time.AddDays(8 - (int)Time.DayOfWeek).Date;
            }

            // passes if core logic isn't paused
            if (!isPausedTillNextDay)
            {
                // Put your core logic here
            }
        }
    }
}

 


@whis.gg

whis.gg
28 Mar 2017, 17:11

I just realized you should update nextDay each new day with following code. Because of the weekends and days when daily net target isn't exceeded.

nextDay = Time.AddDays(1).Date;

And I forgot to set new nextMonday on each monday. Line 56:

nextMonday = Time.AddDays(8 - (int)Time.DayOfWeek).Date;

 


@whis.gg

whis.gg
28 Mar 2017, 17:03

Hi, you can start with that. Sorry if there is any error - I don't have time to test it.

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NotTestedSample : Robot
    {
        [Parameter("Daily Target %", DefaultValue = 1)]
        public double DailyTargetPercentage { get; set; }

        private DateTime nextMonday, nextDay;
        private double weeklyStartingBalance, dailyNetTarget;
        private bool isPausedTillNextDay;

        protected override void OnStart()
        {
            DateTime lastMonday = Time.AddDays(-(int)Time.DayOfWeek + 1).Date;
            HistoricalTrade trade = History.FirstOrDefault(x => x.ClosingTime >= lastMonday); // finds first historical trade of this week

            weeklyStartingBalance = trade != null ? trade.Balance : Account.Balance; // if there is historical trade it uses its balance for better accuracy
            dailyNetTarget = weeklyStartingBalance * DailyTargetPercentage / 100;

            nextMonday = Time.AddDays(8 - (int)Time.DayOfWeek).Date;
            nextDay = Time.AddDays(1).Date;

            Positions.Closed += OnPositionClosed;
        }

        private void OnPositionClosed(PositionClosedEventArgs obj)
        {
            double dailyNet = History.Where(x => x.ClosingTime.Date == Time.Date).Sum(x => x.NetProfit); // sums net profit of current day

            // pauses core logic if daily net target was exceeded
            if (dailyNet >= dailyNetTarget)
            {
                isPausedTillNextDay = true;
            }
        }

        protected override void OnTick()
        {
            // unpauses core logic if it's new day
            if (isPausedTillNextDay && Time >= nextDay)
            {
                isPausedTillNextDay = false;
                nextDay = nextDay.AddDays(1);
            }

            // sets new daily net target on each Monday
            if (Time >= nextMonday)
            {
                weeklyStartingBalance = Account.Balance;
                dailyNetTarget = weeklyStartingBalance * DailyTargetPercentage / 100;
            }

            // passes if core logic isn't paused
            if (!isPausedTillNextDay)
            {
                // Put your core logic here
            }
        }
    }
}

 


@whis.gg

whis.gg
28 Mar 2017, 16:12

Or using System.Linq

double maximumBalance = History.Max(x => x.Balance);
double minimumBalance = History.Min(x => x.Balance);

 


@whis.gg

whis.gg
28 Mar 2017, 16:10

Hi, try this.

double maximumBalance = double.MinValue;
double minimumBalance = double.MaxValue;

foreach (var historicalTrade in History)
{
    maximumBalance = Math.Max(historicalTrade.Balance, maximumBalance);
    minimumBalance = Math.Min(historicalTrade.Balance, minimumBalance);
}

 


@whis.gg

whis.gg
26 Mar 2017, 11:42

Do you mean http://algochart.com/?


@whis.gg

whis.gg
21 Mar 2017, 16:11

Hi, you need to invoke Calculate() method in the referenced indicator. Add this into your cBot.

protected override void OnTick()
{
    double a = impulseSystem.Ema.LastValue;
}

 


@whis.gg

whis.gg
16 Mar 2017, 12:05

You might want to try reinstalling .NET Framework 4.


@whis.gg

whis.gg
16 Mar 2017, 11:47

Try this.

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NotificationTest : Indicator
    {
        protected override void Initialize()
        {
            Timer.Start(3);
        }

        protected override void OnTimer()
        {
            Notifications.PlaySound("C:\\Windows\\Media\\tada.wav");
        }

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

 


@whis.gg

whis.gg
16 Mar 2017, 11:43

Have you tried to edit Lucian solution and use API notifitication instead of system media player? In the first post you are trying to execute the notification on each bar (historical) and then each price change - which may lead to freeze.


@whis.gg

whis.gg
16 Mar 2017, 11:28

Make sure you have correct path to sound file. Notifications are working fine on my end.


@whis.gg

whis.gg
27 Feb 2017, 12:19

Not sure if it's the best way but it's the one cAlgo uses.

using System;
using cAlgo.API;

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

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

        [Parameter("Sigma", DefaultValue = 0.65, MinValue = 0.1, MaxValue = 0.95)]
        public double Sigma { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        public override void Calculate(int index)
        {
            double num = this.Result[index - 1];

            if (double.IsNaN(num))
            {
                num = Source[index - 1];
            }
            double num2 = Sigma * Cmo(index);

            Result[index] = (1.0 - num2) * num + num2 * Source[index];
        }

        private double Cmo(int index)
        {
            double num = 0.0;
            double num2 = 0.0;

            for (int i = 0; i < Period; i++)
            {
                double num3 = Source[index - i] - Source[index - i - 1];

                if (num3 > 0.0)
                {
                    num += num3;
                }
                else
                {
                    num2 += -num3;
                }
            }

            if (num + num2 == 0.0)
            {
                return 0.0;
            }

            return Math.Abs((num - num2) / (num + num2));
        }
    }
}

 


@whis.gg

whis.gg
27 Feb 2017, 02:34

Hi, Time Series Moving Average is equal to Linear Regression Forecast. The cAlgo platform calculates it by multiplying Linear Regression Slope with Period plus Linear Regression Intercept. Here's is better solution that gives you same result.

using cAlgo.API;

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

        [Parameter(DefaultValue = 14)]
        public int Period { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        public override void Calculate(int index)
        {
            double sumX = 0, sumY = 0, sumXY = 0, sumXPower = 0;

            for (int i = 0; i < Period; i++)
            {
                sumXPower += i * i;
                sumX += i;
                sumY += Source[index - i];
                sumXY += i * Source[index - i];
            }

            Result[index] = (sumXPower * sumY - sumX * sumXY) / (sumXPower * Period - sumX * sumX);
        }
    }
}

 


@whis.gg