UPDATE 3-16-2009: Strategies now work on all charts, not just intraday. See code below!
In Think or Swim’s Think Desktop software, you can create your own indicators. These are called “Studies”. You can also create sets of rules for generating entry and exit signals for trades. These are called “Strategies”. Strategies can’t be used to execute actual trades (at least not yet). However, besides painting an annotation on your charts, you can run a simple and quick backtest with your strategies to see the past results, and get a report of the profit or loss from the trades. Here’s how to use them:
Strategy Overview
There are four basic strategy types. Each strategy script must be declared to be one (and only one) of the following:
-LONG_ENTRY
-LONG_EXIT
-SHORT_ENTRY
-SHORT_EXIT
For each trade direction you want to use, you need at least one entry strategy and one exit strategy. For a long only method, you would need at least one “LONG_ENTRY” strategy and one “LONG_EXIT” strategy. If you go long and short, you need at least one of each of the four types. I say “at least” above because you could have more than one entry or exit strategy per trade direction, i.e. one “LONG_ENTRY” and two “LONG_EXIT” strategies, where one exit might represent a profit target and the other one a stop loss.
Strategies are triggered by the use of the code:
AddOrder(condition, price);
The order is triggered if condition = 1, and the price specified is the “fill” price. I give an example of this later on. Once you have the ENTRY or EXIT declaration made with an “AddOrder” statement, you have all the required pieces of a strategy. The rest comes in fleshing out the details of your trade signals that will set condition to 1 and decide what price to fill at. One gotcha is that the order will be added on the bar AFTER condition is true. If you use condition[-1] and price[-1] then the strategy will intuitively appear on the bar you are calculating it from.Just use condition and price with no offset. The [-1] jacks stuff up in real time. Sorry.
Those are the strategy basics.
Adding Strategies to Your Chart
You add strategies to charts in a way similar to how you add studies. On your chart, click the button labeled “Studies”, then select “Edit Strategies”. Then you will see this screen:
You can see the available strategies in the list on the left. You can create new strategies or click on an exsisting one to edit it or see the source code. You can also save and load strategies to/from a folder on your computer. You add the strategies to your chart just like you add studies.
In this example, I have added strategies I wrote based on an exponential moving average (EMA) cross. This method trades both long and short, so I need at least 4–one LONG_ENTRY, one LONG_EXIT, one SHORT_ENTRY and one SHORT_EXIT. This is not a recommendation to use this EMA cross method!! It will probably lose you money. I give it as a simple example that is easy to understand.
The next thing to do is to set the global properties for your strategy execution. Click “Properties for All” and you get this form:
First, you can set the number of simultaneous trades to be taken. I leave mine set to 1 for simplicity. Second, choose the size of the trades. For stocks, it’s the number of shares. For futures, if you enter 1 your P&L from the strategy report will be in points. If you want P&L in dollars, enter the dollars per point of your contract, i.e. 50 for ES, 20 for NQ and 5 for YM.
After your strategies are added to the chart, set up the timeframe and duration that you want to run. In this example, I chose ES on a 24 hour chart, 30 min bars over 5 days. Note that strategies may NOT have any plots in them! If you want to see your indicators on the chart, you must also add the matching studies. Because of this, it’s a good practice to code all of your studies with def and rec variables only, and then define plots at the end. Then your studies can be dropped right into a strategy, sans-plots of course. I added two EMA’s to the chart that match those in my strategies. Here’s an overview of how the strategies look on the chart:
I constrained my strategies to enter trades only during market hours and to always exit at the close. These are not automatic settings; I had to create code inside the strategy scripts. Here’s a closeup of two days of trades:
You can see that we went short right after the open on the first day. When the fast EMA crossed under the slow one on a bar closing basis, I went short at the closing price of that bar. The strategy exits at the close of the day. The next day, we get whipsawed with a long entry followed by a short entry. There was actually a signal for a LONG_EXIT at the same time as the SHORT_ENTRY, but the new entry signal takes precedence on the chart. The strategy basically went from long +1 to short -1 in the same instant. This will only happen if your entry signal one direction is the same as the exit signal the other direction. Otherwise you’ll see both when they happen. Finally, we exit the short at the end of the day.
Backtesting Your Strategies
Once you have the strategies set up, you can run a report of all the signals on the chart. To do this, right-click on one of the strategy signal annotations and select “Show Report”:
A quick backtest report will be calculated. The test will only be run for the visible data. If you hide after hours data, it won’t be considered. Also, it will only test back as far as you have data. This is not a big deal for daily charts, but it does mean that the furthest you can go back with intraday time charts is 20 days, and less for tick charts. Here’s a report for my EMA Cross strategies over the 5 day period:
The report shows things like trade time and direction, trade P&L, overall P&L at the time of the trades, highest profit trade, and the overall P&L for the test. Notice that this method did well with a positive profit; almost any trend-following method has been doing well in this market. An EMA Cross method will get disemboweled during a choppy range-bound market, as will any trend-following method. I’m working on an Excel-based post processor that will generate more information, such as win rate, loss rate, expectancy and so forth. Look for that soon Here’s the post processor!
And that’s it! To help you get started on your own strategies, you can download my Thinkscript Strategy files for the EMA Cross Method and load them into your own list, or use my Strategy Template files as a starting point to make your own.
Tags: strategies, Thinkscript, tutorial






March 3, 2009 at 7:42 pm
So you can’t execute strategy orders automatically? I don’t understand why $SWIM is so popular if you can’t even run an automated strat.
March 3, 2009 at 7:58 pm
Ryan,
As far as I understand, automated trading from a strategy is planned for future development by ToS. But if you are serious about automated algorithmic trading, I’d agree that there are more powerful platforms than ToS.
So why use ToS? They have great tools for options (their specialty). You can trade futures, options, stocks and forex from the same account. You can write your own indicators. Low minimum account size and many different platforms (desktop, web-based, iPhone, mobile browser). They also make new releases of software frequently (usually monthly) with new features and improvements. Commissions are somewhere between deep discount and full retail. One of the other big benefits is that they are big on education, with a streaming radio program built in to the platform, podcasts and many other teaching programs.
If ToS suits your needs with what they offer, then great. It’s not the Holy Grail of brokers. If you have other needs then move on. But maybe that helps to explain why ToS is popular with many traders.
March 3, 2009 at 8:36 pm
thanks for the info. I didn’t know they specialized in options. what are the min account balance requirements?
March 3, 2009 at 8:52 pm
Currently it’s $2000 to start an account at ToS. IB requires $10,000. I think Tradestation is up near $10k too. Many others can have platform fees, but you get tools that are worth it. So ToS becomes a great broker for newer or part-time traders. I’m not a ToS apologist by any means. Choosing a broker is very situationally dependent, and what works for one trader can be bad for another. But if it works for you, ToS is awesome.
March 4, 2009 at 6:21 pm
Wow wow nice work. I didn’t know that function was there. I can’t get results for daily or weekly charts, just intraday – is secondsstilltime available to TOS for those periods? I tried hacking out the references but exits aren’t working, just entries, so report is 0.
I guess that’s better than average lol
Thanks
March 4, 2009 at 7:54 pm
Manatrader,
Thanks for the bug report. I’ll look into it and post an update that works for daily / weekly charts, along with some other bonehead fixes. And in this market, a return of $0 is in the 99th percentile of most Mutual funds
March 6, 2009 at 1:24 pm
Thank you, Pro! You are my master of swim scripting
I have translate this post in my blog with link to you. Good job!
March 15, 2009 at 6:32 pm
Good work, would love to see the fix that allows for daily charting as well as the excel document
March 15, 2009 at 10:28 pm
Thanks nice post. Your previous post got me testing all sorts of things, using other sw. TDI Ameritrade has testing sw that TOS customers will likely get access to, maybe better – can test more data.
March 30, 2009 at 7:35 pm
Hi, Great fan of your site. But was wondering if you knew how to create a strategy to pull report for the fishertransformer. Stump.
Any help is greatly appreciated.
Thanks.
Diana
March 30, 2009 at 8:10 pm
You can copy the study code by clicking on the study icon, then make strategies using prospectus’ 3MA strategies with the MA stuff taken out. Setup inputs you want, use the DEF prefix for everything that needs defining, skip the plotting, then make the signal based on how you use the study. Good fun!
March 30, 2009 at 8:12 pm
Diana,
Thanks for the kind words. I do requests by donation amount priority. So keep an eye out and it’ll show up one day soon, or toss some coins in the tip jar to move it up the list. I have some donor work that is coming first right now.
March 30, 2009 at 8:15 pm
LOL or just do what Manatrader said!! I’ll get to it after I get through my donor requests if you need more help.
March 30, 2009 at 8:28 pm
Hello All,
Diana – I have been looking into creating the same thing, i was able to find a FisherTransformer Upper Study (Signal: Buy/Sell), but I have not been able to come up with a strategy script that works, like i want it too.
Because you would not be able to use the Fisher alone, it would require a filter – and I have not been able to make it thru the Think-a-Language, to make it happen.
Prospectus, if you can provide any information on this one – it would be great – the FisherTransform works great. Thanks
April 1, 2009 at 9:39 am
Diana and Miguel,
I see a FisherTransform indicator in ToS. Is that what you mean? Or is there something else? If so, what are your parameters for buying and selling–a crossover/under?
April 2, 2009 at 1:33 pm
Could Stop Loss, Stop or maybe Trailing Stops be added to this code easy enough? I find MA Crosses interesting, but not without Stop Loss and Stop plans in place..
Thanks
April 2, 2009 at 1:43 pm
@Randy,
Yes, I have trailing stop logic in some of my strategies. I’ll put it on the list of requests. If you donate, I’ll bump it up in priority, as I work first where the demand is, but if not I’ll do it eventually for free.
April 3, 2009 at 9:59 am
Prospectus,
On my end, Yes – thats the FisherTransform I was talking about. What I have been trying to do, is create a strategy with the FisherTransform (for back testing), seems to work okay, but when i try to block out the noise with a TEMA. Then is does not work correctly, or I just suck at thinkscript.
Any help would be great. Thanks for the reply
April 3, 2009 at 11:06 am
@Randy: a donor just asked for a trailing stop strategy and was fine with me posting it, so look for that soon.
@Miguel: post your code in the comments here and I’ll look at it and see if I can see anything.
April 3, 2009 at 2:59 pm
Pro,
I think i got it now – Used a combination of ThinkScripters FisherTransformSignal and your post about InPut Open and Close Times. Over a 20 Day – 5 minute Chart – shows Total Profit and Loss of: $59,062.50 one contract. Dude you and Eric have helped me out tremendously, with your site. Thanks I will have to donate to the cause.
Is there away to block out the Lunch Time Hours?
input opentime=0930;
input closetime=1600;
But with the lunch part blocked out?
April 3, 2009 at 3:06 pm
Miguel,
That sounds amazing, please post for us to look at the strategy.
April 3, 2009 at 3:13 pm
its posted on thinkscripters blog, as a study:http://thinkscripter.wordpress.com/2009/03/07/fisher-transform-signals/ . Not sure if he would want me to post his script out as a strategy, but let me ask him. And I will be back.
April 3, 2009 at 3:18 pm
Miguel,
Yes, please post if you’re willing!
Lunchtime blockout–this goes in your entry strategy:
input lunchstart=1200;
input lunchend=1400;
def lunch=if secondsfromtime(lunchstart)>=0 and secondstilltime(lunchend)>=0 then 1 else 0;
then change the line
def isopen=if !intraday then 1 else if secondsFromTime(opentime)>=0 and secondstillTime(closetime)>=0 then 1 else 0;
to this:
def isopen=if !intraday then 1 else if secondsFromTime(opentime)>=0 and secondstillTime(closetime)>=0 and !lunch then 1 else 0;
That should do it!
p.s. I hate the full justification of this wordpress theme :p
April 3, 2009 at 3:24 pm
Thinkscripter is great, and I recommend everyone check out his work also:
http://thinkscripter.wordpress.com/
April 3, 2009 at 3:29 pm
Pros, I tired that lunchtime code, but the word “intraday” is highlighted red, error.
April 3, 2009 at 3:31 pm
Thanks Pro,
I will put that in now: Here is the script, I still think there is a lot of noise, but any suggestions would help – be gentle – this is my “First” strategy, and the orders to me are ridiculous, but here it is.
I Referenced:
# FisherTransformSignals
# http://thinkscripter.wordpress.com
# thinkscripter@gmail.com
# Last Update 07 Mar 2009
Then started this script, seems to work???
declare LONG_ENTRY;
input signalOffsetFactor = 0.20;
input length = 20;
input opentime=0930;
input closetime=1500;
def signalOffset = AvgTrueRange(high,close,low,10)*signalOffsetFactor;
def maxHigh = Highest(high, length);
def minLow = Lowest(low, length);
rec value = if maxHigh – minLow == 0 then 0 else 0.66 * ((close – minLow) / (maxHigh – minLow) – 0.5) + 0.67 * value[1];
def truncValue = if value > 0.99 then 0.999 else if value < -0.99 then -0.999 else value;
rec FT = 0.5 * (log((1 + truncValue) / (1 – truncValue)) + FT[1]);
def trendDown = if FTFT[2] then 1 else 0;
def trendUp = if FT>FT[1] and FT[1] trendDown and trendup [1] 0.99 then 0.999 else if value < -0.99 then -0.999 else value;
rec FT = 0.5 * (log((1 + truncValue) / (1 – truncValue)) + FT[1]);
def trendDown = if FTFT[2] then 1 else 0;
def trendUp = if FT>FT[1] and FT[1] trendup and trendDown [1] <= trendup [1] then 1 else 0;
addOrder(buySignal,open[+1]);
Please let me know what you think. Thanks
April 3, 2009 at 3:33 pm
This is the ShortEntry:
declare short_ENTRY;
input signalOffsetFactor = 0.20;
input length = 20;
input opentime=0930;
input closetime=1600;
def signalOffset = AvgTrueRange(high,close,low,10)*signalOffsetFactor;
def maxHigh = Highest(high, length);
def minLow = Lowest(low, length);
rec value = if maxHigh – minLow == 0 then 0 else 0.66 * ((close – minLow) / (maxHigh – minLow) – 0.5) + 0.67 * value[1];
def truncValue = if value > 0.99 then 0.999 else if value < -0.99 then -0.999 else value;
rec FT = 0.5 * (log((1 + truncValue) / (1 – truncValue)) + FT[1]);
def trendDown = if FTFT[2] then 1 else 0;
def trendUp = if FT>FT[1] and FT[1] trendup and trendDown [1] <= trendup [1] then 1 else 0;
addOrder(buySignal,open[+1]);
April 3, 2009 at 3:35 pm
Not sure how it works, but i’m sure it can use fixing.
April 3, 2009 at 3:45 pm
In regards to the lunch time hours, can anybody spot what is not correct here?
It is still issuing buy orders between my defined lunchtime hours.
thanks.
========
#
# MomentunLE
# thinkorswim, inc. (c) 2007
#
# slightly modified…
#
declare LONG_ENTRY;
setColor(GetColor(3));
# changed default of 12 to 8
input length = 8;
input price_scale = 100;
input price = close;
# defining open and close time
input opentime=0630;
input closetime=1300;
# don’t issue buy orders during extended lunch timeSeriesForecast
input lunchstart=0940;
input lunchend=1145;
def AP=getaggregationperiod();
def intraday=if AP==aggregationPeriod.MIN OR AP==aggregationPeriod.HOUR OR AP==0 then 1 else 0;
def lunch=if secondsfromtime(lunchstart)>=0 and secondstilltime(lunchend)>=0 then 1 else 0;
def isopen=if !intraday then 1 else if secondsFromTime(opentime)>=0 and secondstillTime(closetime)>=0 and !lunch then 1 else 0;
def delta = price – price[length];
def acceleration = delta – delta[1];
def point = 1 / price_scale;
def condition = delta > 0 and acceleration > 0 and high[-1] >= high + point;
addOrder(condition, Max(open[-1], high + point));
April 3, 2009 at 3:50 pm
Randy,
I was assuming that you have the rest of my strategy code in there (the code from the tutorial is outdated, the code from the thinkscript tip: get aggregation period” post is correct):
#
# If intraday, only enter during market hours:
# Note: Tick charts return Aggregation Period = 0
#
input opentime=0930;
input closetime=1600;
def AP=getaggregationperiod();
def daily=if AP>=aggregationPeriod.DAY then 1 else 0;
def isopen=if daily then 1 else if secondsFromTime(opentime)>=0 and secondstillTime(closetime)>=0 then 1 else 0;
And then you use ‘isopen’ during your entry signal logic.
I need to re-do my strategy templates so they are more clear. Stay tuned.
April 3, 2009 at 4:05 pm
Randy,
Here, you forgot one thing (in bold below).
Also, as far as I know, you put in these times as eastern time, not local time.
#
# MomentunLE
# thinkorswim, inc. (c) 2007
#
# slightly modified…
#
declare LONG_ENTRY;
setColor(GetColor(3));
# changed default of 12 to 8
input length = 8;
input price_scale = 100;
input price = close;
# defining open and close time
input opentime=0630;
input closetime=1300;
# don’t issue buy orders during extended lunch timeSeriesForecast
input lunchstart=0940;
input lunchend=1145;
def AP=getaggregationperiod();
def daily=if AP>=aggregationPeriod.DAY then 1 else 0;
def lunch=if secondsfromtime(lunchstart)>=0 and secondstilltime(lunchend)>=0 then 1 else 0;
def isopen=if daily then 1 else if secondsFromTime(opentime)>=0 and secondstillTime(closetime)>=0 and !lunch then 1 else 0;
def delta = price – price[length];
def acceleration = delta – delta[1];
def point = 1 / price_scale;
def condition = isopen and delta > 0 and acceleration > 0 and high[-1] >= high + point;
addOrder(condition, Max(open[-1], high + point));
April 4, 2009 at 4:42 pm
I know you are not saying that this strategy will work but I do trade a similar strategy with some modifications and it has worked very well since September. As long as the market is making these wild moves, I will continue to take this trade.
If you get a chance, here is a link to a thread called “Short Term Mean Reversion Still Working”.
The 4th comment is where we start discussing this strategy and how it can be tweaked.
Your input would certainly be appreciated.
http://www.ibankcoin.com/woodshedderblog/index.php/2009/04/02/short-term-mean-reversion-still-working/#comment-6285
April 5, 2009 at 1:28 am
@lazy man: The MA cross strategy probably does work well in a highly trending environment. I chose it not for it’s profitability, though. I put it in the example because it is a very simple and easy to see entry setup. I wanted to simplify for the sake of teaching how to use strategies. I’ll take a look at the thread at Shed’s blog.
April 5, 2009 at 9:26 am
I 100% got that you were not endorsing the strategy. I appreciate the site for what it is – an exceptional resource to learn TS coding (and one of VERY few at that).
That said, this caught my attention as you actually do have pretty good entries (if you use the right time frames for your chart).
I would say this is a strategy that will ONLY work with high ADR, highly liquid, futures or Forex (ES, 6E, ZB, EUR/USD for example).
The missing part is the right PT. I have an exit strategy that is discussed in the other blog but, with that, I leave a lot of upside on the table.
Anyway, thanks for the site – you appear to know more about TS codnig than anybody I’ve ever talked with @ TOS.
April 5, 2009 at 9:37 am
@lazy: understood. I appreciate the compliments. I’ve scratched my head about a profit target for an MA cross system for years. I’m thinking that using support/resistance like round numbers (like 800 ES) and pivot levels, or on extreme levels of the TICK would be good. It’s on my giant to-do list.
April 5, 2009 at 10:27 am
Until now, I’ve used an average that somewhat corresponds with ADR (for firm stops and rough PT’s).
I have to say though that I find myself watching the Bollinger bands, MACD, etc. for continued strength before I make an exit so I don’t miss out on extra profits.
Pivots and S/R are certainly things to look for.
Much left up to trader discretion – hard to code a firm rule for the exit other than the firm stop loss, 3pm “almost” mandatory exit, or exit on a bar crossing 50% to the wrong side of the MA.
You have 75% of this system nailed though – the entry. The rest is to find the right trending liquid market and then figure out how to get out with your profit. The best part is that I rarely see trades that would not be profitable (with very little drawdown) at some point very quickly after this entry.
This is not like trying to fade and watching it keep trending wondering if it will ever turn.
BTW – you should re-write the manual for TS and sell it to TOS. That damn thing needs fixing!
April 6, 2009 at 4:27 pm
Pro / Group,
Any thoughts on the FisherTransform information? I’ve only seen silence – Please share your thoughts – thanks.
Miguel
April 6, 2009 at 4:29 pm
On paper it looks to make a ton of money, but it has SO many trade, I can’t imagine that it would turn out well in practice.
April 6, 2009 at 4:45 pm
Thanks Randy, feedback is key.
April 7, 2009 at 8:12 am
Miguel,
My quick look at it found a lot of whipsaws. Maybe some filtering is in order?
April 7, 2009 at 8:53 am
I agree, thats the problem – how do i filter out the whipsaws?
April 7, 2009 at 9:26 am
Some ideas:
Use tick charts instead of time charts
Do not take entries during lunch hour or within 15 mins of open/close
Only take signals beyond certain values of FT (like +-2)
Couple with some overbought/oversold indicator for confirmation
April 7, 2009 at 10:07 am
sweet, and now the question is…how do i do that?
April 7, 2009 at 3:19 pm
Miguel:
Sorry, I’m extremely busy and have to prioritize my time to my donors, but here’s a quick stab:
Tick charts-self explanatory
Limit entry time: it’s in the comment above.
Limit FT to +/- 2:
def buysignal = if FT[2]>FT[1] and FT[1]<FT AND FT<-2 then 1 else 0;
def sellsignal = if FT[2]>FT[1] and FT[1]<FT AND FT>2 then 1 else 0;
Couple with overbought/oversold: Maybe require an RSI above 80 for a sell, RSI below 20 for a buy…
April 7, 2009 at 3:35 pm
Your the man. Thanks
April 8, 2009 at 9:50 am
Is it easy enough to change that to a EMA ((H+L+C)/3) instead – gives more weight to the close. I asked someone at TOS and they were stupified…
Also – Your entry is a market order at the close of the first bar during/after the cross right?
NOT asking you to do this – I know you are really busy and I’m trying to figure it out myself, just discouraged at the response from TOS.
April 8, 2009 at 10:12 am
Sorry – should have said – first bar after the MA cross with OHLC ALL above or below the slower MA.
April 8, 2009 at 10:22 am
@Lazy:
EMA (H+L+C)/3 actually weights the close LESS than just EMA (C).
In the EMA cross, yes, my order is market at the close of the bar that results in an EMA cross. You can set it to be any price you want, though, where it says:
def orderprice=close;
Use anything you want instead of ‘close’.
April 8, 2009 at 10:57 am
Using EMA C yes, my default for EMA is (H+L)/2 rather than ((H+L+C)/3) so I assumed incorrectly that was the default here as well.
Thank you
April 11, 2009 at 12:31 am
So, I was looking at that Fisher indicator… and at first blush with back testing it looked great. But now that I’m looking at it a bit more closely, it seems that the open prices it uses in the “show report” are actually a couple candles back. So, either I’m missing something or this will only yield great results in hindsight?
April 11, 2009 at 8:17 am
skwasha,
I noticed that too. Not sure what thinkscripter does with this indicator, but it does seem to paint the indicator after the fact. There can be a lot of whipsaws with FT, too. Frankly, my head is spinning with all of the strategies I’ve been looking at lately…
April 11, 2009 at 11:18 am
For the script that i put up on top, it uses the Ft and FTOneBarBack cross, which can seem to be prevoius bars back – due to the range of the price quotes, that fall within that particular range. But, primarily this is a basic cross technic, like MA cross. And thus far this has been working great in real time for me, i filter out the noise with Kaufman Osc. – Hope that helps. By using Kaufman Osc. in correlation with Fish, is has been great.
Miguel
April 12, 2009 at 4:12 am
Is this what you are referring to when you talk about the Kaufman Osc? http://www.thinkscripter.com/2009/02/28/kaufmans-adaptive-moving-average-binary-wave/
April 12, 2009 at 1:51 pm
That would work, but i use the Kaufman Efficiency Ratio
, located here: http://www.thinkscripter.com/2009/03/16/kaufman-efficiency-ratio/. It can be used as a trend oscillator. To know when the signal is correct, based on Fish Cross
April 13, 2009 at 10:39 am
I’m looking at a ema cross of 3/50 on a 5 min chart, showing a total profit of 558 pips for the last 20days on eur/usd. Not bad eh?
..but does it reallllyyy work? lol
April 13, 2009 at 2:52 pm
I saw your posts in the Thinkscripter and followed your lead here .
Wa wondering if it is possible to use Strategy with say LOng Entry as above ,, but use the Long exit to , exit on a profit target , or StopLoss.
maybe in the code you provided below , use the def or meaybe rec , to maintain the entry peice and then use that to def. the exit as a distance above/below for profit target???
A few pennies for your thoughts.
Guy
# If market is closing OR EMA’s crossed under then exit on bar close:
#
def trigger=if isclose OR crossunder then 1 else 0;
def orderprice=close;
#
# This code triggers the strategy on the chart.
# Arg. 1 adds order if true, nothing if false
# Arg. 2 is the entry price
#
addorder(trigger,orderprice);
#
# Formatting:
#
setcolor(color.gray);
April 13, 2009 at 3:07 pm
@Jay420: Yes, it works until it doesn’t
@Guy: I have trailing stops and targets for strategies on my to-do list. I have some beta versions working, but they are not yet robust and generalized.
Donations bring topics to the top of my to-do list. I also have some custom work that was commissioned that is taking my top priority right now. Stay tuned.
April 13, 2009 at 3:49 pm
I’m still playing around with the Fisher indicator just to make sure I understand exactly what’s going on with the TOS strategies and I gotta say I’m still a little confused. Using Thinkscripter’s Fisher Trasform study, I recreated an LE and LX Strategy – changing only the plot parts of the Study out for addorder statements. So, theoretically if I add both the study and the the two strategies I should expect to see entry/exit signals correspond to strategy signals. Right? But for some reason, the strategy signal always shows up on the following bar from the study signal. And the entry/exit price for the strategy is the close price for the previous bar. Which with slippage is not gonna be pretty – esp. with longer timeframes.
I’m thinkin it must just be something inherently different between studies and strategies… A study will react realtime, while a strategy will plot an entry for your next bar? Or something like that? Am I just dense?
PS – @Guy – I think Thinkscripter has a Limit Order script somewhere that you might be able to adapt – Or just donate to Prospectus
April 13, 2009 at 3:56 pm
@skwasha: The signals plot on the bar after they are calculated. If you want to mess with when it shows up, you can use references like close[-1] to check for bars ahead, but they won’t show up right in real time.
If you wanted to do this on the daily, instead of close of prior bar for the entry price, use
addorder(*yourcondition*, open[-1]);
and you will enter at the next day’s open.
August 11, 2009 at 9:22 pm
WoW, your post has inspired me to make my own strategy. I am super rusty in programming which is taking me a while to program them. Thank You sir.
Any idea how to make a stop loss exit order?
November 10, 2009 at 10:50 pm
Is it possible to include your accounting as part of the scripting? As in max 2% stop loss / entry size based on your account? How would the coding be like?
November 11, 2009 at 10:17 am
Scud,
You can’t programmatically refer to your account size yet. You could have an input to the strategy that is your account size, but it would only update as often as you went in and changed it.
March 12, 2010 at 1:58 am
Thanks! Very nice article. I’m using TOS too , but it’s really a miss of TOS that it haven’t ability for real automation trading.
April 11, 2010 at 11:43 pm
Any report of when we will be able to execute orders automatically from strategies?
April 12, 2010 at 6:57 am
Not yet. You can use the Prodigio platform to build auto-trade strategies, but it’s very simplistic so far. It is possible to hack Excel to send orders, but it truly is a hack and I don’t know if I’d recommend it, at least not without constant oversight by the trader.
October 13, 2010 at 7:28 am
Just came across this post, just wanted to point out that as for intraday backtesting, though minute charts are only available for 20 days, for hourly charts you can change your scale to as far back as 180 days.
October 13, 2010 at 7:35 am
Yes, thanks! TOS gave us a huge boost in that department.
April 20, 2011 at 12:27 pm
Considerably, the article is really the actual freshest on this notable topic. We agree with your findings and will thirstily anticipate your next updates.I will instantly get your rss feed to stay up to date with any improvements.,
August 22, 2011 at 8:09 pm
I have a question regarding the speed of the TOS system and the information meaning Data feed which puts the pricing that comes up on the screen. Is there a difference in the speed between TOS and all the other platforms or do they all get the same Data feed from the markets. I was reading the Kinetick site which provides Ninjatrader there Data feed and which Eric from Thinkscripter really likes and they make it sound like they are faster then others and they talk about raw data and filtered data. I really like TOS and trade Futures but at times it seems they are late to the game is this my imagination or are all companies like this. I have talked to friends that trade IB or Zaner and it seems they are getting info faster. I have a cable with the spead at 35 it is going to 50 in the near future i do not thing i can get the speed any faster. I hope you understand what i am asking and can give me a good answer this has been driving me crazy and if speed and the Data feed was that important wouldn’t all these companies and the reviewers promote it. I have no idea who provides TOS’s data. Thanks for your Help. Eric
October 27, 2011 at 11:35 am
Hi, very good post! it helped me a lot, thanks!
could you please advise: has TOS some kind of debugging tool to trace over my script or at least to show some debug info for it?
as with rather big scripts it’s almost impossible to detect where i’ve made mistake. looking on chart i see that there should be long entry but script doesnt put it and i cannot find a bug in my script.
thanks in advance!
Ivan
October 27, 2011 at 11:58 am
There’s no good debug tools. The only one you get is compiler errors when you try to save the script. If the script “works” but your algorithm isn’t returning the expected values, you have to go line by line and plot the intermediate values to track down where your error is.
November 1, 2011 at 10:13 pm
Hi prospectus, thanks a lot!
I don´t how visualice the emas strategy in a period of day or year…it´s possible?
Greetings from Argentina!
November 2, 2011 at 6:00 am
Ok, i understand, thank you.
But what you mean under “plot the intermediate values” line by line?
I have a situation – a chart and long-entry script for this chart.
Accordingly to this script at some point of the chart there should be the entry – so i can see the setup on the chart that is programmed in the script for entering but it there is no entry in fact – seems that my script with bug. How i can debug (even using intermediate plot) in this situation? Can you please advise? Thanks
also – can you please advice – is there any way to access one of my drawings from the script? so for example if i have price-level drawing on the chart and i want to have an entry at breakdown of this level – can i access to this price level from the script?
thank you for your help!
Regards,
Ivan
November 4, 2011 at 1:37 am
i know your busy, but i appreciate everything you have done on this site .was wondering if you could answer a quick question please. i saw your strategy templates in the downloads section but am not sure how i would go about doing this. wondering if there is a way to create a buy/sell signal based off the macd crossing. find this works great with heiken ashi bars. thanks for your help!
November 4, 2011 at 7:05 am
Are you looking for an indicator or a strategy to do this?
November 4, 2011 at 10:39 am
a strategy, to go along with your strategy report excel file. essentially i want a strategy that instead of being based off different variables of the ema’s crossing; i want a short/ buy signal for when the macd crosses.
January 2, 2012 at 2:01 pm
mt4…
[...]Tutorial: Using Strategies in Think or Swim « Read the Prospectus[...]…
January 6, 2012 at 8:25 pm
Autotrade Forex Signals by specialists, Forex Expert Advisors, Forex Robots plus Forex Rebate Introducing Broker Program….
[...]Tutorial: Using Strategies in Think or Swim « Read the Prospectus[...]…
March 16, 2012 at 12:24 am
[...] It seems that TOS has some form of strategy backtesting for which I was not aware. Found so here: Tutorial: Using Strategies in Think or Swim Read the Prospectus Possible to test a strat against a group of stocks, or must it be against a chart, or one at a [...]
April 3, 2012 at 10:41 pm
I do not even know the way I stopped up right here, however I thought this publish was great. I do not realize who you are but certainly you’re going to a famous blogger in the event you are not already. Cheers!
April 22, 2012 at 4:08 am
mt4 demo download…
[...]Tutorial: Using Strategies in Think or Swim « Read the Prospectus[...]…
July 14, 2012 at 1:13 am
I need a simple code for think or swim tos (too complicated for me to write) I have absolutely no script experience. I want a strategy that will start at open and end at close (one day) buy at specific quantity to be named by me at a specific market price and sell a specific quantity at a specific market price and direction on where to place what to change later. I need this with easy markers to see as well. This has probably already been made and is easily available but its so simple no one posts anything about it.