BuyAtLimit is not triggering in SM (Trade-Ideas)
Author: Frank1972
Creation Date: 12/15/2016 3:30 PM
profile picture

Frank1972

#1
Hi,

I have created a script, put it into strategy monitor and configured it to use SPY on a 1 minute basis. The script will never take a trade for SPY but will use SetContext to switch to a different symbol and try and enter into the trade for that symbol. After SetContext and a BuyAtLimit, RestoreContext is called.

When I run this the BuyAtLimit is never triggered resulting in an position that is in the ActivePositions. On a long entry (BuyAtLimit) I can see that the stock price drops below the limit price yet the position is never created and put into the ActivePositions.

The code that I use for this shown below:
CODE:
Please log in to see this code.


I must be doing something wrong but can't see or understand why my code doesn't result in an actual position.

Thanks,

-Frank
profile picture

Cone

#2
If you can't see the problem with all of your code, it's not likely we can see the problem with only part of it ;)

In short, it's not enough code to determine what's wrong. There are undefined variables and objects, etc.

Edit:
Although, if you're running it on SPY, and want to trade SPY, why would you use SetContext() to another symbol?
profile picture

Frank1972

#3
Cone,

Thanks for the quick reply. First let me describe what the code is doing so that it will make some sense when you read it. I am using an external trading source, TradeIdeas, to generate entries and exits. I do not know what symbol they are going to recommend so I have to use SetContext when I get the entry order. I have a TCP server running in the script that Trade-Ideas will connect to and send orders to. I have verified that the connection works and entry and exit orders are coming in.
CODE:
Please log in to see this code.
profile picture

Frank1972

#4
Cone,

If you need to see this running I have another application that can be used to test this code. Let me know if you need that.

Thanks again for you time and help.

-Frank
profile picture

Eugene

#5
Frank, does the strategy work as intended in the Strategy window?
profile picture

Frank1972

#6
Eugene,

I have never seen a BuyAtLimit or ShortAtLimit result in an ActivePosition in the Strategy window or the Strategy Monitor.

Thanks again for helping me out with this.

-Frank
profile picture

Eugene

#7
Frank, your strategy code is pretty complex in its present state. It would be optimal if you could make it more manageable. To avoid troubleshooting your TCP listener we need to focus on the WealthScript part of the code. I'd suggest to simplify the code and replace the TCP and logging parts with some dummy code.
profile picture

Cone

#8
It looks like you're trying to load historical trades based on an input file.

If so, where do you synchronize bar with the trade time in the input file?

If not, what is this supposed to do?
profile picture

Frank1972

#9
Eugene and Cone,

Thank you for looking into this issue. As it turns out my strategy is working I wasn't understanding how the Strategy Monitor works. I went and re-read that section in the User's Guide and things make sense now. Sorry to have troubled you.

Thanks again,

-Frank
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).