Hi. I'm completely new to WealthLab. I have a trading strategy that is not based on technical indicators or charting and I'm wondering before I get too deep if WealthLab is a good fit for what I want to do. I would call it a paired trade strategy in which I would need the following capabilities: 1) streaming quotes for 2 securities, 2) loop type programming which would process the price data and automatically execute quick response buy/sell market orders when the system parameters dictated. Ideally I would like the loop to process every 5 or 10 seconds but at intervals no longer than 1 minute. Is that feasible? Any response /feedback would be appreciated. Thank you
Size:
Color:
Hi,
The minimum bar scale for Fidelity data in WLP is 1 Minute. It can deliver the streaming data for 2 instruments which should work in general in a streaming Strategy window. Our IQFeed data provider, on the other hand, supports sub-minute bar scales (Tick and Second). Again, it may work out depending on your strategy's complexity and data loading range. If you provide more insight into your algo and data requirements, we should be able to tell for sure.
Size:
Color:
Thanks Eugene. I'm going to take a shot at it and see what I can get going. I may try to circle back once i know more.
Size:
Color:
Please don't hesitate to ask if you have followup questions.
Size:
Color:
So I have made a good first attempt at the code.but I have a few holes remaining and hoping you might shed some light. If you would rather I email you outside the forum just let me know.
the first section of code I'm using is to set some initial variables and pass through once without any loops. as part of that, I wanted to pull the open price for two ticker symbols for bar 0. I was messing with 2 lines - int bar = 0 and Sopen = GetSessionOpen ("Ticker Symbol") Either by concept or by syntax it won't compile so do you have any suggestions on how best to accomplish?
the second section of code is my big processing loop where I would hope all the bar data for the day would be processed. I found the following statement in the guidance which appears to compile OK, am I using the right one to initiate the loop so to speak?
for (int bar = GetTradingLoopStartBar(1); bar < Bars.Count; bar++)
also, after it runs through the code once in this section, how does it know to loop back? Do I need to add a command?
Within this section, I am trying to "pull" pricing (similar to above) for 2 securities at the close of each bar and I just can't figure it out. Any suggestions? Also within this section I am trying at different times to buy and sell each of the two securities and I found a few commands but again either by concept of syntax I can't get them to compile:
{ BuyAtMarket(Sshares,"ticker"); } and { SellAtMarket(Sshares,"ticker"); } Any suggestions on the best way to do this? I ultimately want these to execute on a fully automated basis. Thank you in advance
Size:
Color:
Before anything else, please
create a support ticket for us to make sure we're supporting a Fidelity customer. Thanks.
Then I'd suggest that you share your trading rules in plain English here. Let technicians try and find an optimal solution first.
P.S. For your future record: when followup questions are specific and substantially different from the original post, ideally you would 1) break them up and 2) start a new topic for each problem. But first please search the forum by entering a few keywords in the "Search Forum..." text box. Chances are you'll find an answer instantly.
Size:
Color:
In the WS programming guide I found the sample script for pairs trading including the classes "PairsBarsLoader" and "PairsScript". Within my code both of these classes are now red underlined with the message that the namespace already contains a definition for them. Any thoughts on what I've done wrong? I can't see anywhere elsewhere that these classes are defined.
Size:
Color:
I have no idea what you might have done wrong. These specific scripts are for live trading. Let's focus on the backtesting side of it. Strike Ctrl-O ("Open Strategy"), click "Download", check "Download public strategies" and uncheck "Published since". Now, "Begin download" will retrieve all publicly available strategies. Among them you'll find some pairs trading scripts if you enter "pair" in Strategy Name field (the same dialog window). This should do for a start.
Size:
Color:
ok, I'll try that out, thanks
Size:
Color:
so, i feel like i have made great progress on my pairs trade program and it appears to do well with backtesting etc. but now I am having trouble getting the strategy to generate alerts/paper trades. In the strategy monitor, the trades are indicated on the chart so I am not sure what is going on. I have read the "no alerts" FAQ you referenced in other threads but I am still not seeing what is wrong. Any suggestions? Would you mind taking a glance at my code? There is one other strange issue also where the sell trade indicator keeps bumping over to the last bar sort of like a phantom indicator. So something is also wrong there.
Size:
Color:
Apparently, something's wrong with the code. Sure, let's have a look at it. It will help if you also include the trading rules.
Size:
Color:
CODE:
Please log in to see this code.
Size:
Color:
Although the script is long enough to follow without a description, clearly this part of it will not trigger Alerts in SM or Strategy window b/c it uses "bar" instead of "bar+1":
CODE:
Please log in to see this code.
Size:
Color:
ok thank you. I was trying to sell at the open of the last bar of the day.
Size:
Color:
You're welcome.
Size:
Color:
can you please make a suggestion as to what script I could use to close my open positions prior to the end of the day? I would be happy for the easiest fix, meaning I just need the positions closed - getting a certain close or open price on the last bar or next to last bar is not important to me. Maybe if I could pass a normal SellAtMarket bar +1 triggered by the next to last bar? something like that?
Size:
Color:
Size:
Color:
thanks i will check it out
Size:
Color:
OK, I was able to work this out, thanks again. now that I have this issue worked out and my bar+1 issues worked out hopefully my strategy will generate alerts today
Size:
Color:
Glad to hear you've made a good progress on this!
Size:
Color:
so one step forward , two back....
so I now have alerts generating for my sell orders but not my buy orders. the buys are being indicated on the strategy window charts. what generates the alerts? I thought the buy and sell command lines did?
Size:
Color:
also, the sell alerts that do generate in the strategy monitor, don't auto-stage into the orders tool even though i have that option selected. I can manually select the alerts and select stage orders and they will stage at that point but the auto feature does not seem to work. any thoughts?
Size:
Color:
never mind on my last question - I found the answer in the User Guide:
QUOTE:
Alerts to exit positions that are not owned in your account are not automatically transmitted to the Orders tool when Auto-Stage or Auto-Place is enabled. These Alerts will still be visible in the Alerts views, however
I think my problems are stemming from the buying not generating alerts and orders
Size:
Color:
Make sure to always load enough bars. Specifying too few bars in the Data Range control may lead to trades/alerts getting out of sync.
Size:
Color:
so when you say load enough bars, I see this a lot in the examples:
CODE:
Please log in to see this code.
is the 20 count for bar the loading you're talking about, as opposed to mine starting at zero?
Size:
Color:
if you're talking about the historical data range, I'm including at least one day prior, which when I'm using one minute bars is starting with at least 390 bars loaded, if I'm understanding the terminology you're using. thanks in advance I appreciate your help
Size:
Color:
The historical data range is what I'm talking about. If your trades ever span more than a day than "at least one day prior" is positively not enough.
Size:
Color:
My trading program is only designed for intraday so in light of that what do you think?
Also does it have anything to do when I open the strategies/turn on streaming with respect to when the market is open or closed?
Size:
Color:
OK let's assume the strategy now closes positions before the end of day. Alerts from the buy side should be fine if you load whatever it required for them to trigger e.g. several days of data. Try to load even more data. If still no go, make the entry condition(s) less restrictive and see if it would improve the buy alerts.
Size:
Color:
OK, so I've gone back and am streaming the intraday 1-minute pair trade strategy (including the PairsBarLoader) with 10 days of data. The strategy, at least according to the strategy window, appears to be working as intended. However, the entry alerts are not generated and passed to the orders tool even though they show up on the strategy window's "trade" log (see attached photo). When applicable, the exit alerts are generated and passed to the orders tool but they error out because it says the shares are not there to sell. Then despite the order tool problems, the strategy window will ultimately show that the pair trade closed out.
You had suggested making the entry condition less restrictive but it already doesn't seem very restrictive as a large number of buys are made per day.so I am not sure what else to try with respect to that tactic. I've listed the buy section of the code below for your reference. Any help you can provide would be greatly appreciated. I feel like I'm right near the end but just have to get over this last obstacle. Thanks in advance.
CODE:
Please log in to see this code.
Size:
Color:
lets try this again
Size:
Color:
That screenshot is really fugly. ;)
To take a screenshot, please strike "Prt Scrn" key on your keyboard. (Make sure the entire WLP window is visible.) Then start MS Paint (which is bundled with Windows). Press Ctrl-V (or choose Paste from menu). Now save as PNG format. Voila!
Size:
Color:
OK see attached
Size:
Color:
Looks good now. Here's the problem in your code:
CODE:
Please log in to see this code.
When it comes to generate an Alert (i.e. bar == Bars.Count), your code throws an IOOB (index out of bounds) exception and then the loop has to
continue. Never a chance to issue a buy Alert.
Size:
Color:
That did the trick! Thank you for all your help!!!
Size:
Color:
Glad to help you.
Size:
Color: