Bars RemoveAt/Insert
Author: Panache
Creation Date: 1/10/2020 4:31 AM
profile picture

Panache

#1
Is there a way to remove or insert a bar in the bars object? I assume the Edit Bar Data tool uses something like this.
profile picture

Eugene

#2
First it was about editing the fundamental data, now comes the Bars object. Could you tell what is your real goal behind the question?
profile picture

Panache

#3
Sure. I'm optimizing my data checking program. Editing FundamentalDataItems was my idea to process bad split data faster and easier than having to modify all the OHLCV data.

My question about Bars.RemoveAt and Bars.Insert relates to removing bars on weekends and market holidays and inserting synthetic bars for trading days when there is no data. Currently, when the program encounters one of those problems, it iteratively writes the Bars information to an IList, makes the change to the IList and then iteratively recreates the Bars information. Obviously, it would be more efficient to make the insertion or deletion directly in the Bars object.

Thinking ahead, my next question is going to be whether there is a Bars.Sort method to more efficiently deal with the problem of out of sequence bars.
profile picture

Eugene

#4
QUOTE:
My question about Bars.RemoveAt and Bars.Insert relates to removing bars on weekends and market holidays

In the data by what data provider are you removing the weekend bars? Fidelity should not contain them. Could you elaborate on your conditions?

QUOTE:
inserting synthetic bars for trading days when there is no data

Inserting Bars (with Bars.Append*) can only be approached by the respective data provider. In a script you can modify a custom Bars object - but not the charted Bars object (you'd get a runtime error).

QUOTE:
Bars.Sort method

I guess you can have one through a C# Extension Method in your class library but first you'd have to code it.
profile picture

superticker

#5
QUOTE:
[Bars.Sort method] ... you can have one through a C# Extension Method in your class library
Hmm. Please correct me if I'm wrong, but the VS Object Browser isn't showing the Bars class as a "static" class definition, so an Extension Method won't be appropriate. But you could certainly used the Bars class as a base class to create your own class (via inheritance) that had a MyBars.Sort() member function. The advantage of this approach is that you would automatically inherit all the member functions from the Bars class into your MyBars class definition, and then you could add your own functions to boot.

Now overriding existing member functions in the Bars class is another matter. I'm not sure if the member functions in the Bars class have an "virtual" attribute in their definition, and I don't know how to tell that from the VS Object Browser. If they do, then you can re-write them as well inside your MyBars class definition.
profile picture

Cone

#6
QUOTE:
the VS Object Browser isn't showing the Bars class as a "static" class definition, so an Extension Method won't be appropriate.
I think you're implying that you can't use an extension method with an instance class, that's wrong. Existing classes can be extended without using inheritance. Indeed, we already use extension methods with Bars in Community.Components. Example: GetAllDataForSymbol

Here's a good walk through:
https://www.c-sharpcorner.com/uploadfile/puranindia/extension-methods-in-C-Sharp-3-0/
profile picture

Panache

#7
QUOTE:
In the data by what data provider are you removing the weekend bars?

I can't point you to a specific example because I clean my data regularly. When I was developing my cleaning program, it did find a lot of weekend and holiday bars, but I can't tell you whether or not they were from Fidelity.
profile picture

Eugene

#8
This could be a feature request to add "Remove weekend bars" to the Data Tool. What do you think?
profile picture

superticker

#9
QUOTE:
I think you're implying that you can't use an extension method with an instance class, that's wrong. Existing classes can be extended without using inheritance.
Thanks for that above link (Post# 5). I see it's the extending class that must be static, and not the class being extended, which can be by reference (i.e. an instance class). I stand corrected.
profile picture

Panache

#10
QUOTE:
This could be a feature request to add "Remove weekend bars" to the Data Tool.

It's not something I would use. I only use the Data Tool for manual fixes that my cleaning program can't deal with, like Yahoo's 0 for 1 stock split for D on 5/20/1983.

If you want to add Remove weekend bars to the Data Tool, I'd be happy to share my code; it's probably less than a dozen lines the way I have it programmed.

However, a fundamental data editor to be able to correct that stock split would be very helpful to me.
profile picture

Eugene

#11
QUOTE:
However, a fundamental data editor to be able to correct that stock split would be very helpful to me.

For a more straightforward way, I replied to the original topic.
profile picture

Eugene

#12
Anyway, I added a Data Cleaner tab with Remove weekend bars feature to the Data Tool v2020.02.
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).