ThinkorSwim Conditional Orders

bigpemby

New member
So I want to an exit order when price pierces the 9 period EMA by 0.25 for example. I can create the order that will exit when 9 period EMA is breached but I cannot get the extra 0.25. I can put an order type trail stop but this doesn't trail the EMA minus 0.25. The offset provisions in the order screen deal with offsetting the number of bars not the price. Its a very simple order but there seems to be no way to make TOS do it. The order needs to move dynamically with the EMA. A simple market order when condition is met is fine with me.

This is the thinkscript conditional order generated for a simple low price break of EMA. I just need to be able to add the dynamic 0.25 below.

Code:
low is less than MovAvgExponential()."AvgExp"

Tradestation has this built in and I cannot figure out how to recreate this in ThinkorSwim.
 
I am trying to use a simple conditional order to see how it works but my order is never triggered. I want my order to be triggered when the price crosses above the high of the previous bar.

So I simply entered: high is greater than high from 1 bar ago.

But it's not working What is the trick here? Thanks for your help
 

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

Code:
input showBreakoutSignals = yes;
def cond1 = if high > high[1] then 1 else 0;

plot a = if cond1 then high else Double.NaN;
a.SetStyle(Curve.POINTS);

plot UpSignal = high crosses above high[1];

UpSignal.SetHiding(!showBreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
 
Yes! It's Working! Thank you so much Christian!!

As you seem to know what you are talking about... do you know if there is a way to use the function SELL_TO_CLOSE on the conditional orders? I would like for example to buy 4 SPY following the rule you gave me

Code:
Def cond1=if high>high[1] then 1 else 0;
plot a= if cond1 then high else Double.NaN;

And then I would like to sell 2 if the price Go up 2%. And SELL_TO_CLOSE at the market if Low<Low [1].

Any idea how to write the SELL TO CLOSE in the conditional order? I couldn't find it anywhere.

I would like to SELL_TO_CLOSE if the price go back to my EntryPrice + 0.01 cts. Is there a way to write this in the order rules of the conditional Order?
 
Try with this and tell me, you can modify any condition. In the case 1 condition is high>high[1] and entry is on the next open bar,4 is number of contracts. I don't use thinkorswim and the most important this is NOT a complete trading system. A complete trading system must include stop, target, risk reward ratio, drawdown and the COMISSSSSSIONNNSSS !!!

1) AddOrder(OrderType.BUY_TO_OPEN, high>high[1],open[-1] ,4,Color.GREEN,Color.GREEN, name = "entry");
2) AddOrder(OrderType.SELL_TO_CLOSE,close>0,close>EntryPrice()*1.02,2,Color.RED,Color.RED, name = "exit");
3) AddOrder(OrderType.SELL_TO_CLOSE,low<low[1],open[-1],2,Color.RED,Color.RED, name = "exit2");
 
I was just wondering if anyone knew of a way to have text alerts and/or conditional orders based on a renko chart because I can only find a way to set them based on time-dependant charts. Any help is welcome, thanks!
 
Hi, thanks for your answer

Unfortunately, we can't use LAST on the conditional order.
So are you working on a strategy, or a conditional order for auto-trading...??? What can and cannot be used in conditional orders is definitely limited... I spent a couple days, on and off, with online support from within TOS trying to get some code to work and eventually scrapped the concept because what they were saying should work wouldn't...
 
I've noticed a couple posts regarding conditional orders, and thought I might forward this information. This is a snippet from the TSL conversation (OneNote Archive date Thursday, July 16th, 2020) -
17:59 JohnnyQuotron_2: I had a lengthy chat with support today regarding Conditional Orders. There is a glitch in the programming when a conditional order is saved and later recalled. The platform is cutting off the code somewhare around 200 characters. It is on the list to fix but unless more users make noise in the chatroom and the trader lounge it is likely to remain low priority.
18:00 UpTheCreek: lovely
18:00 JohnnyQuotron_2: <----- MAKING LOTS OF NOISE
18:01 JohnnyQuotron_2: But here's the really good part. The platform will accept the cut off code without notifying you of the error. And depending on where the code is cut off, the errant code may or may not execute.

I dont use conditional orders, so I have'nt verified this in any way. But if anyone uses conditional orders, it may help to know this and maybe look into it.
 
I can't seem to get the thinkscript for this one right and I was hoping someone here might be able to help me out.

What I want is if at today's close, and only at the close, one moving average is lower than another, sell tomorrow at the open.

What I can't figure out is how to get the script to wait for the close to make the comparison. For example, if I check for a 5EMA < 10EMA, the order will go in immediately if the 5 is less than the 10 or as soon as the cross occurs (which can be anywhere in the trading session).

I don't want it to consider the condition on every tick. I just want it to check when the regular trading session closes (or just before it closes) and then either do nothing or place an order to sell.

Does anyone know if it's possible to accomplish this?
 
I am trying to setup a custom OCO order that would purchase based on input data but sell points based on the following: High of the previous 5 minutes and low of the previous minute. Is this possible?
 
Hi,

I hope this question hasn't been answered somewhere else yet - I've looked. I've been trying to do a study order condition to buy/sell stocks based on a 8/20 EMA crossover on a 5 min graph using thinkscript (with several conditions added on the selling side and a few extra on the buy). The issue that I'm running into is that it appears to be triggering a buy because the EMA's are long enough to go back into extended hours trading (that, or a 5 minute/5 day graph literally looks back the full 5 days for any trigger, but based on how I've seen orders get placed I doubt this).

So I think if the EMAs can go back 40min/100min, if a trigger has happened before 9:30AM when the order is placed somewhere in the range of 100 minutes prior, a buy/sell could occur instantly. I only want it to buy/sell based on a CURRENT trigger crossover from the time the order is placed and on. The basics of my code on the buy side are as follows (nothing super complicated, although I have more conditions than this):

MovAvgExponential("length" = 8)."AvgExp" crosses above MovAvgExponential("length" = 20)."AvgExp"

What I'd like to do is only buy based on a current period trigger - rather than looking back the full lengths of the EMAs. I've tried doing an offset (from negative bars into the future), but this doesn't appear to be working. I've also noticed there's a character limit on thinkscript study conditions (at least with saving templates) that might be clipping my code, but I'm not entirely certain. I'm making sure the code is there before setting up the order mind you; I just dunno if the code is getting clipped in the template if it might also be clipped on the study order itself (AKA it's not even being used).

I've considered ignoring extended hours trading as well, which could almost be effective if there weren't GAPs that would create a false trigger or if triggers didn't happen at the end of the day (really just putting me back in the same situation, although triggers happen less often toward the end of the day from what I've noticed, so it's a somewhat effective solution, but non-ideal). Also tried 5 minute aggregation periods for the EMA's based on 1 minute graph - couldn't get that to work at all.

1 minute/1 day graphs are far too noisy to be a solution.

Hope that's descriptive enough and my question isn't a nuisance.

Thanks!

[edit]

Would something like this work?

MovAvgExponential("price" = OPEN[-1], "length" = 8)."AvgExp" crosses above MovAvgExponential("price" = OPEN[-1], "length" = 20)."AvgExp"
 
Last edited:
Sorry if this is the wrong place; no problem with having it moved.

(FYI there was another post before this one, so I'm not technically double posting). But in all honesty, this isn't really about EMA crossovers, it's more about study order conditions and their timing - any strategy could be considered relevant).
 
Last edited:
@hydrophobe Are you building a Backtesting Strategy or are you under the impression that you can Auto-Trade using AddOrder()...??? Thinkorswim doesn't support true Auto-Trade but you can use Conditional Orders for one-shot orders, unless you save the Conditional Orders and re-initialize once fired... However, Conditional Orders don't utilize AddOrder() but, instead, trigger based on the same criteria that you would use to fire AddOrder() calls...
 
@hydrophobe Are you building a Backtesting Strategy or are you under the impression that you can Auto-Trade using AddOrder()...??? Thinkorswim doesn't support true Auto-Trade but you can use Conditional Orders for one-shot orders, unless you save the Conditional Orders and re-initialize once fired... However, Conditional Orders don't utilize AddOrder() but, instead, trigger based on the same criteria that you would use to fire AddOrder() calls...
Thanks for the reply. Not a backtest and not anything from the regular chart side. I'm essentially just doing conditional orders based on a crossover on a 5 min graph (selected from the conditional orders screen), but the issue is that the orders have been triggering based on crossovers that happen before 9:30 AM (the order placement time). I was thinking this was because my EMA lengths (40min/100min) are long enough crossovers that happen before that time are considered a trigger. I was hoping there was a way to just look at crossovers that occur after 9:30, like maybe forcing it to look a few bars ahead. Don't mind having to re-initialize as needed.
 
Thanks for the reply. Not a backtest and not anything from the regular chart side. I'm essentially just doing conditional orders based on a crossover on a 5 min graph (selected from the conditional orders screen), but the issue is that the orders have been triggering based on crossovers that happen before 9:30 AM (the order placement time). I was thinking this was because my EMA lengths (40min/100min) are long enough crossovers that happen before that time are considered a trigger. I was hoping there was a way to just look at crossovers that occur after 9:30, like maybe forcing it to look a few bars ahead. Don't mind having to re-initialize as needed.

Thanks for the clarification... You can use a time constraint as part of your trade criteria and it sounds like that should resolve your issue... I'll refer you to the GetTime() function in the Thinkscript Learning Center for more information... Good luck...
 
Thanks for the clarification... You can use a time constraint as part of your trade criteria and it sounds like that should resolve your issue... I'll refer you to the GetTime() function in the Thinkscript Learning Center for more information... Good luck...
I think that may work - hadn't thought of using that as an additional condition, thanks! Hopefully I'll have enough room to squeeze it into the 200 character limit. Would GetLastDay() == GetDay() work as well as a condition?
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
306 Online
Create Post

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