Topics
10 May 2019, 10:03
 2445
 11
27 Nov 2018, 07:18
 2793
 6
Replies

alexander.n.fedorov
02 Nov 2018, 15:48

RE:

Panagiotis Charalampous said:

Is it this what you need?

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.RussianStandardTime, AccessRights = AccessRights.FullAccess)]
    public class SandDTrader3 : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("LookBackDays", DefaultValue = 800)]
        public int Bars { get; set; }

        private Dictionary<int, double> highsDict = new Dictionary<int, double>();
        private Dictionary<int, double> lowsDict = new Dictionary<int, double>();
        private int index, _index;
        private double high, low, value, _high, _low;
        private Colors color;

        protected override void OnStart()
        {
            for (int k = 1; k < Bars; k++)
            {
                highsDict.Add(k, MarketSeries.High.Last(k));
                lowsDict.Add(k, MarketSeries.Low.Last(k));
            }          

            var high = highsDict.OrderByDescending(x => x.Value).First();          
            ChartObjects.DrawLine("High" + high.Key, MarketSeries.OpenTime.Last(high.Key), high.Value, MarketSeries.OpenTime.Last(0), high.Value, Colors.Aqua, 1, LineStyle.Solid);
            ChartObjects.DrawText(high.Key.ToString(), "Price = " + high.Value, _index, high.Value, VerticalAlignment.Top, HorizontalAlignment.Right, Colors.DarkGray);

            var low = lowsDict.OrderBy(x => x.Value).First();           
            ChartObjects.DrawLine("Low" + low.Key, MarketSeries.OpenTime.Last(low.Key), low.Value, MarketSeries.OpenTime.Last(0), low.Value, Colors.Red, 1, LineStyle.Solid);
            ChartObjects.DrawText(low.Key.ToString(), "Price = " + low.Value, _index, low.Value, VerticalAlignment.Top, HorizontalAlignment.Right, Colors.DarkGray);
        }
    }
}

Best Regards,

Panagiotis

I tried. It is not what I need

I will have to do mo homework, myabe then I write again

Regards

 

Alexander


@alexander.n.fedorov

alexander.n.fedorov
02 Nov 2018, 15:29

RE:

alexander.n.fedorov said:

When I look at the chart, I know the prices. The the cBot does not

I have to tell him some how

The first blue and the first red

 


@alexander.n.fedorov

alexander.n.fedorov
02 Nov 2018, 15:28

When I look at the chart, I know the prices. The the cBot does not

I have to tell him some how

 


@alexander.n.fedorov

alexander.n.fedorov
02 Nov 2018, 15:25

Current price is (bid or ask - does not matter)

 

The blue line gives you the price (which is written on a chart) above the current price

The red line gives you the price below.

I am tryiing to find them programmatically, as well as there keys, as the are a part of dictionary


@alexander.n.fedorov

alexander.n.fedorov
02 Nov 2018, 15:13

highsDict.Where(x => x.Value > MarketSeries.Close.Last(0)).OrderByDescending(x => x.Value).Last();

 

This one builds, but I do not know what to do with it. I need to find value (1.155)

I am not even concerned about the key

 


@alexander.n.fedorov

alexander.n.fedorov
02 Nov 2018, 14:47

Thank you for reply, Panagiotis!

The code will bild if you take away the underscored row

That will give me the picture I posted

but I was trying to find it programmatically out of dictionary, and so far I could not

If you can, please help find programmatically the first price above (on a blue  line) and below (on a red line)

 

Regards,

 

Alexander

 


@alexander.n.fedorov

alexander.n.fedorov
02 Nov 2018, 13:06 ( Updated at: 21 Dec 2023, 09:20 )

RE:

alexander.n.fedorov said:

Dear Panagiotis, hi!

This much I was able to achieve:

But I still cannot find programmaticaly the closest upper price (or lover) even if print them on a screen

please, find the code

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Collections.Generic;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.RussianStandardTime, AccessRights = AccessRights.FullAccess)]
    public class SandDTrader3 : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

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

        private Dictionary<int, double> highsDict = new Dictionary<int, double>();
        private int index, _index;
        private double high, low, value, _high, _low;
        private Colors color;

        protected override void OnStart()
        {
            _index = MarketSeries.Close.Count;
            for (int k = 1; k < 100; k++)
            {
                high = MarketSeries.High.Last(0);
                low = MarketSeries.Low.Last(0);
                for (int i = 0; i < LookBackDays + 1 - k; i++)
                {
                    if (MarketSeries.High.Last(i) > high)
                    {
                        high = value = MarketSeries.High.Last(i);
                        index = i;
                    }

                    if (MarketSeries.Low.Last(i) < low)
                    {
                        low = value = MarketSeries.Low.Last(i);
                        index = i;
                    }
                    else
                    {
                        continue;
                    }
                }
                LookBackDays = index - 1;

                try
                {
                    highsDict.Add(index, value);
                } catch (ArgumentException)
                {
                    Print("An element with Key = {0} already exists.", index);
                }
                var _high = highsDict.OrderByDescending(v => v.Value).First();
                foreach (var v in highsDict.OrderByDescending(x => x.Value).Take(100))
                {
                    _high = v.Value < _high && v.Value>MarketSeries.Close.Last(0) ? _high = v.Value: _high;
                    color = (v.Value < MarketSeries.Close.Last(0) ? color = Colors.Red : Colors.Aqua);
                    Print("Index: " + v.Key + " Value: " + v.Value + " lookBackDays: " + LookBackDays);
                    ChartObjects.DrawLine("High" + v.Key, MarketSeries.OpenTime.Last(v.Key), v.Value, MarketSeries.OpenTime.Last(0), v.Value, color, 1, LineStyle.Solid);
                    ChartObjects.DrawText(v.Key.ToString(), "Price = " + v.Value,  _index , v.Value, VerticalAlignment.Top, HorizontalAlignment.Right, Colors.DarkGray);
                }

            }

        }
    }
}

 

 

Please , help

 

Regards, 

 

Alexander


@alexander.n.fedorov

alexander.n.fedorov
30 Oct 2018, 11:06

Dear Panagiotis,

is there any way to do that with other versions?

 

Regards, 

Sasha


@alexander.n.fedorov

alexander.n.fedorov
30 Oct 2018, 10:51 ( Updated at: 21 Dec 2023, 09:20 )

Maybe it has smth to do with versions?


@alexander.n.fedorov

alexander.n.fedorov
29 Oct 2018, 12:36

RE:

Panagiotis Charalampous said:

Hi Sasha,

  1. You can use out keyword
  2. A cBot cannot stop other cBots, at least in a direct way. If you could explain what you are trying to do, I could suggest something.

Best Regards,

Panagiotis

 

I think that I will study the link. Thank you.

For the second one , I think, that one of the bots (special bot) when stopped with send and SQL message to change the flag to "stop"

Every other bot OnTick or OnBar will check the flag (through the SQL connection) and if the flag says "stop"  it will stop.

I was just hoping that it is in an API, where Account.Algos.Stop or smth like that

Thank you and regards
Sasha
By the way, how do you right SQL statement  in LINQ?


@alexander.n.fedorov

alexander.n.fedorov
26 Oct 2018, 11:26

Hi, Panagiotis. 
That is what i do, but means, I have to put the whole body of bot inside it

All right. Thank you

 

Regards, 

Sasha


@alexander.n.fedorov

alexander.n.fedorov
26 Oct 2018, 08:06

Dear Panagiotis:

 

I was trying to run a robot on SPA35 index, which opens at 10 am.

I received a message that I couldnot because the maket to this symbol is closed

I could not find correct solution

 

Please, help

Regargs, Sasha


@alexander.n.fedorov

alexander.n.fedorov
26 Oct 2018, 07:05

RE:

Panagiotis Charalampous said:

Hi sebo1999,

See below an example on how to print the trading sessions of a symbol

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.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            foreach (var session in Symbol.MarketHours.Sessions)
            {
                Print("Session Starts: " + session.StartDay + " " + session.StartTime.ToString());
                Print("Session Ends: " + session.EndDay + " " + session.EndTime.ToString());
            }
        }

        protected override void OnTick()
        {
           
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis

This is nice, but hou do I put trades in a correct time?


@alexander.n.fedorov

alexander.n.fedorov
25 Oct 2018, 02:59

RE:

lec0456 said:

/Your function is returning a string but it is not using a string.  you don't need to pass in resul.  Just use empty parenthesis ()

Dear  lec0456. I think I whould really want to talk with you about that issue. My skype is alexander.n.fedorov

If you don't mnd, text me when it would be a good time to talk

Regards.

Alexander 


@alexander.n.fedorov

alexander.n.fedorov
24 Oct 2018, 09:12

Thanks a lot! That is what i finally come up with by the morning :)

 


@alexander.n.fedorov

alexander.n.fedorov
22 Oct 2018, 16:27

RE:

alexander.n.fedorov said:

So, Dictionary is like 2 dimensional (kind of) list and you would do

 

"

for (int i=0.........)

{

     dictionary.Add(i+1, numbers[i]

}

?

Thanks, Panagiotis, it helped a lot!


@alexander.n.fedorov

alexander.n.fedorov
22 Oct 2018, 15:09

for (int i=0.........)

{

     dictionary.Add(i+1, numbers[i])

}

?


@alexander.n.fedorov

alexander.n.fedorov
22 Oct 2018, 15:09

So, Dictionary is like 2 dimensional (kind of) list and you would do

 

"

for (int i=0.........)

{

     dictionary.Add(i+1, numbers[i]

}

?


@alexander.n.fedorov

alexander.n.fedorov
22 Oct 2018, 14:43

RE:

Panagiotis Charalampous said:

Here is an example

            var dictionary = new Dictionary<int, int>();
            dictionary.Add(1, 3);
            dictionary.Add(2, 5);
            dictionary.Add(3, 1);
            dictionary.Add(4, 2);
            dictionary.Add(5, 9);
            dictionary.Add(6, 4);
            dictionary.Add(7, 7);
            dictionary.Add(8, 6);
            dictionary.Add(9, 10);
            dictionary.Add(10, 8);

            foreach (var v in dictionary.OrderBy(x => x.Value).Take(5))
            {
                Print("Index: " + v.Key + " Value: " + v.Value);
            }

Best Regards,

Panagiotis

Thank you Panagiotis, I will try to think of it

Regards

 

 


@alexander.n.fedorov

alexander.n.fedorov
22 Oct 2018, 14:22

RE:

Panagiotis Charalampous said:

Hi Sasha,

OrderBy will not sort the original list/dictionary. It will return a new sorted instance.

Best Regards,

Panagiotis

Unfortunately, I do not know how to do that, so  I guess I will have to find a book and study


@alexander.n.fedorov