Swing High / Swing Low Indicator for Think or Swim

Update 2-18-10: v3–Added optional lines for plotting after the swing points:

As part of some work I have been doing, I needed a way to identify swing highs and swing lows. What is a swing high / low? It depends on your definition, but basically a swing high is the highest high looking a few bars back and a few bars forward. A swing low is the lowest low looking a few back and a few forward. The more bars you include in the series, the more significant the swing, but the confirmation comes further from the actual swing point. Say you wanted to define a swing high as this:

A bar high that is higher than the highs of the two bars just before it AND higher than the highs of the two bars just after it.

The thinkscript code might look like this:

Def swinghigh = if high > high[1] and high > high[2] and high > high[-1] and high > high[-2] then 1 else 0;

The code for a swing low is similar. This method is a pain because it requires you to hard code the swing period. If you want to change to a different number of bars, you have to modify the source code. Note that the confirmation of a swing point does not come until 2 bars after the swing high in this case. If you wanted to extend the swing check to 3 bars before and after, you would add the checks for a high > high[3] and high > high [-3]. The resulting swing will be more significant, but the signal comes 3 bars after the fact.

To plot the swing high you could do something like this:

Plot sh = if swinghigh then high else double.nan;
sh.setstyle(curve.points);

This would paint a dot on all the swing highs, and nothing everywhere else. The code for swing lows is similar. So now you know how to create your own swing high / swing low indicator. Free education; you provide the sweat equity. If you have any questions on making your own, leave a comment and I’ll be glad to help out!

I spent a couple of hours last night figuring out how to make the indicator generalized, meaning that you can input any number of bars to define your swing period, and the code finds the highs and lows for you without modding the indicator source code. This makes it easier to change on the fly for backtesting or responding to market volatility. Here’s what it looks like:

2009-04-29-tos_charts_pro_swingpoints1

My pain + my brain = your gain! Become a donor and you can download my complete generalized swing point script file, ready to be imported into Think Desktop. This is part of my new “Teach for free, Work for fee” philosophy. If you donate, be sure to email me and let me know what you donated for so I can send it to you! All my files (many for free and some for donors only, including the Swing Points) are at my Google site: http://sites.google.com/site/prospectus/welcome

Tags: , ,

39 Responses to “Swing High / Swing Low Indicator for Think or Swim”

  1. JCastellon Says:

    can you post some backtest results?

  2. Prospectus Says:

    I ran some quick backtests today and quickly noted the results on Twitter. Look back through my updates from today on my twitter feed.

    Bottom line is that simply fading the swing point as soon as you get the signal is worse than 50/50 for intraday trading on ES. That said, I don’t think that this indicator is suited for an entry signal on it’s own. Maybe in combination with other support/resistance levels, or just to measure divergences in MACD or some other indicator. Possibly you could measure average cycle length and try to anticipate the next swing point. There’s a lot of places this idea could go to try to find a profitable system, but it’s a lot like panning for gold. Most of the time you will find nothing but mud.

  3. JCastellon Says:

    will do! thanks!

  4. JCastellon Says:

    Very true, I’ve been jotting down ideas but still nothing certain. I figure if you can manage 51% win rate with, lets say, a 50 pt/tick stop and 100 tgt it should prove profitable but i have yet to find a system that has a 51% win rate

  5. DavidDT Says:

    Has been following your work since you coded some paintbars for QuoteTracker – thank you for all you’ve done.
    You and Eric (thinkscripter) are the most valuable part of TOS programming group 🙂
    DavidDT
    If you day trade – stop by at http://chat.paltalk.com/g2/paltalk/1192843448 – a lot of TOS refugees in there 🙂

  6. MACD Divergence Indicator for Think or Swim « Read the Prospectus Says:

    […] Divergence Indicator for Think or Swim By Prospectus Following on the heels of my Swing Points indicator, I wrote an indicator that looks for divergences between the MACD and price. Every time […]

  7. CCI Divergence Indicator for Think or Swim « Read the Prospectus Says:

    […] it’s not complicated to write your own if you already have a swing points logic built, like I outlined previously. I’ll walk through the additional steps […]

  8. robert Says:

    /Hey, just to say thank you for the indicator, i have been hearing of it but i have not got the opportunity to have a look at it or used it for test drive. Could you pleas let me know if i can download it to my plateform to demo trade?.

  9. Prospectus Says:

    Thanks for your interest. I don’t have a demo version of the indicator, unfortunately. Here’s why:

    I have people waiting in line for me to do custom projects for them. Since they pay me for my work, they get top priority on my time. Also, my donor scripts I publish here are usually outgrowths of some of the custom work that I have done. It’s not fair to those who have chipped in a few bucks to just give away what they have either completely paid for or contributed to. Nor is it fair to me to simply give away the products of my labor, skill (debatable) and my investment of time.

    I have written tutorials and offered to answer questions, though, in the interests of freely teaching those who want to learn how to program with Thinkscript. Since I haven’t really gotten any questions, either my tutorial is so comprehensive that anyone can reproduce my indicators, or nobody really cares to learn, or some of both.

    Bottom line is this: Try to write your own indicator and ask questions, and I’ll be glad to teach freely. Donate to my blog ($20 would be great) and you can download the donor scripts like all my other donors (Thanks, all!). Like in my earlier post, I teach for free, and work for fee.

    If neither of these options works for you, try freethinkscript.com, as they are all about giving things away. Make sure to give them my regards. 🙂

  10. Dave Says:

    $20 for a do loop !

  11. Prospectus Says:

    I wish it were that easy! We could do so much more with Thinkscript if we could use loops.

  12. Dave Says:

    Fair point 🙂

  13. Ron Says:

    I am very interested in your chart indicator program on swing high/swing low. Can you give me a link to your tutorial? I have not heard of ThinkScript. How do you insert the code into a chart? I am afraid I am a real newbie and would appreciate all the help I can get. I don’t have a problem with a donation.

  14. Prospectus Says:

    Ron,

    I’ll make a “complete n00b’s guide to Thinkscript” and post it on the blog.

  15. AndyC Says:

    Hi,

    Ron said exactly what I was thinking… How do you insert the code?

    Prospectus, is there a noobie’s guide to ToS… can you post a link to it?

    Thanks!

    AndyC

  16. Prospectus Says:

    I’ve been working on one, but it’s half done in my blog drafts. Maybe I should release as is and add later.

  17. Mahesh Says:

    I like to get SMMA done in thinkscript. That is the smooth moving average. Would you do it for me for a fee? Thanks

    Mahesh

  18. Frank Says:

    Hi, I am interested in the indicator. Does the indictor work for emini and other futures? Would you give instruction and help on installations, and maybe free updates in future? Thank you.

  19. Prospectus Says:

    Yes, it works on any symbol that Think or Swim has. I can help you set it up if you need it. Blog donors only have to donate once.

  20. Frank Says:

    Hi, How do I contact you for the download? Could you send it to my email adress? Thank you.

  21. Frank Says:

    I sent my donation to your website. Please check it.

  22. gugunganteng Says:

    I wonder if this script can be used for intraday play…any idea what timeframe is better for this indicator?…May be we could combined with Trader-X idea in playing Opening Range with script you’ve made last year to identify the Target price…

  23. myb120 Says:

    Is there a version 4 of this? The link for v3 doesn’t seem to be working…

  24. Chris Says:

    What if the 8/2 values could change in relation to MACD’s performance? For example, as MACD hovers in and around the 0 during lower volatility, the swing points look for larger movements.

  25. Taipen Says:

    First, love your site.

    RE: Swing High, Swing Low Indicator.

    This is FRACTAL Trading…….Check out Chaos Trading and Bill Williams. You could combine this indicator with his alligator indicator and AO indicator.

    Enjoy you

  26. Michael Says:

    I wonder if you would use the rec feature to plot the additional lines until a new swing high or low is met. My non coder self tried putting rec in front of the plot lines and shut the code down.

    Thanks for any clues in advance,

  27. Prospectus Says:

    It’s in there now if you choose “show levels” or something like that from the inputs. Unless I haven’t published that update?

  28. Dave Says:

    I believe that despite your yeoman effort, your swing hi and lo definition is incorrect. I think that you got as close to scripting a fairly loose definition as as possible without having to get an army of programmers to write the script. Really, though, your work is great. Try this link http://www.medianline.com/articles/ then go to the article titled “Identifying Swing Highs and Swing Lows”. This guy is no BS.

  29. Prospectus Says:

    I think there’s no canonical definition of many trading terms. One man’s swing high is another man’s higher high. The definition in that article you linked is very technically rigorous, but as far as I’m concerned it’s useless for actual trading. By the time you have a “confirmed” swing high, you’ve missed the entire move down. This is especially true for index futures, as they back and fill a lot more than they trend intraday. My indicator should be called “potential swing highs and lows” since you are making an educated guess that the high of two bars ago will pan out to be a local high. You might end up being wrong, but that’s the game.

    In the end it’s all semantics I guess. And what’s more, none of it is even in the top 5 most important, foundational things to be successful at trading!

  30. Dave Says:

    Hey Prospectus, nice to see that someone read my post. Your take on this was my first take on the stricter definition as well, but as I watched this man, Tim Morge show the trades develop, and how he uses the swings and pseudo swings, then it makes sense. Believe me this method is definitely NOT useless, and it absolutely IS one of the first rules of trading: reduce risk and protect capital. This man is one of the few real deals out there, he was a whale trading for institutions and himself for nearly 40 years and one of the few remaining first students of Dr. Andrews (Andrew’s pitchfork)until he retired. He has free Monday sessions that are worth every minute and that is where one can see it work. Now speaking of waiting to develop, yes, you may miss a few moves by his method but you will dramatically increase the odds of not getting whipsawed thereby protecting capital and reducing risk. He calls developing swings, pseudo swings but still uses them somewhat to see the structure developing, but until a swing is confirmed it simply is not a swing. So many times what many believe to be a swing will be a hicup and then the move continues on its original path drawing them into committing prematurely the wrong way. That’s the reason for confirmation. The confirmations allow you to see the pattern. The swings I’ve seen other people use may never alternate – they may have two or three swing highs in succession without a swing low to separate them. Now how can that be valid? Another site was saying, “if it looks like a swing high, it’s a swing high”. That’s quite cavalier. Such loose ways of trading separate the successful traders from the flashes that are in the pan. The details make the difference. I hate that it does because I have trouble being precise in my trading like many others, but I’ve seen the difference it makes. I hope that you do well however you trade, but please give it another thought.

  31. Dave Says:

    Prospectus, Hi again. I did you a disservice by not giving you the name of another article that should be read along with the other one I named. This one explains the swings and pseudo swings and how to use them much better with great examples. The article can be found in the same location http://www.medianline.com/articles/, and it’s titled: “Swing Highs and Swing Lows: Are We There Yet?”

  32. Jeff Says:

    Hi: I am new at Thinkscript and would like to know if you can help in
    duplicating the input price variable in the ZIGZAG study. I just want to have the curve go from the lower and to the high. As you know it actually does it but if you choose high it does not go to the very low of the candle at the other extreme

  33. Paul Says:

    Hi, How do I contact you for the download? Could you send it to my email address ? Thank you. Paul.

  34. Prospectus Says:

    Just click the donate button on the blog and I’ll send the password to you. Donate what you think the indicator is worth to you. Here’s the link if the button is hard to find:

    https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3232548

  35. BapiKapi Roy Says:

    Stop asking for free everything. Remember when someone writes code you got to honor and pay for his credit if he/she demands. Here this guy is not asking a hefty dollars for indicators, so why to whine. Other options are , It takes little effort to learn scripting from Thinkscript manual , instead of sitting on couch potato and watching sitcom.

  36. Roberta Zerbinato Says:

    Hi.. I made a second donation for your super cool H/L pivots. How do I get it now? Thanks! .

  37. Prospectus Says:

    Email me readtheprospectus at gmail

    >

  38. Kenneth Says:

    Hi Prospectus. Are you still there? Do you have the code for…
    * Swing High / Swing Low Indicator for Think or Swim
    *Update 2-18-10: v3–Added optional lines for plotting after the swing points:

    Does the actual source code come with it?

    Please let me know. Thank you.

  39. Prospectus Says:

    I’m still here. The code is for donors to the blog. The download link is here: https://sites.google.com/site/prospectus/welcome/released-thinkscript-studies/Pro_SwingPointsv3STUDY.zip?attredirects=0&d=1

    All the source code is included. TOS doesn’t support third party compiled code, so source is the only way it works.

    >

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: