Hi Eugene,
I would like to know if there is a way to get the buy and hold curve in a strategy script ? The idea is to interact with it like what we can do with the equity curve.
Size:
Color:
Hi Alexandre,
Yes, it's possible. In the
KB article you could've noticed these lines:
CODE:
Please log in to see this code.
According to an API document found here:
SystemPerformance, it exposes four
SystemResults properties: Results, ResultsLong, ResultsShort and ResultsBuyHold. Check it out for more information, but for now replace the
Results with
ResultsBuyHold where applicable:
CODE:
Please log in to see this code.
Size:
Color:
Thank you Eugene. That's perfect !
Now, what I want to do is to stop to trade and close open positions if the buy and hold curve drops by 3%. According to the KB article, I have to change the code here :
CODE:
Please log in to see this code.
by the new condition here :
CODE:
Please log in to see this code.
Right ? If yes, how can I close position if there are ?
After that, I would like to take a new position if the curve goes up by 2%. How can i do that ?
Size:
Color:
QUOTE:
Right ? If yes, how can I close position if there are ?
No, this snippet controls the entries. It's here where you install the opposite condition i.e. "the curve goes up by 2%":
CODE:
Please log in to see this code.
Entries are processed before exits in this code template.
To close out open positions if the B&H curve drops by 3%, you take the loop by active positions below and, after having obtained the reference to a position...
CODE:
Please log in to see this code.
...wrap the exit routine with your condition:
CODE:
Please log in to see this code.
Size:
Color:
Thank you Eugene.
Size:
Color:
QUOTE:
To close out open positions if the B&H curve drops by 3%, you take the loop by active positions below and, after having obtained the reference to a position...
If that's your
only exit rule, no need in a loop - just use ExitAt... with
Position.AllPositions instead of the active position (
ap).
Size:
Color:
This replicates the WLP Buy Hold equity in any strategy for any symbol. Use of the Margin Factor is optional. Sizing the trade at bar 1 open is optional as WL sizes at bar zero close.
CODE:
Please log in to see this code.
Size:
Color:
Kevin, thanks for sharing. At first glance, here's a couple of improvement suggestions:
1. This equation trick makes the "sizeTime" an optional param (and introduces "divItem" as the param for dividend FundamentalDataSeries) - see #3 below:
CODE:
Please log in to see this code.
2. If OP (a WLD user) were to use your code it'd fail for him since the "dividend" fundamental item is available only in WLP. For WLD users I propose to specify the item explicitly, and to fall back on "dividend" if it's empty, thus assuming WLP:
CODE:
Please log in to see this code.
3. Now you don't need to pass an empty string since this param is made optional in #1:
CODE:
Please log in to see this code.
Size:
Color:
That makes it good for all users. I implemented as:
CODE:
Please log in to see this code.
Otherwise
CODE:
Please log in to see this code.
defaults to no dividend. The "close" has no effect but to clarify the time used.
Do note that the WLP editor says that "Default parameter specifiers are not permitted". Is there some concern there?
Size:
Color:
QUOTE:
Do note that the WLP editor says that "Default parameter specifiers are not permitted". Is there some concern there?
Since it works it's not a concern. The warning message can have something to deal with the Editor (an external component) being outdated.
Size:
Color:
As revised for all users;
CODE:
Please log in to see this code.
Size:
Color: