Auto-trading at close of day with partial data
Author: heech
Creation Date: 11/9/2008 9:41 PM
profile picture

heech

#1
Hi there,

The programming guide pretty interestingly mentions use of partial data from Yahoo, in conjunction with making a trade close to end of day.

I think I understand how the code works. But can someone walk me through how to set this up in Wealth Lab, in more detail?

Say, I want to run on 60 minute bars, except I want the last bar of the day placed at 3:58 PM, with Wealth Lab auto-trading based on that last (partial) bar.

- create a dataset using Yahoo finance data, obviously.
- do I adjust my computer's time to be 2 minutes earlier than real time?
- setup strategy monitor to run every 60 minutes, as before?
profile picture

Cone

#2
That note, in the Alerts section, was talking about using the Y! Provider for a Daily strategy with an AtClose order. Mixing Fidelity data intraday data with a Y! Daily source is obviously more complicated. However, 5.3 might be able to help with a new overload method to GetExternalSymbol that allows you to specify the DataSet, and hence the Provider, from which the data is retrieved.
profile picture

heech

#3
Cone,

Okay, let's say 5.3 allows me to retrieve the partial bar for a sneak peak... how would I place an order actually at close of day?

If I read the manual correctly (and very possibly I didn't), I shouldn't use BuyAtClose() (and my previous experience with ATP tells me trying to trade literally AT the close is scary)... and instead should use BuyAtMarket(). How do I orchestrate this within the Strategy Monitor?
profile picture

Cone

#4
It's covered in the same topic - use a Market order if the Alert is triggered on the last bar of the chart.
profile picture

heech

#5
Cone,

QUOTE:
use a Market order if the Alert is triggered on the last bar of the chart.

I don't understand. If the strategy doesn't get that last bar until market closes, what's the point of a market order?
profile picture

Cone

#6
That's the general problem with the AtClose Strategy. What else do you propose?

All that I'm saying is that if you can get a "closing price" update somewhere, somehow near the close, then the only chance that you have to execute the trade is by sending a market order as fast as you can.
profile picture

heech

#7
QUOTE:
That's the general problem with the AtClose Strategy. What else do you propose?

Okay, that's what I thought. I just wanted to get away from my often inaccurate assumptions.

As far as what else I propose... I mentioned earlier tweaking my computer clock so that it's 2-3 minutes earlier than market time. What are your thoughts with doing that?

Will Fidelity data be screwy, because throughout the day my strategy won't actually have the *current* bar? (I know you said it doesn't see partial bars.) If I moved over to Yahoo data entirely (no Fidelity bars), would that work?
profile picture

Cone

#8
QUOTE:
... I mentioned earlier tweaking my computer clock so that it's 2-3 minutes earlier than market time.
You would just arrive at your appointments earlier, but the bars would be updated using the market timestamps on the trades, which isn't affected by your computer clock.


QUOTE:
If I moved over to Yahoo data
My only experience with Y! data is Daily. You can get on-demand updates, but you'll have the same problem obtaining and processing an update before the scheduled close of the bar using any streaming provider.
profile picture

heech

#9
Cone,

QUOTE:
You would just arrive at your appointments earlier, but the bars would be updated using the market timestamps on the trades, which isn't affected by your computer clock.

Is it possible that this explains a different bug I've been seeing, but which is impossible to replicate?

I regularly have behavior that gives different results in the strategy monitor, then when I run the same code in strategy window. (As in, the results surprise me, I open in strategy monitor... and the results look correct.) If I then immediately hand-run strategy in the strategy monitor (all within 5 minutes), the results are correct.

Is it possible that the strategy in the strategy monitor is running *too soon*? And it's simply not seeing the latest bar? Should I actually tweak my system so that it's 1-2 minutes later?
profile picture

Cone

#10
Indeed, the Strategy Monitor does work off your computer clock to execute the Strategies. It even says so in the User Guide. It's best to synch your computer clock to a premarket TOS, for example. I think the SM delays a few seconds after the minute before executing.

Another difference is that the Strategy Monitor works only with historical bars retrieved from the server, whereas a Streaming window builds the new bars on its own. Potentially a difference can occur since the bars are build in 2 different places.
profile picture

heech

#11
Cone,

Ah, that makes me a little more sane.

I did catch that reference into the User Guide. I don't want to get into a debate about whether it's clear or not, but I definitely didn't realize a few seconds difference could imply losing an hour's worth of bars. I know I synchronized Monday morning, and didn't power off in between. In your testing/experience, is it typical for the clock to deviate enough to affect the strategy monitor within 24 hours?

I've been synching on a weekly basis, but sounds like premarket is the way to go.

To ask a variant of the question I asked earlier... do you see any downside (other than slightly out-dated Bars.Close[bar]) to *delaying* by, say, 30 seconds to avoid this problem?
profile picture

Cone

#12
QUOTE:
I definitely didn't realize a few seconds difference could imply losing an hour's worth of bars.
That shouldn't happen either. The SM should request bars periodically until the data expected is returned. So precise synch is not required, but it just makes the process more efficient.

When you say "results", what precisely are the differences?
Are the data loaded set up for the same range? Sizing? etc.
profile picture

heech

#13
Cone,

QUOTE:
That shouldn't happen either. The SM should request bars periodically until the data expected is returned. So precise synch is not required, but it just makes the process more efficient.

When you say "results", what precisely are the differences?
Are the data loaded set up for the same range? Sizing? etc.

In that case it's back to the drawing board, and another serious bug lurking somewhere.

When I say results are different... When this happened yesterday:

1. the strategy monitor 11:30 generated a Buy at Market order.
2. I open the same strategy in a strategy window, I do not get that Buy at Market alert.
3. I manually click "run strategy now" within the strategy monitor at 11:35, the strategy monitor does *not* generate the Buy at Market order.

Steps 1/3 are both within the strategy monitor, same strategy, no change at all in parameters, sizing, date, etc.

So, drastically different. My theory originally was that at 11:30, the strategy monitor pulled up and fed to my code the *previous* bar at 10:30... and the strategy executed using the early bar. But it seems like you're telling me that couldn't have happened?
profile picture

Cone

#14
This is a bug in 5.1 (fixed for 5.3). As I recall you won't get trades or alerts for Strategies that are "Run now" a second time.
profile picture

heech

#15
Cone,

QUOTE:
This is a bug in 5.1 (fixed for 5.3). As I recall you won't get trades or alerts for Strategies that are "Run now" a second time.

I'm not sure you understood my question...

My problem isn't that orders were generated a second time. My problem is that the *results* were different. In the case I'm referring to, the first time that the strategy ran automatically right on the dot, I ended up with a 'buy at market' which was *wrong*... it seemed to be looking at old bars, without seeing the latest one. Running the strategy again gave me the correct result.

Is this also a known bug fixed for 5.3?
profile picture

Cone

#16
No, but we can't investigate it without specifics. Please create a ticket and provide all the details - especially if there's a way to duplicate it.
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).