Starting threads inside WealthScript strategies?
Author: Frank1972
Creation Date: 11/28/2016 5:11 PM
profile picture

Frank1972

#1
Hi,

Is it possible to start threads inside a wealth-lab script? I need this capability because I am getting my trade data from an external source, Trade-Ideas. When a trade comes in, I want to be able to enter the trade as soon as possible. To illustrate this, I like to think of the wealth-lab bar for loop as a timing diagram. Please see the "General Timing Diagram". The script is triggered to execute on the rising edge. Therefore, if the bars that are being looped over are 1 minute bars then every 1 minute the wealth-lab script will execute.

The "External Source Trigger Timing Diagram" shows that an external source to the wealth-lab script triggers 20 seconds into a 1 minute bar. Is there a way to act on this trigger when it comes in or do I have to wait 40 seconds for the next 1 minute bar to trigger my wealth-lab script to execute and then act on the signal?

If this is the only way to act on this signal is there a way to get the for loop to operate faster than 1 minute? If there is a way to get data faster than 1 minute, how can I limit the the amount of data that is downloaded? Because I don't know what symbol Trade-Ideas is going to send me, I want to avoid any delay that might occur when I call SetContext to switch to that symbol. How can I make it so that SetContext operates as fast as possible so that I can get my orders into the market as soon as possible?

I am a Fidelity client and I am trying to enter orders into Fidelity that are coming from Trade-Ideas. Therefore, I have no interest in back testing I just want to get the orders into the market as soon as they come in from Trade-Ideas. My way of dealing with this was to start a worker thread that would handle the data coming in from Trade-Ideas. Once that data was moved to a shared data structure, the main wealth-lab script thread could then process that data structure and enter the orders into the market. Perhaps I'm going about this entirely wrong. Any help would be greatly appreciated.

Thanks,

-Frank
profile picture

Eugene

#2
WealthScript Strategies are not event driven. There's no access to intra-bar ticks. Here's how the process works in Wealth-Lab according to the Wiki FAQ:

1. A complete bar updates (can be 1-minute, 1-day, etc.)
2. Your strategy executes over all the bars in the chart and determines if it wants to trade on the next bar.
a. If it doesn't, you don't do anything.
b. If it does, you place orders for the next bar and they're worked by your broker. (Process complete).

You can start your threads (here's an example and here's one more) and even program your own events but the evaluation of your strategy will always happen w.t. the basic bar scale as per the numbered list above. No exceptions. Are you of course aware how true streaming data is different from snapshot data? It's something like that.

Even if you get a data provider other than Fidelity capable of operating on bar scales less than 1-minute (e.g. IQFeed paid subscription or custom database feed), you'll lose Strategy Monitor because the minimum scale it can work with is 1-minute. If you can live with this, you might want to give this a try. (Before you're able to download any extensions please create a support ticket to verify your WLP entitlement).
profile picture

Frank1972

#3
Eugene,

Thanks for the response. I think I understand what you are saying but I do have a few questions. What do you mean when you say,

"Are you of course aware how true streaming data is different from snapshot data? It's something like that."?

Where can I get more information about the difference between streaming data and snapshot data? I think snapshot data is historical while streaming data is live and real-time. Anyway if there is more than that please let me know where I can go to get this information.

Also, I want SetContext to work as fast as possible, do you know what I should do to make sure that it is as fast as possible?

Thanks again for your quick response,

-Frank
profile picture

Eugene

#4
QUOTE:
Where can I get more information about the difference between streaming data and snapshot data?

This was just an analogy. In HFT, true streaming data captures every single tick whereas snapshot data is generated at each X ms (sec). Think of the Wealth-Lab strategy execution model as "snapshots". With events or threads you cannot go down to the "tick level".

QUOTE:
Also, I want SetContext to work as fast as possible, do you know what I should do to make sure that it is as fast as possible?

It already works as fast as possible and does not require a speedup. Please carefully re-read my reply above, especially its last 2 paragraphs. You could either go down to the second scale (e.g. with IQFeed) or "wait for 40 seconds for the next 1 minute bar to trigger your Strategy".

P.S. FWIW, this may (or may not) be helpful: Choosing optimal trading tool: Strategy Monitor or Strategy window