Category Other  Published on 18/02/2016

Spread Monitor

Description

This indicator draws Spread on the chart in pips and shows the current spread and min / max.
Spread is the difference between the bid and the ask price of the symbol.


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

namespace cAlgo
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]

    public class Spread : Indicator
    {
        [Output("Spread Min", Color = Colors.Red)]
        public IndicatorDataSeries SpreadResultMin { get; set; }

        [Output("Spread Max", Color = Colors.Blue)]
        public IndicatorDataSeries SpreadResultMax { get; set; }

        private double maxSpread;
        private double minSpread;
        private double maxS;
        private double minS;
        private DateTime mk;

        protected override void Initialize()
        {
            var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
            minSpread = spread;
            minS = spread;
            ChartObjects.DrawText("c", "vk.com/i_fri", StaticPosition.BottomLeft, Colors.Gray);
        }

        public override void Calculate(int index)
        {
            var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
            DateTime mk2 = MarketSeries.OpenTime[index];

            if (spread > maxSpread)
                maxSpread = spread;
            else if (spread < minSpread)
                minSpread = spread;

            if (maxS < maxSpread)
                maxS = maxSpread;
            if (minS > minSpread)
                minS = minSpread;

            if (mk != mk2)
            {
                mk = mk2;
                maxSpread = spread;
                minSpread = spread;
            }

            SpreadResultMax[index] = maxSpread;
            SpreadResultMin[index] = minSpread;

            string text = string.Format("Spread {0}         Min / Max : {1} / {2}", spread, minS, maxS);
            ChartObjects.DrawText("spread", "\t\t" + text, StaticPosition.TopLeft, Colors.White);
        }
    }
}



andiinet's avatar
andiinet

Joined on 18.02.2016

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Spread Monitor.algo
  • Rating: 5
  • Installs: 7085
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
mattia.musiello's avatar
mattia.musiello · 4 years ago

Thanks.