Bid/Ask Custom Indicator

Created at 31 May 2019, 19:04
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
matt92's avatar

matt92

Joined 11.12.2015

Bid/Ask Custom Indicator
31 May 2019, 19:04


I had this indicator (found here: https://ctrader.com/algos/indicators/show/1167#comment-5309 ) But It seems like it is no longer available for download? Also the copy I had no longer works with the newest update to cTrader :\ Any suggestions? Thanks


@matt92
Replies

PanagiotisCharalampous
03 Jun 2019, 10:29

Hi Matt,

The code below should work on the latest version of cTrader

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 BidAsk : Indicator
    {
        [Parameter("To Infinite", DefaultValue = true)]
        public bool ToInfinite { get; set; }

        [Parameter(DefaultValue = 0)]
        public int Displacement { get; set; }

        [Output("Ask", Color = Colors.DodgerBlue, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries SymbolAsk { get; set; }

        [Output("Bid", Color = Colors.Red, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries SymbolBid { get; set; }

        protected override void Initialize()
        {
            // Initialize and create nested indicators
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar)
                return;

            SymbolBid[index + Displacement - 1] = double.NaN;
            SymbolAsk[index + Displacement - 1] = double.NaN;

            for (int i = ToInfinite ? -MarketSeries.Close.Count : Displacement; i < 200; i++)
            {
                SymbolBid[index + i] = Symbol.Ask;
                SymbolAsk[index + i] = Symbol.Bid;
            }
        }
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous

matt92
03 Jun 2019, 10:57

I appreciate that a lot! Many thanks!


@matt92

matt92
04 Jul 2019, 00:31

I could be wrong, but I think your reversed the Bid and Ask....
If you put the indicator on a chart,, The Ask is cTraders Bid.. and vice versa.. The Bid is cTraders Ask..


@matt92