Trade Zones

One of our forum members asked today for a means to programatically draw vertical lines in TOS. Unfortunately, yet another monthly build has gone by and still no means to draw vertical lines from within thinkScript. Yes there is a new handy drawing tool but I have no desire to spend time redrawing the same lines/boxes on a chart day after day. I decided to take matters into my own hands and coax a workable solution out of thinkScript. Trade Zones just puts up either a red or green box around any time you designate in the study properties. There is a selection for “NOTRADE” – translation red box, or “REVERSAL” – translation green box. Just pick one and put the starting and ending time Eastern and it will appear on your chart every day. In the image I have five separate instances of the study: three no-trade zones, and two reversal-zones. Also pictured are the ThinkScripter MultiStops (Fibonacci:1.23) and ThinkScripter RollingPivots (60 minutes).

Trade Zones

Trade Zones

# TS_TRADEZONES
# http://www.thinkscripter.com
# thinkscripter@gmail.com
# Last Update 30 JUN 2009

input zoneStart = 1500;
input zoneEnd = 1615;
input type = {default NOTRADE, REVERSAL};
plot highBar;
plot lowBar;

switch (type){

case NOTRADE:
highBar = if secondsTillTime(zoneStart) <= 0 and secondsTillTime(zoneEnd) >= 0 then highestAll(high) else double.nan;
lowBar = if secondsTillTime(zoneStart) <= 0 and secondsTillTime(zoneEnd) >= 0 then lowestAll(low) else double.nan;
case REVERSAL:
lowBar = if secondsTillTime(zoneStart) <= 0 and secondsTillTime(zoneEnd) >= 0 then highestAll(high) else double.nan;
highBar = if secondsTillTime(zoneStart) <= 0 and secondsTillTime(zoneEnd) >= 0 then lowestAll(low) else double.nan;
}
highBar.assignValueColor(if highBar>lowBar then color.dark_red else color.green);
lowBar.assignValueColor(if highBar>lowBar then color.dark_red else color.green);
addCloud(lowBar, highBar);
This entry was posted in Indicator and tagged , , . Bookmark the permalink.

11 Responses to Trade Zones

  1. Adam says:

    That’s a nice bit of lateral thinking … vertically.

    That’s a spooky looking charts. Gives me a couple of ideas:

    A new twist on seasonal charts: Halloween.

    It also has a sort of “virtual reality” (is VR such a household term now that it doesn’t need quotes?) which is my hot topic these days. I’m pretty sure the next release of thinkScript will include animated fly-through interactive charts with guns and bombs instead of capital and contracts!

    Yippee-ki-aye Mother … friendster … (I’ll keep it family friendly for all those young thinkScripters out there in thinkScriptLand.)

  2. Asimov says:

    Why couldn’t you use this to draw vertical lines?

    Just draw the shaded area some fraction of the width of a single candle. Thinking 1/4 or 1/2 of the width.

    I may steal this idea for that very reason sometime soon, hope you don’t mind. :)

    • Asimov,
      I think you misunderstood my post. I was referring to the native inability to draw a vertical line from within thinkScript through the use of some built-in function call. What you suggest IS why I wrote this study :)
      Eric

  3. Prospectus says:

    That’s a great use of add cloud! Well done.

    You can actually get three different colors with add cloud: Green if plot1 is above plot2, red if plot1 is below plot2, and orange if you plot both a green and a red at the same time.

    Now I wish ToS would let us draw trendlines programmatically…

  4. Mark says:

    I like your box but it doesn’t scale very good. It’s using a high and low to draw the height of the box. As you lower the time frame the box size remains but this forces the candles to shrink. What change would be required to draw the box using each time spans high and low?

  5. Mark,
    It’s not the study it’s your settings in TOS. Go to your style settings panel and turn off “Fit studies to screen.”
    Eric :)

  6. Sam says:

    This is great! I start Forex trading at 06:00 GMT and this will help my sleepy eyes find the start of each day. Just what I needed, but I didn’t know I was looking for it, until I found it.

    Thanks!

  7. Micky says:

    Pretty good trade zone indicator. And very easy to adjust parameters. But one thing I have noticed. This indicator really slows TOS down to a halt. It makes the charts lag when I pan/move the chart, draw fibs, edit studies, etc…..When I take this study off, my charts are lightening fast. But added back on, it slows the chart down to unacceptable slow speeds. I know its just not me, but have a few friends that have experienced this as well. Maybe its the “painted cloud’ coding in TOS that just slows down the chart. Any work around this? THANKS!

    • Micky,
      I haven’t had these on my charts for a while but will give them another look. The code itself is pretty basic so I don’t know why it would bog TOS down. Peculiar to say the least.
      -Eric

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>