Stop loss at the low of previous candle

raviucla

New member
Hi,
Total newbie here. How can I write code that when I go long, I can have the stop loss automatically be placed when the current bar closes below the low of the previous candle. So for example, a long entry is taken at 9:32 a.m. eastern time. If at 9:40 a.m. eastern, we close below the 9:30 a.m.-9:34 a.m. candle, we exit that long entry as a trailing stop loss.

Thanks!
 
Solution
@raviucla The only way to accomplish setting StopLoss at or below the close of the previous candle automatically would be through the use of a Conditional Order, which is an advanced method that requires an understanding of Thinkscript... The code itself is relatively simple (easy for me to say) and is somewhat subjective to how Thinkorswim works...

Ruby:
# For long exit. Reverse the math logic for short exit.
close crosses below low[1]

The code above is the simple answer... But . . . . There is a difference between a confirmed signal and one which may be false... The code above will trigger as soon as your criteria is met which may or may not get you to where you want to be... A confirmed trigger would wait for the current...
@raviucla The only way to accomplish setting StopLoss at or below the close of the previous candle automatically would be through the use of a Conditional Order, which is an advanced method that requires an understanding of Thinkscript... The code itself is relatively simple (easy for me to say) and is somewhat subjective to how Thinkorswim works...

Ruby:
# For long exit. Reverse the math logic for short exit.
close crosses below low[1]

The code above is the simple answer... But . . . . There is a difference between a confirmed signal and one which may be false... The code above will trigger as soon as your criteria is met which may or may not get you to where you want to be... A confirmed trigger would wait for the current candle to close and only then trigger at the instant the new candle opens... For this reason the following code waits for positive confirmation, even if it triggers a bit later...

Ruby:
# For long exit. Reverse the math logic for short exit.
close[1] crosses below low[2]

All that being said, I would suggest watching YouTube videos for "conditional orders in thinkorswim" to gain a complete understanding of how to code and use Conditional Orders... It is beyond the scope of this topic to give a step by step because a full understanding is required rather than a detailed example... We're trading with real money and the concepts of Conditional Orders does not function properly in either PaperMoney or OnDemand trading...

I hope this helps... As I said, this is an advanced concept so you there is a learning curve... Good luck...!!!
 
Last edited by a moderator:
Solution

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

Hi,
Total newbie here. How can I write code that when I go long, I can have the stop loss automatically be placed when the current bar closes below the low of the previous candle. So for example, a long entry is taken at 9:32 a.m. eastern time. If at 9:40 a.m. eastern, we close below the 9:30 a.m.-9:34 a.m. candle, we exit that long entry as a trailing stop loss.

Thanks!

@rad14733 has provided you the correct syntax.
Here is how to test and write your conditional order:
https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-80482
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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