Replies

arthur.albert990
16 Oct 2020, 14:36

RE:

Hello PanagiotisCharalampous,

Thank you for your help, it worked great.!


@arthur.albert990

arthur.albert990
05 Oct 2020, 03:13

RE: Code below.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;


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

        [Parameter(DefaultValue = 9)]
        public int Period1 { get; set; }

        [Parameter(DefaultValue = 30)]
        public int Period2 { get; set; }

        [Parameter("Moving Average Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType { get; set; }

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

        [Output("Média Verde", LineColor = "Green", LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries Result1 { get; set; }

        [Output("Média Vermelha", LineColor = "Red", LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries Result2 { get; set; }

        private MovingAverage _MovingAverage1;
        private MovingAverage _MovingAverage2;

        protected override void Initialize()
        {
            _MovingAverage1 = Indicators.MovingAverage(Source, Period1, MAType);
            _MovingAverage2 = Indicators.MovingAverage(Source, Period2, MAType);
        }

        public override void Calculate(int index)
        {

            if (_MovingAverage1.Result[index] < _MovingAverage2.Result[index])
            {
                Result2[index] = _MovingAverage2.Result[index];
            }
            else
                Result1[index] = _MovingAverage2.Result[index];

        }
    }
}

 


@arthur.albert990

arthur.albert990
30 Sep 2020, 01:34

RE: Unable to Build it.

afhacker said:

Hello,

I want to share the code that I use for backtesting Renko/Range bots on cTrader, follow the below instruction:

  1. Clone the "cAlgo.API.Extensions.Series" repo, and build it
  2. Reference the library on your Indicator/cBot
  3. Use the sample below to implement it on your cBot code. 
using cAlgo.API;
using cAlgo.API.Extensions.Enums;
using cAlgo.API.Extensions.Models;
using cAlgo.API.Extensions.Series;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class RenkoBot : Robot
    {
        // Use RangeMarketSeries for Range bars
        private RenkoMarketSeries _renkoSeries;

        private MovingAverage _ma;

        [Parameter("Size (Pips)", DefaultValue = 10)]
        public double RankoSizeInPips { get; set; }

        protected override void OnStart()
        {
            _renkoSeries = new RenkoMarketSeries(RankoSizeInPips, Symbol, this);

            _renkoSeries.OnBar += RenkoSeries_OnBar;

            // You can initialize cTrader indicators 
            _ma = Indicators.MovingAverage(_renkoSeries.Close, 10, MovingAverageType.Exponential);
        }

        protected override void OnTick()
        {
            // The Renko/Range market series OnTick method must be called on each new up coming ticks
            _renkoSeries.OnTick();
        }

        // This method is called on new Renko/Range bars, you should use this method instead of OnBar method of your Robot
        private void RenkoSeries_OnBar(object sender, OhlcBar newBar, OhlcBar oldBar)
        {
            if (newBar.Type == BarType.Bullish)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol.Name, 1000, string.Empty, 10, 20);
            }
            else if (newBar.Type == BarType.Bearish)
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 1000, string.Empty, 10, 20);
            }
        }
    }
}

 


Hello, i'm unable to build the github files, is it possible to upload the DLL file? Thank you.


@arthur.albert990

arthur.albert990
24 Sep 2020, 16:00

RE: No Result from Macd?

PanagiotisCharalampous said:

Hi arthur.albert990,

It does not display anything because you do not have any output. Read here how to create a custom indicator.

Best Regards,

Panagiotis 

Join us on Telegram

Hello PanagiotisCharalampous, i've tried to add an output to the code and the "Result" on Calculate() but i'm unable to obtain the result from macd, platform tells me that the ZeroLagMACD doesn't has a definition for Result.

Code below. Thank you for your time, have a good day!
 

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

namespace cAlgo
{

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

        [Parameter(DefaultValue = 150)]
        public int PeriodoLongo { get; set; }

        [Parameter(DefaultValue = 30)]
        public int PeriodoCurto { get; set; }

        [Parameter(DefaultValue = 60)]
        public int PeriodoSinal { get; set; }

        private ZeroLagMACD _macd;

        [Output("Zero Lag MACD Output")]
        public IndicatorDataSeries Result { get; set; }


        protected override void Initialize()
        {
            Print("Inicializando Zero Lag MACD");
            _macd = Indicators.GetIndicator<ZeroLagMACD>(PeriodoLongo, PeriodoCurto, PeriodoSinal);
        }

        public override void Calculate(int index)
        {
            Result[index] = _macd.Result[index];
        }
    }
}

 


@arthur.albert990