Hello all. I have a new "kink" to work out in my simple rules-based strategy. Eugene know the strategy already, but I'll post it again for the forum. Then, I'll explain the "kink".
I have one buy entry in my strategy with one condition. The entry is Buy at Market, and the condition is that the fast moving ave. (I use SMA21 for this) is above the slow moving ave. (I use SMA50 for this). I use Daily for Scale, 56 bars for Data Range, and I'm using Raw Profit mode with $100 position size. I also have Multiple Open Positions Allowed checked in my strategy.
I also have one exit entry, which is Sell at Stop Loss, set at 45%.
That's the entire strategy. Now, the current "kink" I need to get worked out is that after buying for several days and not placing Stop Loss orders, today it did not buy (though my rules were met, I was logged in, strategy was activated, auto-place was selected, and Orders window was open with Live Accounts selected), but it did place 1/2 the stop orders it should have placed for my positions.
I'm not a programmer, so I've really been working hard to get this simple strategy to work with just the Rules Based code wizard. Can anyone tell me why the strategy would start placing the stop orders on 1/2 the open positions, and stop buying, even though the buy alert is being created along with the stop loss alerts (and there is more than enough cash in the account available)?
Size:
Color:
Your RP sizing is $100
How many shares of AAPL at $122.37 per share insert can you buy for $100? (Or insert any other stock trading over $100 like PCLN, GOOG, ALXN, etc.). Even in Raw Profit mode your size must be large enough to purchase at least 1 share. This would be a reason that the strategy doesn't purchase stock even if the buy conditions is met.
Your Data Range is 56 bars
If you entered a live position more than 4 days ago (7/26/2015 or earlier), your hypothetical strategy will no longer be aware that that position exists. If you're using the wizard, the trading loop starts on bar 51, which changes every day. When you're trading live you need to either use more seed data or ensure that your Data Range starts from a fixed date. Understood?
Size:
Color:
Hi Cone. I am well aware of share price and what can be bought for $100. I am running 4 instances of the same strategy, with 1 stock symbol in each instance. The stock prices are around $10-$20 (all are much less than $100). Price has remained in the same area for the 2 weeks I have been running the strategy. It has been buying every day (since I learned that I have to log in each morning, and leave the order window open set to live trading, and make sure the strategy is activated and set to auto-place). The rule I have for buying continues to be met each day, so I cannot understand why it should stop buying yesterday.
Likewise, Stop Loss orders had been placing in the evening (I have left the default setting at 4:30 p.m. for the strategy to update), but canceling themselves the next day when I log in, and not being active during the trading day (when you need them). Yesterday, about 1/2 the quantity of Stop Losses (vs. positions) placed and remained active.
So, I have been able to get my daily buys until yesterday, when the strategy stopped buying for some reason. And, Stop Losses (about 1/2 the quantity of my stock buys so far), stayed Active yesterday. Very strange.
Size:
Color:
By the way, I set up Wealth Lab Pro on a dedicated server from the very beginning. That's how I run my ea in my forex trading. That is also the reason I wasn't aware that I would need to log in each day. I had been leaving the program open and expecting it to continue running. I now know I will be automatically logged out after 10 hours.
Size:
Color:
Also, I had used 500 bars to start with when I ran my strategy. But, the strategy was producing numerous Stop Loss orders (I presume from when the strategy might have bought sometime during the past 500 bars), when it had not even bought anything yet.
Size:
Color:
Based on the information you provided, I said "This would be a reason that...". It's not necessarily the only reason. Let's get some more details then.
What stocks are they?
Are the Alerts occurring?
If so, are they making it to the orders tool?
If so, are they being placed?
Do you have a screen shot of the environment showing a failure?
Re: Stop Loss
I stand behind what I said here. If you're using 56 fixed bars (this is what you said in your first post), you're going to lose orders tied to purchases 4 or 5 bars (trading days) earlier.
Re: 500 bars
Don't use fixed bars. Use a date range that corresponds to 51 trading days before you started trading. With about 21 trading days per month, if you set a range starting about 5/5/2015 (and ending anywhere far into the future), it should be just about sync'd with your trading.
Size:
Color:
Here you go. Here's one showing what I have after the 7/31/15 update at 4:30 pm eastern. You can see that some of the stop losses are being staged and placed, but for some reason the buy orders are not being made. The symbols I am using in the 4 instances of strategies are: BYD, FCSC, HIG, and ITG. ITG is not currently meeting my rules, so it should not, and has not been buying. http://screencast.com/t/Mzx4zPWFRHW
Now, here is my Accounts window. You can see that it was buying up until 7/30/15, when it stopped for some reason. There were staged orders for that day, as you can see there are for 7/31/15 in the above screenshot. But, the buys did not occur. http://screencast.com/t/0EkJvxApo2xy
Here's the Account Balance and Position Summary. http://screencast.com/t/TMEDLhL43yqR You can see it has been buying, until 7/30/15.
And here's the Orders window showing filled orders and cancelled ones. Notice the "Unknown" Status on the last 6 orders. Based on the positions shown in my Accounts Window, those orders did not fill. I don't know why they are shown as "Unknown" though. http://screencast.com/t/pzVJVxFxaE
I really appreciate your help. The next thing I will do is set the date range with a starting date as you suggest.
Size:
Color:
Not a complete answer but only an observation to add to Cone's upcoming reply:
Your 2nd screenshot indicates that some of your orders were produced using a 51-day EMA. Not only 56 bars of data is insufficient in general as Cone said (and I noted in the ticket), but in this context it presents a new problem the WealthScript Programming Guide has been warning against for years. See > Indicators > Stability of indicators.
P.S. Note that you can attach screenshot(s) directly to your reply. Just click "Add attachments" (if it didn't work, temporarily disable your ad blocker plugin). External links tend to die and continuity suffers. It's frustrating to stumble upon such a discussion with placeholders years later.
Size:
Color:
Thank you Eugene. I named the strategy with "EMA" in the title, but that was before I got your information about the instability of EMA's. I am actually using SMA's in the strategy. Thanks for looking at what I sent so thoroughly. I have alreadly changed the Data range to what Cone suggested. I do appreciate your responses Very Much!
Size:
Color:
Re: Unknown order status (per User Guide: Orders > Managing the Orders List)
The order status cannot be verified through Fidelity. This will occur, for example, if you shut down Wealth-Lab Pro with active orders. If you then launch the Orders tool without having connected to Fidelity, the status of previous live orders cannot be verified.Note, for example, that your BuyAtMarket orders on 7/29/2015 for HIG, BYD, and FCSC were actually filled per the Local Trade History. Since it appears that you're entering orders after the session closes and then restarting WLP the next day, make sure that you log in to Fidelity before opening the Orders tool or a Workspace that in includes it in order to avoid "Unknown" statuses.
Re: Workspace imageBased on the Alerts given (which are theoretical and not based on live Positions), each company should have 1 buy and 4 stop orders active, but only 3 stop orders made it to the Orders tool. In this case I can't see a plausible reason for the missing orders, and would have to blame it on an intermittent bug we've seen in the past. Programmers haven't been able to duplicate that bug, and that's why we're still living with it.
Note, however, that there is a filtering mechanism that will eliminate duplicate orders. So, if you happen to have multiple stop orders at precisely the same price (a big possibility with your strategy), all but one will be filtered/removed. That's not the case here, however, because the missing stop alert for HIG, for example is $25.85, which is different from the other 3 active orders.
How to Proceed:1. I think you've already done it, but start the Strategy from 5/7/2015 to synch your strategy to your positions. You're missing position entries from 7/30 and 7/31, so you could purchase those at the hypothetical entry prices using GTC Limit orders.
2. Before placing orders for the next day, select all orders, cancel, and remove them. Keeping the list "clean" might aid in avoiding the aforementioned bug.
3. If you see the situation in which the BuyAtMarket orders don't make it to the Orders tool, try clicking the Alert and then click
Place Orders manually. I'd like to know if that works for you.
Aside: A couple things concern me about your strategy:
1. The Strategy only sells positions for a 45%
loss. There's no profit motive, so this is more or less a buy and hold strategy. If the idea is to create a trailing stop, I can help you with that.
2. Commissions. Do you really want to buy $100 positions every day at slightly different prices? It might be wise to buy a $500 position on the first trading day of the week (or maybe even at limit for the average opening price for the previous week). Advantages: 4x fewer Positions, 8x less commissions (entry and exit). Even $2K positions each month may make sense.
Here's the strategy that buys on the first trading day of the week to play with. Run on Daily data, increase Positions to $500:
CODE:
Please log in to see this code.
Size:
Color:
Thanks Cone. I wondered about deleting all the orders before placing them for the next day. I'll try that. I'll also experiment with the weekly idea, with a larger position size. I tried this in my backtesting, but got consistently higher returns with the smaller position size (including the higher commission, which is a very valid point). The idea of "scaling in" with the smaller position, and if price dropped too much, the smaller position sizes took smaller stop losses earlier, helped produced higher profits. Not buying if 21SMA < 50SMA prevents adding positions during larger pullbacks, but does begin buying shortly after the pullback.
The strategy I have built is of course not all the strategy. Part of it is finding stocks that not only fit my price guidelines, but that also are just entering a long-term (monthly) reversal in trend. I find these when I run through various stock scans, then filter by supply/demand zones on larger timeframes, and by some fundamental data as well. The "sequence" is very important in the strategy. Monthly must be up in order to buy on my daily entry timeframe (initial filter for that is 105SMA > 420SMA). If 105SMA falls below 420SMA, I liquidate all positions.
Size:
Color:
I just did the cancel on all orders, then ran the strategy (by right-clicking the strategy and selecting Run Strategy Now). When the strategy ran, it activated all the Stop Loss orders, but not the Buy orders. I then cancelled and removed (as you suggest above) all orders, and this time when I ran the strategy, it activated the Stop Loss orders as well as the Buy orders.
Size:
Color:
I'm not sure it's the case, but if the Orders list had previously-staged market orders from your strategy, then that would explain the failure of those new market orders. We probably should have had you save the Orders.xml to check on that.
Apart from the commissions, the strategy accumulates too many positions - it's too much work for no identifiable gain. (In other words, the entry prices are basically random anyway.) I think the simple change to weekly purchases handily beats the daily results - at least it did for the stocks mentioned above.
Size:
Color:
I just ran my strategy with weekly scale and $500 position. Then I ran the strategy you sent me with $500 position and Daily scale. Yours produces better profit. I'm trying to understand why. I see the code you suggest adding to my strategy:
CODE:
Please log in to see this code.
and also:
CODE:
Please log in to see this code.
Why does your strategy produce a better return than mine, when I set mine to weekly and $500 position size? Also, if your modified strategy buys weekly (as I can see the code tells it to, and the Trades tab verifies that on a backtest), why is it run on the Daily scale?
Size:
Color:
Because the indicators are different using Weekly bars, so it's a different Strategy. Remember, your Strategy is to trigger on 21-bar/50-bar SMA, where the bars are daily. You could approximate it (but not exactly) by changing the averages to 4-bar/10-bar SMA in the Weekly scale.
Size:
Color:
Size:
Color:
Hi Cone. I let my daily buying strategy finish out last week, and loaded your modification (code added that buys just once/wk.). I ran the strategy this morning and it produced the stop orders, but not the buys (though the rules of my strategy are me for buys). Does the code "IsNewWeek" determine the day of the week on Monday at close, then buy on Tuesday? I can see where it would not stage an order today if that is the case.
I tried to search for the definition of "IsNewWeek", but couldn't find it. If you could point me to where I can find definitions for something like this I would appreciate it.
Thanks very much! Hope you have a great day!
Size:
Color:
P.S. Re: definition of "
IsNewWeek". There's simply nothing to "define" there, it's a one-liner in pure C# 101:
1. Wiki FAQ >
How do I start with C# ? (comparison operators)
2. MSDN >
DayOfWeek enum
Size:
Color:
Thanks for the references Eugene. I think Cone's code requests the day of week in terms of an integer, so it can determine if it is a new week or not. From what I've read, Sunday is 0, Monday 1, etc. So was just trying to look at what he coded to see if I can understand how the code is determining if today "IsNewWeek" based on the number assigned to Monday. I'm not a programmer, as you know. I'm just trying to figure out for myself why the strategy did not buy today (Monday, first day of a new week).
Size:
Color:
Thought I'd try using Visual Basic 2015 to view the code and point at keywords to see descriptions, but get error messages for most of them. I guess the library for them is built in WealthLab Pro somewhere, and not accessible with the "Using" libraries in Visual Basic.
Size:
Color:
I think I just got my answer. I just ran the strategy (after 4:30 pm) today and it produced the Buys, as well as the Stops. The data that the strategy needed to determine IsNewWeek must have been based on the close today. So, that must be the reason it didn't stage the orders last Friday at 4:30, and buy this morning.
Size:
Color:
Right. The enum value for Friday is greater than Thursday's but Monday's less than Friday's.
Size:
Color:
So the program "knows" to skip Saturday and Sunday when doing it's comparison I guess?
Size:
Color:
Speaking of the U.S. market, there are no data bars on weekends. Other markets may trade eventually (Russian Federation) or usually (Middle East).
Size:
Color:
Good morning. I have a new "kink" to work out after switching to the new code where I trade once per week. All stop and buy orders were placed yesterday (Tuesday) as expected, based on the code. Today, when I logged in, all the stop orders were showing as Status Unknown. So, I deleted all the orders in the Orders window (including the Filled orders from yesterday), ran the strategy on one of the symbols (BYD), and selected all the alerts produced and clicked on Place orders.
I then get the attached screen, which shows "error" as status for those stop orders. The explanation says the error is due to an existing, conflicting order on BYD. So, I clicked the update button on the orders window to see if those existing orders show. They do not. I logged out and back in, and they still do not show when I click update. I then logged into my account on the Fidelity site and sure enough, the orders are all sitting there with a status of Open.
Is there some reason that WealthLabPro is not seeing these Open orders in my account? And, how will I get WealthLabPro to continue to place these stop orders daily when I log in and run my strategy?
Size:
Color:
Re: IsNewWeek(bar)
I threw that together quickly. It returns true when the current
bar is in the new week. Therefore
bar+1 is the second day of the week. Since the entries are practically random, it shouldn't really make much of a difference in practice - but there will be
a difference. If you really want to buy on Mondays (usually), then we could create a different function.
Re: Error statuses
QUOTE:
Today, when I logged in, all the stop orders were showing as Status Unknown.
That's expected if you open the Orders tool without having logged in first.
QUOTE:
I then get the attached screen, which shows "error" as status for those stop orders.
Based on the sequence described, I'd be surprised at the result too. Are we missing some initial conditions? Is it possible that you had already entered GTC orders for the shares? Since you only started buying on a Weekly basis recently, do you actually have shares that correspond to these [hypothetical] alerts?
QUOTE:
Is there some reason that WealthLabPro is not seeing these Open orders in my account?
Following the dialog, I'm not convinced (yet) that the active orders were placed by WLP. Have you placed GTC orders perhaps? How many shares (total) for the BYD position do you have in the account, for example. (The script, which runs hypothetically, thinks there are 117 shares total.)
WLP has a cool sync feature that allows exit trades to be placed with the correct number of
total shares, but for you this is not desired. In your case, you probably have to do some extra work to synch orders for the shares that you own. For example, play with the date range (or code) so that the script "is aware" only of the position that you bought this week, i.e., 1 stop order. For the shares that you had owned from previous trading, manually place GTC stop orders to manage those separately. After that, it should work. However, managing the stops for the number of positions that you are likely to have over the course of the next year is not for the feint of heart!
Size:
Color:
Thanks Cone. No problem with buying on Tuesday. I just didn't understand the code you wrote until I got some more information from Eugene.
I have not placed any manual orders. The stop orders are close to the amount of my actual shares. So, I haven't been too concerned about the difference in WLP stop orders vs. the actual number of shares I have bought. I planned to do what you say about entering manual orders for the shares that are not covered by the stop order. I'll attach the current stop orders window, the accounts window, and the Orders page from my Fidelity account. Since most the shares were bought when I was buying on a daily basis, I guess the current strategy (buying weekly with your code) doesn't "know" that I was buying daily, and assumes weekly purchases back to the beginning of my data range.
To make sure I wasn't doing something wrong to cause the existing orders not to show up in WLP, I closed the Orders window, logged out, logged back in without the Orders window open, then opened the Orders window and clicked Update. Still no orders showing.
I may play with the beginning date a little, but the qty. of stop orders are fairly close to my actual already, so manual stops for the remainder is probably the easiest.
Size:
Color:
QUOTE:
but the qty. of stop orders are fairly close to my actual already
It's the number of shares that matter. "Account B&P" shows that you own 91 shares of BYD, but the strategy sent stop orders for 117 shares. Nonetheless, I would have expected 3 of the orders to have been accepted. From here, I can't tell you why all those orders errored out.
Size:
Color: