Moving Average & Data Indexing

Created at 25 Nov 2012, 08: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!
lec0456's avatar

lec0456

Joined 14.11.2012

Moving Average & Data Indexing
25 Nov 2012, 08:03


Ok, So I have been trying to figure out how the Moving average data works in cAlgo.  The dataseries  is counted by Bar not by tick.  But When does the count start?  It is different depending on the day and the timeframe you start the robot.  

So, depending on the period you are using, for example a 10sma or a 50sma, the data may or may not be there when you start the bot.  

I would just like to know how the indexing of the data series is handled. In order to predict how many bars will a particular strategy have to wait before having the data necessary to act. 

 

Let me bundle this post by asking a totally separate question out of curiosity, are there any dataseries' indexed by the ontick event?


@lec0456
Replies

lec0456
25 Nov 2012, 10:18

RE:
I think this is particularly important because if you are using a 200sma on a 1hour time frame it will take your robot 4 days to get the data it needs to implement the strategy. Now you can work with this when backtesting by starting your robot a couple days earlier than the period you are interested in testing but although I have not tested it in real time yet, but that would be serious problem.  If you have to wait 4 days for your robot to start working from the time you start it live.  
 
Any answers here are much appreciated!

@lec0456

daemon
06 Mar 2013, 16:55

You want to compare the SMA(200) at the current index to an index when? Can you say a little more about the logic?

    	private SimpleMovingAverage sma;
        protected override void OnStart()
        {
            sma = Indicators.SimpleMovingAverage(MarketSeries.Close, 200);
        }

        protected override void OnTick()
        {
            
             Print("{0}",sma.Result.Count);
        }

The above outputs 8165. So, I believe you don't have to wait for data.
To index an indicator within a Robot you can declare an int index and set it to the last index (MarketSeries.Close.Count -1) then call sma.Result[index] or you can use a loop for(int i = 0; i < index; i++){ do something with sma.Result[i]}. Don't know what you are trying to do exactly...

 


@daemon