I have created my own possizer and using tag to specify the size of position each time I enter, but I found that it is fine in strategy testing and trade details, but when i checked it on the alert, i could only find all buy alerts in zero quantity.
strategy code:
CODE:
Please log in to see this code.
Possizer:
CODE:
Please log in to see this code.
Size:
Color:
Size:
Color:
I read it before, but i don't understand what it mean, does it mean i have no hope to get my quantity in alerts for next day buy before market opening?
QUOTE:
How to pass a value from Strategy to PosSizer for Alert sizing?
Problem:
You're using currentPos.Tag to size positions in a PosSizer which works only if currentPos is not null i.e. not for Alerts.
Size:
Color:
Additionally, in some scenarios Convert.ToDouble(currentPos.Tag) may generate a FormatException when you inadvertently pass an integer number to it e.g. LastPosition.Tag = 2 while a double value is expected. This may require special handling (for instance, by wrapping in a try/catch block).
Size:
Color:
QUOTE:
I read it before, but i don't understand what it mean,
It means that when
currentPos == null, Wealth-Lab is sizing an Alert, so the Position does not exist yet. Therefore you can't consume its properties (including the .Tag property), so the usage of Position.Tag in this particular case is inappropriate and you should achieve the same goal by using Bars.Tag (when sizing an Alert). And when
currentPos != null (sizing the backtest trades), you can continue using your existing Position.Tag logic.
Please
carefully read that FAQ answer to its end, and follow the external source that it suggests to review (the QuickRef), and you'll find the complete solution:
QUOTE:
For a complete code snippet, refer to the Bars.Tag example in the Wealth-Lab QuickRef.
Size:
Color:
First, Eugene, thanks for your patience and guidance towards the Bars.Tag example.
I got your meaning if I am correct, you means I have to write 2 separate codes, one for backtest, another for getting daily alerts, right?
I have changed my code like this
CODE:
Please log in to see this code.
however, it still gives me buy alerts with quantity in zero.
Size:
Color:
QUOTE:
however, it still gives me buy alerts with quantity in zero.
Of course, because you still have to teach your PosSizer to recognize the
Bars.Tag. The changes are required to both your Strategy and the PosSizer, just as you will find explained above.
In PosSizer (pseudocode):
CODE:
Please log in to see this code.
Size:
Color:
According to your code, I have rewritten my own, but still can't do so.
Backtesting is fine, but not for alerts
Code for backtesting:In strategy code:
CODE:
Please log in to see this code.
In PosSizer:
CODE:
Please log in to see this code.
Code for alert:In strategy code:
CODE:
Please log in to see this code.
In PosSizer:
Same as above
is there anything I missed? Thanks in advance.
Size:
Color:
What does the Visual Studio debugger show?
Have you already stepped through the executing code?
Size:
Color:
For me it works correctly.
Size:
Color:
Yeah, it works correctly now, thanks for your help!
Size:
Color:
however, it won't have any sell alerts as it never actually buy in and so no holdings for sell alert to generate out.
Size:
Color:
That's different question. For example?
Size:
Color:
because my code for generating the alerts are using the technique like the following
CODE:
Please log in to see this code.
it doesn't actually make any entry in the testing, but buy alerts. Since no holding in my portfolio, it will not trigger any sell signal (alerts) in the "alert" tab. I am now using my backtesting code to generate the sell signal instead.
However, another problem comes out, that is my strategy is single trade for each symbol, without any holding records in the portfolio, it will generate another buy signal once the criteria meets but in fact i might already have this symbol bought. It is still ok for me if not too much alerts giving out, only see if there is any advice for this issue.
Thanks~
Size:
Color:
In fact, there's no need to modify the entry logic anyhow. Just assign a value to both Bars.Tag and Position.Tag at the same time and make the decision in the PosSizer in a try/catch block (just as you're already doing).
Size:
Color: