<?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>ExcelTrader &#187; How to</title>
	<atom:link href="http://exceltrader.net/tag/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://exceltrader.net</link>
	<description>Excel Based Stock and Futures Trading tools.</description>
	<lastBuildDate>Wed, 11 Aug 2010 15:37:19 +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>Stochastics Indicator &#8211; Excel VBA and Formula versions</title>
		<link>http://exceltrader.net/506/stochastics-indicator-vba-and-formula-versions/</link>
		<comments>http://exceltrader.net/506/stochastics-indicator-vba-and-formula-versions/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 22:32:32 +0000</pubDate>
		<dc:creator>ExcelTrader</dc:creator>
				<category><![CDATA[Excel How to]]></category>
		<category><![CDATA[Free Excel/VBA based Indicators]]></category>
		<category><![CDATA[%D]]></category>
		<category><![CDATA[%K]]></category>
		<category><![CDATA[automated]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[filetype]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[stochastic]]></category>
		<category><![CDATA[stochastics]]></category>
		<category><![CDATA[stocks]]></category>
		<category><![CDATA[trading]]></category>
		<category><![CDATA[vba]]></category>

		<guid isPermaLink="false">http://www.exceltrader.net/?p=506</guid>
		<description><![CDATA[<p>This post includes  two example excel files that show both VBA and Formula based calculations for the indicator "Stochastics".</p>
<p>Both files contain the exact same set of Open High Low Close data. The formula based version should be easier to understand and serves as a way to verify that the VBA code that I wrote is <p>Continue reading <a href="http://exceltrader.net/506/stochastics-indicator-vba-and-formula-versions/">Stochastics Indicator &#8211; Excel VBA and Formula versions</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.exceltrader.net/wp-content/uploads/StochasticFormula.xls"></a>This post includes  two example excel files that show both VBA and Formula based calculations for the indicator "Stochastics".</p>
<p>Both files contain the exact same set of Open High Low Close data. The formula based version should be easier to understand and serves as a way to verify that the VBA code that I wrote is correct. Both methods give the same result for both %k and %D.  The major benefit of using VBA is that the parameters for Stochastics can be easily changed from the input boxes. In addition the VBA method shows only the final result rather than take up five columns.</p>
<p>The VBA based version can be downloaded <a href="http://www.exceltrader.net/wp-content/uploads/StochasticVBA.xls">here</a>.</p>
<p>The formula version can be downloaded <a href="http://www.exceltrader.net/wp-content/uploads/StochasticFormula.xls">here</a>. Below is an image of the formulas used in the formula based version.</p>
<p><a href="http://www.exceltrader.net/wp-content/uploads/StochasticFormula.gif"><img class="alignnone size-full wp-image-514" title="StochasticFormula" src="http://www.exceltrader.net/wp-content/uploads/StochasticFormula.gif" alt="StochasticFormula" width="1120" height="632" /></a></p>
<p>Below is the code that I wrote for the VBA based version.</p>
<p><font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> ETstochastic() <SPAN style="color:#007F00">'written by Exceltrader www.exceltrader.net</SPAN><br /><SPAN style="color:#00007F">Dim</SPAN> StochSetting <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, Ksetting <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, Dsetting <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br /><SPAN style="color:#00007F">Dim</SPAN> A() <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, B() <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, C() <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, D() <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, E() <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br /><SPAN style="color:#00007F">Dim</SPAN> Count <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br /><SPAN style="color:#00007F">Dim</SPAN> Xcounter <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, Xavg <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br /><SPAN style="color:#00007F">Dim</SPAN> Zcounter <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, Zavg <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br /><SPAN style="color:#00007F">Dim</SPAN> x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, y <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, z <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br /><SPAN style="color:#007F00">'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''</SPAN><br /><SPAN style="color:#007F00">''&#160;&#160;The below three lines are the Stochastic settings.</SPAN><br /><SPAN style="color:#007F00">''&#160;&#160;The Values can either be changed here or uncomment the inputbox lines to be prompted.</SPAN><br /><SPAN style="color:#007F00">'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''</SPAN><br />StochSetting = 14 <SPAN style="color:#007F00">'InputBox(Prompt:="Enter Stoch settings Number of Periods.", Title:="Stochastic Period", Default:="13")</SPAN><br />Ksetting = 2 <SPAN style="color:#007F00">'InputBox(Prompt:="Enter Moving Average For %K", Title:="%K Setting", Default:="5")</SPAN><br />Dsetting = 3 <SPAN style="color:#007F00">'InputBox(Prompt:="Enter Moving Average For %D", Title:="%D Setting", Default:="6")</SPAN><br />Set ws = ThisWorkbook.Worksheets("Svba")<br />&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">With</SPAN> ws<br />&#160;&#160;&#160;&#160;LR = .Cells(Rows.Count, "A").End(xlUp).Row<br /><SPAN style="color:#007F00">'does the same as formula =E15-(MIN(D1:D15))</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> DataRange <SPAN style="color:#00007F">In</SPAN> ws.Range(.Cells(2, "A"), .Cells(LR, "A"))<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Count = DataRange.Row<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">ReDim</SPAN> <SPAN style="color:#00007F">Preserve</SPAN> A(1 <SPAN style="color:#00007F">To</SPAN> Count)<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">If</SPAN> Count >= StochSetting + 1 <SPAN style="color:#00007F">Then</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; A(Count) = .Cells(Count, "E") - Application.Min(ws.Range(.Cells(Count - StochSetting, "D") _<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; , .Cells(Count, "D")))<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">Next</SPAN> DataRange<br />&#160;&#160;&#160;&#160; <SPAN style="color:#007F00">'does the same as formula&#160;&#160; =MAX(C36:C50)-MIN(D36:D50)</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> DataRange <SPAN style="color:#00007F">In</SPAN> ws.Range(.Cells(2, "A"), .Cells(LR, "A"))<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Count = DataRange.Row<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">ReDim</SPAN> <SPAN style="color:#00007F">Preserve</SPAN> B(1 <SPAN style="color:#00007F">To</SPAN> Count)<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">If</SPAN> Count >= StochSetting + 1 <SPAN style="color:#00007F">Then</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; B(Count) = Application.Max(ws.Range(.Cells(Count - StochSetting, "C"), .Cells(Count, "C"))) _<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; - Application.Min(ws.Range(.Cells(Count - StochSetting, "D"), .Cells(Count, "D")))<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">Next</SPAN> DataRange<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#007F00">'=100*(I50/J50)</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">ReDim</SPAN> <SPAN style="color:#00007F">Preserve</SPAN> C(StochSetting + 1 <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(B))<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">For</SPAN> Count = StochSetting + 1 <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(B)<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; C(Count) = (A(Count) / B(Count)) * 100<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">Next</SPAN> Count<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#007F00">'=AVERAGE(K49:K50)</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">ReDim</SPAN> <SPAN style="color:#00007F">Preserve</SPAN> D(StochSetting + Ksetting <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(B))<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">For</SPAN> Count = StochSetting + Ksetting <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(B)<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">For</SPAN> Xcounter = Count - Ksetting + 1 <SPAN style="color:#00007F">To</SPAN> Count <SPAN style="color:#007F00">'just go back and get the first C and go forward to current</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Xavg = C(Xcounter) + Xavg<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">Next</SPAN> Xcounter<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;D(Count) = Xavg / Ksetting<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Xavg = <SPAN style="color:#00007F">Empty</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">Next</SPAN> Count<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">ReDim</SPAN> <SPAN style="color:#00007F">Preserve</SPAN> E(StochSetting + Ksetting + Dsetting - 1 <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(B))<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">For</SPAN> Count = StochSetting + Ksetting + Dsetting - 1 <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(B)<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">For</SPAN> Zcounter = Count - Dsetting + 1 <SPAN style="color:#00007F">To</SPAN> Count <SPAN style="color:#007F00">'just go back and get the first C and go forward to current</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Zavg = D(Zcounter) + Zavg<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">Next</SPAN> Zcounter<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;E(Count) = Zavg / Dsetting<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Zavg = <SPAN style="color:#00007F">Empty</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<SPAN style="color:#00007F">Next</SPAN> Count<br />&#160;&#160;x = Empty: y = Empty: z = Empty<br />&#160;&#160;x = <SPAN style="color:#00007F">LBound</SPAN>(E)<br />&#160;&#160;y = <SPAN style="color:#00007F">UBound</SPAN>(E)<br />&#160;&#160;<SPAN style="color:#007F00">'put the stochastics on the workbook. Change column Letter as needed</SPAN><br />&#160;&#160;.Cells(x - 1, "J") = "%D"<br />&#160;&#160;.Cells(x - 1, "I") = "%K"<br />&#160;&#160;<SPAN style="color:#00007F">For</SPAN> z = x <SPAN style="color:#00007F">To</SPAN> y<br />&#160;&#160;.Cells(z, "J") = E(z)<br />&#160;&#160;.Cells(z, "I") = D(z)<br />&#160;&#160;<SPAN style="color:#00007F">Next</SPAN> z<br /> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br /><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<br /></FONT>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=@Exceltrader+Stochastics+Indicator+%E2%80%93+Excel+VBA+and+Formula+versions+http://tinyurl.com/3xejcq2" title="Post to Twitter"><img class="nothumb" src="http://exceltrader.net/wp-content/plugins/tweet-this/icons/tt-twitter-micro4.png" alt="Post to Twitter" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://exceltrader.net/506/stochastics-indicator-vba-and-formula-versions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
