Plot stoploss or target in thinkscript

  • Thread starter Mascapitalllctrader
  • Start date
M

Mascapitalllctrader

New member
Here is my code currently when long or short entry im having to wait for exit or stop to plot once either is hit. Is there a way to plot points as soon as entryt is taken to see where the proit target is and the stop target is. Thank in advance.

Code:
# Long

AddOrder(tickcolor = Color.GREEN, arrowcolor = Color.RED, name = "long", tradeSize = contracts, condition = condition, type = OrderType.BUY_to_open);

# Profit

def target = EntryPrice() + ATR() * profit_mult;

AddOrder(type = OrderType.SELL_to_close, high[-1] >= target, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Target", price = target);

# Trailing stop

def stop = EntryPrice() - ATR() * stop_mult;

AddOrder(OrderType.SELL_to_close, low[-1] <= stop, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", tradeSize = contracts, price = stop);
 
Last edited by a moderator:
R

RickAns

Member
VIP
Have you tried something like this?

Code:
plot ProfitTarget = target;
ProfitTarget.SetPaintingStrategy(PaintingStrategy.Horizontal);
ProfitTarget.SetDefaultColor(Color.Green);

Could do a

Code:
def target = if condition then EntryPrice() + ATR() * profit_mult else DoubleNaN;

in front of the plot as well.
 
K

KRHIlls

New member
VIP
Hello @RickAns I tried the code the just posted it's not working. I'm not sure why
 
R

RickAns

Member
VIP
KRHills, I used the variable names from what was originaly posted. If yours are different then you would need to change what I posted to match yours. Plus I do not know what their 'condition' might be since it is condition = condition in the first line.

What I posted would basically plot a horizontal line at their 'target' price. The other is if their condition is true then use this as target.

Give me some more info to work with and I will help as I can.
 
M

Mascapitalllctrader

New member
Have you tried something like this?

Code:
plot ProfitTarget = target;
ProfitTarget.SetPaintingStrategy(PaintingStrategy.Horizontal);
ProfitTarget.SetDefaultColor(Color.Green);

Could do a

Code:
def target = if condition then EntryPrice() + ATR() * profit_mult else DoubleNaN;

in front of the plot as well.

Thank you very much. just what I was looking for
 
C

csrkk

New member
VIP
Hi, Is that possible to have addOrder created something like this:
Qty 100, TRG +5 Limit, Mark -2 TrailStop, GTC
 
M

Mascapitalllctrader

New member
Am i able to set alerts so when it gets long or short it send a sms alert also can you do that for profit and loss as well.
 
rad14733

rad14733

Well-known member
VIP
Hi, Is that possible to have addOrder created something like this:
Qty 100, TRG +5 Limit, Mark -2 TrailStop, GTC
AddOrder() is very limited in features as it is merely a tool for backtesting potential trading strategies... It is not a panacea for actual real world trading... However, you can use multiple Buy and Sell AddOrder() scenarios to achieve your desired overall trade logic goals... All you can do is play with your logic and see what happens... But remember, what you see afterhours will not be the same as how realtime trading plays out... And TIF orders are not supported for backtesting...
 
M

Mascapitalllctrader

New member
Hi, Is that possible to have addOrder created something like this:
Qty 100, TRG +5 Limit, Mark -2 TrailStop, GTC

You can try something like this
Input contracts = 100;
Your add order buy condition here - - -
AddOrder(OrderType.SELL_TO_CLOSE, close > EntryPrice() + 5 or close < EntryPrice() - 2);
 

Similar threads

Top