<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ThinkScripter &#187; strategy</title>
	<atom:link href="http://www.thinkscripter.com/tag/strategy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thinkscripter.com</link>
	<description>thinkScript Indicators for thinkorswim</description>
	<lastBuildDate>Mon, 06 Sep 2010 19:13:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Vervoort Crossover Strategy and Analysis</title>
		<link>http://www.thinkscripter.com/analysis/vervoort-crossover-strategy-and-analysis/</link>
		<comments>http://www.thinkscripter.com/analysis/vervoort-crossover-strategy-and-analysis/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 23:00:46 +0000</pubDate>
		<dc:creator>ThinkScripter</dc:creator>
				<category><![CDATA[Analysis]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[strategy]]></category>
		<category><![CDATA[thinkscript]]></category>
		<category><![CDATA[vervoort]]></category>

		<guid isPermaLink="false">http://thinkscripter.wordpress.com/?p=908</guid>
		<description><![CDATA[Many of you asked for a method to backtest this study. It is a relatively simple matter to construct a thinkScript strategy from a study. Most of the code from any study can be copied straight across into your strategy. &#8230; <a href="http://www.thinkscripter.com/analysis/vervoort-crossover-strategy-and-analysis/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Many of you asked for a method to backtest this study. It is a relatively simple matter to construct a thinkScript <em><span style="color:#0000ff;">strategy</span></em> from a <em><span style="color:#0000ff;">study</span></em>. Most of the code from any study can be copied straight across into your strategy. You will need to declare the strategy mode with a <code><strong>declare</strong></code> statement with one of the following arguments:</p>
<p><code><strong>LONG_ENTRY; LONG_EXIT; SHORT_ENTRY; SHORT_EXIT</strong></code></p>
<p>Since you can&#8217;t plot anything from a strategy, all <code><strong>plot</strong></code> statements for variables that will be part of the strategy logic should be converted to <code><strong>def</strong></code> statements and their formatting commands removed. Other non-essential plot statements and associated formatting can be removed entirely. Your entire goal when creating a strategy is to define a binary condition that will trigger a trade. In this particular case we are looking for a moving average cross. I had already coded that into the study for use with the signal dots:</p>
<p><code style="text-align:left;"><strong>def buySignal = if TypicalPriceZeroLagTEMA > HeikinAshiZeroLagTEMA and TypicalPriceZeroLagTEMA[1] &lt;= HeikinAshiZeroLagTEMA[1] then 1 else 0;</strong></code></p>
<p>With this condition we can now add the other essential piece of code for strategies &#8211; the <code><strong>addOrder(condition,price)</strong></code> command:</p>
<p><code style="text-align:left;"><strong>addOrder(buySignal,open[-1]);</strong></code></p>
<p>Here you see the binary condition <code style="text-align:left;"><strong>buySignal</strong></code> entered as the trigger argument and the price is the next bar&#8217;s open, hence the [-1] indexing.</p>
<p>Strategies only work in pairs. You can have a Long Entry and Long Exit pair or a Long Entry and Short Entry pair etc. In this case I used a daily chart with six months of data to run the backtest. With proper money and stop management to minimize drawdowns this looks to be a viable strategy. Profit was $7400 on a single ES contract over the preceding six month period. Full results <a href="http://www.thinkscripter.com/wp-content/uploads/2009/03/vervoortstratreport.png">here</a>.<br />
<div id="attachment_907" class="wp-caption aligncenter" style="width: 640px"><a href="http://www.thinkscripter.com/wp-content/uploads/2009/03/vervoortstrat.png"><img src="http://www.thinkscripter.com/wp-content/uploads/2009/03/vervoortstrat.png" alt="Vervoort Crossover Strategy Analysis" title="vervoortstrat" class="size-full wp-image-907" /></a><p class="wp-caption-text">Vervoort Crossover Strategy Analysis</p></div></p>
<p>The Long Entry Code:</p>
<pre class="brush: thinkscript;">
declare LONG_ENTRY;

input period = 55;
def price = (high+low+close)/3;

def TMA1 = 3 * ExpAverage(price, period)
- 3 * ExpAverage(ExpAverage(price, period), period)
+ ExpAverage(ExpAverage(ExpAverage(price, period), period), period);

def TMA2 = 3 * ExpAverage(TMA1, period)
- 3 * ExpAverage(ExpAverage(TMA1, period), period)
+ ExpAverage(ExpAverage(ExpAverage(TMA1, period), period), period);

def difference = TMA1 - TMA2;
def TypicalPriceZeroLagTEMA = TMA1 + difference;

rec haopen = compoundValue(1, ((open[1] + high[1] + low[1] + close[1]) / 4
+ haopen[1]) / 2, hl2);
def haclose = ((open + high + low + close) / 4 + haopen + Max(high, haopen)
+ Min(low, haopen)) / 4;

def HATMA1 = 3 * ExpAverage(haclose, period)
- 3 * ExpAverage(ExpAverage(haclose, period), period)
+ ExpAverage(ExpAverage(ExpAverage(haclose, period), period), period);

def HATMA2 = 3 * ExpAverage(HATMA1, period)
- 3 * ExpAverage(ExpAverage(HATMA1, period), period)
+ ExpAverage(ExpAverage(ExpAverage(HATMA1, period), period), period);

def HAdifference = HATMA1 - HATMA2;
def HeikinAshiZeroLagTEMA = HATMA1 + HAdifference;

def buySignal = if TypicalPriceZeroLagTEMA &gt; HeikinAshiZeroLagTEMA
and TypicalPriceZeroLagTEMA[1] &lt;= HeikinAshiZeroLagTEMA[1] then 1 else 0;

addOrder(buySignal,open[-1]);
setColor(color.green);
</pre>
<p>The Short Entry Code:</p>
<pre class="brush: thinkscript;">
declare SHORT_ENTRY;

input period = 55;
def price = (high+low+close)/3;

def TMA1 = 3 * ExpAverage(price, period)
- 3 * ExpAverage(ExpAverage(price, period), period)
+ ExpAverage(ExpAverage(ExpAverage(price, period), period), period);

def TMA2 = 3 * ExpAverage(TMA1, period)
- 3 * ExpAverage(ExpAverage(TMA1, period), period)
+ ExpAverage(ExpAverage(ExpAverage(TMA1, period), period), period);

def difference = TMA1 - TMA2;
def TypicalPriceZeroLagTEMA = TMA1 + difference;

rec haopen = compoundValue(1, ((open[1] + high[1] + low[1] + close[1]) / 4
+ haopen[1]) / 2, hl2);
def haclose = ((open + high + low + close) / 4 + haopen + Max(high, haopen)
+ Min(low, haopen)) / 4;

def HATMA1 = 3 * ExpAverage(haclose, period)
- 3 * ExpAverage(ExpAverage(haclose, period), period)
+ ExpAverage(ExpAverage(ExpAverage(haclose, period), period), period);

def HATMA2 = 3 * ExpAverage(HATMA1, period)
- 3 * ExpAverage(ExpAverage(HATMA1, period), period)
+ ExpAverage(ExpAverage(ExpAverage(HATMA1, period), period), period);

def HAdifference = HATMA1 - HATMA2;
def HeikinAshiZeroLagTEMA = HATMA1 + HAdifference;

def sellSignal = if TypicalPriceZeroLagTEMA &lt; HeikinAshiZeroLagTEMA
and TypicalPriceZeroLagTEMA[1] &gt;= HeikinAshiZeroLagTEMA[1] then 1 else 0;

addOrder(sellSignal, open[-1]);
setColor(color.red);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thinkscripter.com/analysis/vervoort-crossover-strategy-and-analysis/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>
