Strange behaviour in Indicator

Created at 10 Dec 2013, 19:53
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!
jeex's avatar

jeex

Joined 18.10.2013

Strange behaviour in Indicator
10 Dec 2013, 19:53


Look at the screen dumps. At random times the last bars are not drawn. After moving back and forth to other timeframes, things change. Bug?

In the left image the last 3 bars are missing. In the right image (different timeframe) they are there.


@jeex
Replies

jeex
10 Dec 2013, 20:16

Multi Symbol

i forgot to mention: it is an indicator based on more than one symbol.

[Output("Main")]
public IndicatorDataSeries Result { get; set; }

MarketSeries xyz;

protected override void Initialize()
{
        xyz = MarketData.GetSeries("USDJPY", MarketSeries.TimeFrame);
}

public override void Calculate(int index)
{
        Result[index] = xyz.Close[index];
}

 


@jeex

Spotware
11 Dec 2013, 09:59

You need to translate the index from one series, the one of the chart, to the another. There is a method GetIndexByExactTime

            var indexXyz = xyz.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime.LastValue);
            Result[index] = xyz.Close[indexXyz];

 


@Spotware

jeex
11 Dec 2013, 10:16

RE:

Spotware said:

You need to translate the index from one series, the one of the chart, to the another. There is a method GetIndexByExactTime

          var indexXyz = xyz.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime.LastValue);
          Result[index] = xyz.Close[indexXyz];

 

Thanks. I'll give it a try.


@jeex

jeex
11 Dec 2013, 10:24

RE: No such method

Spotware said:

You need to translate the index from one series, the one of the chart, to the another. There is a method GetIndexByExactTime

            var indexXyz = xyz.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime.LastValue);
            Result[index] = xyz.Close[indexXyz];

 

It sais there is no method by the name of GetIndexByExactTime...


@jeex

Spotware
11 Dec 2013, 10:53

You can try this on Spotware cAlgo. The method will be available in the next release.


@Spotware

jeex
11 Dec 2013, 11:36

RE:

Spotware said:

You can try this on Spotware cAlgo. The method will be available in the next release.

Fixed it by calculating the index-difference:

_XYZindexShift = MarketSeries.Close.Count - _xyz.Close.Count;

And later on use the same indexShift to get the right index.

Thanks for the tip.


@jeex

Spotware
11 Dec 2013, 11:44

RE: RE:

jeex said:

Spotware said:

You can try this on Spotware cAlgo. The method will be available in the next release.

Fixed it by calculating the index-difference:

_XYZindexShift = MarketSeries.Close.Count - _xyz.Close.Count;

And later on use the same indexShift to get the right index.

Thanks for the tip.

The series count difference is not correct to index another series.
Note that when you use the method  GetIndexByExactTime you need to check that the returned value is not equal to -1. The method returns -1 if there is no value at the exact time.


@Spotware

jeex
11 Dec 2013, 12:01

patience

In the tests i just ran, results were positive. But that might be a coincedent.

So just sit back and wait for the update that contains GetIndexByExactTime.


@jeex

jeex
11 Dec 2013, 12:09

Work around

Is there really no other work-around that fixes this, cause now i gotta switch to MT4 to get the robot running and we wouldn't want that. ;-)


@jeex

Spotware
11 Dec 2013, 14:51

You can use this method for now:

        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i >= 0; i--)
            {
                if (time == series.OpenTime[i])
                    return i;
            }
            return -1;
        }


 


@Spotware

jeex
11 Dec 2013, 15:43

That works

The test with GetIndexByExactTime gave no result. The workaround works fine. Thanks. That saves me a trip down memory lane, into the dark ages of MT4.


@jeex