Entries and Target For ThinkOrSwim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Should get you close. Will have to set your levels based on your trading style.

Ruby:
input TakeProfitPct = 15;
input TakeProfitPct2 = 30;
input StopLossPct = 10;

def Qty = GetQuantity();
def Prc = GetAveragePrice();

Plot Trade = If Prc > 0 then Prc else double.Nan;
Trade.SetStyle(Curve.SHORT_DASH);
Trade.AssignValueColor(color.green);

Plot TP = if Qty > 0 then Prc + (Prc * (TakeProfitPct/100)) else double.Nan;
TP.SetStyle(Curve.SHORT_DASH);
TP.AssignValueColor(color.yellow);

Plot TP2 = if Qty > 0 then Prc + (Prc * (TakeProfitPct2/100)) else double.Nan;
TP2.SetStyle(Curve.SHORT_DASH);
TP2.AssignValueColor(color.blue);

Plot SL = if Qty > 0 then Prc - (Prc * (StopLossPct/100)) else double.Nan;
SL.SetStyle(Curve.SHORT_DASH);
SL.AssignValueColor(color.red);

AddLabel(Trade > 0, "Risk: "+ asDollars(round(Qty*Prc)), color.white);
AddLabel(Trade > 0, "Shares: "+Qty, color.gray);
AddLabel(Trade > 0, "Entry: "+Trade, color.green);
AddLabel(Trade > 0, "Stop: "+SL, color.red);
AddLabel(Trade > 0, "Target: "+TP, color.yellow);
AddLabel(Trade > 0, "Target: "+TP2, color.blue);
7pVi2Zy.png
 
Last edited by a moderator:
If you don't have a trade then it won't print anything since, well, it wouldn't make any sense to have targets with no trade. I have a trade on for AA at 64.64 so it shows that line plus the 15% and 30% take profit levels and the -10% stop loss.

Here's a link, but until you make a trade, nothing will show up http://tos.mx/yga4aZy
 
Last edited by a moderator:
Hi,

I would like to have the ATR added to my entry price and show as a target in the chart

Any idea how I can do that??

Thank you so much for your help!
 
Hi,

I would like to have the ATR added to my entry price and show as a target in the chart

Any idea how I can do that??

Thank you so much for your help!

It is standard to set targets to a multiple of the ATR. So included is a setting for profit_mult. Default is 1 as that is your coding request. But it is available if you want to increase the target to 1.5x or 2x the ATR.
Ruby:
#Entries & Targets
#@JoeDV 2/23/22
#edited @merryday 3/20/22  to use ATR as target  #requested by wam1234

input profit_mult = 1 ;
def Qty = GetQuantity();
def Prc = GetAveragePrice();
def ATR = reference ATR();

Plot Trade = If Prc > 0 then Prc else double.Nan;
     Trade.SetStyle(Curve.SHORT_DASH);
     Trade.SetDefaultColor(color.green);
     Trade.SetLineWeight(2);

Plot TP = if Qty > 0 then Prc + (ATR* profit_mult) else double.Nan;
     TP.SetStyle(Curve.SHORT_DASH);
     TP.SetDefaultColor(color.yellow);
     TP.SetLineWeight(2);

AddLabel(Trade > 0, "Risk: "+ asDollars(round(Qty*Prc)), color.white);
AddLabel(Trade > 0, "Shares: "+Qty, color.orange);
AddLabel(Trade > 0, "Entry: "+round(Trade,2), color.green);
AddLabel(Trade > 0, "ATR: "+round(ATR,2), color.pink);
AddLabel(Trade > 0, "Target: "+round(TP,2), color.yellow);
UhhGsuV.png
 
Last edited:
Been looking around to find this particular code but unable to find it in the forum.

What I am looking for is a label that shows:

The current price and the distance from the EMA (using the 20ema on 1min). So basically if my entry was lets say $26.00, and the 20EMA is at $25, the label will display it is 1.00 away from the entry price. It will show red. When the EMA is over the entry price, it will turn green on the label once it hits above the avg. entry share price. I have this part of the code which shows me the current price to the EMA but I'm trying to write it in a way to show the average per share price to EMA.

input price = close;

input length = 9;

plot avg = ExpAverage(price, length);

AddLabel(1, "Distance from " + length + " EMA = " + AsDollars(price - avg), Color.green);

Any help will be great.. thanks in advance...
 
Been looking around to find this particular code but unable to find it in the forum.

What I am looking for is a label that shows:

The current price and the distance from the EMA (using the 20ema on 1min). So basically if my entry was lets say $26.00, and the 20EMA is at $25, the label will display it is 1.00 away from the entry price. It will show red. When the EMA is over the entry price, it will turn green on the label once it hits above the avg. entry share price.
This script doesn't take the current stock price into account. Reflects nothing as to profit or loss.
But here ya go:
iNmfIgP.png

ToS ONLY PROVIDES THE DATA REQUIRED FOR THIS SCRIPT ON TIMEFRAMES less than ONE HOUR AND THE DAILY -- NO OTHER!

Ruby:
#Entries & Targets
#@JoeDV 2/23/22
#edited @merryday 3/23/22  to use EMA as target  #requested by pipmonster

input emaLength = 20 ;
def Qty = GetQuantity();
def Prc = GetAveragePrice();

def EMA = MovAvgExponential("length" = emaLength)."AvgExp" ;

Plot Trade = If Prc > 0 then Prc else double.Nan;
     Trade.SetStyle(Curve.SHORT_DASH);
     Trade.SetDefaultColor(color.blue);
     Trade.SetLineWeight(2);

Plot TP = if Qty > 0 then EMA else double.Nan;
     TP.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
     TP.SetDefaultColor(color.yellow);
     TP.SetLineWeight(2);

def distance = TP - Trade ;

AddLabel(Trade > 0, "Risk: "+ asDollars(round(Qty*Prc)), color.white);
AddLabel(Trade > 0, "Shares: "+Qty, color.orange);
AddLabel(Trade > 0, "Entry: "+round(Trade,2), color.green);
AddLabel(Trade > 0, "EMA: "+round(EMA,2), color.pink);
AddLabel(Trade > 0, "Distance from EMA: " +AsDollars(distance),
                  if distance > 0 then color.green else color.red);
 
Last edited:
Ruby:
#Entries & Targets
#@JoeDV 2/23/22
#edited @merryday 3/23/22  to use EMA as target  #requested by pipmonster

input emaLength = 20 ;
def Qty = GetQuantity();
def Prc = GetAveragePrice();

def EMA = MovAvgExponential("length" = emaLength)."AvgExp" ;

Plot Trade = If Prc > 0 then Prc else double.Nan;
     Trade.SetStyle(Curve.SHORT_DASH);
     Trade.SetDefaultColor(color.blue);
     Trade.SetLineWeight(2);

Plot TP = if Qty > 0 then EMA else double.Nan;
     TP.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
     TP.SetDefaultColor(color.yellow);
     TP.SetLineWeight(2);

def distance = TP - Trade ;

AddLabel(Trade > 0, "Risk: "+ asDollars(round(Qty*Prc)), color.white);
AddLabel(Trade > 0, "Shares: "+Qty, color.orange);
AddLabel(Trade > 0, "Entry: "+round(Trade,2), color.green);
AddLabel(Trade > 0, "EMA: "+round(EMA,2), color.pink);
AddLabel(Trade > 0, "Distance from EMA: " +AsDollars(distance),
                  if distance > 0 then color.green else color.red);
[/QUOTE]

I believe I explain this incorrectly, so let me clarify

The purpose of the code or the strategy is know when the 20EMA in this example touches your entry price. My goal is to use the 20EMA as a B/E point on the trade.

For example, you place a trade on the stock at $26. Ideally the code would know, base on your AVG share price (I use Active Trader so it shows that) that lets say the 20EMA is currently at 25.20. The code would display a box on the chart that says "20EMA away from AVG Price = .80" because the order entry price is 26 and the 20EMA is at 25,20. As the price moves further away from your AVG price, or point of entry, the 20 EMA will move respectively. When the 20EMA is at your entry price because lets say the current traded price of the stock is currently at 28.90 etc, then that label will turn green, letting the trader know the price is at the AVG price (entry price of $26). Besides that, the label would be red.

The risk between that 20EMA and the AVG Price is good concept because it allows the trader to know that they are x amount away from B/E (break even) and can move STP in that area. I use OCO (order cancel order) for STPs in TOS. So typically, I'm trailing price allowing it to form and move around following the moving averages.

The initially label is reference the distance in dollar and cent as to where the EMA is to the AVG price of the shares you purchase...

I also wanted to mention the code didn't work in onDemand function in TOS. Will it only work during the live market?

I guess help me understand what part of the process doesn't make sense? TOS wouldn't be able to tell you the distance from your entry price to the EMA?
 
Last edited by a moderator:
I also wanted to mention the code didn't work in onDemand function in TOS. Will it only work during the live market?

I guess help me understand what part of the process doesn't make sense? TOS wouldn't be able to tell you the distance from your entry price to the EMA?
This script https://usethinkscript.com/threads/entries-and-target-for-thinkorswim.10302/#post-94080 provides you the distance to ema.

ToS platform does not provide for these calculations to work in onDemand.
The calculations do work in the regular ToS app, independent of market hours, as long as you have an open position.

I apologize, if it makes sense to you and forwards your strategy go for it.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
440 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top