Moving Average & Data Indexing
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?
Replies
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
lec0456
25 Nov 2012, 10:18
RE:
@lec0456