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.
 

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

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?

@hydrophobe I suggest using SecondsFromTime(0930) >= 0 and SecondsFromTime(1600) <= 0 as part of your conditional criteria to insure that trades are only made during regular trading hours... That would be the simplest way that I know of... In addition, using @MerryDay's suggestion to reference a Study would be the way to go... Let us know how things turn out...
 
@hydrophobe You can write it as a custom study and then reference it in the conditional order. Easier, cleaner, and no character limit ;)
rad14733 and MerryDay, these suggestions a perfect. Thank you! Looks good in the preview so it should work. The custom study makes everything a lot easier as well.

EDIT/UPDATE: didn't want to double post, but it looks like this worked! Thank you so much for the help. This has been driving me crazy for a few days.
 
Last edited:
Hello

I am looking to create a conditional order that would trigger based on:

If the three minute candles closes below the last 10 minute candle close.

Can anyone help me code this?

Thank you,
 
pga0008 If you are asking if you can use multiple time frames in a conditional order, the answer is no, that is not currently supported by the TOS platform. Not in conditional orders nor in scans.
HTH
 
pga0008 If you are asking if you can use multiple time frames in a conditional order, the answer is no, that is not currently supported by the TOS platform. Not in conditional orders nor in scans.
HTH
But I could do it on the same time frame so if five minute closes below last five min candle? If they pssoble I would like help with that just trying to gauge exits bettee
 
While the time restriction code is working great, I have noticed that (even in the past) ToS appears to randomly sell things based on 1 minute graph, when I clearly used a 5 min graph as a basis. That's the only explanation I could come up with for some triggers, and it matches up perfectly with a 1 minute graph (despite a 5 minute graph being used). Anyone else run into this?
 
@hydrophobe I would recommend using triggers that are the same across all timeframes if that is an issue. Instead of price for instance, perhaps a 3ema?
That's not a bad idea. I think it might've been something else. Since I was using low("period" = AggregationPeriod.FIVE_MIN, "priceType" = PriceType.MARK) without an aggregation period specified (originally), it appeared to be selling correctly on the charts, but in the condition I think it decided to assume a 1 minute agg period, or less. In any case, forcing a five minute agg didn't appear to negatively effect my profitability.

One other question (since I am also swing trading my retirement fund), if GetLastDay() == GetDay() and SecondsFromTime(0930) >= 0 and SecondsFromTime(1600) <= 0 is in my condition criteria at order activation, will it be stuck on the day of order activation or will this update to the most recent day, every day?
 
@MerryDay @RConner7 On the conditional orders is it possible to exclude extended hours signals, when using Day level aggregation? My study (super trend study) https://usethinkscript.com/threads/supertrend-yahoo-finance-type-for-thinkorswim.1998/ shows buy/sell signal during EXT hrs and conditional orders wouldn't work on EXT, so it is too late when the market opens, as such I was curious if I could exclude EXT hrs or have the study show signal excluding after hours ?

I typically trade at D level aggregation, but also tried below D level aggregation by unchecking exclude EXT hrs, but i guess the signal is still showing at EXT hrs (the Alert value trigger is shown in EXT hrs), so basically no signal during regular hours for our condition to work.

Also, when using 5min aggregation I'm seeing study giving buy and sell signal prematurely (before candle completes) and my study based conditional orders got filled on 5 min interval on false positives. Should I increase the value of within X bar field, so that my signal looks X candles back from a few bars ago thus avoiding any trigger incurred during candle formation or false positives? so currently i have a trigger set to 1 candles and increasing to 2 should help in this case?

Alternatively, do you think this will work at higher aggregation period like may be Day level better than lower level? Is there anything else I could do differently to setup the conditional order placement based on those up/down arrows please?

As always thank you for your time on this.
 
Last edited:
I've had some issues with false positives myself - but it's generally gone both ways, it's helped and it's hurt equally, so I'm not sure if I should care or not. There's times I should have had a 5% gain, but I ended up with a 10% loss and times I had a 10% gain when I should have had a 5% loss. Something to that effect. Overall still profitable all considered.

Only other question I have at the moment relates to the EntryPrice() function. Is this allowed as a sell order condition? e.g.

MovAvgExponential(length = 5) is less than entryPrice()*.98

I have concerns that it doesn't and it might entirely override my sell order conditions just because that's additional criteria. Can't be certain though. Unfortunately, ToS gives no warnings over its use as a condition. I know it works fine in the charts.

sunnybabu, I've found SecondsFromTime(0930) >= 0 and SecondsFromTime(1600) <= 0 as sell order conditions works great for restricting to regular trading hours. Kudos to rad14733 for coming up with it. I also add "GetLastDay() == GetDay()" to make sure I'm only using triggers that occurred today.
 
@hydrophobe @rad14733 Conditional based orders cannot be traded during extended hours isn't it? so i'm not sure why we need to specify your below condition to exclusively trade during regular hours? Isn't it by default only regular hours?
Code:
SecondsFromTime(0930) >= 0 and SecondsFromTime(1600) <= 0
Or perhaps is this a command to trick TOS :)If Yes, then can i use the below code to enable extended hours trading along with some study signal for buy and sell order based on "1st trgs Seq"

Code:
plot _Data_ = SecondsFromTime("fromTime" = 0400) is greater than or equal to 0 and SecondsFromTime("fromTime" = 2000) is less than or equal to 0 and MACD()."UpSignal" is true within 2 bars;
plot _Data_ = SecondsFromTime("fromTime" = 0400) is greater than or equal to 0 and SecondsFromTime("fromTime" = 2000) is less than or equal to 0 and MACD()."DownSignal" is true within 2 bars;

my screenshot.
RJT9Sb3.jpg


Also, is it similar to "D" level aggregation "GetLastDay() == GetDay()" ? Could u plz send me screenshot of your conditional orders? how are you using these commands?

Please advise??
 
Last edited:
@hydrophobe conditional based orders cannot be traded during extended hours isn't it? so i'm not sure why we need to specify your below condition to exclusively trade during regular hours? Isn't it by default only regular hours?
Code:
SecondsFromTime(0930) >= 0 and SecondsFromTime(1600) <= 0
Or perhaps is this a command to trick TOS :)If Yes, then can i use the below code to enable extended hours trading along with some study signal for buy and sell order based on "1st trgs Seq"

Code:
plot _Data_ = SecondsFromTime("fromTime" = 0400) is greater than or equal to 0 and SecondsFromTime("fromTime" = 2000) is less than or equal to 0 and MACD()."UpSignal" is true within 2 bars;
plot _Data_ = SecondsFromTime("fromTime" = 0400) is greater than or equal to 0 and SecondsFromTime("fromTime" = 2000) is less than or equal to 0 and MACD()."DownSignal" is true within 2 bars;

my screenshot.
RJT9Sb3.jpg


Also, is it similar to "D" level aggregation "GetLastDay() == GetDay()" ? Could u plz send me screenshot of your conditional orders? how are you using these commands?

Please advise??
sunnybabu, from what I've seen conditional orders do appear to look at triggers that happen during extended trading hours, but loosely reading your post I assumed you were trying to limit yourself to regular trading hours, avoiding EXT signals. I assume you could reverse-engineer the logic to exclusively look at extended trading hours as you have done here, but I'm not an expert on this matter.

I generally create a study, then reference it in the conditional order (study = true would be the condition). e.g. using your condition

MACD()."UpSignal" is true within 2 bars and GetLastDay() == GetDay() and SecondsFromTime(0400) >= 0 and SecondsFromTime(2000) <= 0

I'm not a coding expert/programmer, so that could probably be written more efficiently, but it is what it is.
 
sunnybabu, from what I've seen conditional orders do appear to look at triggers that happen during extended trading hours, but loosely reading your post I assumed you were trying to limit yourself to regular trading hours, avoiding EXT signals. I assume you could reverse-engineer the logic to exclusively look at extended trading hours as you have done here, but I'm not an expert on this matter.

I generally create a study, then reference it in the conditional order (study = true would be the condition). e.g. using your condition

MACD()."UpSignal" is true within 2 bars and GetLastDay() == GetDay() and SecondsFromTime(0400) >= 0 and SecondsFromTime(2000) <= 0

I'm not a coding expert/programmer, so that could probably be written more efficiently, but it is what it is.
@hydrophobe Correct i wanted to do opposite if feasible that is trigger during EXT and regular hours, so i extended the time period from 4:00am to 8:00pm. Sadly I did place these orders yesterday on paper trading and none got triggered during extended hours and when I closely look at the order it clearly shows GTC. The moment we select GTC_EXT it doesn't allow. Is there any other way we can get this triggered including EXT hours please??

bwsRh9j.jpg


Appreciate your time
 
@hydrophobe Correct i wanted to do opposite if feasible that is trigger during EXT and regular hours, so i extended the time period from 4:00am to 8:00pm. Sadly I did place these orders yesterday on paper trading and none got triggered during extended hours and when I closely look at the order it clearly shows GTC. The moment we select GTC_EXT it doesn't allow. Is there any other way we can get this triggered including EXT hours please??

bwsRh9j.jpg


Appreciate your time
To my knowledge, that would be the best way to do it, but I'd have to defer to someone else in the community. Sorry I couldn't help - again, I am no expert here, just thought I'd throw something out there based on what worked for me in regular trading hours. Hope someone can help you!
 
@sunnybabu I was playing with SecondsFromTime and SecondsTillTime last night, before getting distracted, and they were ignoring Extended Hours for some reason... In fact I had a partial reply typed up and just deleted it because of the issues I was encountering... I was just trying to verify their performance using AddLabel and was surprised they didn't work as expected even though I found similar information elsewhere on the internet... Unless something is broker in Thinkscript/Thinkorswim...
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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