Creating a Synthetic Index Bars Object for Charting
Author: jonludwig
Creation Date: 2/21/2009 3:40 PM
profile picture

jonludwig

#1
Any help out there to create a synthetic Bars object to see OHLC on a chart?
I am trying to create an equal $ weighted index of stocks.
Example:
CODE:
Please log in to see this code.


Just doesn't seem to work.
profile picture

Cone

#2
If you create a new Bars object, then you'll need to add some bars to it. But really I think you should just use multiple DataSeries since you don't need the overhead of a Bars object.

CODE:
Please log in to see this code.
profile picture

jonludwig

#3
On this topic,
Is there a way to create a List of DataSeries of n items, where n is the number of items in a DataSetSymbol list,
And then modify each item in that list on a bar by bar basis and finally plot the list on a ChartPane?
profile picture

Cone

#4
Sure. Above you can see how to create a new DataSeries. Just do that n times.
profile picture

aykuts

#5

Hi Cone,

Within the same context:

* assume that I need to create a sort of a synthetic index - just one the like you mentioned in this thread.

* On one hand, yes, whatever you suggest here (i.e. creating a series of DataSeries instead of creating and working with a Bars object) might work in a lot of cases.

*But, Cone, assume that I would like to calculate the ADX indicator of this synthetic index. In that case, I need this syntheticIndex not in the form of a bunch of DataSeries (of OHLC/V), but instead in the form of a Bars object, as this indicator accepts Bars as input, not the DataSeries.

i.e."DataSeries ADXOfMySyntheticIndex = ADX.Series(mySyntheticAsBar, 9);"

So, my question is, how is a Bars object created?


I tried the following but frankly I could not think of a decent way to add bars to that Bars object:

CODE:
Please log in to see this code.


So, in contrast with what you suggest at #2, I need to create a Bars object in order to be more flexible while using this synthetic information within the strategy.

Anyhelp is appreciated.

profile picture

aykuts

#6

Opps.

I got it.

And, I would like to present the code (that in theory creates a synthetic Bars object on the fly ) for those who are as bad as me in coding, and who fail just like me to master the very basics of C# ! :-)


CODE:
Please log in to see this code.
profile picture

Eugene

#7
Aykut,

Like Cone suggested above, first you have to add some bars using Bars.Add:

CODE:
Please log in to see this code.


UPDATE: Glad you've got it sorted out while I was typing ;-)

P.S. In addition to this on-the-fly approach there exists a more complicated technique: Create a Custom Index for use in Index-Lab.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).