mattastic1
New member
Hey everyone,
I’m looking for some help creating a Thinkscript that can calculate the number of contracts I should trade based on my account size, risk percentage, and stop-loss distance.
Here’s what I’m trying to do:
• Input my account size (manually updated daily is fine).
• Use a fixed risk percentage (e.g., 1% of my account).
• Automatically calculate the number of contracts based on the entry price and stop-loss distance. (On the contracts chart on thinkorswim if this label could show up so the # of contracts adjusts automatically based on current price)
• And then Display the result as a label on the chart (e.g., “Contracts to Trade: X”).
Right now, I manually calculate this on google sheets for every trade and sometimes that is where emotionally I break a rule “since I didn’t update the latest price let’s say from $1.30 to $1.10 for example (my current stop loss is based on a 20% Stop Loss upon entry) so if that same percentage stop loss method can be used on the CHART WINDOW AS A LABEL… and dynamic price I feel like it will be a huge help for me or anyone who needs that disciplined entry!! ,
I’m assuming someone has automated it. Is it possible to also pull the entry price or stop-loss from the chart or current market data to make it more dynamic?
Any ideas or examples to get started? Thanks in advance!
This is what the code somewhat could be like:
Thinkscript Code
# Input parameters
input AccountSize = 10000; # Set your account size (update daily if needed)
input RiskPercent = 1.0; # Set your risk percentage per trade (e.g., 1%)
input EntryPrice = 1.20; # Adjust to your planned entry price
input StopLossPrice = (20% of the current price) # Adjust to your planned stop-loss price
# Calculations
def DollarRisk = AccountSize * (RiskPercent / 100);
def StopLossDistance = EntryPrice - StopLossPrice;
def Contracts = if StopLossDistance > 0 then Round(DollarRisk / (StopLossDistance * 100), 0) else Double.NaN;
# Display labels
AddLabel(yes, "Contracts to Trade: " + Contracts, Color.GREEN);
AddLabel(yes, "Risk per Trade: $" + AsDollars(DollarRisk), Color.CYAN);
AddLabel(yes, "Stop-Loss Distance: " + StopLossDistance, Color.YELLOW);
Something like that…
I’m looking for some help creating a Thinkscript that can calculate the number of contracts I should trade based on my account size, risk percentage, and stop-loss distance.
Here’s what I’m trying to do:
• Input my account size (manually updated daily is fine).
• Use a fixed risk percentage (e.g., 1% of my account).
• Automatically calculate the number of contracts based on the entry price and stop-loss distance. (On the contracts chart on thinkorswim if this label could show up so the # of contracts adjusts automatically based on current price)
• And then Display the result as a label on the chart (e.g., “Contracts to Trade: X”).
Right now, I manually calculate this on google sheets for every trade and sometimes that is where emotionally I break a rule “since I didn’t update the latest price let’s say from $1.30 to $1.10 for example (my current stop loss is based on a 20% Stop Loss upon entry) so if that same percentage stop loss method can be used on the CHART WINDOW AS A LABEL… and dynamic price I feel like it will be a huge help for me or anyone who needs that disciplined entry!! ,
I’m assuming someone has automated it. Is it possible to also pull the entry price or stop-loss from the chart or current market data to make it more dynamic?
Any ideas or examples to get started? Thanks in advance!
This is what the code somewhat could be like:
Thinkscript Code
# Input parameters
input AccountSize = 10000; # Set your account size (update daily if needed)
input RiskPercent = 1.0; # Set your risk percentage per trade (e.g., 1%)
input EntryPrice = 1.20; # Adjust to your planned entry price
input StopLossPrice = (20% of the current price) # Adjust to your planned stop-loss price
# Calculations
def DollarRisk = AccountSize * (RiskPercent / 100);
def StopLossDistance = EntryPrice - StopLossPrice;
def Contracts = if StopLossDistance > 0 then Round(DollarRisk / (StopLossDistance * 100), 0) else Double.NaN;
# Display labels
AddLabel(yes, "Contracts to Trade: " + Contracts, Color.GREEN);
AddLabel(yes, "Risk per Trade: $" + AsDollars(DollarRisk), Color.CYAN);
AddLabel(yes, "Stop-Loss Distance: " + StopLossDistance, Color.YELLOW);
Something like that…