Topics
28 Feb 2023, 14:22
 42
 3743
 23
Replies

Capt.Z-Fort.Builder
30 Apr 2022, 11:17 ( Updated at: 21 Dec 2023, 09:22 )

I look forward to seeing the function to be implemented. Especially, when the customised indicator has many parameters.

Anyone like this idea please vote 

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
26 Apr 2022, 12:27

RE: RE: RE:

Oh, yes, I tried locking the object, but the highlight is still there when hovering over it. Anyway, it's a tiny issue here.   

Thanks for the reply again. :)

amusleh said:

TheNiatpac said:

Oh, thanks.  I just realised.

Generally, if the object in chart is IsInteractive = True, is there any way to get rid of the highlight when the mouse hovers over? Maybe not, I guess...

 

amusleh said:

Hi,

To show the time on x axis you have to set the line IsInteractive property to true.

 

Hi,

You can try setting the IsLocked property of object to True, this will lock the object and user will not be able to update the object unless it's unlocked.

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
25 Apr 2022, 13:34

RE:

Oh, thanks.  I just realised.

Generally, if the object in chart is IsInteractive = True, is there any way to get rid of the highlight when the mouse hovers over? Maybe not, I guess...

 

amusleh said:

Hi,

To show the time on x axis you have to set the line IsInteractive property to true.

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
21 Apr 2022, 15:23

RE:

Thank you very much. It works very well.

BTW, I checked the BearOutlineColor but I didn't get the correct syntax until you put your sample code above.

Thanks again. :)

amusleh said:

Hi,

Try this:

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class SampleSMA : Indicator
    {
        protected override void Initialize()
        {
            // Bullish bars
            Chart.ColorSettings.BullFillColor = Color.Blue;
            Chart.ColorSettings.BullOutlineColor = Color.Blue;
            // Bearish bars
            Chart.ColorSettings.BearFillColor = Color.Gold;
            Chart.ColorSettings.BearOutlineColor = Color.Gold;
        }

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

 

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
20 Apr 2022, 13:34

RE:

Thank you like always, it works perfectly.  :)

amusleh said:

Hi,

Try this:

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class USDCorelation : Indicator
    {
        [Parameter("Reset Time", DefaultValue = "2022-4-19 22:15:00", Group = "Ver. 1.01")]
        public string ResetPoint { get; set; }

        [Output("GBP", LineColor = "FFB600FF", Thickness = 2, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries GBP { get; set; }

        [Output("NZD", LineColor = "FF00BF00", Thickness = 2, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries NZD { get; set; }

        private DateTime dt_RstPnt; //Reset Time Point;

        //Bars to load for Calculate
        private Bars EURUSD, GBPUSD, NZDUSD;

        //Index at ResetTimePoint of EachSymbol;
        private int in_EURUSD, in_GBPUSD, in_NZDUSD;

        //BaseValue at ResetTimePoint of EachSymbol;
        private double db_EURUSD, db_GBPUSD, db_NZDUSD;

        protected override void Initialize()
        {
            //1.Get MarketData in Series Ready
            EURUSD = MarketData.GetBars(Bars.TimeFrame, "EURUSD");
            GBPUSD = MarketData.GetBars(Bars.TimeFrame, "GBPUSD");
            NZDUSD = MarketData.GetBars(Bars.TimeFrame, "NZDUSD");

            //2.Get ResetTimePoint Index
            dt_RstPnt = DateTime.Parse(ResetPoint).Add(-Application.UserTimeOffset);

            in_EURUSD = EURUSD.OpenTimes.GetIndexByTime(dt_RstPnt);
            in_GBPUSD = GBPUSD.OpenTimes.GetIndexByTime(dt_RstPnt);
            in_NZDUSD = NZDUSD.OpenTimes.GetIndexByTime(dt_RstPnt);

            //3.Get OpenPrice of each symbol at ResetTimePoint
            db_EURUSD = EURUSD[in_EURUSD].Open;
            db_GBPUSD = GBPUSD[in_GBPUSD].Open;
            db_NZDUSD = NZDUSD[in_NZDUSD].Open;
        }

        public override void Calculate(int index)
        {
            if (Bars.OpenTimes[index] < dt_RstPnt) return;
                
            var gbpIndex = GBPUSD.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            var gbpGap = gbpIndex - in_GBPUSD;
            
            GBP[index] = ((GBPUSD[in_GBPUSD + gbpGap].Close) + db_EURUSD - db_GBPUSD);
            
            var nzdIndex = NZDUSD.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            var nzdGap = nzdIndex - in_NZDUSD;
            
            NZD[index] = ((NZDUSD[in_NZDUSD + nzdGap].Close) + db_EURUSD - db_NZDUSD);
        }
    }
}

 

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
20 Apr 2022, 03:24

RE:

Thank me, the problem has been resolved. 

There are some bars gaps between the data series to the bars' index number. Get the gap value e.g gap_EURUDS and put them in the right place as below would fix the problem.

...
        {
            USD[index] = 200*(  (1/EURUSD[index + gap_EURUDS].Close)
                               *(1/GBPUSD[index + gap_GBPUSD].Close)
                               *(1/AUDUSD[index + gap_AUDUSD].Close)
                               *(1/USDCAD[index + gap_USDCAD].Close)
                               *(1/NZDUSD[index + gap_NZDUSD].Close)
                               *  (USDCHF[index + gap_USDCHF].Close)
                               *  (USDJPY[index + gap_USDJPY].Close)
                               -137);
        }
...

 

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
10 Feb 2022, 15:59

RE:

Thank you Musleh as always, it works pretty well. :)

amusleh said:

Hi,

You can use a bool flag to avoid the second call:

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class HorizentalLineTest : Robot
    {
        private ChartHorizontalLine hlStopLoss;

        private bool _updatingComment;

        protected override void OnStart()
        {
            hlStopLoss = Chart.DrawHorizontalLine("StopLoss", Symbol.Bid, Color.FromHex("#BBFF7777"), 1, LineStyle.LinesDots);
            hlStopLoss.IsInteractive = true; hlStopLoss.IsLocked = false; hlStopLoss.Comment = Symbol.Bid.ToString();
            Chart.ObjectsUpdated += SLModified;
        }

        protected override void OnTick()
        { }

        protected override void OnStop()
        { Chart.RemoveObject(hlStopLoss.Name); }

        private void SLModified(ChartObjectsUpdatedEventArgs obj) //Modify HorizentialLine, to update Price in Comments
        {
            if (_updatingComment)
            {
                _updatingComment = false;

                return;
            }

            var horizentalLine = obj.ChartObjects.FirstOrDefault(iObject => iObject.ObjectType == ChartObjectType.HorizontalLine && iObject.Name.Equals(hlStopLoss.Name, StringComparison.OrdinalIgnoreCase));

            if (horizentalLine != null)
            {
                _updatingComment = true;

                hlStopLoss.Comment = hlStopLoss.Y.ToString("0.00000");
                Print("HorizentalLine's Y: " + hlStopLoss.Y.ToString("0.00000"));
            }
        }
    }
}

 

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
09 Feb 2022, 16:49

RE: RE: RE:

OK, thanks. I've posted in the suggestion section. I hope more users would like to have this function. Cheers.

amusleh said:

TheNiatpac said:

OK, thanks for the reply.  Any possible future versions to support this function?

amusleh said:

Hi,

No, you can't set/get the Output attribute properties programmatically.

 

Hi,

No, it's not planned, please create a thread under suggestions section and then we will consider it if it got enough vote from other users.

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
08 Feb 2022, 15:14

RE:

OK, thanks for the reply.  Any possible future versions to support this function?

amusleh said:

Hi,

No, you can't set/get the Output attribute properties programmatically.

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
31 Jan 2022, 12:22 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

Hi Musleh,

Thanks for the reply. I found the problem. 

            var icon = Chart.DrawIcon(sMessage, ChartIconType.UpArrow, Bars.LastBar.OpenTime, Bars.LastBar.Low * 0.999, Color.FromHex("#DDE7E7E7"));

I should define the icon first. So that we can set the properties for it.  

Much appreciated.

L

amusleh said:

TheNiatpac said:

Hi Musleh,

I've just tested the code. Please advise.

 

Hi,

There is no such issue on my posted code, most probably you made some changes on it, the error says that the variable "icon" does not exist.

 

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
28 Jan 2022, 14:22

RE:

Hi Musleh,

I've just tested the code. Please advise.

 

amusleh said:

Hi,

You can set the object IsInteractive flag to True:

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DrawIcon : Robot
    {

        protected override void OnStart()
        {
            string sMessage = "Long " + Bars.LastBar.OpenTime;
            var icon = Chart.DrawIcon(sMessage, ChartIconType.UpArrow, Bars.LastBar.OpenTime, Bars.LastBar.Low * 0.999, Color.FromHex("#DDE7E7E7"));

            icon.IsInteractive = true;
            icon.IsLocked = true;
        }

        protected override void OnTick() {}

        protected override void OnStop() {}
    }
}

The IsLocked is an additional optional step which disables moving of object, but you can turn it on/off from object settings.

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
28 Jan 2022, 14:08 ( Updated at: 28 Jan 2022, 16:16 )

RE:

Hi Musleh,

I've just tested the code, there are some error information when compiling. 

L

amusleh said:

Hi,

You can set the object IsInteractive flag to True:

using cAlgo.API;

namespace cAlgo.Robots
{
...    
}

The IsLocked is an additional optional step which disables moving of object, but you can turn it on/off from object settings.

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
26 Jan 2022, 23:05

RE:

Thank you Musleh, much appreciated.

I will use the Collections and List<> way on my case. Both methods need modifying items one by one, just like you said. 

Thanks again, I learned many from you. Hope you have a good day and week. :)

amusleh said:

Hi,

Here is an example that might help you:

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

namespace cAlgo
{
 ...
}

You can also check each examples of each control I used above on API references.

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
25 Jan 2022, 15:29

RE: RE: RE:

Hi Amusleh,

Thanks very much for the hints, I've made this code to define a group of buttons, by c# collections.

Would you mind showing me the technique to do the same job via 'parent custom control'?

L

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


namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Buttons : Indicator
    {

        private Button DS_Btn = new Button { Text = "DS", VerticalAlignment = VerticalAlignment.Top };
        private Button DL_Btn = new Button { Text = "DL", VerticalAlignment = VerticalAlignment.Bottom };
        private Button BM_Btn = new Button { Text = "BM", VerticalAlignment = VerticalAlignment.Center };

        private readonly Color clrBtnFrtMd = Color.FromHex("#FF000000"); //ChartButton FrontColor
        private readonly Color clrBtnBktMd = Color.FromHex("#55CFCFCF"); //ChartButton Background
        private readonly Color clrBrdFrtUp = Color.FromHex("#EE88FF88"); //Red   BackGround
        private readonly Color clrBrdFrtDn = Color.FromHex("#EEFF8888"); //Green BackGround
        
        private bool _DS, _DL, _BM; 

        protected override void Initialize()
        {
            //Add-Controls: Buttons
            var buttons = new List<Button>();
            buttons.Add(DS_Btn);
            buttons.Add(DL_Btn);
            buttons.Add(BM_Btn);
            foreach (var button in buttons)
            {
                button.Margin = "0 1 0 1";
                button.Padding = "4 0 4 0";
                button.Height = 16;
                button.FontSize = 9;
                button.IsVisible = true;
                button.ForegroundColor = clrBtnFrtMd;
                button.BackgroundColor = clrBtnBktMd;
                button.HorizontalAlignment = HorizontalAlignment.Center;
            }

            IndicatorArea.AddControl(DS_Btn); DS_Btn.Click += DS_Btn_Click;
            IndicatorArea.AddControl(DL_Btn); DL_Btn.Click += DL_Btn_Click;
            IndicatorArea.AddControl(BM_Btn); BM_Btn.Click += BM_Btn_Click;
        }

        public override void Calculate(int index)
        {
        }
        
        private void DS_Btn_Click(ButtonClickEventArgs obj) 
        { _DS = _DS ? false : true; DS_Btn.BackgroundColor = _DS ? clrBrdFrtUp : clrBrdFrtDn; }

        private void DL_Btn_Click(ButtonClickEventArgs obj) 
        { _DL = _DL ? false : true; DL_Btn.BackgroundColor = _DL ? clrBrdFrtUp : clrBrdFrtDn; }

        private void BM_Btn_Click(ButtonClickEventArgs obj) 
        { _BM = _BM ? false : true; BM_Btn.BackgroundColor = _BM ? clrBrdFrtUp : clrBrdFrtDn; }

    }
}

amusleh said:

TheNiatpac said:

Thank you Amusleh,  I believe this is the right way to process the code. 

Well, in my practice, the following question is,  there are multiple TextBlocks in a Grid or several Grids,  and they all need to change ForegroundColors and Positions by the price up or down. Is there any quick way, I can change all the TextBlocks' ForegroundColor and other properties rather than one by one which makes the code extremely long?

Thanks again in advance.

amusleh said:

Hi,

I will answer each of your point:

1. Yes, it will, you should not create a new button or canvas on each tick/bar

2. It will, because any control you create will live on memory as long as you remove it from chart or remove your indicator from chart

3. You should use OnInitilaize method and only change the control properties based on your criteria.

Here is your indicator code that is properly written:

using cAlgo.API;

namespace cAlgo
{
   ...
}

 

 

Hi,

You can put all the controls inside a collection like list and then change them one by one or use a parent custom control.

There is no other way except updating each control on a sequential order.

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
24 Jan 2022, 18:39 ( Updated at: 24 Jan 2022, 18:41 )

RE:

Thank you Amusleh,  I believe this is the right way to process the code. 

Well, in my practice, the following question is,  there are multiple TextBlocks in a Grid or several Grids,  and they all need to change ForegroundColors and Positions by the price up or down. Is there any quick way, I can change all the TextBlocks' ForegroundColor and other properties rather than one by one which makes the code extremely long?

Thanks again in advance.

amusleh said:

Hi,

I will answer each of your point:

1. Yes, it will, you should not create a new button or canvas on each tick/bar

2. It will, because any control you create will live on memory as long as you remove it from chart or remove your indicator from chart

3. You should use OnInitilaize method and only change the control properties based on your criteria.

Here is your indicator code that is properly written:

using cAlgo.API;

namespace cAlgo
{
   ...
}

 

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
07 Jan 2022, 12:57

RE:

Thanks, mate. I'm keen to see the new coming version. You guys are great at supporting the community! 

amusleh said:

Hi,

You can use Visual Studio 2022 after we released cTrader 4.2, right now you can't use it.

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
07 Jan 2022, 12:56 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

amusleh said:

TheNiatpac said:

Hi Panagiotis,

I just reinstalled my system and started to use Visual Studio 2022. Would you consider supporting the new version soon? or any advice please

Thanks

PanagiotisCharalampous said:

Hi FireMyst,

No ETA at the moment but it should be in one of the upcoming upcoming updates.

Best Regards,

Panagiotis

 

Hi,

You can use Visual Studio 2022 on cTrader 4.2 which is the next major version of cTrader.

Thanks that's would be great!


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
06 Jan 2022, 15:12 ( Updated at: 21 Dec 2023, 09:22 )

RE:

Hi Panagiotis,

I just reinstalled my system and started to use Visual Studio 2022. Would you consider supporting the new version soon? or any advice please

Thanks

PanagiotisCharalampous said:

Hi FireMyst,

No ETA at the moment but it should be in one of the upcoming upcoming updates.

Best Regards,

Panagiotis

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
03 Jan 2022, 20:27 ( Updated at: 03 Jan 2022, 20:37 )

RE:

Thank you amusleh,

I've tested your code, it has perfectly solved the problem of signalling on the chart. Thanks.

But it will continue sending emails when the single triggered in the last bar running. However, I've managed to add 2 bools to control the email sending, which make it what it originally planned to do. 

Thank you very much.

 

amusleh said:

Hi,

It doesn't show the dots because your limiting it to only draw the dot if it's a LastBar, try this:

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

namespace cAlgo
{
...
        private SimpleMovingAverage SMA;
        private bool _XaboveSilent;
        private bool _XbelowSilent;
...

        public override void Calculate(int index)
        {
...
                if (IsLastBar && !_XaboveSilent)
                {
                    Notifications.SendEmail("*****@icloud.com", "*****@icloud.com", "X 50 SMA - " + Symbol.Name, "X ABOVE"); 
                    _XaboveSilent = true; _XbelowSilent = false;
                }
...
                if (IsLastBar && !_XbelowSilent)
                {
                    Notifications.SendEmail("*****@icloud.com", "*****@icloud.com", "X 50 SMA - " + Symbol.Name, "X BELOW");
                    _XbelowSilent = true; _XaboveSilent = false;
                }
...
}

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
03 Jan 2022, 15:15 ( Updated at: 03 Jan 2022, 15:16 )

RE:

Thank you Amushleh, very kind of you. And it's perfect!

amusleh said:

Hi,

Try this:

using cAlgo.API;
using System;
using System.Globalization;

namespace cAlgo
{
   ...
}

 

 


@Capt.Z-Fort.Builder