Topics

Forum Topics not found

Replies

liwik10297
08 Jan 2020, 20:30 ( Updated at: 21 Dec 2023, 09:21 )

Hi, I've tested the following code, but the indicator doesn't work properly. It returns NaN values for about 100 bars (the number of bars depend on the time frame selected).

The 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)
        {

            Print("Renko: ", _renkoSeries.Close.Last(1));
            Print("MA: ", ma.Result.Last(1));
            Print("Count", _renkoSeries.Close.Count);

        }
    }
}


@liwik10297