Archive for December, 2009

Moving Average Cross Alert Study for Think or Swim

December 11, 2009

Here’s a script that shows how to trigger an alert on a moving average crossover, but only after the bar that caused a crossover has completed. I have an arrow plotted intrabar if the averages cross, and it disappears if they uncross. This same thing can happen to alerts based on the crossover, giving you an alert that is later invalidated. The way around it is to have the alert look one bar back, so it won’t trigger until the first tick after a crossover bar is finished.

The script is called “MACrossover_w_AlertsSTUDY.ts”, and is free at my Google site under
“Released Thinkscript Studies”.

Some Wise Quotations

December 8, 2009

I saw a quotations page today on and thought it was worth passing on. Several “spoke” to me:

5. The pessimist complains about the wind; the optimist expects it to change; the realist adjusts the sails.
—William Arthur Ward
(Or alternately, I’d say “The Bear complains about the wind; the Bull expects it to change; the Trader adjusts the sails.”)

6. If you don’t make mistakes, you’re not working on hard enough problems. And that’s a big mistake.
—Frank Wilczek

10. I don’t know the key to success, but the key to failure is trying to please everybody.
—Bill Cosby
(This one applies to me BIG TIME)

18. Good judgment comes from experience, and experience comes from bad judgment.
—Barry LePatner

45. There is nobody so irritating as somebody with less intelligence and more sense than we have.
—Don Herold

See the full list here.

Thinkscript Tip: Creating Alerts Using Thinkscript in Think or Swim

December 8, 2009

The newest Think or Swim release brings us the ability to create alerts from Thinkscript code! Here’s how to use them.

The syntax of the “alert” function is as below:

alert(condition, text, alert type, sound);

The required arguments are Condition and Text. The other two are optional, but have defaults if you don’t supply them:

alert type default value: Alert.ONCE
sound default value: Sound.NoSound

Condition is the logical value that will trigger the alert, and should be calculated to either 1 or 0 (true or false).
Text is the text string that will appear in the alert window when it is triggered.
Alert Type tells the alert how often it can trigger. The different ‘alert type’ parameters are:

Alert.ONCE – alert can be triggered only once after adding study
Alert.BAR – alert can be triggered only once per bar
Alert.TICK – alert can be triggered after each tick

Sound tells the alert what sound to play (if any). The different ‘sound’ parameters are:


Now some examples! This code will call an alert once on every single bar:


If you wanted an alert on RSI(2)>80 for example, you could use

def condition=if RSIWilder(2)>80 then 1 else 0;

If you had a plot of the NYSE TICK and wanted an alert every single time that a tick comes across as above 1000 or below -1000 (and didn’t value your sanity), you could use

alert(close>1000,”High TICK!”,alert.TICK,sound.DING);
alert(close<-1000,"Low TICK!",alert.TICK,sound.DING);

A slightly less ADD version would be to alert only once per bar, like so:

alert(close>1000,”High TICK!”,alert.BAR,sound.DING);
alert(close<-1000,"Low TICK!",alert.BAR,sound.DING);

And finally, if you only wanted the first +1000 tick of the day, you could use

alert(close>1000,”High TICK!”,alert.ONCE,sound.DING);

If you have any cool uses of Thinkscript alerts, feel free to share in the comments!

December Think or Swim Release: Auto-Trading!

December 4, 2009

Here’s the release notes on tomorrow’s TOS release. Lots of big changes, including auto-trading!!

For the latest news and developments, go to >


Black Friday has a completely different meaning for our developers. Some bad experiences with the shopping public the past few years convinced them that they’re better off indulging friends and family with gift cards for 64-core super servers and beta-versions of the next “Close Combat” (ordered safely online). But the Friday before a software release, their mood can still get ugly. Balancing their benevolent nature with a streak of vengeance, they consider striking a blow against “those traders” on behalf of unappreciated Java coders the world over, and releasing not just a slew of cool trading tools, but a ‘virtual shopping maze’ only a programmer could win. Only a bit of Holiday magic keeps their dark forces at bay…

On Saturday, December 5 at 5:00am CST, we will be releasing version 1530. New features include:

Trading: Check out Prodigio scanning later next week! It offers custom indicators and automatic trading functionality combining drag-and-drop ease with real-time data filters and signal-based order routing through TOS. Look for ‘Prodigio’ updates later this week as we begin to accept users on a per-request basis. Prodigio will only be available to funded accounts.

Trading: See Widget 360! Click on an option chain column header and click ‘Widget 360’ to see a chart of the data for easy visual interpretation. Available for these data points: Implied Vol, Delta, Gamma, Theta, Rho, Vega, Extrinsic, Open Interest, Volume, Mark, Intrinsic, Theoretical Price, Covered Return, Return on Risk, Return on Capital, Probability of Expiring and Probability of Touching.

Forex: New NBBO forex commission-based trading with tighter bid/ask spreads and $1,000 contract size. Check the FX watchlist for symbols. Live inter-bank quotes will be available starting Sunday evening, December 6th. Live inter-bank trading will be available Sunday, December 20th.
Positions: User-defined sub accounts for custom segregation of positions and p/l.

Totally redesigned “Chart Settings” dialog featuring:
Changing color setting for each chart type separately.
Special colors for neutral bars and Doji candles.
Specifying color for area chart.
Previewing new colors.
Selecting time frame (time period plus aggregation period).
Icons for adding shortcuts to menu.
Keeping zoom for each axis.
Managing auto-expansion.
Hiding daily rollover and yearly marking lines.
Size fits to screen on NetBooks.
Two price scaling modes: manual and auto.
Fill colors are used to draw borders when candle size is too small.
Fixed missing bars for COMP.
Improved PPS.
Finding highest high or lowest low in the last number of days. See ‘LookUpHighes’t and ‘LookUpLowest’.
Crossover studies. See group of the same name.
Fixed historical filter for ‘PersonsPivots’.
Translated to thinkScript:
‘CumulativeVWAP’ renamed simply ‘VWAP’.
“Copy source…” item in context menu.
Triggering alerts from user studies. See ‘alert’.
Changing chart background color from code. See ‘assignBackgroundColor’.
Changing cloud color. See new parameters of ‘addCloud’.
Lightweight dynamic past offset. See ‘getValue’.
Corporate-action-related functions. See ‘Corporate Actions’ group.
Checking if the value is infinite. See ‘isInfinite’.
Painting Strategies: Painting strategies for plots with boolean values. See constants starting with BOOLEAN.
“Apply” button in editor.
Performance improvements.
Trade is considered as number of contracts.
Drawings: Drawing squares and circles by holding the ‘Ctrl’ key.
Prophet Charts: Now offers Ratio Charts which can be accessed by entering a formula directly within the symbol entry box or choosing the Ratio Charts menu item from Chart Settings. This feature allows you to enter a formula based on symbols and mathematical operators to show synthetic charts, such as the ratio between silver and gold, the sum of all the prices of the four horsemen of the NASDAQ, and so on.

Please remember: As of December 1, 2009, the 25% maintenance margin for leveraged ETFs is now being multiplied by the amount of the leverage, not to exceed 100%. For instance, a 2x leveraged ETF now has a maintenance margin of 50%, and a 3x leveraged ETF has a maintenance margin of 75%. This will affect all accounts, including margin and portfolio margin accounts.

thinkorswim support
(866) 839-1100

Leveraged and inverse ETFs have unique risks, including leverage, derivatives and complex investment strategies. They are not appropriate for a long-term or buy and hold investment strategy and they are designed for investors that manage their investments as frequently as daily. They are not suitable for all investors. It is important to read an ETF’s prospectus, which provides detailed information related to the ETFs’ investment objectives, principal investment strategies, risks, and costs. The SEC’s EDGAR system, as well as search engines, can help you locate a specific ETF prospectus. You can also find the prospectuses on the websites of the financial firms that issue a given ETF, as well as through your broker. FINRA warns, “Only invest if you are confident the product can help you meet your investment objectives and you are knowledgeable and comfortable with the risks associated with these specialized ETFs.” For more information, read the SEC’s Leveraged and Inverse ETFs.

The risk of loss in trading securities, options, futures and forex can be substantial. Customers must consider all relevant risk factors, including their own personal financial situation, before trading. Options involve risk and are not suitable for all investors. See the Options Disclosure Document: Characteristics and Risks of Standardized Options. A copy can be requested via email at or via mail to 600 W. Chicago Ave., #100, Chicago, IL 60654-2597. Trading foreign exchange on margin carries a high level of risk, as well as its own unique risk factors. Forex investments are subject to counter-party risk, as there is no central clearing organization for these transactions. Please read the following risk disclosure before considering the trading of this product: Forex Risk Disclosure. thinkorswim is compensated through a portion of the forex dealing spread. Funds deposited into an account with a broker-dealer for investment in any currency, or which are the proceeds of a currency position, or any currency in an account with a broker-dealer, are not protected by the Securities Investor Protection Corporation (SIPC).

thinkorswim, Inc. is a wholly owned subsidiary of TD AMERITRADE Holding Corporation.

thinkorswim, Inc. Member SIPC FINRA NFA
2009 © TD AMERITRADE IP Company, Inc.

Must-Visit Site: Strictly Market Profile

December 4, 2009

Gary’s website on Market Profile is great. Give him a visit.