Hi to all.
For some of my strategies, I need to close a long position size N and open a short position size M in one bar. Does SetPositionSize () allow to set a different position size in one bar?
Hi to all.
For some of my strategies, I need to close a long position size N and open a short position size M in one bar. Does SetPositionSize () allow to set a different position size in one bar?
The SetPositionSize()
function only specifies the size of positions that are opened. When you exit a position, it closes the entire position no matter what size it is.
Thank you for your replay! Сan you advise something for the realization of my task?
Assuming you have set N and M to your desired position sizes for long and short trades, and that your Buy and Short arrays have already been assigned, you can just do something like this:
SetPositionSize(IIf(Buy,N,M), spsValue);
Thx, it works. I tried another method - SetPositionSize(IIf(Buy OR Sell , N, M), spsShares) - it does not work.
As I said in my first post, you don't need to set the position size when you exit (Sell or Cover). And in your case, you have an exit (Sell) on the same bar as an entry (Short), so the logic you were using would not work.
Also, if a post has solved your question you should mark it as the Solution so others can easily find it as well.