Contract / Position management by IG
Forums › ProRealTime English forum › ProOrder support › Contract / Position management by IG
- This topic has 24 replies, 4 voices, and was last updated 3 years ago by
PeterSt.
-
-
05/20/2022 at 6:50 PM #19353405/20/2022 at 7:27 PM #19353505/20/2022 at 9:07 PM #193544
If, for example, you had max possize set at 6 then you may only be able to buy / sellshort possize 3 if using a strategy that reverses a Long straight into a Short.
So you expected to Sellshort 6 but you only got 3 … hence you were downsized.
05/20/2022 at 9:24 PM #193545I don’t think it works that way, closing a Long position (something you own) is different from selling (SellShort) a position (something you don’t own).
I think the order is:
- Closing your Long position
- Selling a (short) position
I think that when your maximum position size is 6 you can actually be 6 contracts Long or Short.
05/20/2022 at 9:31 PM #19354605/20/2022 at 10:32 PM #193547In a ‘reverse direction’ strategy above must be executed in a few milliseconds and so data may get screwed up (at times) and result in a downsizing maybe.
We are scraping the barrel for reasons, but would be worth, as a trial, doubling your max position size if indeed the strategy you are having trouble with is a reverse direction?
Feel free to post your code as somebody may spot some anomaly you are missing.
A few of us have had odd things happen recently re possize … excess positions have been executed. I had an excess of 10 and made £15K ish and PeterSt and Nonetheless had excesses and made losses … all ours were on our Demo Accounts! 🙁
05/20/2022 at 10:45 PM #19354805/21/2022 at 4:08 AM #193549I don’t think it has to do with margin but more to do with an algo of IG…
Just saying : Manually it works exactly the same although with IG you can’t do that (not the last time I looked into that). With IB you can invert the position where it is totally clear that you do a transaction of 280000 (20 x Nasdaq), be that from Long to Short or from Short to Long. And if you have 140000 in open position that totals to 420000.
Notice that in this example of inversion the broker checks this in advance of the transaction (logically) which is also exactly why it does not work out. Without sufficient margin for the whole lot in total (420K) the order is rejected. Do it in two steps and it works. But then it works even differently because it is then seen as a cancellation of a position and that always works (unless shares are not available like it easily can happen with Shorts).There is an other situation but this is very hidden (not in order here); IIRC with IBEX (Spanish Future) there is a limit on the transaction of 5. Try 6 or more and the order is rejected. Do it in two steps and it works. I could have a 100 if I wanted, but I’d have to do it in 20 steps. And big fun : once you have say 10, you can’t sell 10. It has to be done in 2x 5 (you try to cross away the position but internally it is an order of sell 10).
In all these situations that I know of, the order is rejected in full. Thus no partial execution. And regarding this, you, JS, may wonder whether a few contracts were rejected or that those few were taken out for existing position after they have been there (for again a few ms). You would not be able to see the difference, but internally it will show and can be sorted out. In any event, a position can and will be closed partially if that helps regarding sustaining the margin. And would this have happened then it is still so that for this very brief time you would have had 420000 instead of the expected 140000. And regarding this, do notice that the broker does not know of the sequence in your code of selling 10 and next buying 20 (or vise versa). For you it would logically be to first sell the 10 but ProRealTime just hands orders of plus 20 and minus 10. You can again see this not-so-smartness by manually inverting where it now is PRT being not smart because it could net it in advance. But it just doesn’t.
FYI and background : I am not sure whether you can see that with IG, but with IB you can easily see that PRT knows of your margin (yellow triangles may pop up); it tracks it and it even uses it. BUT it lags and nobody could ever tell me when it is updated (it seems like 5 minute-ish). If you gain a lot (and I mean a LOT) per time unit then you can see that you can’t trade because you first need to wait until PRT has updated that margin remaining value. Think like the portfolio added 10K = 200000 more headroom, but you wouldn’t be able to trade even 5K because that margin value was not updated yet. And when it is finally updated, it is 200000 margin space behind again.
… But I am fairly sure that this can only happen with manual trading because only then PRT can track these things (again, I am not so sure this can be done with IG) because it can add all up from its own charts and positions from your running desktop instance. On the autotrading server side this is all unknown. That is only a dumn executing machine, running your code.
Last thing : just give this to PRT to sort out; they have a data department and the people in that department are explicitly there to sort out these things; they like to do it as it is their job. Next “we” (at least me) like to learn from it so we can be ahead of such anomalies the next time. Thus, if my code would suddenly be running 3 positions instead of the expected 10, many things would go wrong, I’m sure.
05/31/2022 at 9:14 PM #194357It happened again, far too few contracts were opened.
I now also understand what is happening.
In my code I go from Long to Short in 1 time and vice versa:
If Cond1 > x then
Buy x contracts at Market
EndIf
If Cond2 < y then
SellShort y contracts at Market
EndIf
As a result, the StrategyProfit is not/later updated (it is above the conditions).
The solution for me is to do the whole thing in multiple steps (as already indicated by PeterSt)
So first close the position with Sell or ExitShort and only then Buy or SellShort.
It works well now.
1 user thanked author for this post.
06/01/2022 at 2:18 AM #194360As a result, the StrategyProfit is not/later updated (it is above the conditions).
You will only see it updated in the next bar / next call of your code. 🙂
This is because the execution of the order(s) only happen (if not rejected etc.) after the current call of your code is finished.****): When your bars are e.g. 1 minute long, then this is after 1 minute of you in the code giving the order(s) – this is not even easy for me to wrap my head around and maybe this is incorrect. Pressing “Submit” to this post after 10 minutes of sitting back. 🙂
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on