I have a strategy that I'm backtesting & live testing but it keeps buying more than one position. In my code have the following for the only buy portion of the code:
CODE:
Please log in to see this code.
But still, during paper trading and live trading, WL opens multiple positions (buys) for the same stock for the strategy. How can I restrict the strategy so it only buys if there are no other positions open for the strategy ? Thanks
Size:
Color:
It won't be possible to program Portfolio-level rules like that until PosSizer become available in 5.6 late this year.
Hold on, you said "(buys) for the same stock for the strategy". If that's the case, then your Strategy code is the problem. (My comment about Portfolio-level rules pertain to only holding 1 open position at a time for the entire portfolio.)
Size:
Color:
Hmm, I dont understand what I could be doing wrong, considering that I only have one place where I place a buy, and its only if the active positions == 0
Size:
Color:
I'm confident we could explain it if you were to post the entire script.
Size:
Color:
Cone,
Can you send a short example of how to restrict a strategy to buying only if there are no other positions open ?
I'm following how the WealthLab QuickRef guide under "Position Management" > "Active Positions" , which restricts the total number of positions example. I only have one place where I buy and its wrapped in the if statement above.
This is the last thing holding me up from trading, as I cant trade until this is resolved because it will keep opening positions. Thanks in advance.
Edit: I edited the only buy portion of the code so it prints out the total active positions and it still reports them as being zero.
CODE:
Please log in to see this code.
I then saved and compiled the strategy and ran the strategy in the strategy monitor against a Paper account 15 min ago. It still buys multiple times (while previous positions are open) and prints out every time for the signal:
"ActivePositions: 0 ; ActiveCount: 0"
Size:
Color:
Sorry, but I can't tell where the mistake is without seeing all of the code.
Maybe we're still talking about 2 different things? Based on what you're telling me, if you click one symbol, there's no way for the logic to enter simultaneous multiple Positions for the same symbol, but it is? So, either there's a bug in WLP or it's in your code, and it's just more efficient for me to debug your code since I don't see the problem with any other strategy I've ever run (and I've been at this a while).
Size:
Color:
Cone,
I think you are correct, as I have created a new barebone strategy that blindly buys and sells with the only BuyAtMarket() being wrapped around the if logic above, and running the strategies against my paper account during live trading results in only one position being opened at once.
I'm not sure how my other strategy is causing WL to allow multiple buys for the same position, but I will continue to look into it.
Size:
Color: