Have a strategy I want to execute at the end of each month. Created the buy rules including "Date is Last Day of Month". Executing without any sell rules give me exactly the buys I was expecting. However, once I add sell rule, all is lost!
In simplest terms, on the last day of the month, I'd like to sell all bought at the end of last month & buy again those passing the buy criteria. The issue arises when a stock was purchased at the end of last month then is eligible to be bought again at the end of the current month.
I've tried single & multiple open positions, all combinations of buy at and sell at (close and market), and even added that the position needs to be more than 1 day old (which I discovered is not the last entry, but any addition to the position).
Any suggestions as to how I could achieve this would be greatly appreciated.
Ram
Size:
Color:
The end of month rule seems to work pretty well for me. Are you adding the condition to a "SellAt" signal or are you putting it under "BuyAt"?
In other words, you should have something that looks like this:
BuyAtMarket
- condition1
- condition2
- etc.
SellAtMarket
- Date is last trading day of month.
Size:
Color:
The condition "Date is last trading day of month" is in both the BuyAt & SellAt!
I have tried all combination of BuyAt & SellAt. Both set to Market or both to Close cause the transaction to close either the same day or the next ... not the end of the upcoming month.
BuyAtMarket with SellAtClose gives an error ... "Runtime error: Bar number must be 107 or greater" despite the data range set to 18 months. Haven't figured out why ... happens consistently.
BuyAtClose with SellAtMarket has the transaction bought the last day and sold the next.
Tried adding "positon held for x days". Tried both 1 and 7. Discovered that this rule applies to the total position ... so for a stock bought last month and then qualifies for a purchase the next, the original position is not closed.
Using the single/multiple positions allowed on the rules screen, has a problem similar to the hold for x days.
Here are the rules (constructed to simply demonstrate the problem) ...
Data Range 18 months
Symbol EP
RULES:
Buy at Close
Price is higher by x% than it was a number of bars ago (x% set to 5, lookback set to 50)
Date is last trading of month
MULTIPLE OPEN POSITIONS ALLOWED SET ON
Running the above without any sell rules give all the trades that qualify! It is every month in 2011
Now Add the following sell rules
Sell at Close
Date is last trading of month
With MULTIPLE still set on
All trades are bought and sold the same day.
With SINGLE open position on, you positions are held multiple months & some months are not bought.
Again, as stated above I've tried every combination of Market and Close without success.
As simply as I can state it ... on the last trading day of the months I was to sell all purchased on the last day of the previous month, then run the buy rules for purchases I will hold until the last day of the upcoming month.
Any help would be appreciated.
Size:
Color:
QUOTE:
Both set to Market or both to Close cause the transaction to close either the same day or the next ... not the end of the upcoming month.
It's relative to the chart's timeframe. If you want the "next bar" to be "next month" (instead of the trading day or week of the next month) then you should switch the chart to Monthly bars.
QUOTE:
As simply as I can state it ... .
Don't be simple, be explicit. Not everything can be done with the wizard. Sometimes it's just a good way to get started, but then you have to finish it manually. I can't tell if this is the case for your strategy, because I don't have all the rules.
Let's cut to the chase - provide all the rules, otherwise I can already see this as one of those threads that goes back and forth all week, and then I'll end up asking for all the rules anyway.
Size:
Color:
The tone of your response was surprising. If it was sometime I said, please understand it was unintended.
If what I'm trying to do can't be done, knowing that would save me a great deal of time. Unless there is something productive to do after this post, it will be my last.
Now, my message above has the rules that cause the problem. Maybe it wasn't clear enough so let me retype them ...
Data Range 18 months
Symbol EP
RULES:
BUY AT CLOSE
- Price is higher by x% than it was a number of bars ago (x% set to 5, lookback set to 50)
- Date is last trading day of month
SELL AT CLOSE
- Date is last trading day of month
Using either Single or Multiple positions does not yield the expected results. As best I can tell, only a buy or the sell is executed ... not both ... which is what I wanted. My previous post tries to describe how to recognize the problem.
Again, any suggestion or even a "Give Up" would be much appreciated.
Bob
BTW, I can program, but not in C# ... if WLP generated IBM 360 assembler language, I'd have no problem!!! :-) I have successfully modified generated WLP code in other strategies, but my attempts with this one haven't succeeded. If I can't succeed with WLP though, I will code it as a Excel macro.
Oh one last thing, I tried your suggestion for changing to Monthly bars. However, it consistently causes the following error ...
Runtime error: DataSeries do not have equal number of values for mathematical operations.
Unless resolution of this error would lead to a solution for the original problem, I'm not asking you to address this.
Size:
Color:
Bob,
QUOTE:
Runtime error: DataSeries do not have equal number of values for mathematical operations.
Regarding this error, please scroll down to "DataSeries do not have equal number of values for mathematical operation" in this FAQ:
Errors | StrategyHopefully it can give some food for thought to help solve the issue.
Size:
Color:
QUOTE:
BuyAtMarket with SellAtClose gives an error ... "Runtime error: Bar number must be 107 or greater"
This is occuring because the wizard code attempts to sell the Position that you buy at market on the
next bar on the close of the
current bar.
Even if the Exit logic is above the Entry logic (visually in the wizard), the wizard rearranges it to execute the entry logic first
if multiple positions are selected. Frankly I don't know why it was required to do this, but this is an example of something you have to edit manually by just rearranging the entry and exit logic.
In the same way, for the two AtClose signals, execution order is important to sell what you bought last month first
before you buy again. Otherwise, the wizard will buy and sell on the same day. This appears to be working correctly for the two AtClose orders -
CODE:
Please log in to see this code.
Specifically, for the "DataSeries do not have equal number" Runtime error, you need to select at least 51 months so that the code can perform the 50-period calculation.
Size:
Color:
Thank you for the help and effort. Your code worked perfectly.
The error explanations is also appreciated. Clearly I must change my thinking if I am to use WLP properly.
It's bars not days!!!
Size:
Color:
It's usually not that hard to create a simple strategy - and it shouldn't be for your case either. I'll try to remember to investigate why the Wizard doesn't respect the visual order for multiple position strategies. It would help me to remember if you created a Support Ticket for that (upper menu) :)
Size:
Color: