Issue with exits in a multi-position strategy
Author: Pablo4646
Creation Date: 7/8/2013 7:20 AM
profile picture

Pablo4646

#1
When I try to compile multi position strategy there were some troubles. When I collect position by parts with putting protective stop at each addition process has been stopping when the first stop order was taken. Therefore I can't collect full position.
profile picture

Eugene

#2
Is this a question or assertion? How can we help you if we don't know what you're doing wrong?

Please provide more details. Is this a rule-based Strategy? Shows us its rules. Or is it code-based? (Then I'd expect that you asked in the "WealthScript" forum, not here in "General".) You have to share your Strategy, at least a "cleaned up" version of it so we could inspect it.

profile picture

Pablo4646

#3
Excuse for an inexact statement. The question in that why WLD doesn't allow to continue setting position by parts after operation of the first stop. The text of Strategy attached.

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

Eugene

#4
This code is pretty problematic to say the least:

1. First and foremost, it suffers from two "peeking into the future" errors:

A. You can't check for "High[bar]" and issue a BuyAtStop[bar]/ShortAtStop[bar]. It's simply impossible with regard to how Wealth-Lab operates. If you checked for a price on "bar", the stop/limit order should be for "bar+1".
B. You're checking for !IsLastPositionActive on the same bar for which you're triggering exits. (WealthScript Programming Guide > Programming Trading Strategies > Peeking > Trading based on Position Active Status).

[On the bright side, you're avoiding entries and exits using stop orders on the same bar with that "bar!=StopBar" because as you seem to know, one can't realistically backtest with stop/limit orders on the same bar.]

2. Defining a class-level variable (here: EntryPrice) sometimes becomes a recipe for disaster. Usually it's done unintentionally but has a big effect on how a Strategy operates. In such cases, the Strategy behavior might be different depending on whether you clicked "Execute" or "Go". Since storing EntryPrice is not something one'd want to keep between strategy executions, don't define a variable as class level unless you really intended to do it.

3. No entry alerts due to wide usage of "bar".

4. At the risk of something like existing trades disappearing in the beginning of the data range because indicator value suddenly changes, you can't use GetTradingLoopStartBar(58) with an 57-period EMA. The main loop should start at least on bar 57*3. For more, see the WealthScript Programming Guide > Indicators > Stability of Indicators.

5. NumberOfActivePositions is superfluous. Just call ActivePositions.Count instead.


What are its entry and exit rules in plain English? It may benefit from rewriting from scratch.
profile picture

Pablo4646

#5
In this case peeking in the future does not happen. I am familiar with such mistakes. Strategy is trial. We add to a position each time when High or low is updated. On each addition we put protective stop. We leave at once all position at low or high breakdown. Unfortunately as soon as works the first stop more position it is not added. Ex. Adding 1 2 3 part of position and getting stop. Full position have 5 parts. But after stop WLD can't make new addition.
profile picture

Eugene

#6
Sounds like you didn't review my point 1A too carefully. I leave the inflated results up to you but if you want me to take a stab at it, I need more clear and formal rules than what you outlined in post #5. It cries for a rewrite since the use of StopBar is not elegant and makes the code harder to read (than it should be).
profile picture

Pablo4646

#7
Yes you are right. I rewrote code and it is working. Thank you.
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).