Topics
06 Dec 2023, 18:20
 4
 333
 1
09 May 2023, 00:11
 489
 2
24 Feb 2023, 23:26
 547
 3
14 Feb 2023, 23:15
 1125
 10
10 Sep 2021, 00:29
 14
 1725
 4
12 Jun 2021, 21:12
 1932
 9
25 Feb 2019, 20:43
 1352
 5
Replies

DelFonseca
06 Dec 2023, 18:18

RE: [Native] Supertrend Indicator - doesn't allow Bars bars

PanagiotisCharalampous said: 

Hi DelFonseca,

You can post this in the Suggestions section. Here it will be lost.

Best regards,

Panagiotis

Hi my friend,

Thank you! Done.


@DelFonseca

DelFonseca
02 Aug 2023, 18:16 ( Updated at: 02 Aug 2023, 19:34 )

[EDIT] After reinstalling cTrader, the problem has been solved. Thanks


@DelFonseca

DelFonseca
17 Jul 2023, 22:35

cTrader Team,

Check out this example, where a button is created at startup. Clicking on it should bring up two new buttons.

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;

namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.None)]
    public class Test3 : Indicator
    {
        private Grid mainGrid;
        private Button MainButton, leftButton, rightButton;

        protected override void Initialize()
        {
            mainGrid = new Grid(1, 3)
            {
                Width = 300,
                Height = 50,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                ShowGridLines = true
            };            
            
            CreateMainButton();
            
            Chart.AddControl(mainGrid);
        }
        
        private void CreateMainButton()
        {
            MainButton = new Button()
            {
                Text = "Create",
                BackgroundColor = Color.White,
                ForegroundColor = Color.Black,
            };
            mainGrid.AddChild(MainButton, 0, 0);
            MainButton.Click += mainButton_Click;
        }
        
        private void CreateLeftButton()
        {
            Print("CreateLeftButton()");
            leftButton = new Button()
            {
                Text = "Remove me",
                BackgroundColor = Color.White,
                ForegroundColor = Color.Black,
            };
            mainGrid.AddChild(leftButton, 0, 1);
            leftButton.Click += leftButton_Click;
        }
        
        private void CreateRightButton()
        {
            Print("CreateRightButton()");
            rightButton = new Button()
            {
                Text = "Remove me",
                BackgroundColor = Color.White,
                ForegroundColor = Color.Black,
            };
            mainGrid.AddChild(rightButton, 0, 2);
            rightButton.Click += rightButton_Click;
        }
        
        private void mainButton_Click(ButtonClickEventArgs obj)
        {
            Print("mainButton_Click");
            CreateLeftButton();
            CreateRightButton();
        }
        
        private void leftButton_Click(ButtonClickEventArgs obj)
        {
            Print("leftButton_Click");
            mainGrid.RemoveChild(leftButton);
            CreateRightButton();
        }
        
        private void rightButton_Click(ButtonClickEventArgs obj)
        {
            Print("rightButton_Click");
            mainGrid.RemoveChild(rightButton);
            CreateLeftButton();
        }

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

 


@DelFonseca

DelFonseca
03 Jun 2023, 19:45

[SOLVED]

Problem solved. My cTrader was not up to date, follow the code below with HttpClient replaced by cAlgo.API.Http.
Thanks to "The T"
 

using System;
using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class TelegramSample : Indicator
    {
        [Parameter("Token", DefaultValue = "")]
        public string TOKEN { get; set; }

        [Parameter("ChatId", DefaultValue = "")]
        public string CHATID { get; set; }


        protected override void Initialize()
        {

        }

        public void SendTelegram(string msg)
        {
            try
            {
                var url = $"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={CHATID}&text={msg}";
                var response = Http.Get(url);//httpClient.GetAsync(url).Result;

                if (!response.IsSuccessful)
                {
                    msg += $": Error Sending Telegram Message: {response.StatusCode}, {response.Body}";
                }
                else
                {
                    msg += ": Success";
                }
            }
            catch (Exception e)
            {
                msg += ": EXCEPTION : " + e.Message + "\n\n" + e.StackTrace;
            }

            Print(msg);
        }

        public override void Calculate(int index)
        {
            SendTelegram("Hello World.");
        }
    }
}

 


@DelFonseca

DelFonseca
02 Jun 2023, 22:56

RE:

firemyst said:

(...)

The example in the video does not work as it requires AccessRights.FullAccess.
According to the documentation, the example I shared should work with AccessRights.None, but it gives the error that is in my thread.
I don't know if I'm missing something because I've tried several methods without success to make it work with AccessRights.None


@DelFonseca

DelFonseca
06 May 2023, 17:40

RE:

amusleh said:

Hi,

This works fine for me on 4.6.2 and .NET 6:

(...)

 

Check event signature before using it: SelectedItemChanged Event - cTrader Automate API

Hi amusleh,

I was testing the indicator I am developing and came across a ctrader bug.

For example, with the code you provided, select "Item 2", change chart tab and go back to the tab where you have the indicator. It should keep "Item 2" selected. I have tried to solve it via code, but the logs return "Item 2" selected, I believe it is a visual bug. Can you test it there please?

Thanks in advance


@DelFonseca

DelFonseca
02 Mar 2023, 22:40

RE: RE: RE:

heinrich.munz said:

(...)

The question was whether it is possible. Not if it was functional.
Functional is relative, if it is for example to "clone" the trades, no. If it is for report documents or notify followers on telegram, yes.


@DelFonseca

DelFonseca
01 Mar 2023, 22:23

RE:

dthetten said:

Hello

(...)

Thanks

Yes, search for "web scraping"


@DelFonseca

DelFonseca
28 Feb 2023, 23:44

RE:

PanagiotisChar said:

(...)


Hello my Friend,

First of all, I hope your career path is being a success....

Thanks for your reply, in the meantime I have resolved and thought the opposite, if I want to do merging, why not start with 1 column and add what I want like "unmerge"? Solved it :)

Thanks!!

Here is an example in case someone in the future needs it.

using System;
using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MergeCells : Indicator
    {
    
        private Grid mainDataGrid, insideDataGrid;

        protected override void Initialize()
        {
            mainDataGrid = new Grid(5, 1)
            {
                Width = 100,
                Height = 100,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                ShowGridLines = true,            
            };
            
            TextBlock MergeCellsText = new TextBlock()
            {
                Text = "Merged Cells",
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
            };
            mainDataGrid.AddChild(MergeCellsText, 0, 0);          
            
            insideDataGrid = new Grid(1, 3);
            insideDataGrid.ShowGridLines = true;
            
            for (int i = 0; i < 3; i++)
            {
                TextBlock ExampleText = new TextBlock()
                {
                    Text = i.ToString(),
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                };
                insideDataGrid.AddChild(ExampleText, 0, i);
            }
            
            mainDataGrid.AddChild(insideDataGrid, 1, 0);
            
            Chart.AddControl(mainDataGrid);            
        }

        public override void Calculate(int index)
        {

        }
    }
}

 


@DelFonseca

DelFonseca
21 Feb 2023, 18:19 ( Updated at: 21 Feb 2023, 23:41 )

RE:

amusleh said:

Hi,

This works fine for me on 4.6.2 and .NET 6:

//...

Check event signature before using it: SelectedItemChanged Event - cTrader Automate API

Thank you so much my friend!! Thank you

For those who are interested, the solution:

Change the line:

private void myDropList_SelectedIndexChanged(object sender, ComboBoxSelectedItemChangedEventArgs e)

to:

private void indicatorsDropList_SelectedIndexChanged(ComboBoxSelectedItemChangedEventArgs obj)

 


@DelFonseca

DelFonseca
21 Feb 2023, 15:46

up


@DelFonseca

DelFonseca
14 Jun 2021, 20:27

RE:

amusleh said:

Hi,

To use WinForms on your cBot/Indicator, you have to follow these steps:

  • (...)

Open it with VS to see the cBot full code.

Thank you so much for your hel, it was perfect!!


@DelFonseca

DelFonseca
23 Jul 2020, 23:51

RE:

PanagiotisCharalampous said:

Hi ghcaplan,

Thanks for posting in our forum. No this is still not possible.

Best Regards,

Panagiotis

Hi 

 

Forecasts for renko backtesting

Best Regards


@DelFonseca

DelFonseca
23 Jul 2020, 23:49

+1


@DelFonseca

DelFonseca
23 Jun 2020, 01:58

RE:

Jiri said:

Hi, try this: 

History.Any() ? History.Last(x => x.ClosingTime.Date < Time.Date).Balance : Account.Balance

 

 

Thank you very much for your help. Work perfectly!
Best regards


@DelFonseca

DelFonseca
22 Jan 2020, 20:30

RE:

PanagiotisCharalampous said:

(...)

Thank you so much, you rock!!.


@DelFonseca

DelFonseca
21 Jan 2020, 20:12

RE:

PanagiotisCharalampous said:

Hi DelTrader,

Can you please post the complete cBot code so that we can have a look?

Best Regards,

Panagiotis 

Join us on Telegram

 

 

Thank you very much for your reply!

The robot has almost 8 thousand lines with arrays and connections to databases, I created a basic one to facilitate you and the situation is the same.

Start cBot a stop. Close manually opened trades to be part of the history, after that starts cBot again and confirms that the 'HistoricalProfitInCash' in the 'Chart.DrawStaticText' will significantly change tick by tick and meaningless.

Please check. I am grateful to you!!

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 Teste : Robot
    {
        [Parameter("1st Symbol", Group = "First Symbol", DefaultValue = "EURUSD")]
        public string FirstSymbol { get; set; }
        [Parameter("Lote: Buy Symbol", Group = "First Symbol", DefaultValue = 0.01, MinValue = 0.01)]
        public double QuantityToFirst { get; set; }

        [Parameter("2nd Symbol", Group = "Second Symbol", DefaultValue = "USDJPY")]
        public string SecondSymbol { get; set; }
        [Parameter("Lote: Sell Symbol", Group = "Second Symbol", DefaultValue = 0.01, MinValue = 0.01)]
        public double QuantityToSecond { get; set; }

        [Parameter("Date (ddMMyyyy)", Group = "Settings", DefaultValue = "21012020")]
        public string TodaysDate { get; set; }

        private double VolumeInUnitsFirst
        {
            get { return Symbol.QuantityToVolumeInUnits(QuantityToFirst); }
        }
        private double VolumeInUnitsSecond
        {
            get { return Symbol.QuantityToVolumeInUnits(QuantityToSecond); }
        }

        private Symbol FirstSymbolGetSymbol, SecondSymbolGetSymbol;
        private const string Label = "Teste -  ";
        private int _FirstSymbolCount, _SecondSymbolCount;
        private double HistoricalProfitInCash;

        protected override void OnStart()
        {
            HistoricalProfitInCash = 0;
            FirstSymbolGetSymbol = Symbols.GetSymbol(FirstSymbol);
            SecondSymbolGetSymbol = Symbols.GetSymbol(SecondSymbol);
            HistoricalTradeByLabel();
        }

        protected override void OnTick()
        {
            HistoricalTradeByLabel();

            _FirstSymbolCount = Positions.Where(p => p.Label == Label + "1stSymbol " + FirstSymbol + " 2ndSymbol " + SecondSymbol + " - " + TodaysDate).Where(p => p.TradeType == TradeType.Buy).Count(p => p.SymbolName == FirstSymbol);
            _SecondSymbolCount = Positions.Where(z => z.Label == Label + "1stSymbol " + FirstSymbol + " 2ndSymbol " + SecondSymbol + " - " + TodaysDate).Where(z => z.TradeType == TradeType.Buy).Count(z => z.SymbolName == SecondSymbol);

            if (_FirstSymbolCount == 0)
                ExecuteMarketOrder(TradeType.Buy, FirstSymbolGetSymbol.Name, VolumeInUnitsFirst, Label + "1stSymbol " + FirstSymbol + " 2ndSymbol " + SecondSymbol + " - " + TodaysDate, 0, 10);
            if (_SecondSymbolCount == 0)
                ExecuteMarketOrder(TradeType.Buy, SecondSymbolGetSymbol.Name, VolumeInUnitsSecond, Label + "1stSymbol " + FirstSymbol + " 2ndSymbol " + SecondSymbol + " - " + TodaysDate, 0, 10);
        }

        private void HistoricalTradeByLabel()
        {
            //foreach (HistoricalTrade trade in History.FindAll(Label + "1stSymbol " + FirstSymbol + " 2ndSymbol " + SecondSymbol + " - " + TodaysDate))
            foreach (HistoricalTrade trade in History)
            {
                //if (trade.Label.Contains(Label + "1stSymbol " + FirstSymbol + " 2ndSymbol " + SecondSymbol + " - " + TodaysDate))
                if (trade.Label == (Label + "1stSymbol " + FirstSymbol + " 2ndSymbol " + SecondSymbol + " - " + TodaysDate))
                {
                    HistoricalProfitInCash += trade.NetProfit;
                }
            }
            Chart.DrawStaticText("LabelOutputForTeste", NewLine(10) + "HistoricalProfitInCash: " + HistoricalProfitInCash + " €", VerticalAlignment.Top, HorizontalAlignment.Right, Color.Yellow);
        }

        private string NewLine(int n)
        {
            return new string('\n', n);
        }
    }
}

 


@DelFonseca

DelFonseca
20 Jan 2020, 22:54

RE:

PanagiotisCharalampous said:

Hi DelTrader,

See below

            if (Positions.Count(x => x.Id == PosID1) > 0)
            {
                Positions.First(x => x.Id == PosID1).Close();
            }

Best Regards,

Panagiotis 

Join us on Telegram

 

Thank you so much Sir.


@DelFonseca

DelFonseca
20 Jan 2020, 22:48

I said layer but the correct is label

I try this too, but the problem is the same.

private void HistoricalTradeByLabel()
{
   foreach (HistoricalTrade trade in History.FindAll(Label + "1stSymbol " + FirstSymbol + " 2ndSymbol " + SecondSymbol + " - " + TodaysDate))
   {
      HistoricalProfitInCash += trade.NetProfit;
   }
}

 


@DelFonseca

DelFonseca
02 Jan 2020, 23:59 ( Updated at: 21 Dec 2023, 09:21 )

RE: Correlation Coefficient

cAlgo_Fanatic said:

The correlation coefficient compares how currency pairs have moved in relation to each other.

The correlation coefficient formula is:

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

namespace cAlgo.Indicators
{
    [Levels(-1, -0.5, 0, 0.5, 1)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, ScalePrecision = 2)]
    public class CorrelationCoefficient : Indicator
    {
        private MarketSeries series2;
        private Symbol symbol2;

        [Parameter(DefaultValue = "EURUSD")]
        public string Symbol2 { get; set; }

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

        [Output("Correlation Coefficient", Color = Colors.Yellow)]
        public IndicatorDataSeries Result { get; set; }

        protected override void Initialize()
        {
            symbol2 = MarketData.GetSymbol(Symbol2);
            series2 = MarketData.GetSeries(symbol2, TimeFrame);
        }

        public override void Calculate(int index)
        {
            if (index < Period)
                return;

            double sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0, sumY2 = 0;
            double x, y, x2, y2;

            int index2 = GetIndexByDate(series2, MarketSeries.OpenTime[index]);

            if (index2 == -1)
                return;

            for (int i = 0; i < Period; i++)
            {
                x = MarketSeries.Close[index - i];
                y = series2.Close[index2 - i];

                x2 = x * x;
                y2 = y * y;
                sumX += x;
                sumY += y;
                sumXY += x * y;
                sumX2 += x2;
                sumY2 += y2;
            }

            Result[index] = (Period * (sumXY) - sumX * sumY) / 
                               Math.Sqrt((Period * sumX2 - sumX * sumX) * (Period * sumY2 - sumY * sumY));
        }

        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i >= 0; i--)
            {
                if (time == series.OpenTime[i])
                    return i;
            }
            return -1;
        }
    }
}

 

Good night,

 

I want to get the correlation of 2 symbols, for example EURGBP with GBPCHF but showing on EURUSD chart.

Can someone help me? 

Thank you so much

@DelFonseca