Hi -
I've loaded a strategy into the strategy monitor and it doesn't seem to detect when a position is active. Here's the sequence of events:
1). Debugging is enabled in VS2008.
2). The test strategy is loaded and activated in the Strategy Monitor
3). When control is passed to the dll, the logic can be stepped through in VS2008
4). A BuyAtMarket(bar+1,"test") is correctly issued to wealthlab pro v6.
5). The Buy order displays in the Alerts section of the Strategy Monitor
6). In the Alerts section of Strategy Monitor, the Buy Alert is highlighted and the Place Order button is clicked
7). The Order Window shows receipt of the Buy and the Order Window Status field changes to Filled
8). Subsequent iterations of the code test for IsLastPositionActive and the boolean always shows false. Additionally, the LastPostion is null at this point.
I'm missing something ... any insights would be appreciated.
Thanks.
PS The inability to detect an active position was also experienced when the strategy was loaded w/o VS2008.
Size:
Color:
Hi,
Can you show the strategy code, or at least the skeleton w/o your sensitive know-how?
Size:
Color:
Here's the code. Thanks Eugene.
CODE:
Please log in to see this code.
Size:
Color:
Well, sure. This script has no memory of any positions before the last bar of the chart. In other words, it's a screen, not a Strategy. The exit logic can never be executed.
Add the trading loop to fix it -
CODE:
Please log in to see this code.
Also, keep in mind that Strategy run theoretically only. This won't be a problem for a Market or Stop order Strategy, but it's possible not to be actually filled with a Limit order. See User Guide: Orders > Portfolio Synch > Theoretical vs. Actual
Size:
Color:
Hi Cone,
Thanks for update. As I'm sure you can see, I'm still wrestling with fundamental concepts ... maybe you could shed some light on current areas of confusion: (i.) what is the difference between a screener and a strategy - the example of a screener in the programming guide issues a BuyAtMarket, so I assumed that cognizance of the position would be maintained; (ii.) just looking at the for loop,which I have been using to backtest in strategies, it is not intuitive why IsLastPositionActive would work in either a screener or strategy scenario as it is not indexed when it is referenced.
If there are not simple answers here please point me to any readings that might help to clarify. Thanks again to both of you guys for taking the time to help me out.
Regards, Jay
Size:
Color:
For a screener, you're only looking at the last bar of the chart for a signal. Previous bars can be used to build indicators or whatever, but you're only interested in a signal on the last bar. Your code assigns nBar to the last bar of the chart Bars.Count - 1, and that's the only bar processed.
Compare that to my edit with the loop, which will process all bars in chart starting with bar #1. It buys, sells, buys, sells. There's a history of trading. That's Strategy processing.
See the WealthScript Programming Guide (Help menu): Programming Trading Strategies
Size:
Color:
So when running a screener, if cognizance of a prior Buy is required, it must be persisted externally, IE saving the Alerts to a file. I think I got it. Thanks.
Size:
Color:
You could do it that way, or, you could simply run the Strategy. You'll get all of the Alerts, Buy and Sell that way.
Generally, a screener is used just to generate a list of potential candidates - to work with only a subset of the entire DataSet. Buy you shouldn't use a screener if you have the buy and sell logic - just run the Strategy for all Alerts!
Size:
Color: