Position Sizing Calculator for ThinkorSwim

korygill

korygill

Active member
VIP
Based on another thread, I reverse engineered what I think the two labels show.

This is the output of that work.



thinkScript Code

Code:
#
# PositionSizingCalculator
#
# Author: Kory Gill, @korygill
#
#

input RiskUnit = 100;
input AggregationPeriod = AggregationPeriod.FIFTEEN_MIN;

def highVal = high(period = AggregationPeriod);
def lowVal = low(period = AggregationPeriod);

AddLabel(
    yes,
    "High: " + highVal + " Low: " + lowVal,
    Color.Gray
    );

def diff = highVal-LowVal;

AddLabel(
    yes,
    AsDollars(RiskUnit) + " risk with " + AsDollars(diff) + " stop = " + Floor(Round(RiskUnit/diff)) + " shares",
    Color.Gray
    );

Link to the study

http://tos.mx/HwObLl

Thanks,
Kory Gill, @korygill
 
Last edited by a moderator:
G

GetRichOrDieTrying

Member
Is this a fully functioning position sizer? I'm not in front of my computer to test it.
 
G

GetRichOrDieTrying

Member
That's what the original thread was about. A position sizing tool.
 
G

GetRichOrDieTrying

Member
It appears to be that. Your code says PositionSizingCalculator
 
korygill

korygill

Active member
VIP
I don't see anywhere in there what it calculates. High and low over last X minutes? How much the stock can move for +/- $x.x.x in gain/loss? I just wrote code that seems to calculate what the first image showed. Define the rules, and we can write code to do that. Thanks.
 
R

rudy seena

New member
Hi, I copied and pasted in TOS but nothing happens? Any suggestions?
 
J

jdstrader

New member
Hello,

I've been looking for a very simple indicator that can divide my buying power with the price of the stock I'm looking at so it can show me the shares I need to buy quickly. For example, If I have $100k in buying power, I'd like to set up the indicator to divide $50k (I scale into positions) with the current price of the stock let's say $20 so it would show me I need to buy 2,500.
I've been doing this calculation manually every time but I make quick trades and sometimes these seconds I use for my calculations are very costly.

Does anyone know if an indicator like this exists? I haven't been able to find something on my own so far.

Thanks a lot!
 
S

soary

Member
@korygill Hi, I added this script to my 1 min chart and it shows the high and low as the same amount, 0.00 for the stop and the number of shares is incorrect. Other than the TF there are no other inputs. What am I missing? Also what is high and low? Is high the that limit target and low the stop loss?
 
P

Pensar

Member
@jdstrader Here is something I coded up, might do what you want.

Code:
#Simple_ScaleIn_Label
#Pensar, 6/10/2020

input max_size = 100000.00;
input scale_in = yes;
input times_to_scale_in = 4;

def Size = if !scale_in then (max_size / close) else
              (max_size / times_to_scale_in) / close;

AddLabel(1, (if scale_in then "Scale In: " else "") + "Buy " + RoundDown(Size, 0) + " shares" + (if scale_in then " " + times_to_scale_in + " times" else "") + "  ---  Total Trade Size: " + AsDollars(max_size), color.white);

#End code
 
R

rlohmeyer

New member
This is so elegant. I have used an Excel file I keep floating on my desktop for years. Since I trade 5 min, it worked OK when I didn't have access to NinjaTrader and the like. This is so much nicer.
 
Thread starter Similar threads Forum Replies Date
G Position Sizing Calculator for ThinkorSwim Questions 35
Zachc Position Sizing Questions 5
RmS59 Multiple entries into a position? Questions 2
G Arrow position on lower study Questions 5
A Profit & Loss on a Position Questions 0
Top