Need help with profit target code


Hello all - I have an indicator that is working but i would like to enhance it a bit so that when the profit target from entry price is hit it will stop end.

This is a snippet of code that i'm struggling with how to make work.:
plot entry;
plot exit;

def EntryPr;
def pos;
def co = BarNumber() > Max(SellExit, BuyExit);
def ExitTgt;

switch (BuyorSell) {

case Buy:
    entry = QB[1];
    exit = LL[1];
    pos = if ST_UP and co and high > QB[1] then 1
            else if low < LL[1] then 0
                else pos[1];
    EntryPr = if high > QB[1] and pos == 1 and pos[1] < 1
              then QB[1]
              else if pos == 0
                  then Double.NaN
              else EntryPr[1];
    ExitTgt = EntryPr + (TargetATRMult * 2 * mATR);   

case Sell:
    entry = QS[1];
    exit = HH[1];
    pos = if ST_DN and co and low < QS[1] then -1
                 else if high[1] > HH[2] then 0
                      else pos[1];
    EntryPr = if low < QS[1] and pos == -1 and pos[1] > -1
              then QS[1]
              else if pos == 0
                  then Double.NaN
              else EntryPr[1];
    ExitTgt = EntryPr - (TargetATRMult * 2 * mATR);

on the pos line for the BUY case, i need to somehow make it that ---else if low < LL[1] or high > ExitTGT then 0. ExitTgt is defined after the pos and EntryPr. EntrPr relies on pos to be defined first.

How can i make this work??


New member
Hi ,

Does anyone have a TOS script to tell me the profit target price from my entry price . Say my average price is 1.22$ and i need 10% from my entry what would be my limit sell order price ? It would be very helpful for scalpers , its difficult to calculate the target price while a stock is very volatile . If we can find the stop price of 5% . Thant would be a great helpful . But all this has to be depended on my entry price . I tried using EntryPrice() but it didnt work . Experts please help me , this has to work on the live 1 min timeframe chart . Here is the updated script -

input stopPercent = 5;
def Data = EntryPrice ()-(stopPercent/100)*EntryPrice ();
def showDiv = yes;

AddLabel(showDiv, Data + " stop loss", Color.RED);

input sellPercent = 10;
def sellPrice = EntryPrice ()+(sellPercent/100)*EntryPrice();
def showLab = yes;

AddLabel(showLab, sellPrice + " sell limit", Color.GREEN);


Well-known member
I tried using EntryPrice() but it didnt work .
In what case did EntryPrice() not work? If it's OnDemand or PaperMoney, it's not going to work. Otherwise I've never noticed any problem with it. I always have my entry price plotted on my charts. You should try plotting EntryPrice so you can see if it's working. Once you add that plot you can look at previous trading days and it'll show where you had those positions even if they're closed now.

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.