Round shares down to nearest whole number


Category:
0
0

I am doing  a calculation risk amount base on a Inside Bar

For example if the risk  is PRevHigh-PrevLow

then If I want to no loose more thank 50 dollars for example

I divide 50/risk  then it gives me the total shares I need to buy.

I would like to round for example if the risk is 19 cents.  So when it divides 50/.19 = 263.15 Those are the shares  But since I cannot buy 263.15 I want it to round to 263. How can i do that? I tried rounddown it shows the same.

the code is :

def risk=50;

def riskAmount = PrevHigh – PrevLow;
AddLabel(yes, ” | PrevHigh: ” +
AsDollars(PrevHigh) + ” | PrevLow: ” + AsDollars(PrevLow), Color.YELLOW);
AddLabel(yes, “Risk: ” + riskAmount + ” Shares: ” + (Rounddown(risk / riskAmount) ), Color.WHITE);

thanks

Marked as spam
Posted by (Questions: 4, Answers: 1)
Asked on June 20, 2021 9:54 am
51 views
0
Private answer

I had to update the title of your question to include a full description of your request. This is very important to ensure other viewers searching for a similar solution will be able to quickly locate this post using the search function of the forum. I also had to move this out of the "Frequently Asked Questions" topic and into the "Chart Studies" topic since your request includes a chart study as it's solution.

You are missing only one detail in your attempt to solve this. Here is the link to the language reference for the RoundDown() function on Thinkorswim:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/RoundDown

Go ahead and read those details and you should very quickly identify the one small piece you forgot to include in your attempted solution.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on June 20, 2021 1:17 pm