EVOLUTION-MANAGER
Edit File: newTA.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Create A New TA Indicator For chartSeries</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for newTA {quantmod}"><tr><td>newTA {quantmod}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Create A New TA Indicator For chartSeries </h2> <h3>Description</h3> <p>Functions to assist in the creation of indicators or content to be drawn on plots produced by chartSeries. </p> <h3>Usage</h3> <pre> addTA(ta, order = NULL, on = NA, legend = "auto", yrange = NULL, ...) newTA(FUN, preFUN, postFUN, on = NA, yrange = NULL, legend.name, fdots = TRUE, cdots = TRUE, data.at = 1, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>ta</code></td> <td> <p> data to be plotted </p> </td></tr> <tr valign="top"><td><code>order</code></td> <td> <p> which should the columns (if > 1) be plotted </p> </td></tr> <tr valign="top"><td><code>legend</code></td> <td> <p> what custom legend text should be added to the chart. </p> </td></tr> <tr valign="top"><td><code>FUN</code></td> <td> <p> Main filter function name - as a symbol </p> </td></tr> <tr valign="top"><td><code>preFUN</code></td> <td> <p> Pre-filter transformation or extraction function </p> </td></tr> <tr valign="top"><td><code>postFUN</code></td> <td> <p> Post-filter transformation or extraction function </p> </td></tr> <tr valign="top"><td><code>on</code></td> <td> <p> where to draw </p> </td></tr> <tr valign="top"><td><code>yrange</code></td> <td> <p> length 2 vector of y-axis range </p> </td></tr> <tr valign="top"><td><code>legend.name</code></td> <td> <p> optional legend heading, automatically derived otherwise </p> </td></tr> <tr valign="top"><td><code>fdots</code></td> <td> <p> should any ... be included in the main filter call </p> </td></tr> <tr valign="top"><td><code>cdots</code></td> <td> <p> should any ... be included in the resultant function object. <code>fdots=TRUE</code> will override this to TRUE. </p> </td></tr> <tr valign="top"><td><code>data.at</code></td> <td> <p> which arguement to the main filter function is for data. </p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p> any additonal graphical parameters/default to be included. </p> </td></tr> </table> <h3>Details</h3> <p>Both <code>addTA</code> and <code>newTA</code> can be used to dynamically add custom content to a displayed chart. </p> <p><code>addTA</code> takes a series of values, either in a form coercible to <code>xts</code> or of the same length as the charted series has rows, and displays the results in either a new TA sub-window, or over/underlayed on the main price chart. If the object can be coerced to <code>xts</code>, the time values present must only be within the original series time-range. Internally a merge of dates occurs and will allow for the plotting of discontinuous series. </p> <p>The <code>order</code> argument allows for multiple column data to be plotted in an order that makes the most visual sense. </p> <p>Specifying a <code>legend</code> will override the standard parsing of the addTA call to attempt a guess at a suitable title for the sub-chart. Specifying this will cause the standard last value to <em>not</em> be printed. </p> <p>The ... arg to <code>addTA</code> is used to set graphical parameters interpretable by <code>lines</code>. </p> <p><code>newTA</code> acts as more of a skeleton function, taking functions as arguments, as well as charting parameters, and returns a function that can be called in the same manner as the built-in TA tools, such as <code>addRSI</code> and <code>addMACD</code>. Essentially a dynamic code generator that allows for highly customizable chart tools with minimal (possibly zero) coding. It is also possible to modify the resultant code to further change behavior. </p> <p>To create a new TA function with <code>newTA</code> certain arguments must be specified. </p> <p>The <code>FUN</code> argument is a function symbol (or coercible to such) that is the primary filter to be used on the core-data of a chartSeries chart. This can be like most of the functions within the <span class="pkg">TTR</span> package — e.g. RSI or EMA. The resultant object of the function call will be equal to calling the function on the original data passed into the chartSeries function that created the chart. It should be coercible to a matrix object, of one or more columns of output. By default all columns of output will be added to the chart, unless suppressed by passing the appropriately positioned <code>type='n'</code> as the ... arg. Note that this will not suppress the labels added to the chart. </p> <p>The <code>preFUN</code> argument will be called on the main chart's data prior to passing it to FUN. This must be a function symbol or a character string of the name function to be called. </p> <p>The <code>postFUN</code> argument will be called on the resultant data returned from the <code>FUN</code> filter. This is useful for extracting the relevant data from the returned filter data. Like <code>preFUN</code> it must be a function symbol or a character string of the name of the function to be called. </p> <p>The <code>yrange</code> argument is used to provide a custom scale to the y-axis. If <code>NULL</code> the min and max of the data to be plotted will be used for the y-axis range. </p> <p>The <code>on</code> is used to identify which subchart to add the graphic to. By default, <code>on=NA</code> will draw the series in a new subchart below the last indicator. Setting this to either a positive or negative value will allow for the series to be super-imposed on, or under, the (sub)chart specified, respectively. A value of 1 refers to the main chart, and at present is the only location supported. </p> <p><code>legend.name</code> will change the main label for a new plot. </p> <p><code>fdots</code> and <code>cdots</code> enable inclusion or suppression of the ... within the resulting TA code's call to <code>FUN</code>, or the argument list of the new TA function, respectively. In order to facilitate user-specified graphical parameters it is usually desireable to not impose artificial limits on the end-user with constraints on types of parameters available. By default the new TA function will include the dots argument, and the internal FUN call will keep all arguments, including the dots. This may pose issues if the internal function then passes those ... arguments to a function that can't handle them. </p> <p>The final argument is <code>data.at</code> which is the position in the <code>FUN</code> argument list which expects the data to be passed in at. This default to the sensible first position, though can be changed at the time of creation by setting this argument to the required value. </p> <p>While the above functions are usually sufficient to construct very pleasing graphical additions to a chart, it may be necessary to modify by-hand the code produced. This can be accomplished by dumping the function to a file, or using <code>fix</code> on it during an interactive session. </p> <p>Another item of note, with respect to <code>newTA</code> is the naming of the main legend label. Following addTA convention, the first ‘add’ is stripped from the function name, and the rest of the call's name is used as the label. This can be overridden by specifying <code>legend.name</code> in the construction of the new TA call, or by passing <code>legend</code> into the new TA function. Subtle differences exist, with the former being the preferred solution. </p> <p>While both functions can be used to build new indicators without any understanding of the internal chartSeries process, it may be beneficial in more complex cases to have a knowledge of the multi-step process involved in creating a chart via chartSeries. </p> <p>to be added... </p> <h3>Value</h3> <p><code>addTA</code> will invisibly return an S4 object of class <code>chobTA</code>. If this function is called interactively, the <code>chobTA</code> object will be evaluated and added to the current chart. </p> <p><code>newTA</code> will return a function object that can either be assigned or evaluated. Evaluating this function will follow the logic of any standard addTA-style call, returning invisibly a <code>chobTA</code> object, or adding to the chart. </p> <h3>Note</h3> <p>Both interfaces are meant to fascilitate custom chart additions. <code>addTA</code> is for adding any arbitrary series to a chart, where-as <code>newTA</code> works with the underlying series with the main chart object. The latter also acts as a dynamic TA skeleton generation tool to help develop reusable TA generation code for use on any chart. </p> <h3>Author(s)</h3> <p> Jeffrey A. Ryan </p> <h3>See Also</h3> <p><code><a href="chartSeries.html">chartSeries</a></code>, <code><a href="TA.html">TA</a></code>, <code><a href="chob-class.html">chob</a></code>, <code><a href="chobTA-class.html">chobTA</a></code> </p> <h3>Examples</h3> <pre> ## Not run: getSymbols('SBUX') barChart(SBUX) addTA(EMA(Cl(SBUX)), on=1, col=6) addTA(OpCl(SBUX), col=4, type='b', lwd=2) # create new EMA TA function newEMA <- newTA(EMA, Cl, on=1, col=7) newEMA() newEMA(on=NA, col=5) ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>quantmod</em> version 0.4.20 <a href="00Index.html">Index</a>]</div> </body></html>