Here is this month's selection of Traders' Tips, contributed by various developers of technical analysis software to help readers more easily implement some of the strategies presented in this and other issues. April 2008
TRADERS' TIPSYou can copy these formulas and programs for easy use in your spreadsheet or analysis software. Simply "select" the desired text by highlighting as you would in any word processing program, then use your standard key command for copy or choose "copy" from the browser menu. The copied text can then be "pasted" into any open spreadsheet or other software by selecting an insertion point and executing a paste command. By toggling back and forth between an application window and the open Web page, data can be transferred with ease.
This month's tips include formulas and programs for:
AMIBROKER: RSI BANDS
TRADESTATION: RSI BANDS
METASTOCK: RSI BANDS
WEALTH-LAB: RSI BANDS
eSIGNAL: RSI BANDS
NEUROSHELL TRADER: RSI BANDS
WORDEN BROTHERS Blocks: RSI BANDS
OMNITRADER: RSI BANDS
STRATASEARCH: RSI BANDS
AIQ: RSI BANDS
NINJATRADER: RSI BANDS
VT TRADER: RSI BANDS
SWINGTRACKER: RSI BANDSor return to April 2008 Contents
Editor's note: This month's Traders' Tips are based on François Bertrand's article in this issue, "RSI Bands." Code written in the AmiBroker formula language is already provided by Bertrand in the article's sidebars. Additional code is presented here.
Readers will find our Traders' Tips section in its entirety at the STOCKS & COMMODITIES website at www.Traders.com in the Traders' Tips area, from where the code can be copied and pasted into the appropriate program. In addition, the code for each program is usually available at the respective software company's website. Thus, no retyping of code is required for Internet users.
For subscribers, code found in François Bertrand's article can be copied and pasted into AmiBroker from the Subscriber Area at www.Traders.com. Login is required using your subscriber number (found on your magazine mailing label) and last name.
AMIBROKER: RSI BANDS
// RSI Bands use a variation of the RSI calculations to figure // out what price level a stock should be at to be considered // overbought/oversold. // // This sample code was built off the "BuiltInRSIEquivalent" // sample RSI calculation code found on the AmiBroker website. function BuiltInRSIEquivalent_RSI_Band_Version( period, TargetRSILevel ) { P = N = 0; result = Null; for( i = 1; i < BarCount; i++ ) { // Standard RSI code diff = C[ i ] - C[ i - 1 ]; W = S = 0; if( diff > 0 ) W = diff; if( diff < 0 ) S = -diff; // Compute the hypothetical price close to reach the // target RSI level based on yesterday's RSI and close // Depending on whether we would need the price to // or decrease, we use a different formula if(result[i-1] > C[i-1]) HypotheticalCloseToMatchRSITarget = C[i-1]+P-P*period-((N*period)-N) *TargetRSILevel/(TargetRSILevel -100); else HypotheticalCloseToMatchRSITarget = C[i-1]-N-P+N*period+P*period+(100*P) /TargetRSILevel-(100*P*period)/TargetRSILevel ; // Optional clamping code // Uncomment this section if parameters used cause // too much volatility (generally caused by using a very // short period) This will keep the RSI Bands within // roughly 10% of the price // if( (HypotheticalCloseToMatchRSITarget - C[i]) > 0.1*C[i]) // HypotheticalCloseToMatchRSITarget = C[i]*1.1; // if( (HypotheticalCloseToMatchRSITarget - C[i]) < - 0.1*C[i]) // HypotheticalCloseToMatchRSITarget = C[i]*0.9; // Resume standard RSI code to update the // running P and N averages P = ( ( period -1 ) * P + W ) / period; N = ( ( period -1 ) * N + S ) / period; // Store result if( i >= period ) result[ i ] = HypotheticalCloseToMatchRSITarget ; } return result; } Plot( BuiltInRSIEquivalent_RSI_Band_Version(14,70), "RSIB70", colorBlue ); Plot( BuiltInRSIEquivalent_RSI_Band_Version(14,30), "RSIB30", colorBlue );
--François Bertrand
TRADESTATION: RSI BANDSFrançois Bertrand's article in this issue, "RSI Bands," describes a visualization technique that allows the price required for a specific Rsi value to occur to be drawn on a chart. Bertrand includes an optional dampening scheme. Here is some EasyLanguage code for a function that calculates the RSI bands, both with and without dampening. The indicator, RSI Bands, calls the function and also plots the bands. See Figure 1 as a sample.
FIGURE 1: TRADESTATION, RSI BANDS INDICATOR. Here is a sample TradeStation chart of François Bertrand's RSI bands indicator applied to a daily chart of Alcoa, Inc. (AA). The RSI bands, without dampening, are the thick blue and red lines. The dampened RSI bands are the thinner yellow and cyan lines.
To download the EasyLanguage code for this study, go to the Support Center at TradeStation.com. Search for the file "Rsi_Bands.Eld."TradeStation does not endorse or recommend any particular strategy.
Indicator: RSI Bands inputs: RSILength( 14 ), OverSold( 30 ), OverBought( 70 ), PlotDampedLines( true ), Dampening( 0.1 ) ; variables: UpperBand( 0 ), LowerBand( 0 ), UpperBandDamp( 0 ), LowerBandDamp( 0 ) ; UpperBand = RSI_Band( RSILength, OverBought, 0 ) ; LowerBand = RSI_Band( RSILength, OverSold, 0 ) ; UpperBandDamp = RSI_Band( RSILength, OverBought, Dampening ) ; LowerBandDamp = RSI_Band( RSILength, OverSold, Dampening ) ; if CurrentBar >= RSILength then begin Plot1( UpperBand, "UpperBand" ) ; Plot2( LowerBand, "LowerBand" ) ; if PlotDampedLines then begin Plot3( UpperBandDamp, "UpperBndDamp" ) ; Plot4( LowerBandDamp, "LowerBndDamp" ) ; end ; end ; Function: RSI Band inputs: Period( numericsimple ), TargetRSILevel( numericsimple ), Dampening( numericsimple ) ; { set to 0 for undamped calculation } variables: CloseToMatchRSI( 0 ), W( 0 ), S( 0 ), P( 0 ), N( 0 ), Result( 0 ), Diff( 0 ) ; Diff = Close - Close[1] ; if Diff > 0 then begin W = Diff ; S = 0 ; end else if Diff < 0 then begin S = -Diff ; W = 0 ; end ; if RSI_Band[1] > Close[1] then CloseToMatchRSI = Close[1] + P - P * Period - ( ( N * Period ) - N ) * TargetRSILevel / ( TargetRSILevel - 100 ) else CloseToMatchRSI = Close[1] - N - P + N * Period + P * Period + ( 100 * P ) / TargetRSILevel - ( 100 * P * Period ) / TargetRSILevel ; if Dampening <> 0 then if CloseToMatchRSI - Close > Dampening * Close then CloseToMatchRSI = Close * ( 1 + Dampening ) else if CloseToMatchRSI - Close < -Dampening * Close then CloseToMatchRSI = Close * ( 1 - Dampening ) ; P = ( ( Period - 1 ) * P + W ) / Period ; N = ( ( Period - 1 ) * N + S ) / Period ; if CurrentBar >= Period then RSI_Band = CloseToMatchRSI ;
--Mark Mills
TradeStation Securities, Inc.
A subsidiary of TradeStation Group, Inc.
www.TradeStation.com
METASTOCK: RSI BANDSFrançois Bertrand's article, "RSI Bands," describes the calculation and use of these bands. The MetaStock formulas and instructions for adding it to MetaStock are as follows:
1. In the Tools menu, select Indicator Builder.
2. Click New to open the Indicator Editor for a new indicator.
3. Type the name of the formula: "RSI Bands"
4. Click in the larger window and type in the following formula:topv:=Input("overbought level",1,100,70); botv:=Input("oversold level",1,100,30); tp:=Input("RSI Time Periods",1,100,14); change:= ROC(C,1,$); Z:=Wilders(If(change>0,change,0),tp); Y:=Wilders(If(change<0,Abs(change),0),tp); tx:=(tp-1)*(Y*topv/(100-topv)-Z); bx:=(tp-1)*(Y*botv/(100-botv)-Z); tband:=If(tx>0,C+tx,C+tx*(100-topv)/topv); bband:=If(bx>0,C+bx,C+bx*(100-botv)/botv); tband; bband
5. Click OK to close the Indicator Editor.The article also makes reference to using "clamping" when volatility causes the bands to widen beyond a usable range. Here is the same indicator with the option to enable clamping at a variable range:
Name: RSI Bands with clamping Formula: topv:=Input("overbought level",1,100,70); botv:=Input("oversold level",1,100,30); tp:=Input("RSI Time Periods",1,100,14); clamp:=Input("use clamping 1=Yes/0=No",0,1,0); cper:= Input("clamping percent",5,50,10); change:= ROC(C,1,$); Z:=Wilders(If(change>0,change,0),tp); Y:=Wilders(If(change<0,Abs(change),0),tp); tx:=(tp-1)*(Y*topv/(100-topv)-Z); bx:=(tp-1)*(Y*botv/(100-botv)-Z); tb1:=If(tx>0,C+tx,C+tx*(100-topv)/topv); bb1:=If(bx>0,C+bx,C+bx*(100-botv)/botv); tband:=If(clamp=1 AND tb1>C*(1+cper/100),C*(1+cper/100),tb1); bband:=If(clamp=1 AND bb1<C*(1-cper/100),C*(1-cper/100),bb1); tband; bband--William Golson
Equis International
WEALTH-LAB: RSI BANDSA nice feature of Wealth-Lab Version 5.0 (.Net) is the ability to immediately employ new indicators in the Strategy Builder, formerly known as the ChartScript Wizard. As shown in Figure 2, the Strategy Builder's Conditions tab contains a group of rules for "General indicators." To access a rule for any indicator, drag and drop one of the general conditions on an entry or exit, and then click where indicated to select the desired indicator from the Indicators dialog.
You'll find technical indicators introduced by this magazine, such as the RsiBand, organized under the STOCKS & COMMODITIES magazine group of indicators (Figure 2).
FIGURE 2: WEALTH-LAB, RSI BANDS. This single-indicator, drag-and-drop strategy returned more than 5% annualized on the DJIA for the six years ending 12/31/2007. This assumes 5% of equity sizing, $8 commissions, 2% interest on free cash, and dividends as applicable.
WealthScript code: /* None! */--Robert Sucher
www.wealth-lab.com
eSIGNAL: RSI BANDSFor this month's tip, we've provided the eSignal formula named "Rsi_Bands.efs," based on the code from François Bertrand's article in this issue, "RSI Bands."
The study contains formula parameters that may be configured through the Edit Studies option in the Advanced Chart to change the number of periods, upper band, lower band, color, thickness, and clamping filter.
To discuss this study or download a complete copy of the formula, please visit the EFS Library Discussion Board forum under the Forums link at www.esignalcentral.com or visit our EFS KnowledgeBase at www.esignalcentral.com/support/kb/efs/.
The eSignal formula script (EFS) is also available for copying and pasting from the STOCKS & COMMODITIES website at www.Traders.com.
--Jason Keck
eSignal, a division of Interactive Data Corp.
800 815-8256, www.esignalcentral.com
/********************************* Provided By: eSignal (Copyright © eSignal), a division of Interactive Data Corporation. 2007. All rights reserved. This sample eSignal Formula Script (EFS) is for educational purposes only and may be modified and saved under a new file name. eSignal is not responsible for the functionality once modified. eSignal reserves the right to modify and overwrite this EFS file with each new release. Description: RSI Bands by Francois Bertrand Version: 1.0 2/5/2008 Notes: * April 2008 Issue of Stocks & Commodities Magazine * Study requires version 8.0 or later. Formula Parameters: Defaults: Periods 14 Upper Band 70 Lower Band 30 Band Color Blue Band Thickness 2 Enable Clamping false **********************************/ function preMain() { setPriceStudy(true); setStudyTitle("RSI Bands "); setCursorLabelName("RSIB70", 0); setCursorLabelName("RSIB30", 1); setShowTitleParameters(false); var fp1 = new FunctionParameter("nPeriods", FunctionParameter.NUMBER); fp1.setName("Periods"); fp1.setLowerLimit(0); fp1.setDefault(14); var fp2 = new FunctionParameter("nUpper", FunctionParameter.NUMBER); fp2.setName("Upper Band"); fp2.setLowerLimit(0); fp2.setDefault(70); var fp3 = new FunctionParameter("nLower", FunctionParameter.NUMBER); fp3.setName("Lower Band"); fp3.setLowerLimit(0); fp3.setDefault(30); var fp4 = new FunctionParameter("cColor", FunctionParameter.COLOR); fp4.setName("Band Color"); fp4.setDefault(Color.blue); var fp5 = new FunctionParameter("nThick", FunctionParameter.NUMBER); fp5.setName("Band Thickness"); fp5.setLowerLimit(1); fp5.setDefault(2); var fp6 = new FunctionParameter("bClamp", FunctionParameter.BOOLEAN); fp6.setName("Enable Clamping"); fp6.setDefault(false); } // Global Variables var bVersion = null; // Version flag var bInit = false; // Initialization flag var xUpperRSI = null; var xLowerRSI = null; function main(nPeriods, nUpper, nLower, cColor, nThick, bClamp) { var nState = getBarState(); var nIndex = getCurrentBarIndex(); if (bVersion == null) bVersion = verify(); if (bVersion == false) return; if (bInit == false) { setStudyTitle("RSI Bands (" + nPeriods + ", " + nUpper + ", " + nLower + ")"); setCursorLabelName("RSIB"+nUpper, 0); setCursorLabelName("RSIB"+nLower, 1); setDefaultBarFgColor(cColor, 0); setDefaultBarFgColor(cColor, 1); setDefaultBarThickness(nThick, 0); setDefaultBarThickness(nThick, 1); xUpperRSI = efsInternal("RSI_Band", nPeriods, nUpper, bClamp ); xLowerRSI = efsInternal("RSI_Band", nPeriods, nLower, bClamp ); bInit = true; } var nUpperRSI = xUpperRSI.getValue(0); var nLowerRSI = xLowerRSI.getValue(0); if (nUpperRSI == null || nLowerRSI == null) return; return new Array(nUpperRSI, nLowerRSI); } var result = null; var result_1 = null; var P = 0; var N = 0; var P_1 = 0; var N_1 = 0; function RSI_Band( period, TargetRSILevel, clamp ) { var diff = null; var HypotheticalCloseToMatchRSITarget = 0; var nState = getBarState(); if (nState == BARSTATE_NEWBAR) { result_1 = result; P_1 = P; N_1 = N; } if (close(-period) == null) return; var W = 0; var S = 0; var diff = close(0) - close(-1); if( diff > 0 ) W = diff; if( diff < 0 ) S = -diff; // Compute the hypothetical price close to reach the target RSI level // based on yesterdayís RSI and close // Depending on if we would need the price to increase or decrease, // we use a different formula if (result_1 != null && result_1 > close(-1)) { HypotheticalCloseToMatchRSITarget = close(-1)+P_1-P_1*period-((N_1*period)-N_1) *TargetRSILevel/(TargetRSILevel - 100); } else { HypotheticalCloseToMatchRSITarget = close(-1)-N_1-P_1+N_1*period+P_1*period+(100*P_1) /TargetRSILevel -(100*P_1*period)/TargetRSILevel; } if (clamp == true) { // Optional clamping code // Enable the clamping option in Edit Studies if parameters used cause too much volatility. // (generally caused by using a very short period) This will keep the RSI Bands // within roughly 10% of the price if ( (HypotheticalCloseToMatchRSITarget - close(-1)) > 0.1*close(-1)) { HypotheticalCloseToMatchRSITarget = close(-1)*1.1; } else if ( (HypotheticalCloseToMatchRSITarget - close(-1)) < -0.1*close(-1)) { HypotheticalCloseToMatchRSITarget = close(-1)*0.9; } // Resume standard RSI code to update the running P and N averages } P = ( ( period -1 ) * P_1 + W ) / period; N = ( ( period -1 ) * N_1 + S ) / period; if (getCurrentBarCount() >= period) { result = HypotheticalCloseToMatchRSITarget; return result; } else { return null; } } function verify() { var b = false; if (getBuildNumber() < 779) { drawTextAbsolute(5, 35, "This study requires version 8.0 or later.", Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT, null, 13, "error"); drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=https://www.esignal.com/download/default.asp", Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT, null, 13, "upgrade"); return b; } else { b = true; } return b; }
NEUROSHELL TRADER: RSI BANDSThe RSI bands indicator described by François Bertrand in his article in this issue can be easily implemented in NeuroShell Trader using NeuroShell Trader's ability to program functions in standard languages such as C, C++, Power Basic or Delphi. You can recreate the Rsi band indicator by moving the AmiBroker code given in the article -- which has the same syntax as the C programming language -- to your preferred compiler and creating the corresponding function. You can insert the resulting indicator into NeuroShell Trader as follows:
1. Select "New Indicator …" from the Insert menu.
2. Choose the RSI Bands indicator category.
3. Select the RSI Bands indicators.
4. Select the Finished button.
A sample chart is shown in Figure 3. FIGURE 3: NEUROSHELLS, RSI BANDS. Here is a NeuroShell Trader chart that shows the RSIBand indicators along with the traditional RSI.Users of NeuroShell Trader can go to the STOCKS & COMMODITIES section of the NeuroShell Trader free technical support website to download a copy of this or any previously published Traders' Tips.For more information on NeuroShell Trader, visit www.NeuroShell.com.
--Marge Sherald, Ward Systems Group, Inc.
301 662-7950, sales@wardsystems.com
www.neuroshell.com
WORDEN BROTHERS BLOCKS: RSI BANDSTo use the RSI bands indicator, you will need the free Blocks software. Go to www.Blocks.com to download the software and get detailed information on the available data packs.
To load the RSI bands indicator described in the article by François Bertrand titled, "Visual Variation On An Index: Rsi Bands," open Blocks, then click the Indicators button. Type in "RSI bands" to filter the list, then click and drag "RSI bands" to the price plot and release the mouse. The default settings use an RSI period of 15 and overbought and oversold levels of 70 and 30, respectively. You can edit these settings using the QuickEdit menu.
For more information and to view Blocks tutorial videos, go to www.Blocks.com.
--Bruce Loebrich and Patrick Argo
Worden Brothers, Inc.
OMNITRADER: RSI BANDSThis month's tip is based on François Bertrand's article in this issue, "RSI Bands." Here, we'll provide an RSI band indicator and code for the standard RSI. The first file, "RsiBand.txt," calculates the closing price necessary to cause the RSI to cross its target (usually 30 or 70). The plot forms an upper or a lower band depending on the target.
By default, OmniTrader uses a slightly modified RSI calculation. For this reason, the StdRsi indicator should be used when using the RSI bands indicator. In addition, viewing the source for "StdRsi.txt" will provide some insight as to the inner workings of the indicator.
Figure 4 shows a plot of Applied Materials alongside the RSI-based indicators.
FIGURE 4: WORDEN BLOCKS, RSI BANDS. Here are the RSI bands plotted on a price chart with the traditional RSI plotted below the price chart for comparison.To use the indicator, first copy the files "RsiBands.txt" and "StdRsi.txt" to C:\Program Files\Nirvana\OT2008\VBA\ Indicators. Next, open OmniTrader and click Edit: OmniLanguage. You should see the RsiBands and StdRsi in the Project Pane. Click compile. Now the code is ready to use. FIGURE 5: OMNITRADER, RSI BANDS. Here's a daily price chart of AMAT with an upper (70) and lower (30) RSI band plotted. Band crossovers are reflected in the RSI plot below the price pane.For more information and complete source code, visit https://www.omnitrader.com/ProSI.
#Indicator '************************************************************** '* RSI Bands Indicator (RSIBands.txt) '* by Jeremy Williams '* Feb. 12, 2008 '************************************************************** #Param "Period",14 #Param "TargetRSI",30 Dim Gain As Single Dim Loss As Single Dim Diff As Single Dim P As Single Dim N As Single Dim HCTMRSIT As Single 'Hypothetical Close to match RSI Target ' Calculate the gains and losses Diff = c - c[1] Gain = IIF(Diff > 0 , Diff, 0) Loss = IIF(Diff < 0, 0 - Diff,0) ' Calculate the value of the band If HCTMRSIT[1] > c[1] Then HCTMRSIT = C[1] + P[1] - P[1]*Period - ((N[1]*Period)-N[1])*TargetRSI/(TargetRSI - 100) Else HCTMRSIT = C[1] - N[1] - P[1] + N[1]*Period + P[1]*Period + (100*P[1])/TargetRSI - (100*P[1]*Period)/TargetRSI End If ' Update the averages for tommorrow's calculation P = ((Period-1)*P[1] + Gain)/Period N = ((Period-1)*N[1] + Loss)/Period 'Plot The Band PlotPrice("RSI Band", HCTMRSIT) ' Return the value calculated by the indicator Return HCTMRSIT #Indicator '************************************************************** '* Standard RSI Indicator (StdRSI.txt) '* by Jeremy Williams '* Feb. 12, 2008 '************************************************************** #Param "Period",14 Dim Diff As Single Dim Gain As Single Dim Loss As Single Dim N As Single Dim P As Single Dim myRS As Single Dim myRSI As Single ' Calculate the gains and losses Diff = C - C[1] Gain = IIF( Diff > 0 , Diff, 0) Loss = IIF (Diff < 0 , 0 - Diff, 0) ' Calculate the averages N = (N[1]*(Period-1) + Gain ) / Period P = (P[1]*(Period-1) + Loss ) / Period ' Calculate the RSI myRS = N/P myRSI = 100 - 100/(1+myRS) ' Plot the RSI SetScales(0,100) Plot("RSI",myRSI) PlotLabel(30) PlotLabel(70) ' Return the value calculated by the indicator Return myRSI
--Jeremy Williams, Trading Systems Researcher
Nirvana Systems, Inc.
www.omnitrader.com
www.nirvanasystems.com
STRATASEARCH: RSI BANDSIn "RSI Bands" in this issue, François Bertrand has given us a new and creative way to implement the relative strength index. Indeed, there are times when it's most helpful to see the signal line overlaid on the price chart, and this new approach allows us to do that quite well (Figure 6).
FIGURE 6: STRATASEARCH, RSI BANDS. The RSI bands provide signals that are similar to those given by the relative strength index, but they can be viewed more easily alongside price.
To compare the old and new RSI versions, we ran about 2,500 parameter combinations for each against the NASDAQ 100 sector of 100 symbols. The results between the new RsiB and traditional RSI versions were roughly identical, confirming that the RSI bands are a comparable approach. From a trading system perspective, it's important to note that the relative strength index can create very long holding periods when waiting for a stock to become overbought. For this reason, the use of supporting indicators alongside the RSI or RSI bands can be immensely helpful.As with all other StrataSearch Traders' Tips, additional information, including plug-ins, can be found in the Shared Area of the StrataSearch user forum. This month's plug-in contains a number of prebuilt trading rules that will allow you to include this indicator in your automated searches. Simply install the plug-in and let StrataSearch identify which supporting indicators might be helpful.
//************************************************************************************ // RSI BANDS //************************************************************************************ RSIBANDVERSION_API int RSIB(Prices *pPrices, Values *pResults, int nTotDays, Values *pValue1, Values *pValue2, Values *pValue3) { double P = 0; double N = 0; int i; int period; int unclamp; double TargetRSILevel; double diff; double W, S; double HypotheticalClose; period = (int) pValue1->dValue; TargetRSILevel = pValue2->dValue; unclamp = (int) pValue3->dValue; pResults[0].dValue = 0; pResults[0].chIsValid = 0; for( i = 1; i < nTotDays; i++ ) { // Standard RSI code diff = pPrices[i].dClose - pPrices[i-1].dClose; W = S = 0; if( diff > 0 ) W = diff; if( diff < 0 ) S = -diff; // Compute the hypothetical price if(pResults[i-1].dValue > pPrices[i-1].dClose) HypotheticalClose=pPrices[i-1].dClose+P-P*period- ((N*period)-N)*TargetRSILevel/(TargetRSILevel-100); else HypotheticalClose=pPrices[i-1].dClose-N-P+N*period+P*period+ (100*P)/TargetRSILevel-(100*P*period)/TargetRSILevel ; // Optional clamping code if(unclamp) { if((HypotheticalClose-pPrices[i].dClose)>0.1*pPrices[i].dClose) HypotheticalClose=pPrices[i].dClose*1.1; if((HypotheticalClose-pPrices[i].dClose)<-0.1*pPrices[i].dClose) HypotheticalClose=pPrices[i].dClose*0.9; } // Resume standard RSI code to update the running P and N averages P = ((period-1) * P + W) / period; N = ((period-1) * N + S) / period; // Store result if( i >= period ) { pResults[i].dValue = HypotheticalClose; pResults[i].chIsValid = 'Y'; } else { pResults[i].dValue = 0; pResults[i].chIsValid = 0; } } return 0; }
--Pete Rast
Avarin Systems Inc
www.StrataSearch.com
AIQ: RSI BANDSThe AIQ code for François Bertrand's article in this issue, "RSI Bands," is shown here. Figure 7 shows the unclamped RSI bands in green and magenta versus the standard Bollinger bands in red. The clamped mode can be switched on by changing the "clamp" input to a "1" (it is currently set to zero) in the EDS code file, or by plotting each type of indicator separately as individual single line indicators.
FIGURE 7: AIQ, RSI BANDS. Here is an example of unclamped RSI bands (upper in green, lower in magenta) compared to Bollinger bands (in red) with the 14-period RSI for KBH.
This code can be downloaded from the AIQ website at www.aiqsystems.com and also from www.tradersedge systems.com/traderstips.htm.
! RSI BANDS ! Author: Francois Bertrand, TASC April 2008 ! Coded by Richard Denning 02/11/08 ! ABBREVIATIONS: C is [close]. C1 is valresult(C,1). ! INPUTS: period is 14. upTgt is 70. dnTgt is 30. clamp is 0. ! 1=use clamping; <>1=do not use clamping !! RSI WILDER (standard RSI code for three different length RSI indicators): ! To convert Wilder Averaging to Exponential Averaging: ! ExponentialPeriods = 2 * WilderPeriod - 1. U is C - C1. D is C1 - C. W1 is period. L1 is 2 * W1 - 1. avgU is ExpAvg(iff(U>0,U,0),L1). avgD is ExpAvg(iff(D>=0,D,0),L1). rsi is 100-(100/(1+(AvgU/AvgD))). ! RSI BAND CODE STARTS HERE: avgU1 is valresult(AvgU,1). avgD1 is valresult(AvgD,1). upFact is 100 / (100 - upTgt) - 1. dnFact is 100 / (100 - dnTgt) - 1. ! UPPER AND LOWER VALUES WITHOUT CLAMPING: upRSIr is C1 + (upFact * avgD1*(period-1) - avgU1*(period-1)). dnRSIr is C1 - (avgU1*(period-1)/dnFact - avgD1*(period-1)). ! OPTIONAL CLAMPING MODE: upRSIc is max(min(upRSIr, C1*1.1),max(dnRSIr, C1*0.9)). dnRSIc is min(max(dnRSIr, C1*0.9),min(upRSIr, C1*1.1)). ! PLOT AS SINGLE LINE INDICATOR IN CHART PANEL-UPPER RSI BAND upRSI is iff(clamp=1,upRSIc,upRSIr). ! PLOT AS SINGLE LINE INDICATOR IN CHART PANEL-LOWER RSI BAND dnRSI is iff(clamp=1,dnRSIc,dnRSIr).
--Richard Denning, AIQ Systems
richard.denning@earthlink.net
NINJATRADER: RSI BANDSThe RSI bands indicator as discussed by François Bertrand in his article in this issue, "Visual Variation On An Index: RSI Bands," is available for download from www.ninjatrader.com/SC/April2008SC.zip.
Once it's downloaded, from within the NinjaTrader Control Center window, select the menu File > Utilities > Import NinjaScript, and select the downloaded file. This indicator is for NinjaTrader Version 6.5 or greater.
You can review the indicator's source code by selecting the menu Tools > Edit NinjaScript > Indicator from within the NinjaTrader Control Center window and selecting "RSIBands." See Figure 8 for a sample.
FIGURE 8: NINJATRADER, RSI BANDS. This screenshot shows the RSI bands indicator on a one-minute chart of the March 2008 S&P emini contract.NinjaScript indicators are compiled DLLs that run native, not interpreted, which provides you with the highest performance possible.--Raymond, NinjaTrader, LLC
www.ninjatrader.com
VT TRADER: RSI BANDSFor this month's Traders' Tip, we will recreate the RSI bands indicator as described by François Bertrand in his article, "Visual Variation On An Index: RSI Bands." The RSI bands trace RSI overbought and oversold levels directly over price data. This makes it easier to visualize and associate data with the price and market trends as the standard RSI indicator is analyzed in a separate window.
In addition, according to Bertrand, "RSI bands open up new analysis possibilities, as the RSI can now be analyzed and mixed with other price-based indicators such as Bollinger Bands and even moving averages."
The VT Trader code and instructions for recreating the RSI bands indicator are as follows:
RSI Bands Indicator 1. Navigator Window>Tools>Indicator Builder>[New] button 2. In the Indicator Bookmark, type the following text for each field: Name: TASC - 04/2008 - RSI Bands Short Name: vt_RsiBands Label Mask: TASC - 04/2008 - RSI Bands (RSI: %price%,%periods% | RSI Target Levels: %TargetRSIOBLevel%,%TargetRSIOSLevel% | Band Clamping Enabled: %ClampingLogic:ls%) Placement: Price Frame Inspect Alias: RSI Bands 3. In the Input Bookmark, create the following variables: [New] button... Name: price, Display Name: RSI Price , Type: price , Default: close [New] button... Name: periods , Display Name: RSI Periods , Type: integer , Default: 14 [New] button... Name: TargetRSIOBLevel , Display Name: Target RSI OverBought Level , Type: integer , Default: 70 [New] button... Name: TargetRSIOSLevel , Display Name: Target RSI OverSold Level , Type: integer , Default: 30 [New] button... Name: ClampingLogic , Display Name: Enable Band "Clamping"? , Type: Enumeration , Select [..] Button -> Select [New] Button -> Type "No" (without the quotes) -> Select [New] Button -> Type "Yes" (without the quotes) -> Select [OK] Button -> Default: No 4. In the Output Bookmark, create the following variables: [New] button... Var Name: DisplayHypotheticalCloseToMatchRSIOBTarget Name: (RSI OB Band) Line Color: red Line Width: thin Line Type: dashed [New] button... Var Name: DisplayHypotheticalCloseToMatchRSIOSTarget Name: (RSI OS Band) Line Color: red Line Width: thin Line Type: dashed 5. In the Formula Bookmark, copy and paste the following formula: {Provided By: Visual Trading Systems, LLC & Capital Market Services, LLC (c) Copyright 2008} {Description: RSI Bands Indicator} {Notes: T.A.S.C., April 2008 - "Visual Variation On An Index - RSI Bands" by François Bertrand} {vt_RsiBands Version 1.0} {Calculate Relative Strength Index (RSI)} diff:= price - ref(price,-1); _W:= if(diff>0, diff, 0); _S:= if(diff<0, -diff, 0); _P:= ((periods - 1) * PREV(0) + _W) / periods; _N:= ((periods - 1) * PREV(0) + _S) / periods; _RSI:= if(BarCount()>=periods, 100 * _P / (_P + _N), NULL); {Calculate RSI OverBought and OverSold Price Bands} HypotheticalCloseToMatchRSIOBTarget:= if(ref(_RSI,-1)>ref(price,-1), ref(price,-1) + _P - _P * periods - ((_N * periods) - _N) * TargetRSIOBLevel / (TargetRSIOBLevel - 100), ref(price,-1) - _N - _P + _N * periods + _P * periods + (100 * _P) / TargetRSIOBlevel - (100 * _P * periods) / TargetRSIOBLevel); HypotheticalCloseToMatchRSIOSTarget:= if(ref(_RSI,-1)>ref(price,-1), ref(price,-1) + _P - _P * periods - ((_N * periods) - _N) * TargetRSIOSLevel / (TargetRSIOSLevel - 100), ref(price,-1) - _N - _P + _N * periods + _P * periods + (100 * _P) / TargetRSIOSLevel - (100 * _P * periods) / TargetRSIOSLevel); {Calculate Additional "Clamping" Code for RSI Bands} {Certain input parameter values may cause too much volatility of the bands. This optional logic keeps the RSI Bands within roughly 10% of the price. It should be noted, however, that when dealing with FX currency pair instruments, this additional band clamping logic may never be utilized.} DisplayHypotheticalCloseToMatchRSIOBTarget:= if(ClampingLogic=1 AND ((HypotheticalCloseToMatchRSIOBTarget - price) > (0.1 * price)), (price * 1.1), if(ClampingLogic=1 AND ((HypotheticalCloseToMatchRSIOBTarget - price) < (-0.1 * price)), (price * 0.9), HypotheticalCloseToMatchRSIOBTarget)); DisplayHypotheticalCloseToMatchRSIOSTarget:= if(ClampingLogic=1 AND ((HypotheticalCloseToMatchRSIOSTarget - price) > (0.1 * price)), (price * 1.1), if(ClampingLogic=1 AND ((HypotheticalCloseToMatchRSIOSTarget - price) < (-0.1 * price)), (price * 0.9), HypotheticalCloseToMatchRSIOSTarget)); 7. Click the Save icon to finish building the Rsi bands indicator.
To attach the indicator to a chart, click the right mouse button within the chart window and then select "Add Indicators" -> "TASC - 04/2008 ? RSI Bands" from the indicator list.A sample figure is shown in Figure 9.
FIGURE 9: VT TRADER, RSI BANDS. Here are the RSI bands (red) and Bollinger Bands (green) displayed over a EUR/USD 30-minute candle chart along with the RSI shown in a separate frame below the price frame.To learn more about VT Trader, please visit www.cmsfx.com.? Chris Skidmore
CMS Forex
(866) 51-CMSFX, trading@cmsfx.com
www.cmsfx.com
SWINGTRACKER: RSI BANDSThe RSI bands overlay, as discussed in the article "Rsi Bands" by François Bertrand in this issue, has now been introduced in SwingTracker 5.13.088 for Windows/Mac/Linux. A sample chart is shown in Figure 10. The parameters for this indicator are shown in the preferences window.
FIGURE 10: SWINGTRACKER, RSI BANDS. Here are François Bertrand's RSI bands overlay in SwingTracker, along with the indicator parameters.To discuss these tools, please visit our user forum at forum.mrswing.com. If you need assistance, our development staff can help at support.mrswing.com.For more information or for a free trial, visit www.swingtracker.com.
--Larry Swing
+1 (281) 968-2718 , theboss@mrswing.com
www.mrswing.com
GO BACK
Return to April 2008 Contents
Originally published in the April 2008 issue of Technical Analysis of STOCKS & COMMODITIES magazine. All rights reserved. © Copyright 2008, Technical Analysis, Inc.