• LIMITED TIME OFFER: use coupon code PRIMEDAY at checkout to save $50 off VIP membership (down to $149 / year). Valid through Tuesday 6/22.

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);


Active 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