Is there a way that I can exit a long before the [0]candle closes as a stop?

Scoopy

New member
Say if I want to exit if price goes below low[1] as a stop sell order instead of waiting for [0] to close? Messed around with the auto sell, but think I'm doing it wrong.
 
Solution
Remember that we're not looking at true algo trading. ToS is only so good for predicting future returns using back testing. I wouldn't worry about a few cents since you'll never meet the outcomes of ToS in reality anyway.

EDIT: As I reread your post, I think what you want is for ToS to do something mid-bar. It won't (as a part of normal back-testing... perhaps on-demand works differently with simulated orders). It will wait for the bar to close before it does things I'm fairly sure. You can tell your strategy to sell at whatever price you want though it may distort the reality of the backtest beyond usefulness. I mean you could create a sell_to_close that sold at your entryPrice + 10% and ToS would report it as such. It just...
This thread:
https://usethinkscript.com/threads/add-stoploss-price-order-to-thinkscript-strategy.1106/

has in it this order:
Code:
AddOrder(OrderType.SELL_TO_CLOSE, low < EntryPrice() - (EntryPrice() * 0.1), EntryPrice() - (EntryPrice() * 0.1), 100);
which you should be able to modify to suit your purposes. Note that the condition is low is above the stop loss and the next term of the code is the price at which the sell_to_close is executed. Here it is not open[-1] as is the standard (default) setting.

hth,
mashume
 

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

This thread:
https://usethinkscript.com/threads/add-stoploss-price-order-to-thinkscript-strategy.1106/

has in it this order:
Code:
AddOrder(OrderType.SELL_TO_CLOSE, low < EntryPrice() - (EntryPrice() * 0.1), EntryPrice() - (EntryPrice() * 0.1), 100);
which you should be able to modify to suit your purposes. Note that the condition is low is above the stop loss and the next term of the code is the price at which the sell_to_close is executed. Here it is not open[-1] as is the standard (default) setting.

hth,
mashume
@mashume Thanks for the reply. I tried to implement that code, but maybe I'm doing something wrong. This is kind of what I'm working with. It trails the lows pretty well. I just want to get out exactly when the price goes below the low instead of waiting for the close.

def selllong = low[0] < low[1];

AddOrder(condition = selllong, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, tradeSize = 1, type = OrderType.SELL_TO_CLOSE);
 
Remember that we're not looking at true algo trading. ToS is only so good for predicting future returns using back testing. I wouldn't worry about a few cents since you'll never meet the outcomes of ToS in reality anyway.

EDIT: As I reread your post, I think what you want is for ToS to do something mid-bar. It won't (as a part of normal back-testing... perhaps on-demand works differently with simulated orders). It will wait for the bar to close before it does things I'm fairly sure. You can tell your strategy to sell at whatever price you want though it may distort the reality of the backtest beyond usefulness. I mean you could create a sell_to_close that sold at your entryPrice + 10% and ToS would report it as such. It just wouldn't be realistic. ToS will use whatever price you want it to regardless of when it executes the sell_to_close command. In real trading, of course, stop loss orders are executed at market as soon as the condition is reached.

mashume
 
Last edited:
Solution

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
221 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