Replies

AlgoCreators
04 Nov 2024, 08:59

I think the OnDestroy function is never executed. There is no such feature in the indicators


@AlgoCreators

AlgoCreators
25 Oct 2024, 17:20 ( Updated at: 26 Oct 2024, 05:45 )

RE: RE: RE: RE: RE: Indicator incompatibility on Mac

PanagiotisCharalampous said: 

AlgoCreators said: 

This is the source code of the indicator: 
 

Hi there,

It looks fine on our side. If the issue persists for the user, please ask him send us some troubleshooting info and quote the link to this discussion.
 

Best regards,

Panagiotis

Thank you, Your presence with the programmers of CTrader is encouraging :-)


@AlgoCreators

AlgoCreators
24 Oct 2024, 15:48

RE: RE: RE: Indicator incompatibility on Mac

This is the source code of the indicator: 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using System.Globalization;
namespace cAlgo
{
   [Indicator(AccessRights = AccessRights.FullAccess, IsOverlay = true, TimeZone = TimeZones.UTC)]
   public class TradingSessions : Indicator
   {
       [Parameter("Version:", DefaultValue = "1.0.1")]
       public string Version { get; set; }

       [Parameter("Show for how many days", Group = "Sessions", DefaultValue = 15, MinValue = 0)]
       public int Back_days { get; set; }
       [Parameter("Filled Zones", DefaultValue = true, Group = "Sessions")]
       public bool Filled_Zones { get; set; }
       [Parameter("Show Labels", DefaultValue = true, Group = "Sessions")]
       public bool Show_Labels { get; set; }
       [Parameter("Infinitie range", DefaultValue = Infinite_Range.None, Group = "Sessions")]
       public Infinite_Range InfiniteRange { get; set; }
       public enum Infinite_Range
       {
           Up,
           Down,
           Both,
           None
       }

       [Parameter("Show Session 1", DefaultValue = true, Group = "Session 1")]
       public bool S1_Show { get; set; }
       [Parameter("Session Label", DefaultValue = "Sydney", Group = "Session 1")]
       public string S1_Label { get; set; }
       [Parameter("Start time", DefaultValue = "21:00", Group = "Session 1")]
       public string S1_open { get; set; }
       [Parameter("End time", DefaultValue = "06:00", Group = "Session 1")]
       public string S1_close { get; set; }
       [Parameter("Color", Group = "Session 1", DefaultValue = "#20BEBF00")]
       public Color S1_Color { get; set; }
       [Parameter("Line Style", Group = "Session 1", DefaultValue = LineStyle.DotsRare)]
       public LineStyle S1_LineStyle { get; set; }

       [Parameter("Show Session 2", DefaultValue = true, Group = "Session 2")]
       public bool S2_Show { get; set; }
       [Parameter("Session Label", DefaultValue = "Tokyo", Group = "Session 2")]
       public string S2_Label { get; set; }
       [Parameter("Start time", DefaultValue = "00:00", Group = "Session 2")]
       public string S2_open { get; set; }
       [Parameter("End time", DefaultValue = "09:00", Group = "Session 2")]
       public string S2_close { get; set; }
       [Parameter("Color", Group = "Session 2", DefaultValue = "#2001AF50")]
       public Color S2_Color { get; set; }
       [Parameter("Line Style", Group = "Session 2", DefaultValue = LineStyle.DotsRare)]
       public LineStyle S2_LineStyle { get; set; }

       [Parameter("Show Session 3", DefaultValue = true, Group = "Session 3")]
       public bool S3_Show { get; set; }
       [Parameter("Session Label", DefaultValue = "London", Group = "Session 3")]
       public string S3_Label { get; set; }
       [Parameter("Start time", DefaultValue = "07:00", Group = "Session 3")]
       public string S3_open { get; set; }
       [Parameter("End time", DefaultValue = "16:00", Group = "Session 3")]
       public string S3_close { get; set; }
       [Parameter("Color", Group = "Session 3", DefaultValue = "#2033C1F3")]
       public Color S3_Color { get; set; }
       [Parameter("Line Style", Group = "Session 3", DefaultValue = LineStyle.DotsRare)]
       public LineStyle S3_LineStyle { get; set; }

       [Parameter("Show Session 4", DefaultValue = true, Group = "Session 4")]
       public bool S4_Show { get; set; }
       [Parameter("Session Label", DefaultValue = "New York", Group = "Session 4")]
       public string S4_Label { get; set; }
       [Parameter("Start time", DefaultValue = "13:00", Group = "Session 4")]
       public string S4_open { get; set; }
       [Parameter("End time", DefaultValue = "22:00", Group = "Session 4")]
       public string S4_close { get; set; }
       [Parameter("Color", Group = "Session 4", DefaultValue = "#20FF3334")]
       public Color S4_Color { get; set; }
       [Parameter("Line Style", Group = "Session 4", DefaultValue = LineStyle.DotsRare)]
       public LineStyle S4_LineStyle { get; set; }

       [Parameter("Show Session 5", DefaultValue = false, Group = "Session 5")]
       public bool S5_Show { get; set; }
       [Parameter("Session Label", DefaultValue = "", Group = "Session 5")]
       public string S5_Label { get; set; }
       [Parameter("Start time", DefaultValue = "00:00", Group = "Session 5")]
       public string S5_open { get; set; }
       [Parameter("End time", DefaultValue = "09:00", Group = "Session 5")]
       public string S5_close { get; set; }
       [Parameter("Color", Group = "Session 5", DefaultValue = "#75939695")]
       public Color S5_Color { get; set; }
       [Parameter("Line Style", Group = "Session 5", DefaultValue = LineStyle.DotsRare)]
       public LineStyle S5_LineStyle { get; set; }

 

       public List<Session> _sessions = new();

       protected override void Initialize()
       {
           if (Bars.TimeFrame > TimeFrame.Hour4) return;

           if (S1_Show && S1_Label != "")
               _sessions.Add(new Session { name = S1_Label, Open = TimeSpan.Parse(S1_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S1_close), Color = S1_Color, LineStyle = S1_LineStyle });
           if (S2_Show && S1_Label != "")
               _sessions.Add(new Session { name = S2_Label, Open = TimeSpan.Parse(S2_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S2_close), Color = S2_Color, LineStyle = S2_LineStyle });
           if (S3_Show && S1_Label != "")
               _sessions.Add(new Session { name = S3_Label, Open = TimeSpan.Parse(S3_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S3_close), Color = S3_Color, LineStyle = S3_LineStyle });
           if (S4_Show && S1_Label != "")
               _sessions.Add(new Session { name = S4_Label, Open = TimeSpan.Parse(S4_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S4_close), Color = S4_Color, LineStyle = S4_LineStyle });
           if (S5_Show && S1_Label != "")
               _sessions.Add(new Session { name = S5_Label, Open = TimeSpan.Parse(S5_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S5_close), Color = S5_Color, LineStyle = S5_LineStyle });

           foreach (var session in _sessions)
           {
               Draw_rect(session.name, session.Open, session.Close, session.Color, session.LineStyle);
           }
           var bars_m1 = MarketData.GetBars(TimeFrame.Minute, Symbol.Name);
           bars_m1.BarOpened += bars_m1_BarOpened;

           var Current_bars = MarketData.GetBars(Bars.TimeFrame, Symbol.Name);
           Current_bars.BarOpened += Current_bars_BarOpened; ;
       }

       private void Current_bars_BarOpened(BarOpenedEventArgs obj)
       {
           RemoveAllobjects();
           foreach (var session in _sessions)
           {
               Draw_rect(session.name, session.Open, session.Close, session.Color, session.LineStyle);
           }
       }

       private void bars_m1_BarOpened(BarOpenedEventArgs args)
       {
           foreach (var session in _sessions)
           {
               if (args.Bars.Last(0).OpenTime.AddMinutes(5) == (DateTime)(args.Bars.Last(0).OpenTime.Date + session.Open))
               {
                   Print("open " + session.name);
               };
           }
       }
       private void RemoveAllobjects()
       {
           foreach (var element in Chart.FindAllObjects(ChartObjectType.Text))
               if (element.Name.Contains(this.ToString()))
                   Chart.RemoveObject(element.Name);
           foreach (var element in Chart.FindAllObjects(ChartObjectType.Rectangle))
               if (element.Name.Contains(this.ToString()))
                   Chart.RemoveObject(element.Name);

       }
       public override void Calculate(int index)
       {
           // Calculate value at specified index
           // Result[index] = 
       }
       public TimeSpan NormalizeTime(string STime)
       {
           DateTime TimeWithDate = Time.Date + TimeSpan.Parse(STime);
           return TimeSpan.Parse(TimeWithDate.ToString("HH:mm"));
       }
       private void Draw_rect(string session, TimeSpan Opentime, TimeSpan Closetime, Color color, LineStyle lineStyle)
       {
           double Min = 0.0;
           double Max = 0.0;
           DateTime OpenDate, CloseDate;
           int index, Openindex, Closeindex;
           bool validation = true;
           if (Closetime < Opentime)
           {
               OpenDate = Time.Date + Opentime;
               CloseDate = (Time.Date + Closetime).AddDays(1);
           }
           else
           {
               OpenDate = Time.Date + Opentime;
               CloseDate = Time.Date + Closetime;
           }
           for (int j = 0; j < Back_days; j++)
           {
               validation = true;
               Openindex = Bars.OpenTimes.GetIndexByExactTime(OpenDate);
               Closeindex = Bars.OpenTimes.GetIndexByExactTime(CloseDate);
               if (Openindex < 0)
                   validation = false;
               if (CloseDate.DayOfWeek == DayOfWeek.Saturday || CloseDate.DayOfWeek == DayOfWeek.Sunday)
                   validation = false;
               if (validation)
               {
                   Min = Bars[Openindex].Low;
                   Max = Bars[Openindex].High;
                   int i = Openindex;
                   for (i = Openindex; i < Bars.Count; i++)
                   {
                       if (Bars[i].OpenTime >= CloseDate) break;
                       Min = Math.Min(Bars[i].Low, Min);
                       Max = Math.Max(Bars[i].High, Max);
                   }

                   ChartRectangle rectangle = Chart.DrawRectangle(session + i + this.ToString(), OpenDate, Min, Bars[i - 1].OpenTime, Max, color, 1, lineStyle);
                   if (InfiniteRange == Infinite_Range.Up)
                       rectangle.Y2 *= 2;
                   else if (InfiniteRange == Infinite_Range.Down)
                       rectangle.Y1 /= 2;
                   else if (InfiniteRange == Infinite_Range.Both)
                   {
                       rectangle.Y1 /= 2;
                       rectangle.Y2 *= 2;
                   }
                   if (Filled_Zones)
                       rectangle.IsFilled = true;
                   if (Show_Labels)
                   {
                       ChartText text = Chart.DrawText("text" + rectangle.Name, session, OpenDate, Max, color);
                       text.VerticalAlignment = VerticalAlignment.Top;
                       text.FontSize = 10;
                       text.ZIndex = 10;
                   }
               }
               OpenDate = OpenDate.AddDays(-1);
               CloseDate = CloseDate.AddDays(-1);
           }
       }
   }

   public class Session
   {
       public string name { get; set; }
       public TimeSpan Open { get; set; }
       public TimeSpan Close { get; set; }
       public Color Color { get; set; }
       public LineStyle LineStyle { get; set; }
   }
}


@AlgoCreators

AlgoCreators
24 Oct 2024, 13:05

RE: Indicator incompatibility on Mac

PanagiotisCharalampous said: 

Hi there,

Can you explain what is the exact problem?

Best regards,

Panagiotis

One of the users who installed the indicator on Mac sent me this message


@AlgoCreators

AlgoCreators
21 Jun 2024, 12:43

RE: RE: RE: Non -executing the OnDestroy() function

Spotware said: 

AlgoCreators said: 

PanagiotisCharalampous said: 

Hi there,

I don't think this was ever working. When the indicator is unloaded and destroyed, all references created by the indicator will do as well, same for the indicator's log. If you want to check this, write in an external file.

Best regards,

Panagiotis

Ok, now there is no way for the indicator to clear the interactive objects it created when it is deleted.

I am not sure what you mean, can you elaborate?

When my indicator is on the chart. Adds objects to the chart, such as rectangles and trend lines
These objects are interactive.
"IsInteractive = true;"
When I remove the indicator from the chart, those objects remain in the chart! If their interactive feature is false, they will be deleted automatically, but as I said, I will turn on their interactive feature.
I want to delete all the objects added to the chart when the indicator is deleted


@AlgoCreators

AlgoCreators
20 Jun 2024, 09:18

RE: Non -executing the OnDestroy() function

PanagiotisCharalampous said: 

Hi there,

I don't think this was ever working. When the indicator is unloaded and destroyed, all references created by the indicator will do as well, same for the indicator's log. If you want to check this, write in an external file.

Best regards,

Panagiotis

Ok, now there is no way for the indicator to clear the interactive objects it created when it is deleted.


@AlgoCreators

AlgoCreators
28 May 2024, 16:13 ( Updated at: 28 May 2024, 16:16 )

The problem was solved!
I was creating a new object by mistake when there was no need to do this and I should have used "this".

Print(Check(this));

thank you.


@AlgoCreators

AlgoCreators
28 May 2024, 16:09

RE: accessing LocalStorage in a static method

PanagiotisCharalampous said: 

Here you go

        public static bool Check(Robot robot)        {            string MyLocalStorage = robot.LocalStorage.GetString("Data", LocalStorageScope.Type);            if (MyLocalStorage == null)            {                return false;            }            else            {                return true;                     }        }

Dear friend, unfortunately, I could not call it correctly and with the error:
Crashed in Initialize with NullReferenceException: Object reference not set to an instance of an object.

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class test_indi : Indicator
    {
        public static bool Check(Indicator indicator)
        {
            string MyLocalStorage = indicator.LocalStorage.GetString("Data", LocalStorageScope.Type);
            if (MyLocalStorage == null)
            {
                return false;
            }
            else
            {
                return true;
         
            }
        }
        protected override void Initialize()
        {
        Indicator indicator=new test_indi();
        Print(Check(indicator));
        }

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

 

 


@AlgoCreators

AlgoCreators
28 May 2024, 06:27

Great, thank you very much


@AlgoCreators

AlgoCreators
17 May 2024, 14:34

+1


@AlgoCreators

AlgoCreators
30 Mar 2024, 09:44 ( Updated at: 30 Mar 2024, 10:06 )

Hi andrea

you can see this robot

https://ctrader.com/algos/show/3835


@AlgoCreators

AlgoCreators
16 Feb 2024, 23:31

try this:

Time7 = Time.Date + TimeSpan.Parse("07:00:00");
Chart.DrawVerticalLine("Vertical Line 7", Time7, Color.Red);


@AlgoCreators

AlgoCreators
16 Feb 2024, 23:15

Your explanation is a little unclear, but have you checked this out?

  1. Trend = TM1.Trend.LastValue;

@AlgoCreators

AlgoCreators
28 Jan 2024, 09:14

Hi, you need to use this command to change the stop loss


Position.ModifyStopLossPips(newStopLoss);

@AlgoCreators

AlgoCreators
19 Jan 2024, 14:17

How to make string variable writable?

hi, Check this code, I hope it solves your problem

using cAlgo.API;
using System.Text.RegularExpressions;
namespace cAlgo
{
    // This sample indicator shows how to use TextChangedEventArgs
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TextChangedEventArgsSample : Indicator
    {
        protected override void Initialize()
        {
            var stackPanel = new StackPanel
            {
                BackgroundColor = Color.Gold,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Opacity = 0.6,
            };
            var textBox = new TextBox
            {

                Text = "Enter text here...",
                FontWeight = FontWeight.ExtraBold,
                Margin = 5,
                ForegroundColor = Color.White,
                HorizontalAlignment = HorizontalAlignment.Center,
                Width = 150
            };
            textBox.TextChanged += TextBox_TextChanged;
            stackPanel.AddChild(textBox);
            Chart.AddControl(stackPanel);
        }
        private void TextBox_TextChanged(TextChangedEventArgs obj)
        {
            string str = obj.TextBox.Text;
            if (str.Length > 0)
                if (str[str.Length - 1] == '.')
                {
                    var x = Regex.Replace(str,@"[.]+", ",");              
                    obj.TextBox.Text = "";
                    obj.TextBox.Text = x;
                }
        }
        public override void Calculate(int index)
        {
        }
    }
}

 


@AlgoCreators

AlgoCreators
29 May 2023, 19:11

RE:

jim.tollan said:

 

You seem to be under the illusion that firemyst is one of your employees. I suggest you adopt a better bedside manner. Thereafter, you'll be pleasantly surprised at the number of folk that  that will be willing to help out with any issues you have. Until then - business as usual.

FWIW - this was the extended approach that firemyst was alluding to:

foreach (var indicatorArea in Chart.IndicatorAreas)
{
    foreach (var indicator in indicatorArea.Objects)
    {
        Print($"Indicator => Area: {indicatorArea.GetType().Name} Name: {indicator.Name}");
    }
}

Whilst it is frustrating to not be presented with the answer that you WANT, sometimes you just have to be grateful that folk have taken the time to point you in the right direction.

thank you for your help But this code doesn't show anything. Because indicatorArea.Objects.Count =>> 0 And the internal for command is not executed at all

Unfortunately, I am not fluent in English and I use Google translator for help. Maybe I can't ask my question correctly!!


@AlgoCreators

AlgoCreators
20 May 2023, 00:33

RE: RE: RE: RE: RE: RE:

firemyst said:

meeting.chegini said:

Dear friend, do you want to teach me how to split the nucleus of an atom?

This is a simple question! If you know the solution, please guide me

How to split the nucleus of an atom: there's plenty of "how to's" on Google and YouTube already on how to do it.

Guiding you on this issue - I already started. Second post in this thread is how you would start going about doing it through C# code. If you're not trying by writing any code, I'm not writing code for you. Best way to learn is to do it on your own.

If you're just looking at the chart and wondering where they are on the chart, then look for the indicator name on the chart:

 

If the name of the indicator isn't on your chart, then put it there by choosing to display "Indicator Titles":

 

 

I wanted to find out through C# what oscillators are placed on the chart, but I couldn't find a solution. And I think there is no way
And I respect your wrong way of thinking.
Good luck.


@AlgoCreators

AlgoCreators
20 May 2023, 00:01

RE: RE: combine rsi and stochastic

arash.box said:

meeting.chegini said:

سلام آرش جان ببین این کارتو راه میندازه

 

سلام

آقای چگینی عزیز متشکرم از راهنماییتون

 

پیروز و سربلند باشید

خواهش میکنم دوست عزیز
شما هم همینطور


@AlgoCreators

AlgoCreators
18 May 2023, 21:48

combine rsi and stochastic

سلام آرش جان ببین این کارتو راه میندازه

 


@AlgoCreators

AlgoCreators
18 May 2023, 20:45

RE: RE: RE: RE:

firemyst said:

meeting.chegini said:

firemyst said:

meeting.chegini said:

Hello
How do I know the name of the indicator in the IndicatorAreas?

For example, What is the name of the Chart.IndicatorAreas[0] indicator?

Try something like this:

Chart.IndicatorAreas[0].Objects[0].Name

Because each indicator area can have more than 1 object in it, you'll have to loop through all the objects to get all their names.

I don't want this!!

I want a code that gives me the name of the oscillator

 

I just gave you the general code above on what you have to do.

It's up to you to implement depending on the rest of your code.

I'm not going to write everything for you.

 

Dear friend, do you want to teach me how to split the nucleus of an atom?
This is a simple question! If you know the solution, please guide me


@AlgoCreators