Phil
New member
I love the TradingView position tool and have always wanted something similar built into Thinkorswim. I finally decided to attempt to create my own tool based on ATR. All you have to do is enter your position and choose short or long. You can set the ATR period, multiplier for stop loss, and multiplier for take profit. I looked for something on this forum but I had no real luck.
Don't know if anyone will find it useful but I use it for every trade so I thought I would share it. Let me know if it's as useful to you as it is to me.
Don't know if anyone will find it useful but I use it for every trade so I thought I would share it. Let me know if it's as useful to you as it is to me.
Rich (BB code):
# Position Tool Proxy with ATR Multipliers for Thinkorswim
input PositionType = {default Long, Short};
input EntryPrice = 0.0; # Base entry price
input ATRPeriod = 14; # ATR period (default 14)
input StopLossATRMultiplier = 1.5; # Stop loss as multiple of ATR (e.g., 1.5x)
input TakeProfitATRMultiplier = 2.0; # Take profit as multiple of ATR (e.g., 2.0x)
input ShowLabels = yes;
# Calculate ATR
def ATR = Average(TrueRange(high, close, low), ATRPeriod);
# Calculate Stop and Profit Prices based on ATR and Position Type
def StopLossPrice = if PositionType == PositionType.Long
then EntryPrice - (ATR * StopLossATRMultiplier)
else EntryPrice + (ATR * StopLossATRMultiplier);
def TakeProfitPrice = if PositionType == PositionType.Long
then EntryPrice + (ATR * TakeProfitATRMultiplier)
else EntryPrice - (ATR * TakeProfitATRMultiplier);
# Plot the lines
plot EntryLine = if EntryPrice > 0 then EntryPrice else Double.NaN;
plot StopLine = if StopLossPrice > 0 then StopLossPrice else Double.NaN;
plot ProfitLine = if TakeProfitPrice > 0 then TakeProfitPrice else Double.NaN;
AddCloud(EntryLine, StopLine, Color.light_red, Color.light_red);
AddCloud(EntryLine, ProfitLine, Color.light_green, Color.light_green);
# Styling
EntryLine.SetDefaultColor(Color.YELLOW);
EntryLine.SetLineWeight(2);
EntryLine.SetStyle(Curve.FIRM);
StopLine.SetDefaultColor(Color.RED);
StopLine.SetLineWeight(2);
StopLine.SetStyle(Curve.FIRM);
ProfitLine.SetDefaultColor(Color.GREEN);
ProfitLine.SetLineWeight(2);
ProfitLine.SetStyle(Curve.FIRM);
# Labels
AddLabel(ShowLabels and EntryPrice > 0, "Entry: " + EntryPrice, Color.YELLOW);
AddLabel(ShowLabels and StopLossPrice > 0, "Stop: " + Round(StopLossPrice, 2), Color.RED);
AddLabel(ShowLabels and TakeProfitPrice > 0, "Profit: " + Round(TakeProfitPrice, 2), Color.GREEN);
AddLabel(ShowLabels, "ATR: " + Round(ATR, 2), Color.GRAY);
# Risk-Reward
def Risk = if PositionType == PositionType.Long then EntryPrice - StopLossPrice else StopLossPrice - EntryPrice;
def Reward = if PositionType == PositionType.Long then TakeProfitPrice - EntryPrice else EntryPrice - TakeProfitPrice;
def RRRatio = if Risk != 0 then Round(Reward / Risk, 2) else Double.NaN;
AddLabel(ShowLabels and Risk > 0 and Reward > 0, "R:R = " + RRRatio, Color.WHITE);