Replies

mohsabry.ms
23 Dec 2021, 12:26

RE: RE: RE:

amusleh said:

mohsabry.ms said:

Hi,

Did you mean that  "  if (Server.TimeInUtc.TimeOfDay.TotalMinutes == 1)"

or What?

 

 

Hi,

No, I mean if you know the time you want to pause your cBot then you can do it with code, ex:

using cAlgo.API;
using System;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        private List<DayOfWeek> _pauseDays;

        private TimeSpan _startTime, _endTime;

        private bool _isPaused;

        [Parameter("Days", DefaultValue = "Friday,Saturday", Group = "Pause")]
        public string Days { get; set; }

        [Parameter("Start Time", DefaultValue = "07:00:00", Group = "Pause")]
        public string StartTime { get; set; }

        [Parameter("End Time", DefaultValue = "16:00:00", Group = "Pause")]
        public string EndTime { get; set; }

        protected override void OnStart()
        {
            _pauseDays = Days.Split(',').Select(day => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), day)).ToList();

            if (TimeSpan.TryParse(StartTime, CultureInfo.InvariantCulture, out _startTime) == false)
            {
                Print("Invalid StartTime");
                Stop();
            }

            if (TimeSpan.TryParse(EndTime, CultureInfo.InvariantCulture, out _endTime) == false)
            {
                Print("Invalid EndTime");
                Stop();
            }

            Timer.Start(1);
        }

        protected override void OnTimer()
        {
            if (_pauseDays.Contains(Server.Time.DayOfWeek) && Server.Time.TimeOfDay >= _startTime && Server.Time.TimeOfDay <= _endTime)
            {
                _isPaused = true;
            }

            _isPaused = false;
        }

        protected override void OnBar()
        {
            if (_isPaused) return;

            // Otherwise continue running cBot logic
        }

        protected override void OnTick()
        {
            if (_isPaused) return;

            // Otherwise continue running cBot logic
        }
    }
}

The above cBot will be paused based on your provided start/end time and days of week.

Appreciate your help

Thanx Alot


@mohsabry.ms

mohsabry.ms
21 Dec 2021, 22:50

RE:

Hi,

Did you mean that  "  if (Server.TimeInUtc.TimeOfDay.TotalMinutes == 1)"

or What?

 

 


@mohsabry.ms

mohsabry.ms
21 Dec 2021, 00:33

RE:

Thanx , But I need a time function to run condition at certain time everyday and stop at another certain time also everyday

 


@mohsabry.ms

mohsabry.ms
18 Nov 2021, 11:59

RE:

amusleh said:

Hi,

Did you checked the API references example: cAlgo API Reference - IndicatorDataSeries Interface (ctrader.com)

You have to store your calculation result inside an IndicatorDataSeries, then you can use that data series on your cBots.

Thank you for your advice it works well

Regards,


@mohsabry.ms

mohsabry.ms
15 Nov 2021, 14:47

RE:

PanagiotisCharalampous said:

Hi mohsabry.ms,

To be able to access your indicator's values from a cBot, you first need to expose them in a public variable, preferably an IndicatorDataSeries.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook 

Appreciate your valuable help,

Forgive me as just a begineer

But I tired trying expose  "a" variable to be an output as a IndicatorDataSeries.

 

The calculation made as a series not index

I search how to make series type deals with IndicatorDataSeries but I really can't find a way

 private void LinearRegression(DataSeries series) 

   // Linear regresion

            double sum_x = 0, sum_x2 = 0, sum_y = 0, sum_xy = 0;

            int start = series.Count - Bars;
            int end = series.Count - 1;

            for (int i = start; i <= end; i++)
            {
                sum_x += 1.0 * i;
                sum_x2 += 1.0 * i * i;
                sum_y += series[i];
                sum_xy += series[i] * i;
            }

            double a = (Bars * sum_xy - sum_x * sum_y) / (Bars * sum_x2 - sum_x * sum_x);

}

 

and there is no output 

 

 

Thank you in Advance

Regards,

 


@mohsabry.ms

mohsabry.ms
08 Nov 2021, 20:41

RE:

Thank you for your valuable helping

Best Regards;


@mohsabry.ms

mohsabry.ms
06 Nov 2021, 01:29

RE: RE: Thank you for helping

Hi,

If I wanna to choose from history some specific closed trades that i labeled it before as "sell_today"

how to modify this code to select them only;

var netProfit = History.Sum(trade => trade.NetProfit);

 

Forgive me I'm just a beginner

Thank you in advace

Best Regards,


@mohsabry.ms

mohsabry.ms
05 Nov 2021, 14:41

RE: Thank you for helping

amusleh said:

Hi,

You can use history to sum the net profit of all your closed positions (trades):

var netProfit = History.Sum(trade => trade.NetProfit);

To get net profit of all your open positions you can use Positions:

var netProfit = Positions.Sum(position => position.NetProfit);

 

It works well,

Appreciate your help

Regards,

 


@mohsabry.ms