Category Trend  Published on 13/10/2020

Katana

Description

Someday, humanity will share the same currency, or not, only God knows

TFm1

TFm5


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Katana : Indicator
    {
        [Output("Result1", LineColor = "lightGreen")]
        public IndicatorDataSeries Result1 { get; set; }

        [Output("Result2", LineColor = "Red")]
        public IndicatorDataSeries Result2 { get; set; }

        [Output("Result3", LineColor = "Aqua")]
        public IndicatorDataSeries Result3 { get; set; }

        [Output("Result4", LineColor = "Red")]
        public IndicatorDataSeries Result4 { get; set; }

        [Output("Result5", LineColor = "lightGreen")]
        public IndicatorDataSeries Result5 { get; set; }

        [Output("Result6", LineColor = "Aqua")]
        public IndicatorDataSeries Result6 { get; set; }

        private Bars tf;

        private int idx;
        private int previousIdx;
        private int buyPeriod;
        private int sellPeriod;
        private double buyAverage;
        private double sellAverage;
        private double bullBandWhidth, bearBandWhidth;
        private double bullMean, bearMean;

        protected override void Initialize()
        {
            tf = MarketData.GetBars(Bars.TimeFrame);
        }

        public override void Calculate(int index)
        {
            idx = tf.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            if (idx > previousIdx)
            {
                buyPeriod++;
                sellPeriod++;

            }

            if (Bars.HighPrices[index] > buyAverage)
                buyPeriod = 1;

            if (Bars.LowPrices[index] < sellAverage)
                sellPeriod = 1;

            buyAverage = Bars.HighPrices.Sum(buyPeriod) / buyPeriod;
            sellAverage = Bars.LowPrices.Sum(sellPeriod) / sellPeriod;

            if (Bars.HighPrices[index] == Bars.HighPrices.Maximum(sellPeriod))
                bullBandWhidth = Bars.HighPrices.Maximum(sellPeriod) - sellAverage;

            bullMean = (2 * sellAverage + bullBandWhidth) / 2;

            if (Bars.LowPrices[index] == Bars.LowPrices.Minimum(buyPeriod))
                bearBandWhidth = Bars.LowPrices.Minimum(buyPeriod) - buyAverage;

            bearMean = (2 * buyAverage + bearBandWhidth) / 2;

            Result1[index] = sellAverage;
            Result2[index] = sellAverage + bullBandWhidth;
            Result3[index] = bullMean;
            Result4[index] = buyAverage;
            Result5[index] = buyAverage + bearBandWhidth;
            Result6[index] = bearMean;


            previousIdx = idx;
        }
    }
}


srm_bcn's avatar
srm_bcn

Joined on 01.09.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Katana.algo
  • Rating: 0
  • Installs: 1123
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
KE
kenneyy_eur · 3 years ago

Humanity IS sharing the same currency - its called Bitcoin