Topics

Forum Topics not found

Replies

cwik_m
02 Mar 2021, 08:23

Nice initiative with the Award, Spotware.

And congratulations, Paul Hayes! I myself began learning to code from your videos back in 2018 when Youtube had almost no tutorials on cAlgo. With the knowledge you shared I began learning from scratch. Keep doing the amazing job and good luck!


@cwik_m

cwik_m
29 Jun 2018, 09:15

May I ask what exactly this piece of code does ?

And why its necessary in the above sample cBot code?

Positions.Opened += OnPositionsOpened;
Positions.Closed += OnPositionsClosed;

 


@cwik_m

cwik_m
26 Jun 2018, 17:28

RE:

Panagiotis Charalampous said:

Hi cwik_m.

The reason is that the cBot seems to crash due to a wrong number of parameters when initializing the indicator. Change your initialization code to the following

 fastMa = Indicators.GetIndicator<HullMovingAverage>(MarketSeries.Close, 21);

Best Regards,

Panagiotis

Thank you Mr Panagiotis! It seems to work properly now!


@cwik_m

cwik_m
26 Jun 2018, 16:40

Thank you Mr Panagiotis,

I am surprised it worked now (according to your version of the code and the HullMovingAverage https://ctdn.com/algos/indicators/show/144). I am very thankful for such quick help.

Unfortunatelly while doing the backtesting - this cBot code you posted makes no trades. Seems that it cannot retrieve the Hull MA values from the custom indicator into the cBot.

Could you advise please how code the cBot to get access to these list of values or dataseries (like from any Moving Average or Indicator - I mean these references https://ctdn.com/api/reference/dataseries and https://ctdn.com/api/reference/functions) ?


@cwik_m

cwik_m
26 Jun 2018, 14:58 ( Updated at: 21 Dec 2023, 09:20 )

RE:

Panagiotis Charalampous said:

Hi cwik_m,

Thanks for posting in our forum. What is the error you receive? Can you please post a screenshot?

Best Regards,

Panagiotis

Dear Mr Panagiotis,

Thank you for a quick reply. I have tried to include the Hull MA (https://ctdn.com/algos/indicators/show/144) to the Sample Trend cBot. Problem is the cBot cannot build itself because the HMA indicator does not have the 'Result' definition (pls forgive me the error is not in english, although I have set the cTrader language to ENG...)

 

Below is the cBot full code for your reference

//#reference: C:\Users\HP\Documents\cAlgo\Sources\Indicators\HMA.algo

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 SampleTrend : Robot
    {
        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

        [Parameter()]
        public DataSeries SourceSeries { get; set; }

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

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

        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        private MovingAverage slowMa;
        private HMA fastMa;
        private const string label = "Sample Trend";

        protected override void OnStart()
        {
            fastMa = Indicators.GetIndicator<HMA>(21);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
        }

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

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

            if (currentSlowMa <= currentFastMa && longPosition == null)
            {
                if (shortPosition != null)
                    ClosePosition(shortPosition);
                ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label);
            }
            else if (currentSlowMa >= currentFastMa && shortPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);
                ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label);
            }
        }

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

 


@cwik_m

cwik_m
26 Jun 2018, 12:15

Hello cAlgo fans,

I just want to continue this topic since its the latest one that I have found - I am having the same problems as other traders with importing a custom indicator.

I have started to experiment with using custom indicators from ctdn.com and I have been doing exactly according to this link https://ctdn.com/api/guides/indicators#el8

Apparently my cAlgo cannot Build successfully ANY robot with ANY custom indicator. Somehow maybe problem is in the code 'GetIndicator'.

I have searched it thoroughly and also checked on other cBots - for example the one RsiAtrII  https://ctdn.com/algos/cbots/show/551  which is based on a custom indicator PipsAtr https://ctdn.com/algos/indicators/show/549.

Now If I add the robot and indicator to my cTrader and try to 'Build' the robot, it cannot be built because cannot find any PipsAtr indicator... I mean it cannot 'Get' it onto the cBot script. I am sure it was well tested by the author so the problem is not in the code... Its the same with other custom indicators.

Recently there has been and update of cTrader which merged cAlgo together with cTrader into one tool. Maybe this caused some bug while invoking custom indicators..? Pls note I have done everything according to the instruction for a proper indicator reference as it says here - ctdn.com/api/guides/indicators#el8

Anyone found a reason for that... ?


@cwik_m