Information

Username: mapseam
Member since: 24 May 2016
Last login: 24 May 2016
Status: Active

Activity

Where Created Comments
Algorithms 0 2
Forum Topics 1 0
Jobs 0 0

Last Algorithm Comments

MA
mapseam · 5 years ago

Can I do the calculation of Renko bars inside the bot?

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 My_RenkoRobot : Robot
    {
        [Parameter("Renko (Pips)", DefaultValue = 10.0, MinValue = 0.1, Step = 1)]
        public double RenkoPips { get; set; }

    protected class Brick
        {
            public double Open { get; set; }
            public double Close { get; set; }
        }

        protected List<Brick> Bricks = new List<Brick>();

        private double closeLastValue, renkoPips, renkoLastValue;
    private MarketSeries M1;

        protected override void OnStart()
        {
        // ...
            renkoPips = RenkoPips * Symbol.PipSize;
        
        M1 = MarketData.GetSeries(TimeFrame.Minute);        
        var open = M1.Open.LastValue;
            renkoLastValue = open - (open % renkoPips) + renkoPips / 2;

        int totalBars = Math.Min(LookupBars + 1, M1.Close.Count);

        for (int i = 0; i < totalBars; i++)
        {
                closeLastValue = M1.Close[i];

                while (closeLastValue >= renkoLastValue + renkoPips * 1.5)
                {
                    renkoLastValue += renkoPips;
                    Bricks.Insert(0, new Brick
                    {
                            Open = renkoLastValue - renkoPips / 2,
                Low = Open,
                            Close = renkoLastValue + renkoPips / 2,
                High = Close
                    });
                }

                while (closeLastValue <= renkoLastValue - renkoPips * 1.5)
                {
                    renkoLastValue -= renkoPips;
                    Bricks.Insert(0, new Brick
                    {
                            Open = renkoLastValue + renkoPips / 2,
                High = Open,
                            Close = renkoLastValue - renkoPips / 2,
                Low = Close
                    });
                }        
        }
        // ...
    }

        protected override void OnTick()
        {
        // ...
            double y1, y2;
            var top = Math.Max(Bricks[0].Open, Bricks[0].Close);
            var bottom = Math.Min(Bricks[0].Open, Bricks[0].Close);

        closeLastValue = M1.Close[0];

            if (closeLastValue > top)
                y1 = top;
            else if (closeLastValue < bottom)
                y1 = bottom;
            else
                y1 = closeLastValue;

            y2 = closeLastValue;

            Bricks[0].Open = y1;
            Bricks[0].High = y1 > y2 ? y1 : y2;
            Bricks[0].Low = y1 < y2 ? y1 : y2;
            Bricks[0].Close = y2;
        // ...
    }
    }
}

MA
mapseam · 6 years ago

Thanx for you renko indi!

renko = Indicators.GetIndicator<Renko>(RenkoPips, BricksToShow, 3, "SeaGreen", "Tomato");
Buy renko.Bricks.Count() = 0.

Tell me please, why?