Dear All,
I need some help with my SQL query... I am trying to build a SQL query with which I can calculate the so-called Average True Range (ATR) (-> http://stockcharts.com/help/doku.php?id=chart_school:technical_indicators:average_true_range_a).
I have a table which contains stock prices; the columns are Ticker, dDate, Open, High, Low, Close, Volume.
What I have done so far is a query which gives me four columns:
How do I have to adjust the code so that I do not only get the result for one date (i.e. dDate= dRefDate) but for let's say the last 60 trading days? Any ideas?
Diana
I need some help with my SQL query... I am trying to build a SQL query with which I can calculate the so-called Average True Range (ATR) (-> http://stockcharts.com/help/doku.php?id=chart_school:technical_indicators:average_true_range_a).
I have a table which contains stock prices; the columns are Ticker, dDate, Open, High, Low, Close, Volume.
What I have done so far is a query which gives me four columns:
- Ticker
- The current High less the current Low.
- The absolute value of the current High less the previous Close.
- The absolute value of the current Low less the previous Close.
Code:
dRefDate = #11/28/2008#
query1 = "SELECT Ticker, Abs(High-Low) AS HiLo, High, Low" & _
" FROM Data.txt" & _
" WHERE dDate=" & CDateSQL(dRefDate) & _
" GROUP BY Ticker, High-Low, High, Low"
query2 = "SELECT TOP 1 Ticker, Close AS CloseYday" & _
" FROM Data.txt" & _
" WHERE dDate<=" & CDateSQL(dRefDate) & _
" GROUP BY dDate, Ticker, Close" & _
" ORDER BY dDate DESC"
query3 = "SELECT Q1.Ticker, Q1.HiLo, Abs(Q1.High-Q2.CloseYday) AS ClHi, Abs(Q1.Low-Q2.CloseYday) AS ClLo" & _
" FROM (" & query1 & ") AS Q1 INNER JOIN (" & query2 & ") AS Q2" & _
" ON Q1.Ticker = Q2.Ticker"
How do I have to adjust the code so that I do not only get the result for one date (i.e. dDate= dRefDate) but for let's say the last 60 trading days? Any ideas?
Diana