MarketSeries.Open, Close, Low etc all the same value

Created at 06 Dec 2015, 21:03
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!
RI

riou.benson

Joined 06.12.2015

MarketSeries.Open, Close, Low etc all the same value
06 Dec 2015, 21:03


Hi,

What am I doing wrong here, all MarketSeries values seem to be the same (Open, Low, Close etc)?  Obviously this is making the bots completely worthless.

I have made a very simple example.  This is via backtesting on all sorts of symbols and time frames:

I am not the only person hitting this issue: /forum/cbot-support/7227

Thanks,

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Test : Robot
    {

        protected override void OnStart()
        {
        }

        protected override void OnBar()
        {
            var index = MarketSeries.Close.Count - 1;
            double previousClose = MarketSeries.Close[index];
            double previousOpen = MarketSeries.Open[index];
            double previousLow = MarketSeries.Low[index];

            Print("Example 1...Prev Close: {0}, Prev Open {1}, Prev Low {2}", previousClose, previousOpen, previousLow);
            Print("Example 2...Prev Close: {0}, Prev Open {1}, Prev Low {2}", MarketSeries.Close.LastValue, MarketSeries.Open.LastValue, MarketSeries.Low.LastValue);
        }
    }
}


@riou.benson
Replies

riou.benson
06 Dec 2015, 21:19

I think I solved this - I was misunderstanding the API.

MarketSeries.Close.LastValue will return the value in the given bar, and as this is called right start of the creation of the bar, these values will all be the same.


To get the previous value I use MarketSeries.Close.Last(1).


@riou.benson