Problem trading reliably with UserSpecified contract sizing  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
User avatar
jwebster503
Posts: 24
Joined: 13 Mar 2014
Has thanked: 9 times
Been thanked: 14 times

Problem trading reliably with UserSpecified contract sizing

Postby jwebster503 » 27 Apr 2016

TL,DR: In same market, multiple algorithms each with their own signal work fine. However, trying to combine multiple algorithms under one signal results in problems when try to close more than once without switching market direction.

Pie in the sky hope
I'm hoping to be able to simply specify my market direction and size in one shot. I now want to be +800, then +1200, then +500, then -400, then -2000, etc. Instead, I looks like I need to send a BUY 800 then BUY 400 then SELL 700 then SHORT 400 then SHORT 1600 to accomplish the same positions. The logic to compute deltas trivial, but it will be slightly more tricky dealing with different order types, especially if I have to do extra work to clear the instability issue found. Is this "simpler" method of specifying direction and size available?

The Problem
We wish to trade multiple algorithms on the same market simultaneously (e.g. Above or Below Moving Average, in top or bottom of Trading Range, etc.) Right now, we're giving each algorithm its own signal, with its own contracts, and everything is working. The MovAvg algorithm is Long with 6 contracts, so that's +6. TradingRange is Short with 2 contracts which is -2, AlgXYZ is neutral which is 0, and our net position in the market is +4. There are no problems here. The problem comes when we try to switch to using a "summarization" algorithm with a "User Specified" contract sizing driving a single signal, seemingly always while sending more than one exit before the market switches to the other direction.

Sample algorithm to build different scenarios
I'm assuming the algorithm itself is irrelevant. I'm using a "rotator" algorithm which over eight phases goes through positions of [0, 1, 2, 1, 0, -1, -2, -1], with x seconds spent in each phase, then the cycle repeats. This is multiplied by the contract size to yield this algorithm's portion. This was chosen because it was easy, and with slightly differently sized versions, creates a wide variety of patterns. Using the example code, against AUDUSD starting Apr 25 midnight using 1 minute bars, and with three rotators (#1 rotates every 300 seconds and has 30 contracts, #2 rotates every 310 seconds and has 50 contracts, and #3 rotates every 315 seconds and has 75 contracts).
_Portfolio strategy and view.pln
_Portfolio strategy and _Portfolio_View indicator
(3.74 KiB) Downloaded 538 times
AUDUSD with Portfolio Signal.wsp
Workspace with signal and indicator
(78.33 KiB) Downloaded 523 times
An example of things actually working:
Bar 1: 0 + 0 + 0 = 0 [Market Position = 0 -- OK]
Bar 5: 30 + 0 + 0 = 30 -- send BUY 30 [Market Position = 30 -- OK]
Bar 6: 30 + 50 + 75 = 155 -- send BUY 125 [Market Position = 155 -- OK]
Bar 10: 60 + 50 + 75 = 185 -- send BUY 30 [Market Position = 185 -- OK]

We can see everything is fine because the yellow line (actual market position) matches the histogram, which is the calculated summary of all component values.

Problem Pattern #1 starts in bar 162 -- Order Exits are not processed at all
Bar 160: 0 + -50 + -75 = -125 [Market Position = -125 -- OK]
Bar 161: 30 + -50 + -75 = -95 -- send COVER 30 [Market Position = -95 -- OK]
Bar 162: 30 + 0 + -75 = -45 -- send COVER 50 [Market Position = -95 -- WRONG!] Logging statement shows code sends cover, but market position doesn't change.
Bar 164: 30 + 0 + 0 = 30 -- send BUY 30 [Market Position = 30 -- OK] BUY closes problem open orders and opens Long, and things work again for awhile.
Problem #1 Exit.PNG
Problem #1 - Exits skipped entirely
(211.49 KiB) Downloaded 1135 times
Problem Pattern #2 starts in bar 201 -- Order Exits are partially processed
Bar 199: 0 + -50 + -150 = -200 [Market Position = -200 -- OK]
Bar 200: 30 + -50 + -75 = -95 -- send COVER 105 [Market Position = -95 -- OK]
Bar 201: 30 + 0 + -75 = -45 -- send COVER 50 [Market Position = -50 -- WRONG!] Market only covered 45 instead of 50.
Problem #2 Exit.PNG
Problem #2 - Exits partially filled
(212.01 KiB) Downloaded 1133 times
Problem Pattern #1 again starts in bar 221, but on the Long side coming down.

Problem Pattern #1 again starts in bar 240, 260 and 281.

Problem Pattern #2 again starts in bar 300.

Problem Pattern #3 starts in bar 321, 342, 362 and 383 -- just like pattern #1, but there is an entry in the middle which doesn't clear things.
Problem #3 Exit.PNG
Problem #3 - Same direction Entry doesn't clear exit
(198.79 KiB) Downloaded 1130 times
Analysis?
The pattern seems to be that you can always make new order entries without problems. You can exit an order without problems one time. But, if you try to make subsequent exits, problems MAY arise. If there are problems, they seem to hang around until you switch direction from Long to Short, or Short to Long, which exits any open orders. I've already tried different signal properties such as allowing multiple entries and exits per bar. I've also looked at OrderExit.FromAll and OrderExit.Total values on the SOrderParameters, but this seems to have no effect. I'm sure the issue is that I haven't configured the orders right, or the signal right, or something right. Does anyone have any suggestions, or experience with a single signal with varying contract sizes?

Thanks,

Jeff

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Problem trading reliably with UserSpecified contract siz  [SOLVED]

Postby Henry MultiСharts » 29 Apr 2016

Hello jwebster503,

You need to add the following attribute to your code:
[ExitFromOneEntryOnce(Value = ExitFromOneEntryOnce.FillAndKillExitOrder )]
You can find more details here:
https://www.multicharts.com/trading-sof ... gine_works


Return to “MultiCharts .NET”