Account Percent Risk Position Size Calculator


Category:
0
0

Possible to get some help on my Position Size Script getting an error at def currentPrice.  There may be more issues I’m not aware of I’m very green at this!  Code:

# Position Size Calculator based on max % account risk with variable position riskPercent %.
declare upper;

# Input max percentage of a portfolio that one stock should be
input Max_Percent = 0.50;
input price = close;

def netliq = GetNetLiq();

### Risk of Portfolio

def twoperc = netliq * (Max_Percent / 100);
AddLabel(yes, Max_Percent + “% Act Risk: ” + AsDollars(twoperc), Color.CYAN);

# Input position risk
input RiskPercent = .05 ;

# Position Size
def currentPrice = priceType.LAST;
def dollarRisk = (currentPrice * RiskPercent);
def stopPrice = (currentPrice – dollarRisk);
def SHAREStoBUY = twoperc / (currentPrice – stopPrice);

input showlabel = yes;
AddLabel (yes, ” POS ” + SHAREStoBUY, Color.CYAN);

RESOLVED
Marked as spam
Posted by (Questions: 2, Answers: 3)
Asked on June 20, 2021 1:39 pm
380 views
0
Private answer

This is not the correct way to reference the current price:

def currentPrice = priceType.LAST

Current price in Thinkscript is always going to be "close":

def currentPrice = close;

In addition to that, it is not the correct way to use "PriceType.LAST". Details here showing the proper use of the "PriceType.LAST" constant:

https://toslc.thinkorswim.com/center/reference/thinkScript/Constants/PriceType/PriceType-LAST

But like I said, it is NOT the correct metric to use to read the current price. In Thinkscript, the most current price is ALWAYS found by using the "close", all by itself.

 

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 20, 2021 3:09 pm
0
Pete wondering if you could help me with this code once again. I added target plotted lines on the chart. The problem is they are plotting current trade averages and prior averages for trades I havent been in in quiet some time. Also added a predetermined stop loss for trades I have not entered yet in order to see my risk real time at the current price. This plots under all candles displayed on the chart. Idk why. Lastly I’m having trouble extending these target plots right. Any help will be greatly appreciated. Below is the code:: http://tos.mx/jqvxOsc
( at September 1, 2021 3:09 pm)
0
There is no way I can debug and correct this code in the brief 15 minutes I allocate toward each free solution I provide in the Q&A Forum.
( at September 1, 2021 5:49 pm)
0
I would still like to work with you on this Pete if you have time. Maybe follow up via email.
( at September 7, 2021 7:36 am)
0
I edited your comment to remove the email. One thing you never want to do is to post your email address in a public forum. There are bots that crawl websites constantly looking for email addresses. You will get massive spam or worse. If you would like to pursue a professional solution for this request you can find all the details on the following webpage: https://www.hahn-tech.com/about/
( at September 7, 2021 7:50 am)