Close positions on different bars in a MP Strategy
Author: algotradingwl
Creation Date: 3/31/2016 11:51 AM
profile picture

algotradingwl

#1
I modified the code from sp to mp strategy. Multiple positions are opened on different bars for the same conditions, as intended. But multiple positions are closed on one bar (exit name only Sell2 and Cover2), should have a different. Can you tell me plz what is wrong?
CODE:
Please log in to see this code.
profile picture

Eugene

#2
QUOTE:
But multiple positions are closed on one bar (exit name only Sell2 and Cover2), should have a different.

No, they shouldn't. The logic behind your exit conditions is the same to close the first/subsequent trades. That's why they're being exited on the same bar.

Another observation. You query the entry signal for the last created Position irrespective of its PositionType and assign the "signal" variable:
CODE:
Please log in to see this code.


But then you start operating the current active Position like this:
CODE:
Please log in to see this code.


So if your last Position to be created was e.g. "Short2" and you're processing the first long Position in the loop, you exit it if the exit condition is true. That looks like an inadvertent logic error. Are you sure you didn't intend to code it like below?
CODE:
Please log in to see this code.
profile picture

algotradingwl

#3
This is exactly what I need !
Thank you very much Eugene!
The code is executed as it should!
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).