tradingcat Posted February 16, 2023 Report Share Posted February 16, 2023 (edited) Hi, I've got a buy at market hotkey which helps me automatically work out position size based on how much I want to risk, ask price, and stop loss price. I have it set up as per image below (It's set to risk $30 per trade). I'm now trying to incorporate a way to have a cap on the maximum position size, at say $10,000. How would I put that into the formula? Tried searching through help & forums on how to do this but couldn't figure it out. Edited February 16, 2023 by tradingcat typo Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted February 16, 2023 Report Share Posted February 16, 2023 When you say maximum position size, you mean you don't want to add more to existing position if it is $10K? Quote Link to comment Share on other sites More sharing options...
tradingcat Posted February 17, 2023 Author Report Share Posted February 17, 2023 Sorry I wasn't very clear. I mean just for this one trade. So if I already have $15k of this position, I don't mind buying more. just that I want this specific trade capped at a specific amount. Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted February 17, 2023 Report Share Posted February 17, 2023 well.. you have Qty as 30/(Ask-PriceAtMouse). Should really be floor(30/(Ask-PriceAtMouse)) - because quantity is an integer. So then the total amount of the transaction would be (since it is a Market Buy, let's assume it is at Ask) Ask * floor(30/(Ask-PriceAtMouse)) You don't want that to be more than $10k, so that amount would be Min(10000, Ask * floor(30/(Ask-PriceAtMouse))) Thus the appropriate quantity should be that amount divided by Ask (and floor taken for it so that it is integer) floor(Min(10000, Ask * floor(30/(Ask-PriceAtMouse))) / Ask) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.