Trades are skipped by monthly AtClose Strategy (25% equity, 4 positions)
Author: MDA
Creation Date: 3/28/2018 1:13 PM
profile picture

MDA

#1
Hello,

is it possible to query the number of all open positions in the script? I mean about all the symbols in the portfolio test.


Thank you
Matthias
profile picture

Eugene

#2
Hi Matthias,

It's possible but not that simple: Any Open Position (in Other Symbols) in Portfolio Mode

Could you clarify: why do you think you need to get the active position count of a portfolio in a Strategy? There may be an easier solution to your task than having to rewrite your Strategy if you share your objective.
profile picture

MDA

#3
I tried it with the "Positins Options", but....
- for example, I can enter a maximum of 4 open positions
- then sometime I have 4 open positions
- if I sell 1 position at the close (3 positions are still open) I cannot buy 1 new position at the close

That's my problem.
profile picture

Eugene

#4
QUOTE:
- if I sell 1 position at the close (3 positions are still open) I cannot buy 1 new position at the close

Maybe your system doesn't have enough capital to take the 4th trade?
profile picture

MDA

#5
I' m investing 4x 25% and have margin factor 10:1, so enough Capital.
profile picture

Eugene

#6
You can never be sure. How many skipped trades are there on the bottom of the Trades tab? If zero, try my link in post #2 above.
profile picture

MDA

#7
The strange thing is, if I close to the next open 1 position, then WL regularly immediately opens 1 new position at the same time. The problems close/open at the same time I have only at the closing price.
profile picture

Eugene

#8
QUOTE:
I' m investing 4x 25% and have margin factor 10:1, so enough Capital.

Looks like you're adhering to the same myth debunked in posts #10, #16 and #18 in a year-old discussion with you: Open and Close at the same bar with AtClose orders.
profile picture

MDA

#9
yes, the same problem now in another strategy. an acquaintance told me that problem did not exist earlier in WL 4. It's annoying and I have to complicate the codes now.
profile picture

Eugene

#10
If you don't wish to complicate the code, try to avoid "investing 4x 25% and margin factor 10:1". This is a recipe for skipped trades.
profile picture

MDA

#11
how should I adjust it if I wish to have a maximum of 4 open positions?
profile picture

Eugene

#12
See post #8 right above. Sorry, I don't have anything more to add to this.
profile picture

Cone

#13
Wealth-Lab processes exits for AtMarket signals and frees buying power for other signals for the same bar. The same is not true for other signal types. Nonetheless, if you have set over 2:1 margin, and you're properly limiting the Strategy to 4 trades with 25% equity sizing, I cannot think of a reason other than a large amount of commission, or a size that doesn't allow the purchase of at least 1 share, (or, ok, I guess there could be reasons) .. that you cannot purchase that 4th position when another position is exited AtClose on the same bar.

If you want to post the script here or in support, and provide your settings for sizing, DataSet symbols, etc. I could take a closer look.
profile picture

MDA

#14
Hi Cone,

here is an example Code:

CODE:
Please log in to see this code.


If you use "Position Options" with 25% "Pct of Equity" and "Max open Position"=4 (and Margin Factor 10) then you will see the problem in the trade list. If positions are closed at the closing price, no new positions are opened.

If you make the whole thing the opening price, the position management works correctly. Here is the code with the small change.

CODE:
Please log in to see this code.


However, if possible, I need an uncomplicated solution at the closing price.
profile picture

Eugene

#15
QUOTE:
If you make the whole thing the opening price, the position management works correctly. Here is the code with the small change.

Maybe Cone knows a trick but having tried different ways I couldn't make both the entry and exit to align at close. An uncomplicated solution at the close price might be...
CODE:
Please log in to see this code.

...while changing your entry to bar+1:
CODE:
Please log in to see this code.


Another idea that might work is to switch the scale to Monthly while retaining AtClose for entry/exit.
profile picture

MDA

#16
Thanks for the tips. I'm afraid they won't help me. The code was a simple example to demonstrate the problem. Most of my strategies have signals at the daily closing price. These are to be implemented.

Can I take a variable from one symbol to the next? Some kind of superordinate signal counter?
profile picture

Eugene

#17
QUOTE:
Can I take a variable from one symbol to the next?

I tried to come up with a DataSetSymbols-looping script like this but my attempt didn't work as expected. Have you considered Raw Profit mode? Buying power is freed in this case.
profile picture

MDA

#18
Yes, Raw Profit mode works. But I cannot set how many positions (general, long, short, etc.) should be opened. The "Positions Options" is a perfect tool if only this one problem would not be.
profile picture

Cone

#19
The problem here must be how ActivePositions is reported to the PosSizer. That's preventing new Positions to be sized on the same bar.

I don't have a simple work-around, but it works if you run a "DataSetSymbols" loop, and execute the strategy on one symbol only - like the rotation scripts. In this case, you only buy the n (4) symbols that you select by some priority (RSI), which limits the number of "raw ActivePositions" that the engine has to deal with.

To run the script below, you need to add a reference to:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Data.Linq.dll
check "System.Core" in the Strategy Editor > References... button > NET References tab.


1. Use the regular % of Equity sizer, 25%, with, say, 3:1 margin.
2. Run on one symbol (one with the longest history) only!

CODE:
Please log in to see this code.


p.s. This solution may exit and enter the same symbol on the same bar. With a little extra code, we can prevent the exit in those cases.
profile picture

Eugene

#20
QUOTE:
To run the script below, you need to add a reference to:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Data.Linq.dll

Nice job Robert. One note: adding the file reference isn't required. Instead, topic starter should simply check "System.Core" in the Strategy Editor > References... button > NET References tab.
profile picture

Cone

#21
Hmmm, something is wrong with the sort... seems to always return the same result... stand by.
profile picture

Cone

#22
Code above in post #19 corrected. After a test, I had accidentally left a [Bars.Count - 1] where [bar] should have been ;)
profile picture

Cone

#23
Here's the version that doesn't unnecessarily exit a Position.

Comments in Post #19 still apply.

CODE:
Please log in to see this code.
profile picture

MDA

#24
thank you very much Cone. I'll try the codes. This is the "more complicated" variant. As I said before, this was just a simple example code. The signals from my trading systems are more complex. It'll take me a while to reprogram the logics. It won't be easy.
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).