Conditional Order Tutorial For ThinkOrSwim

JohnZee

New member
Hello,

I use Thinkorswim platform for trading Micro E-mini SPY futures and prices move quickly as you know. It's hard to manually close a position so most of the time I preset close orders but sometimes it's hard to catch the small move up. I am interested in scalping with a 1:1 ratio. So let's say if I buy /MES futures one contract for 4400, my position should close at 4397 or 4403. I would like to program this strategy so I can just attach it to a chart when I have an open position and if it reaches the conditions specified then it should close that opened position.

I am new to Thinkscript coding but am an experienced programmer, so hopefully can learn it quick. Is that possible just using this one line of code or do I need to add more code?

AddOrder(OrderType.SELL_TO_CLOSE, close > EntryPrice() + 3 or close < EntryPrice() - 3);

Thank you
John
 
I don't think any Thinkscript is required for what you just mentioned.

Since you want to reference the chart, you could leverage "Active Trader"
and use a TRG w/ Bracket" to enter your buy order, along with the corresponding sell orders.
If you turn on Auto-send, you can even submit the order without verification.


@ the Thinkorswim.com link below, there are some videos that might help.
References:
https://tlc.thinkorswim.com/center/howToTos/thinkManual/Trade/Active-Trader.html

The screenshots are for example (if this is what you're intending to do.)

KsqVKdk.png



ZLBdCPR.png



FGur5Qv.png




Hope this helps!
 
I can just attach it to a chart when I have an open position and if it reaches the conditions specified then it should close that opened position.
I mis-read your post. In your case, you already have the position open. In that case, you want this one:

OCO (one cancels other) Two orders are placed simultaneously; if one order is executed, the other is canceled.

Reference: https://tlc.thinkorswim.com/center/howToTos/thinkManual/Trade/Order-Entry-Tools/Order-Types

[Note: if it moves really fast (which you also mentioned), TRG w/ Bracket might be better to set your limit and stops at time of entry, but this example works if you're already in the position.]


hPkqseU.png
 
I don't think any Thinkscript is required for what you just mentioned.

Since you want to reference the chart, you could leverage "Active Trader"
and use a TRG w/ Bracket" to enter your buy order, along with the corresponding sell orders.
If you turn on Auto-send, you can even submit the order without verification.


@ the Thinkorswim.com link below, there are some videos that might help.
References:
https://tlc.thinkorswim.com/center/howToTos/thinkManual/Trade/Active-Trader.html

The screenshots are for example (if this is what you're intending to do.)

KsqVKdk.png



ZLBdCPR.png



FGur5Qv.png




Hope this helps!
Thank you.
 
Couldn’t this be solved by an OCO (one cancels other) order? That is what I do. I create the order on any stock (just to get the template setup) with the criteria I want i.e. A buy order (the “trigger” for the OCO) with a $0.50 trailing stop followed by the OCO part of the order, a $1.00 trailing stop and a $2.00 take profit limit sell. I then save that as a template. When I am actually ready to buy a stock I will right click, custom order, select the order template I created, and submit.

You can even click the gear icon right next to the order you want to modify and dive deep into certain conditions (like study parameters, time of day, etc) as well
 
Couldn’t this be solved by an OCO (one cancels other) order?
OCO means you already have an order and you are trying to box it (stop and profit target). If you want stop and limit order palaced at the time or trade you need to follow @JohnZee suggestion using 2 braket.
 
OCO means you already have an order and you are trying to box it (stop and profit target). If you want stop and limit order palaced at the time or trade you need to follow @JohnZee suggestion using 2 braket.
If you do as I said above the actual buy order will trigger the OCO order with a take profit and stop loss. If your buy order doesn’t get filled than there will also be no OCO orders.
 
Dear MerryDay, I try to use a script (custom strategy or indicator) while placing conditional orders. Unfortunately, I cannot place the code properly for correct execution. This was the reason for my post. When I use the option "study" as a condition for buy or sell order, I need to make a choice, but I shall try all options till I find the proper choice.
 
Last edited by a moderator:
Dear MerryDay, I try to use a script (custom strategy or indicator) while placing orders in order to utilize auto trading. Unfortunately, I cannot place the code properly for correct execution. This was the reason for my post. When I use the option "study" as a condition for buy or sell order, I need to make a choice, but I shall try all options till I find the proper choice.
OCOs (conditional orders) use the same triggers as you used when you tested it in the strategy.

3. Type in the desirable symbol name in the corresponding form. Click on the Method cell and choose "STUDY" from the drop-down list. Choose Edit... to open the Study Order Condition window.

Conditional Orders:
https://tlc.thinkorswim.com/center/howToTos/thinkManual/Trade/Order-Entry-Tools/Order-Types/thinkScript-in-Conditional-Orders#:~:text=You can use both the Condition Wizard and the thinkScript Editor to set your condition or define a numerical value, e.g., a study. When finished, click OK.

The condition wizard / thinkscript widget that opens in the step described above is also used for chart alerts, and for scan hacker amongst others.
You can watch the scan hacker tutorial for an explanation of the condition wizard.
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/
You can practice creating conditional orders in the chart alerts (right-click anywhere on your chart, scroll down to create an alert


Please note: it is never recommended to use a repainting indicator in an OCO.
Yes, it looks perfect in Backtesting because all the false signals are erased so it only displays perfect trades.
read more:
https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-57833
 
Last edited:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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