PanagiotisCharalampous's avatar
PanagiotisCharalampous
26 follower(s) 0 following 1006 subscription(s)
Replies

PanagiotisCharalampous
24 Mar 2020, 08:44

Hi dannyilumi,

See below an example

// -------------------------------------------------------------------------------------------------
//
//    This code is a cTrader Automate API example.
//
//    This cBot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk.
//    
//    All changes to this file might be lost on the next application update.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
//    The "Sample Trend cBot" will buy when fast period moving average crosses the slow period moving average and sell when 
//    the fast period moving average crosses the slow period moving average. The orders are closed when an opposite signal 
//    is generated. There can only by one Buy or Sell order at any time.
//
// -------------------------------------------------------------------------------------------------

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleTrendcBot : Robot
    {
        [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("MA Type", Group = "Moving Average")]
        public MovingAverageType MAType { get; set; }

        [Parameter("Source", Group = "Moving Average")]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Slow Periods", Group = "Moving Average", DefaultValue = 10)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", Group = "Moving Average", DefaultValue = 5)]
        public int FastPeriods { get; set; }


        private MovingAverage slowMa;
        private MovingAverage fastMa;
        private const string label = "Sample Trend cBot";
        private bool _buyOpened;
        private bool _sellOpened;

        protected override void OnStart()
        {
            fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
        }

        protected override void OnTick()
        {
            var longPosition = Positions.Find(label, SymbolName, TradeType.Buy);
            var shortPosition = Positions.Find(label, SymbolName, TradeType.Sell);

            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(1);
            var previousFastMa = fastMa.Result.Last(1);

            if (previousSlowMa > previousFastMa && currentSlowMa <= currentFastMa && longPosition == null)
            {
                if (shortPosition != null)
                    ClosePosition(shortPosition);
                if (!_buyOpened)
                {
                    ExecuteMarketOrder(TradeType.Buy, SymbolName, VolumeInUnits, label);
                    _buyOpened = true;
                }
            }
            else if (previousSlowMa < previousFastMa && currentSlowMa >= currentFastMa && shortPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);
                if (!_sellOpened)
                {
                    ExecuteMarketOrder(TradeType.Sell, SymbolName, VolumeInUnits, label);
                    _sellOpened = true;
                }
            }
        }

        private double VolumeInUnits
        {
            get { return Symbol.QuantityToVolumeInUnits(Quantity); }
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
24 Mar 2020, 08:32 ( Updated at: 21 Dec 2023, 09:21 )

Hi travkinsm1,

It seems ok to me

 

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
24 Mar 2020, 08:25

Hi Nobody,

You can use Chart.DrawEquidistantChannel() method.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
24 Mar 2020, 07:58

Hi Shares4UsDevelopment,

I cannot reproduce the case with the zeros in the stats. Whenever you have some time, please provide us with the necessary information to look into this further.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 15:06 ( Updated at: 21 Dec 2023, 09:21 )

Hi Sune,

cBot Log only appears after you add a cBot on the chart. See below

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 15:01

Hi Shares4UsDevelopment,

I still need cBot parameters, dates and optimization parameters so that we can reproduce the results you are seeing.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 11:39

Hi,

The button can be used alone.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 11:23

Hi Shares4UsDevelopment,

Please provide us with the cBot code, cBot parameters, dates and optimization parameters so that we can reproduce the results and explain the statistics.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 10:59

Hi,

I explained to you what is the problem with your code. If you don't know how to solve it or you are not familiar with C# programming, you can ask a professional to help you.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 10:26

Hi,

IsChecked is not an event handler but a property. It takes a boolean value. This is why you get the error. 

What are you trying to do?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 10:21

Hi,

If you mean the chart UI controls, then this is not possible. WinForms have their own controls. You can drag them on the form editor from Visual Studio toolbox.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 10:18

Hi Sascha,

See an example below

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; }

        Button _button;
        protected override void OnStart()
        {
            _button = new Button 
            {
                Text = "Click Me 1",
                Top = 100,
                Left = 100
            };
            var canvas = new Canvas 
            {
                            };
            canvas.AddChild(_button);
            Chart.AddControl(canvas);
            Chart.MouseMove += OnChartMouseMove;
        }

        void OnChartMouseMove(ChartMouseEventArgs obj)
        {
            _button.Top = obj.MouseY;
            _button.Left = obj.MouseX;
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

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

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 09:35

Hi dannyilumi,

What should it do instead?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 09:22 ( Updated at: 21 Dec 2023, 09:21 )

RE: RE:

dordkash@gmail.com said:

PanagiotisCharalampous said:

Hi xavier.affringue,

See an example below

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class NewIndicator : Indicator
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private Form1 _f1;
        private Thread _thread;

        protected override void Initialize()
        {
            _f1 = new Form1();
            _thread = new Thread(() => _f1.ShowDialog());
            _thread.SetApartmentState(ApartmentState.STA);
            _thread.Start();

        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
        }
    }
}


Best Regards,

Panagiotis

Dear PanagiotisCharalampous

Please paste this code with a button or Stakepanel
I'm confused and this is very helpful
Thankful

Hi,

Where do you want to add the button or stackpanel?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 09:17 ( Updated at: 21 Dec 2023, 09:21 )

RE: RE:

dordkash@gmail.com said:

ClickAlgo said:

I forgot to mention, you do not need to write the GUI (presentation) code, just create your form with the controls and open the Form.Designer.cs file and copy and paste into your Indicator, you can can then create nice and clean complex forms in a very short time.

HI

TextBoxes dont work

Please correct it
It can be very useful
Thankful

Hi,

Can you explain what do you mean?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 09:12

Hi TSepp,

Yes this is correct. cTrader Automate is only available in cTrader Desktop.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 09:06 ( Updated at: 21 Dec 2023, 09:21 )

Hi Sune,

ChartMouseEventArgs also has a YValue property. See below

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 09:01

Hi tb135qet13,

There is no such option for this method. you can try Chart.DrawText() instead which allows you to draw text at a specific bar index and price level.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 08:54 ( Updated at: 21 Dec 2023, 09:21 )

RE: RE:

dordkash@gmail.com said:

 

var checkBox = new CheckBox()
{
    Text = "Show Volume",
    IsChecked = Chart.DisplaySettings.TickVolume,
    VerticalAlignment = VerticalAlignment.Top,
    HorizontalAlignment = HorizontalAlignment.Left,
    Margin = 5
};
checkBox.Click += e => Chart.DisplaySettings.TickVolume = e.CheckBox.IsChecked.Value;
Chart.AddControl(checkBox);

Hi
what is the problem?

            var checkBox = new CheckBox 
            {

                Text = "Show SYMBOLS",
                IsChecked = Chart.AddControl(STMU),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = "70 0"
            };
            checkBox.Click += e => Chart.AddControl(STMU) = e.CheckBox.IsChecked.Value;
            Chart.AddControl(checkBox);

Error CS0029: Cannot implicitly convert type 'void' to 'bool?'

Error CS0131: The left-hand side of an assignment must be a variable, property or indexer

Error CS0029: Cannot implicitly convert type 'bool' to 'void'

Hi,

Your problem is here

 IsChecked = Chart.AddControl(STMU)

What are you trying to do?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

PanagiotisCharalampous
23 Mar 2020, 08:49 ( Updated at: 21 Dec 2023, 09:21 )

Hi colel1410,

Go to your Backtesting Settings and choose Tick Data from Server

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous