Jump to content
Medved Trader Forums

Help with formula for setting a maximum dollar value for order quantity


tradingcat

Recommended Posts

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.

 

image.png.55b6b179bf961d635bd38b4a378d4add.png

Edited by tradingcat
typo
Link to comment
Share on other sites

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)


 



 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...