Adding a bar to the Bars Object
Author: ss161
Creation Date: 6/15/2009 10:51 PM
profile picture

ss161

#1
i asked a similar question before, but am just now getting around to trying to implement this. I have a daily script that generates trades based on the closing prices over the past 21 trading days. After generating a signal, I want to buy or sell the shares on the close of the day the signal is generated, not the next day at the open or any other time.

the way i've come up with doing this is to maintain a similar dataset with 30 minute bar data; at 3:30 i update the dataset, and then run a program that extracts only the 330 prices and saves it into a wealth-lab 4 binary file (for each symbol), this creates a daily dataset of 3:30 data. in backtesting then, on each day i generate my signal using 20 days of actual closing prices and on the last day, i substitute the 3:30 price for the close that day, generate the signal, and then put back the original close data in the dataset so i can move to the next day. it's a bit cumbersome, but it works -- EXCEPT FOR THE LAST DAY -- which is of course the only day that really matters for live trading.

the problem i'm having is that my daily dataset doesn't have a bar for the last day yet. to get around this, i wrote a function AddBar which compiles, but produces a run-time error "Bars object has been locked and can not be updated".

Here is the function: If anyone has any ideas or other design thoughts, i'd appreciate the help.

Thanks
CODE:
Please log in to see this code.

profile picture

Eugene

#2
Hi Steve,

The error message is pretty self-descriptive: WL won't allow to modify the already existing Bars object. You need to create a new Bars object and fill it with the data:
CODE:
Please log in to see this code.
profile picture

ss161

#3
the error is self-descriptive. i thought it was locking all bars objects, not just the main one. thanks for the help.

it would be great to have an unlock function.

that possibly could allow for some "ghost bar" functionality of trading assuming the current price in the market is the closing price.
profile picture

Eugene

#4
Last time I heard about it was that ghost bar functionality is on Fidelity's long term plans.
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).