Warning: Newbie Question

Created at 24 Mar 2014, 20:25
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!
PR

Prospect

Joined 21.03.2014

Warning: Newbie Question
24 Mar 2014, 20:25


Hi All,

This is my first post to the forum, so it is in part to say hi, but also to assist me with my learning process.

I implemented and modified the example code found here at the following link under "Indicator Example 2":

/forum/whats-new/1531

I thought it would be nice to plot the spreads in a graph against each other, no practical application, just a way for me to learn. I was trying to start with just looking at one symbol and then work from there, anyway something that I thought would be straightforward has been less than successful.

I suspect this is either a very quick fix for someone who knows what they're doing, or it's not possible.

Below is as far as I got.

Thanks.

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class SpreadGraph : Indicator
    {

        private Symbol symbol1;
        private IndicatorDataSeries spread1;

        [Parameter()]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = "GBPUSD")]
        public string Symbol1 { get; set; }

        [Output("GBPUSD", Color = Colors.Turquoise)]
        public IndicatorDataSeries Result1 { get; set; }


        protected override void Initialize()
        {
            symbol1 = MarketData.GetSymbol(Symbol1);

            spread1 = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
            spread1[index] = Math.Round(symbol1.Spread / symbol1.PipValue, 1);

            Result1[index] = spread1[index];
        }
    }
}

 

 


@Prospect
Replies

Spotware
26 Mar 2014, 10:35

        public override void Calculate(int index)
        {
            spread1[index] = Math.Round(symbol1.Spread / symbol1.PipValue, 1);

Such expression is not correct, because Symbol.Spread is a current value of Spread. You can not match historical index with current value of spread. Probably you will see line with the same value in every point.


@Spotware

Prospect
26 Mar 2014, 12:04

RE:

Spotware said:

        public override void Calculate(int index)
        {
            spread1[index] = Math.Round(symbol1.Spread / symbol1.PipValue, 1);

Such expression is not correct, because Symbol.Spread is a current value of Spread. You can not match historical index with current value of spread. Probably you will see line with the same value in every point.

Perfect, that's what I needed to know thanks. Seems obvious now in the API reference "The current spread of this symbol", as opposed to something like "Open price series of historical trendbars".


@Prospect