AW Spread free

by khoshroomahdi in category Other at 15/07/2021
Description

show spread on chart

 

 

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
//AcademyWave
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Linq;


namespace cAlgo
{

    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWSpread : Indicator
    {
        TextBlock tb = new TextBlock();
        [Parameter("Font Size", DefaultValue = 12)]
        public int FontSize { get; set; }
        [Parameter("Space to Corner", DefaultValue = 10)]
        public int Margin { get; set; }
        [Parameter("Horizental Alignment", DefaultValue = HorizontalAlignment.Right)]
        public HorizontalAlignment HAlignment { get; set; }
        [Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Bottom)]
        public VerticalAlignment VAlignment { get; set; }
        [Parameter("Color", DefaultValue = "Red")]
        public string Color1 { get; set; }



        protected override void Initialize()
        {
            Chart.AddControl(tb);
        }
        public override void Calculate(int index)
        {

            if (IsLastBar)
                DisplaySpreadOnChart();
        }

        public void DisplaySpreadOnChart()
        {

            var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
            string sp = string.Format("{0}", spread);
            tb.Text = sp;
            tb.FontSize = FontSize;
            tb.ForegroundColor = Color1.TrimEnd();
            tb.HorizontalAlignment = HAlignment;
            tb.VerticalAlignment = VAlignment;
            tb.Margin = Margin;

        }



    }


}

Comments
0