Thanks for these hotkeys Kyle, they are awesome! Something I have realized is that when a symbol is restricted by IB to not allow using margin (like shown in the screen shot where it says long margin rate is 100% - that means you cannot use margin), then DAS trader calculates my buying power as only my cash balance because for that symbol, that's all it truly is, I don't get margin. Then when I use the dynamic hot key to risk a % of my balance, I end up only getting 1/4th of the amount of shares I would expect. I spent the better portion of today digesting the code in the dynamic hotkeys to try to figure out what's happening and I finally get it! (It was quite an achievement LOL!) I just don't know how to fix my problem here. Actually, I think it probably cannot be fixed, but before I give up, I wanted to pose the question to the community and see if there is something I am missing or if somebody might be able to come up with a very creative solution which I have not thought of yet.
So the script compares the total amount of shares you can afford based on buying power to the total shares you can buy based on your selected stop price and how much you want to risk losing if the trade goes against you, then sends a buy order to market for the lesser of these two amount of shares (genius script Kyle! Took me a whole day's effort just to understand it LOL!). The problem I am having is when DAS sees my buying power as $30K instead of $120K because of the limitation as shown in the screen shot attached (IB does not allow margin, only cash on certain symbols on certain days), then the first part of the equation (shares based on BP) calculates fine, but the second part (amount based on desired risk level) gets incorrectly limited to 1/4th of what it should be and the shares that get sent is this lower amount. This is because of the part of the equation where it says, "Share=DefShare*0.25*Price*0.01" (assuming I want to risk 1% of my portfolio balance), comes up with a much lower number than it should since DefShare was just set to "BP*.97" in the previous line of code and now it's being divided in a quarter again and in this instance BP was only $30K (normally it is $120K) which was equal to my cash balance, not my cash balance times 4. In essence, in this particular scenario, the script should not multiply DefShare*0.25, that is where it goes wrong and this is why I end up only buying 1/4 of the amount of shares I should have gotten. But in all other normal cases, i.e. when margin is allowed by IB, it has to multiply DefShare*0.25 or you would be getting 4x the amount you want, which would be really bad.
I do not think there is a way to fix this automatically. I think the only options are to either have two sets of hotkeys, one where it doesn't cut DefShare in 1/4 and another where it does. Then I would just have to be sure and use the right set of hotkeys depending on if margin is allowed or not. Or, the other alternative would be to not use the % of risk hotkey at all, but rather go to the fixed dollar risk hotkey and just update the amounts to manually calculate the % of my portfolio balance as my account balance changes.
Is there any other way around this that I might be missing? Is there a way to continue using the % of risk hotkey and somehow have it not cut my shares in 1/4 size when the symbol is limited to cash only but I still have enough buying power?
To be clear, I am not talking about a situation where I do not have enough buying power. Let me put some numbers to this to illustrate:
I want to risk 1% of my portfolio balance when buying a stock that is selling for $20 with a stop loss of $19.80, with all the cushions and what not in place, that would get me 1,372 shares which would cost $27,437, so I have enough cash to buy it. But the hotkey only gets me 1/4 of 1,372 shares, or 343 because of the equation "Share=DefShare*0.25*Price*0.01" which in this instance = $72. $72 is then used as the risk based loss (instead of 4x that amount which would be $288) and at a loss of $0.21/share I can only buy 343 shares in order to lose $72. It then compares the calculated 343 shares to the max shares I can afford, which would be 1,455 and sends the lesser of the two, 343 shares when what I really wanted to buy was 1,372 shares which would have risked $288 (0.21 X 1,372 = 288).