TRADERS’ TIPS

August 2012

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.

Other code appearing in articles in this issue is posted in the Subscriber Area of our website at http://technical.traders.com/sub/sublogin.asp. Login requires your last name and subscription number (from mailing label). Once logged in, scroll down to beneath the “Optimized trading systems” area until you see “Code from articles.” From there, code can be copied and pasted into the appropriate technical analysis program so that no retyping of code is required for subscribers.

You 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.

article thumbnail

For this month’s Traders’ Tips, the focus is Giorgos Siligardos’ article in this issue, “Applying The Sector Rotation Model.”

Code for MetaStock is already provided in Siligardos’s article. Subscribers will find this code in the Subscriber Area of our website, Traders.com. (Click on “Article Code” from our homepage.) Presented here is additional code and possible implementations for other software.


logo

TRADESTATION, SECTOR ROTATION MODEL (SRM)

In the article “Applying The Sector Rotation Model” in this issue, author Giorgos Siligardos describes the use of several sector ETFs to calculate a sector rotation indicator based on several sectors. Siligardos suggests the indicator can be used to aid in analyzing stock index charts by providing a macro view of the economic cycle. The article provides examples of how the indicator can be used in this analysis.

Provided here is some indicator code for the sector rotation indicator (_SRMInd). This code utilizes multiple data streams in the chart. See the code for the data stream setup.

_SRMind ( Indicator )

{ TASC - August 2012 }
{ Applying the Sector Rotation Model }
{ Giorgos E. Siligardos, PhD }

{ 
Chart setup of data streams:
	Data1 = Stock Index
	Data2 = XLY
	Data3 = XLF
	Data4 = XLE
	Data5 = XLU
	Data6 = XLP
}

inputs:
	ROCLength( 75 ), { Rate of Change Length }
	AboveZeroColor( Green ),
	BelowZeroColor( Red ) ; 

variables:
	Bull01( 0, Data2 ), { XLY }
	Bull02( 0, Data3 ), { XLF }
	Bear01( 0, Data4 ), { XLE }
	Bear02( 0, Data5 ), { XLU }
	Bear03( 0, Data6 ), { XLP }
	Bear( 0 ),
	Bull( 0 ),
	Osc( 0 ) ;

once
	begin
	if  BarType <> 2 or 
		BarType of Data2 <> 2 or
 		BarType of Data3 <> 2 or
		BarType of Data4 <> 2 or 
		BarType of Data5 <> 2 or
		BarType of Data6 <> 2
	then
		RaiseRunTimeError( "This indicator is " +
			"designed for Daily bars in all data " +
			"streams." ) ;

	if Symbol of Data2 <> "XLY" then
		RaiseRunTimeError( "Data2 Symbol " +
			"should be XLY." ) ;
	
	if Symbol of Data3 <> "XLF" then
		RaiseRunTimeError( "Data3 Symbol " +
			"should be XLF." ) ;
	
	if Symbol of Data4 <> "XLE"  then
		RaiseRunTimeError( "Data4 Symbol " +
			"should be XLE." ) ;
			
	if Symbol of Data5 <> "XLU" then
		RaiseRunTimeError( "Data5 Symbol " +
			"should be XLU." ) ;				
	
	if Symbol of Data6 <> "XLP" then
		RaiseRunTimeError( "Data6 Symbol " +
			"should be XLP." ) ;
	end ;

{ Calculate Rate of Change }
Bull01 = RateofChange( Close of Data2, ROCLength )
 of Data2 ;
Bull02 = RateofChange( Close of Data3, ROCLength )
 of Data3 ;
Bear01 = RateofChange( Close of Data4, ROCLength )
 of Data4 ;
Bear02 = RateofChange( Close of Data5, ROCLength )
 of Data5 ;
Bear03 = RateofChange( Close of Data6, ROCLength )
 of Data6 ;

{ Calculate Averages }
Bear = ( Bear01 + Bear02 + Bear03 ) / 3 ;
Bull = ( Bull01 + Bull02 ) * 0.5 ;

{ Calculate Oscillator }
Osc = 100 * ( Bull - Bear ) ;

Plot1( Osc, "SRM Osc" ) ;
Plot2( 0, "Zero" ) ;

if Osc >= 0 then
	SetPlotColor( 1, AboveZeroColor )
else
	SetPlotColor( 2, BelowZeroColor ) ;

To download the EasyLanguage code for the indicator, first navigate to the EasyLanguage FAQs and Reference Posts Topic in the EasyLanguage support forum (https://www.tradestation.com/Discussions/Topic.aspx?Topic_ID=47452), scroll down and click on the link labeled “Traders’ Tips, TASC.” Then select the appropriate link for the month and year. The ELD filename is “_SRMIND.ELD.”

A sample chart is shown in Figure 1.

Image 1

FIGURE 1: TRADESTATION, SECTOR ROTATION MODEL INDICATOR (SRMIND). A daily bar chart of $INX (S&P 500) with a 200-day simple moving average (magenta plot) is shown. The indicator is plotted in the subgraph beneath price with a rate of change length of 75 days. The ETF data streams are also inserted per the setup described in the code and are hidden.

This article is for informational purposes. No type of trading or investment recommendation, advice, or strategy is being made, given, or in any manner provided by TradeStation Securities or its affiliates.

—Chris Imhof
TradeStation Securities, Inc.
A subsidiary of TradeStation Group, Inc.
www.TradeStation.com

BACK TO LIST

logo

THINKORSWIM, SECTOR ROTATION MODEL (SRM)

In true Olympic fashion, author Giorgos Siligardos has delivered us a gold medal in the form of his new sector rotation model (SRM) study, described in his article in this issue, “Applying The Sector Rotation Model.”

The article goes over the macroeconomic concepts needed to understand the logic behind the theory of market rotation. Siligardos also briefly explains rotation theory, and describes how this study is interpreted with the knowledge of rotation. The study uses ETFs that are built to track the movement of specific market sectors, that when charted on daily charts are used to recognize market tops, bottoms, and reversals (Figure 2).

Image 2

FIGURE 2: THINKORSWIM, SECTOR ROTATION MODEL STUDY. The sector rotation model study uses ETFs that are built to track the movement of specific market sectors, that when charted on daily charts are used to recognize market tops, bottoms, and reversals.

We have recreated Siligardos’ study for thinkorswim users in our proprietary scripting language, thinkScript. The lower study is not going to be affected by the charted symbol but rather by the prices of each sector ETF used in the code. The sector rotation model is built to be used with traditional technical analysis for long-term stock market analysis.

The code is shown here along with instructions for applying it. You can also download the code here.

  1. From TOS charts, select “Studies” → “Edit Studies”
  2. Select the “Studies” tab in the upper left-hand corner
  3. Select “New” in the lower left-hand corner
  4. Name the study (such as “sector rotation model”)
  5. Click in the script editor window, remove “plot data = close,” and paste in the following code:
    declare lower;
    
    input length = 75;
    
    def bull1 = close("XLY") / close("XLY")[length] - 1;
    def bull2 = close("XLF") / close("XLF")[length] - 1;
    def bear1 = close("XLE") / close("XLE")[length] - 1;
    def bear2 = close("XLU") / close("XLU")[length] - 1;
    def bear3 = close("XLP") / close("XLP")[length] - 1;
    
    def bull = (bull1 + bull2) / 2;
    def bear = (bear1 + bear2 + bear3) / 3;
    
    plot Osc = 100 * (bull - bear);
    plot ZeroLine = 0;
    
    Osc.SetDefaultColor(GetColor(4));
    Osc.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
    Osc.SetLineWeight(3);
    Osc.DefineColor("Positive", Color.UPTICK);
    Osc.DefineColor("Negative", Color.DOWNTICK);
    Osc.AssignValueColor(if Osc > 0 then Osc.color("Positive") else Osc.color("Negative"));
    ZeroLine.SetDefaultColor(GetColor(7));
    

—thinkorswim
A division of TD Ameritrade, Inc.
www.thinkorswim.com

BACK TO LIST

logo

eSIGNAL, SECTOR ROTATION MODEL (SRM)

For this month’s Traders’ Tip, we’ve provided the formula SRMind.efs based on Giorgos Siligardos’ article in this issue, “Applying The Sector Rotation Model.”

The study contains formula parameters to set the ROC period, which may be configured through the Edit Chart window.

To discuss this study or download a complete copy of the formula code, please visit the EFS library discussion board forum under the forums link from the support menu at www.esignal.com or visit our EFS KnowledgeBase at www.esignal.com/support/kb/efs/. The eSignal formula script (EFS) is also available for copying & pasting below.

/*********************************
Provided By:  
eSignal (Copyright c eSignal), a division of Interactive Data 
Corporation. 2012. 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:        
Applying The Sector Rotation Model by Giorgos E. Siligardos

Version:            1.00  13/06/2012

Formula Parameters:                     Default:
Roc Period                              75

Notes:
The related article is copyrighted material. If you are not a subscriber
of Stocks & Commodities, please visit www.traders.com.

**********************************/

var fpArray = new Array();

function preMain()
{   
    setStudyTitle("SRMind");
  
    setPlotType(PLOTTYPE_HISTOGRAM, 0);
    
    setIntervalsBackfill(true);

    var x=0;
    
    fpArray[x] = new FunctionParameter("gPeriod", FunctionParameter.NUMBER);
    with(fpArray[x++])
    {
        setName("Roc Period");
        setLowerLimit(10);
        setUpperLimit(200);
        setDefault(75);
    } 
}


var bInit = false;
var bVersion = null;

var xXLY = null;
var xXLF = null;
var xXLE = null;
var xXLU = null;
var xXLP = null;

function main(gPeriod)
{
    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return; 
    
    if(!bInit)
    {
        xXLY = close(sym("XLY"));
        xXLF = close(sym("XLF"));
        xXLE = close(sym("XLE"));
        xXLU = close(sym("XLU"));
        xXLP = close(sym("XLP"));
        
        bInit = true;
    }
    
    var nBull01 = xXLY.getValue(0) / xXLY.getValue(-gPeriod) - 1;
    var nBull02 = xXLF.getValue(0) / xXLF.getValue(-gPeriod) - 1;
        
    var nBear01 = xXLE.getValue(0) / xXLE.getValue(-gPeriod) - 1;
    var nBear02 = xXLU.getValue(0) / xXLU.getValue(-gPeriod) - 1;
    var nBear03 = xXLP.getValue(0) / xXLP.getValue(-gPeriod) - 1;
    
    if (nBull01 == null || nBull02 == null || nBear01 == null || nBear02 == null || nBear03 == null)
        return;
     
    var nBeer = (nBear01 + nBear02 + nBear03) / 3;
    var nBull = (nBull01 + nBull02) / 2;
    
    var result = 100 * (nBull - nBeer);
    
    return result;
}

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=http://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;
}

A sample chart is shown in Figure 3.

Image 3

FIGURE 3: eSIGNAL.

—Jason Keck
eSignal, an Interactive Data company
800 779-6555, www.eSignal.com

BACK TO LIST

logo

WEALTH-LAB, SECTOR ROTATION MODEL (SRM)

This Traders’ Tip is based on “Applying The Sector Rotation Model” by Giorgos Siligardos in this issue. The WealthScript code to replicate Siligardos’s SRMind oscillator is provided here. Wealth-Lab customers should create and update a DataSet with the sector ETF symbols and then click any symbol in any DataSet to run the script.

Wealth-Lab 6 Strategy Code (C#):

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies
{
   public class SRMind : WealthScript
   {
      StrategyParameter _lookback;
      StrategyParameter _maPeriod;
            
      public SRMind()
      {
         _lookback = CreateParameter("Lookback Period", 75, 20, 200, 5);
         _maPeriod = CreateParameter("MA Period", 200, 50, 200, 25);         
      }
      
      protected override void Execute()
      {
         int lbp = _lookback.ValueInt;         
         DataSeries xly = GetExternalSymbol("XLY", true).Close;
         DataSeries xlf = GetExternalSymbol("XLF", true).Close;
         DataSeries xle = GetExternalSymbol("XLE", true).Close;
         DataSeries xlu = GetExternalSymbol("XLU", true).Close;
         DataSeries xlp = GetExternalSymbol("XLP", true).Close;
         DataSeries bear = (ROC.Series(xle, lbp)
            + ROC.Series(xlu, lbp)
            + ROC.Series(xlp, lbp)) / 3d;
         DataSeries bull = (ROC.Series(xly, lbp)
            + ROC.Series(xlf, lbp)) / 2d;
         
         DataSeries srm = 100 * (bull - bear);
         srm.Description = "SRMind";
         ChartPane srmPane = CreatePane(40, true, true);
         PlotSeriesOscillator(srmPane, srm, 0, 0, Color.LightGreen, Color.LightPink, Color.Black, LineStyle.Solid, 1);
         
         DataSeries sma = SMA.Series(Close, _maPeriod.ValueInt);
         PlotSeries(PricePane, sma, Color.Blue, LineStyle.Solid, 2);
      }
   }
}

Solidly positive for virtually every day in 2012, the SRMind oscillator appears to suggest that the S&P 500’s recent setback to the 200-day moving average will be just that — a setback, despite the fundamental backdrop of Europe’s expanding crisis (Figure 4).

Image 4

FIGURE 4: WEALTH-LAB, SRMIND OSCILLATOR. Here is the SRMind oscillator atop the S&P 500, which recently tested the 200-day moving average.

—Robert Sucher
www.wealth-lab.com

BACK TO LIST

logo

NEUROSHELL TRADER, SECTOR ROTATION MODEL (SRM)

The sector rotation model (SRMind) described by Giorgos Siligardos can be easily implemented with a few of NeuroShell Trader’s 800+ indicators. Simply select “New Indicator” from the Insert menu, use the Indicator Wizard to set up the following indicator and select “Other Instrument Data” to choose the ETFs as indicator parameters:
Subtract( Avg2( %Change(XLY,75), %Change(XLF,75) ), Avg3( %Change(XLE,75), %Change(XLU,75), %Change(XLP,75) ) )

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 previous Traders’ Tips.

A sample chart is shown in Figure 5.

Image 5

FIGURE 5: NEUROSHELL TRADER, SRMIND INDICATOR. This sample NeuroShell Trader chart shows the SRMind indicator alongside the S&P 500.

—Marge Sherald, Ward Systems Group, Inc.
301 662-7950, sales@wardsystems.com
www.neuroshell.com

BACK TO LIST

logo

AIQ, SECTOR ROTATION MODEL (SRM) INDICATOR

The AIQ code based on Giorgos Siligardos’ article in this issue, “Applying The Sector Rotation Model,” is provided at the following website: www.TradersEdgeSystems.com/traderstips.htm.

Siligardos’ approach relies on sector ETFs. Since sector ETFs have limited price history, I searched for similar sector representations that would have more history. I found that there are S&P 500 sector indexes that start on 9/11/1989 and thus have almost 23 years of history.

In the table in Figure 6, I show the symbols for the sector representations for the three data services DialData from Track Data, Yahoo! from yahoo.com, and PremiumData from Norgate. The first column of the table shows the ETF symbol. The second column shows the AIQALL (a group/sector list structure) sector symbols. You could code the sector rotation indicator using the program-computed sectors as shown, but the results will vary from user to user because the sector values depend on the stocks that are in the user’s database.

Image 6

FIGURE 6: AIQ, SECTORS. Here are the symbols for the sector representations for the three data services DialData, Yahoo, and PremiumData from Norgate.

Since I couldn’t find symbols for some of the sectors at DialData and Yahoo, I decided to use the sector indexes from Norgate (shown in bold in Figure 6). AIQ can use data from any source by using the data transfer utility to import the data from ASCII text files. In the code file I provide, there is an input that allows you to switch between the ETF data symbols and the indexes (useIDX=0 for ETFs and useIDX=1 for indexes).

Please note that I changed the Norgate symbols upon import to remove the “$” as I wasn’t sure this symbol would be allowed as a ticker symbol. So the symbol “$SPXA” from Norgate is changed to “SPXA,” and so on. I have also provided extra code for the other sectors that are not used by the author in case you want to try using different sector combinations in the bull-bear indicator.

Since Siligardos does not provide a mechanical trading system that uses the indicator, I devised one that uses two moving averages of the bull-bear indicator: one set at 50 bars and the other set at 200 bars. Entries to go long occur when the fast average crosses over the slower average. I exit on cross downs or whenever the SPX 50-bar average is lower than it was 10 bars ago.

Since this is mainly a market timing device, I then tried trading the NASDAQ 100 list of stocks using the Portfolio Manager for the period 1/1/1992 to 6/12/2012. The following capitalization settings were used:

The resulting equity curve is shown in Figure 7, which is compared to the NASDAQ 100 index (NDX). With these settings, the internal rate of return averaged 7.9% with a maximum drawdown of 22.4% on 11/20/1995.

Image 7

FIGURE 7: AIQ, EQUITY CURVE. Here is a sample equity curve for a test system that uses the bull-bear indicator for market timing over the period 1/1/1992 to 6/12/2012. NASDAQ 100 stocks were traded on each buy signal.

The code and EDS file can be downloaded from www.TradersEdgeSystems.com/traderstips.htm. The code is also shown below.

!APPLYING THE SECTOR ROTATION MODEL
!Author: Giorgos E. Siligardos, TASC August 2012
!Coded by: Richard Denning 6/6/2012
!www.TradersEdgeSystems.com

!For the US market, the S&P 500 sector exchange traded funds
!(ETFs) or SP500 indexes [IDX] used by author:
	!financial 		(XLF) or [SPXF] or [BIX] 
	!consumer discretionary (XLY) or [SPXD] or
	!energy 		(XLE) or [SPXE] or [OSX]
	!consumer staples 	(XLP) or [SPXS] or 
	!utilities		(XLU) or [SPXU] or [UTY]	
!Other S&P 500 sectors:
	!health care		(XLV) or [SPXA] or [HCX]
	!materials		(XLB) or [SPXM]
	!industrials		(XLI) or [SPXI]
	!telcom			(XLT) or [SPXT]
	!technology		(XLK) or [SPXT]

!INPUTS:
RC_LEN is 95.	!LENGTH FOR RATE OF CHANGE 
useIDX is 1.	!SWITCHES BETWEEN ETF=0 AND IDX=1

!ABBREVIATIONS:
C is [close].

!CUSTOM FORMULAS:
FIN is iff(useIDX=1,TickerUDF("SPXF",C),TickerUDF("XLF",C)).
CDS is iff(useIDX=1,TickerUDF("SPXD",C),TickerUDF("XLY",C)).
ENE is iff(useIDX=1,TickerUDF("SPXE",C),TickerUDF("XLE",C)).
CSP is iff(useIDX=1,TickerUDF("SPXS",C),TickerUDF("XLP",C)).
UTL is iff(useIDX=1,TickerUDF("SPXU",C),TickerUDF("XLU",C)).
HLT is iff(useIDX=1,TickerUDF("SPXA",C),TickerUDF("XLV",C)).
MAT is iff(useIDX=1,TickerUDF("SPXM",C),TickerUDF("XLB",C)).
IND is iff(useIDX=1,TickerUDF("SPXI",C),TickerUDF("XLI",C)).
TEL is iff(useIDX=1,TickerUDF("SPXL",C),TickerUDF("XLI",C)).
TEK is iff(useIDX=1,TickerUDF("SPXT",C),TickerUDF("XLK",C)).
SPX is TickerUDF("SPX",C).

FINrc is (FIN/valresult(FIN,RC_LEN)-1)*100.
CDSrc is (CDS/valresult(CDS,RC_LEN)-1)*100.
ENErc is (ENE/valresult(ENE,RC_LEN)-1)*100.
CSPrc is (CSP/valresult(CSP,RC_LEN)-1)*100.
UTLrc is (UTL/valresult(UTL,RC_LEN)-1)*100.
HLTrc is (HLT/valresult(HLT,RC_LEN)-1)*100.
MATrc is (MAT/valresult(MAT,RC_LEN)-1)*100.
INDrc is (IND/valresult(IND,RC_LEN)-1)*100.
TELrc is (TEL/valresult(TEL,RC_LEN)-1)*100.
TEKrc is (TEK/valresult(TEK,RC_LEN)-1)*100.

BullSR is (FINrc + CDSrc) / 2.
BearSR is (ENErc + CSPrc + UTLrc) / 3.

!PLOT AS HISTORIGRAM:
BullBearOsc is BullSR - BearSR. 

!PLOT AS TWO LINE INDICATOR WITH ZERO LINE SUPPORT:
BBavgF is simpleavg(BullBearOsc,50).
BBavgS is simpleavg(BullBearOsc,200).

!REPORTS & TRADING SYSTEM USING THE INDICTOR:
List if 1.
FirstDate is firstdatadate().

HD if hasdatafor(200+10) >= 200.
HDsec if TickerRule("XLF",HD) and TickerRule("XLY",HD)
	and TickerRule("XLE",HD) and TickerRule("XLP",HD) 
	and TickerRule("XLU",HD) and TickerRule("SPX",HD).
HDidx if TickerRule("SPXF",HD) and TickerRule("SPXD",HD)
	and TickerRule("SPXE",HD) and TickerRule("SPXS",HD) 
	and TickerRule("SPXU",HD) and TickerRule("SPX",HD).
SPXma is simpleavg(SPX,50).
Buy if BBavgF > BBavgS and valrule(BBavgF < BBavgS,1)
	and ((useIDX=1 and HDidx) or (useIDX<>1 and HDsec)).
xBuy if BBavgF < BBavgS and valrule(BBavgF> BBavgS,1)
	or SPXma < valresult(SPXma,10).

!FOR RANKING STOCKS TO TRADE:	
StockRC is (C/valresult(TEK,RC_LEN)-1)*100.

—Richard Denning
info@TradersEdgeSystems.com
for AIQ Systems

BACK TO LIST

logo

TRADERSSTUDIO, SECTOR ROTATION MODEL (SRM)

The TradersStudio code based on Giorgos Siligardos’ article in this issue, “Applying The Sector Rotation Model,” is provided at the following websites:

The following code files are provided in the download:

Although the author designed this system to trade ETFs, I wanted to test it on other markets since there is such limited data for ETFs and the author’s tests would all be considered “in-sample” tests. I found that the S&P 500 sector indexes have data back to 9/11/1989, which allows us almost 23 years of data to use. In addition, there are 10 sectors of which four tend to outperform during bear markets and six that tend to outperform during bull markets as follows:

Norgate Symbol Description Phase
$SPXA S&P 500 Health Care Sector Bear
$SPXS S&P 500 Consumer Staples Sector Bear
$SPXU S&P 500 Utilities Sector Bear
$SPXE S&P 500 Energy Sector Bear
$SPXD S&P 500 Consumer Discretionary Sector Bull
$SPXF S&P 500 Financials Sector Bull
$SPXI S&P 500 Industrials Sector Bull
$SPXL S&P 500 Telecommunication Services Sector Bull
$SPXM S&P 500 Materials Sector Bull
$SPXT S&P 500 Information Technology Sector Bull

The symbols are from Premium Data by Norgate. The system code and the indicator code have 196 types, which represent up to four bull and four bear sector rates of change that are fed into the BULL_BEAR_OSC function to get the values for that combination. With all these coded, it is possible to do an optimization on the sector combinations that work best for timing the market by changing the “type” parameter.

Using the simple market timing system that buys the SPX index when the BBO average is higher than it was one bar ago and sells the SPX index when it is lower than it was one bar ago, and optimizing, I found that one of the better combinations was type 175, which uses the consumer discretionary sector alone for the bullish sector and a three-sector combination of health care, consumer staples, and utilities for the bearish sectors.

Image 8

FIGURE 8: TRADERSSTUDIO, EQUITY CURVE. Here is a sample equity curve for optimized combination trading 100 shares of the SPX from 1990 to 2012.

Figure 8 shows the resulting equity curve and Figure 9 shows the underwater equity curve using the following parameters:

RC_LEN = 95	LENGTH FOR RATE OF CHANGE 
BB_LEN = 70	LENGTH FOR BULL_BEAR_OSC AVG
Type = 175	SECTOR COMBO FOR BULL_BEAR INDICATOR
Image 9

FIGURE 9: TRADERSSTUDIO, UNDERWATER EQUITY CURVE. Here is a sample underwater equity curve for optimized combination trading 100 shares of the SPX from 1990 to 2012.

Figure 10 shows how the data must be set up in TradersStudio to work properly with the code file.

Image 10

FIGURE 10: TRADERSSTUDIO, DATA SETUP. Here is the data series setup for TradersStudio using S&P 500 sector indexes.

'APPLYING THE SECTOR ROTATION MODEL
'Author: Giorgos E. Siligardos, TASC August 2012
'Coded by: Richard Denning 6/10/2012
'www.TradersEdgeSystems.com

Function BULL_BEAR_OSC(BULLrc1,BULLrc2,BULLrc3,BULLrc4,BEARrc1,BEARrc2,BEARrc3,BEARrc4)
'input a -99999 if an input is not used
Dim BULLsr As BarArray
Dim BEARsr As BarArray
Dim BULLcount As BarArray
Dim BEARcount As BarArray

BULLcount = IIF(BULLrc1>-99999,1,0)+IIF(BULLrc2>-99999,1,0)+IIF(BULLrc3>-99999,1,0)+IIF(BULLrc4>-99999,1,0)
BEARcount = IIF(BEARrc1>-99999,1,0)+IIF(BEARrc2>-99999,1,0)+IIF(BEARrc3>-99999,1,0)+IIF(BEARrc4>-99999,1,0)

BULLsr = (IIF(BULLrc1>-99999,BULLrc1,0)+IIF(BULLrc2>-99999,BULLrc2,0)+IIF(BULLrc3>-99999,BULLrc3,0)+IIF(BULLrc4>-99999,BULLrc4,0))/BULLcount
BEARsr = (IIF(BEARrc1>-99999,BEARrc1,0)+IIF(BEARrc2>-99999,BEARrc2,0)+IIF(BEARrc3>-99999,BEARrc3,0)+IIF(BEARrc4>-99999,BEARrc4,0))/BEARcount
BULL_BEAR_OSC = BULLsr - BEARsr

End Function
'-------------------------------------------------------------------------------------------------------------------------------------------
'APPLYING THE SECTOR ROTATION MODEL
'Author: Giorgos E. Siligardos, TASC August 2012
'Coded by: Richard Denning 6/10/2012
'www.TradersEdgeSystems.com

Sub MKT_TM_SR(RC_LEN,BB_LEN, TYPE)
'INPUTS:'RC_LEN = 95    LENGTH FOR RATE OF CHANGE 
        'BB_LEN = 70    LENGTH FOR BULL_BEAR_OSC AVG
        'Type = 175     SECTOR COMBO FOR BULL_BEAR INDICATOR
Dim FIN As BarArray
Dim CDS As BarArray
Dim ENE As BarArray
Dim CSP As BarArray
Dim UTL As BarArray
Dim HLT As BarArray
Dim MAT As BarArray
Dim IND As BarArray
Dim TEL As BarArray
Dim TEK As BarArray
Dim SPX As BarArray
Dim FINrc As BarArray
Dim CDSrc As BarArray
Dim ENErc As BarArray
Dim CSPrc As BarArray
Dim UTLrc As BarArray
Dim HLTrc As BarArray
Dim MATrc As BarArray
Dim INDrc As BarArray
Dim TELrc As BarArray
Dim TEKrc As BarArray
Dim SPXrc As BarArray
Dim BULLsr As BarArray
Dim BEARsr As BarArray
Dim BULL_BEAR As BarArray
Dim BBfun As BarArray
Dim BBAVG As BarArray

'DATA SERIES:                              STRONGET DURING:
HLT = C Of independent1  ' "SPXA" or "XLV"         [BEAR]
CDS = C Of independent2  ' "SPXD" or "XLY"    [BULL]
ENE = C Of independent3  ' "SPXE" or "XLE"         [BEAR]
FIN = C Of independent4  ' "SPXF" or "XLF"    [BULL]
IND = C Of independent5  ' "SPXI" or "XLI"    [BULL]
TEL = C Of independent6  ' "SPXL" or "XLI"    [BULL]
MAT = C Of independent7  ' "SPXM" or "XLB"    [BULL]
CSP = C Of independent8  ' "SPXS" or "XLP"         [BEAR]
TEK = C Of independent9  ' "SPXT" or "XLK"    [BULL]
UTL = C Of independent10 ' "SPXU" or "XLU"         [BEAR]
SPX = C Of independent11 ' "SPX"

FINrc = roc(FIN,RC_LEN,0)
CDSrc = roc(CDS,RC_LEN,0)
ENErc = roc(ENE,RC_LEN,0)
CSPrc = roc(CSP,RC_LEN,0)
UTLrc = roc(UTL,RC_LEN,0)
'OPTIONAL OTHER SECTOR ROCs THAT COULD BE TRIED:
HLTrc = roc(HLT,RC_LEN,0)
MATrc = roc(MAT,RC_LEN,0)
INDrc = roc(IND,RC_LEN,0)
TELrc = roc(TEL,RC_LEN,0)
TEKrc = roc(TEK,RC_LEN,0)
SPXrc = roc(SPX,RC_LEN,0)

BULLsr = (FINrc+CDSrc)/2
BEARsr = (ENErc+CSPrc+UTLrc)/3

If TYPE=0 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=1 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,-99999,-99999,ENErc)
If TYPE=2 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=3 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,-99999,-99999,ENErc)
If TYPE=4 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=5 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,-99999,-99999,ENErc)
If TYPE=6 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=7 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,-99999,-99999,ENErc)
If TYPE=8 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=9 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=10 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,-99999,-99999,ENErc)
If TYPE=11 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=12 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,-99999,-99999,ENErc)
If TYPE=13 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=14 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=15 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=16 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=17 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=18 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=19 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=20 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=21 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=22 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=23 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=24 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=25 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=26 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=27 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=28 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=29 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=30 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=31 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=32 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=33 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=34 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=35 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=36 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=37 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=38 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=39 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=40 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=41 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=42 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=43 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=44 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=45 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=46 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=47 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=48 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=49 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=50 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=51 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=52 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=53 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=54 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=55 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=56 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=57 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=58 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=59 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=60 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=61 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=62 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=63 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=64 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=65 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=66 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=67 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=68 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=69 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=70 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=71 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=72 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=73 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=74 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=75 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=76 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=77 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=78 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=79 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=80 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=81 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=82 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=83 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=84 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=85 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=86 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=87 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=88 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=89 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=90 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=91 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=92 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=93 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=94 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=95 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=96 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=97 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=98 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=99 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=100 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=101 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=102 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=103 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=104 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=105 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=106 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=107 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=108 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=109 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=110 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=111 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=112 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=113 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=114 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=115 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=116 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=117 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=118 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=119 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=120 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=121 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=122 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=123 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=124 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=125 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=126 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=127 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=128 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=129 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=130 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=131 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=132 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=133 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=134 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=135 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=136 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=137 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=138 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=139 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=140 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=141 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=142 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=143 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=144 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=145 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=146 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=147 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=148 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=149 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=150 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=151 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=152 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=153 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=154 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=155 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=156 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=157 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=158 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=159 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=160 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=161 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=162 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=163 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=164 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=165 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=166 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=167 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=168 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=169 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=170 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=171 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=172 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=173 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=174 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=175 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=176 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=177 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=178 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=179 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=180 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=181 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=182 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=183 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=184 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=185 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=186 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=187 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=188 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=189 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=190 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=191 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=192 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=193 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=194 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=195 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,CSPrc,UTLrc,ENErc)

BBAVG = Average(BBfun,BB_LEN)
'Print FormatDateTime(Date)," ",BULL_BEAR," ",BBfun
If BBAVG > BBAVG[1] Then Buy("LE",1,0,Market,Day)
If BBAVG < BBAVG[1] Then ExitLong("LX","",1,0,Market,Day)
If BBAVG < BBAVG[1] Then Sell("SE",1,0,Market,Day)
If BBAVG > BBAVG[1] Then ExitShort("SX","",1,0,Market,Day)
End Sub
'--------------------------------------------------------------------------------------------------------------------
Sub BULL_BEAR_IND(RC_LEN,BB_LEN, TYPE)
Dim FIN As BarArray
Dim CDS As BarArray
Dim ENE As BarArray
Dim CSP As BarArray
Dim UTL As BarArray
Dim HLT As BarArray
Dim MAT As BarArray
Dim IND As BarArray
Dim TEL As BarArray
Dim TEK As BarArray
Dim SPX As BarArray
Dim FINrc As BarArray
Dim CDSrc As BarArray
Dim ENErc As BarArray
Dim CSPrc As BarArray
Dim UTLrc As BarArray
Dim HLTrc As BarArray
Dim MATrc As BarArray
Dim INDrc As BarArray
Dim TELrc As BarArray
Dim TEKrc As BarArray
Dim SPXrc As BarArray
Dim BULLsr As BarArray
Dim BEARsr As BarArray
Dim BULL_BEAR As BarArray
Dim BBfun As BarArray
Dim BBAVG As BarArray

'DATA SERIES:                              STRONGET DURING:
HLT = C Of independent1  ' "SPXA" or "XLV"         [BEAR]
CDS = C Of independent2  ' "SPXD" or "XLY"    [BULL]
ENE = C Of independent3  ' "SPXE" or "XLE"         [BEAR]
FIN = C Of independent4  ' "SPXF" or "XLF"    [BULL]
IND = C Of independent5  ' "SPXI" or "XLI"    [BULL]
TEL = C Of independent6  ' "SPXL" or "XLI"    [BULL]
MAT = C Of independent7  ' "SPXM" or "XLB"    [BULL]
CSP = C Of independent8  ' "SPXS" or "XLP"         [BEAR]
TEK = C Of independent9  ' "SPXT" or "XLK"    [BULL]
UTL = C Of independent10 ' "SPXU" or "XLU"         [BEAR]
SPX = C Of independent11 ' "SPX"

FINrc = roc(FIN,RC_LEN,0)
CDSrc = roc(CDS,RC_LEN,0)
ENErc = roc(ENE,RC_LEN,0)
CSPrc = roc(CSP,RC_LEN,0)
UTLrc = roc(UTL,RC_LEN,0)
'OPTIONAL OTHER SECTOR ROCs THAT COULD BE TRIED:
HLTrc = roc(HLT,RC_LEN,0)
MATrc = roc(MAT,RC_LEN,0)
INDrc = roc(IND,RC_LEN,0)
TELrc = roc(TEL,RC_LEN,0)
TEKrc = roc(TEK,RC_LEN,0)
SPXrc = roc(SPX,RC_LEN,0)

BULLsr = (FINrc+CDSrc)/2
BEARsr = (ENErc+CSPrc+UTLrc)/3

If TYPE=0 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=1 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,-99999,-99999,ENErc)
If TYPE=2 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=3 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,-99999,-99999,ENErc)
If TYPE=4 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=5 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,-99999,-99999,ENErc)
If TYPE=6 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=7 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,-99999,-99999,ENErc)
If TYPE=8 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=9 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=10 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,-99999,-99999,ENErc)
If TYPE=11 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=12 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,-99999,-99999,ENErc)
If TYPE=13 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,-99999,-99999,ENErc)
If TYPE=14 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=15 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=16 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=17 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=18 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=19 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=20 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=21 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=22 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=23 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=24 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=25 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=26 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,-99999,UTLrc,-99999)
If TYPE=27 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,-99999,UTLrc,-99999)
If TYPE=28 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=29 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=30 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=31 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=32 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=33 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=34 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=35 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=36 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=37 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=38 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=39 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=40 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,-99999,UTLrc,ENErc)
If TYPE=41 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,-99999,UTLrc,ENErc)
If TYPE=42 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=43 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=44 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=45 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=46 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=47 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=48 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=49 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=50 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=51 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=52 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=53 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=54 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,CSPrc,-99999,-99999)
If TYPE=55 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,CSPrc,-99999,-99999)
If TYPE=56 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=57 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=58 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=59 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=60 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=61 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=62 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=63 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=64 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=65 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=66 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=67 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=68 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,CSPrc,-99999,ENErc)
If TYPE=69 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,CSPrc,-99999,ENErc)
If TYPE=70 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=71 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=72 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=73 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=74 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=75 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=76 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=77 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=78 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=79 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=80 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=81 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=82 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,CSPrc,UTLrc,-99999)
If TYPE=83 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,CSPrc,UTLrc,-99999)
If TYPE=84 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=85 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=86 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=87 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=88 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=89 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=90 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=91 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=92 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=93 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=94 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=95 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=96 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,-99999,CSPrc,UTLrc,ENErc)
If TYPE=97 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,-99999,CSPrc,UTLrc,ENErc)
If TYPE=98 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=99 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=100 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=101 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=102 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=103 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=104 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=105 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=106 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=107 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=108 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=109 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=110 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,-99999,-99999,-99999)
If TYPE=111 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,-99999,-99999,-99999)
If TYPE=112 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=113 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=114 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=115 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=116 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=117 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=118 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=119 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=120 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=121 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=122 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=123 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=124 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,-99999,-99999,ENErc)
If TYPE=125 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,-99999,-99999,ENErc)
If TYPE=126 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=127 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=128 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=129 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=130 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=131 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=132 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=133 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=134 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=135 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=136 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=137 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=138 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,-99999,UTLrc,ENErc)
If TYPE=139 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,-99999,UTLrc,ENErc)
If TYPE=140 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=141 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=142 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=143 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=144 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=145 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=146 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=147 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=148 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=149 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=150 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=151 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=152 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,CSPrc,-99999,-99999)
If TYPE=153 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,CSPrc,-99999,-99999)
If TYPE=154 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=155 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=156 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=157 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=158 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=159 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=160 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=161 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=162 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=163 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=164 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=165 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=166 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,CSPrc,-99999,ENErc)
If TYPE=167 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,CSPrc,-99999,ENErc)
If TYPE=168 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=169 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=170 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=171 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=172 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=173 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=174 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=175 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=176 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=177 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=178 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=179 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=180 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,CSPrc,UTLrc,-99999)
If TYPE=181 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,CSPrc,UTLrc,-99999)19
If TYPE=182 Then BBfun = BULL_BEAR_OSC(-99999,-99999,-99999,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=183 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=184 Then BBfun = BULL_BEAR_OSC(-99999,-99999,INDrc,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=185 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=186 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,-99999,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=187 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=188 Then BBfun = BULL_BEAR_OSC(-99999,FINrc,INDrc,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=189 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=190 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,-99999,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=191 Then BBfun = BULL_BEAR_OSC(CDSrc,-99999,INDrc,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=192 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=193 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,-99999,MATrc,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=194 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,-99999,HLTrc,CSPrc,UTLrc,ENErc)
If TYPE=195 Then BBfun = BULL_BEAR_OSC(CDSrc,FINrc,INDrc,MATrc,HLTrc,CSPrc,UTLrc,ENErc)

BBAVG = Average(BBfun,BB_LEN)
Plot1(BBfun)
Plot2(BBAVG)

End Sub
'----------------------------------------------------------------------------------------------------------------------

—Richard Denning
info@TradersEdgeSystems.com
for TradersStudio

BACK TO LIST

logo

AMIBROKER, SECTOR ROTATION MODEL (SRM) INDICATOR

In “Applying The Sector Rotation Model” in this issue, author Giorgos Siligardos presents his sector rotation model (SRM) indicator.

A ready-to-use AmiBroker formula for implementing the SRM is presented below. To use it, enter the formula in the AFL Editor, then press Insert Indicator. To modify the lookback period, right-click on the chart and select “parameters” from the menu.

// SRM Indicator 

Lbp = Param("Lookback period", 75, 10, 200 ); 

Bull01 = 0.01 * ROC( Foreign("XLY", "C" ), Lbp ); 
Bull02 = 0.01 * ROC( Foreign("XLF", "C" ), Lbp ); 
Bear01 = 0.01 * ROC( Foreign("XLE", "C" ), Lbp ); 
Bear02 = 0.01 * ROC( Foreign("XLU", "C" ), Lbp ); 
Bear03 = 0.01 * ROC( Foreign("XLP", "C" ), Lbp ); 

Bull = ( Bull01 + Bull02 )/2; 
Bear = ( Bear01 + Bear02 + Bear03 ) /3; 

Plot( 100 * ( Bull - Bear ), "SRM"+_PARAM_VALUES(), colorRed, styleHistogram );

A sample chart is shown in Figure 11.

Image 11

FIGURE 11: AMIBROKER, SECTOR ROTATION MODEL (SRM) INDICATOR. Here is a daily price chart of the S&P 500 (upper pane) and the SRM indicator (bottom pane).

—Tomasz Janeczko, AmiBroker.com
www.amibroker.com

BACK TO LIST

logo

NINJATRADER, SECTOR ROTATION MODEL (SRM) INDICATOR

The sector rotation model (SRM), as discussed in Giorgos Siligardos’ article in this issue, “Applying The Sector Rotation Model,” has been implemented as an indicator available for download at www.ninjatrader.com/SC/August2011SC.zip.

Once you have it 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 7 or greater.

You can review the indicator source code by selecting the menu Tools → Edit NinjaScript → Indicator from within the NinjaTrader Control Center window and selecting “SRM.”

A sample chart implementing the strategy is shown in Figure 12.

Image 12

FIGURE 12: NINJATRADER, SECTOR ROTATION MODEL (SRM) INDICATOR. This screenshot shows the SRM applied to a daily chart of the S&P 500 index (∧SP500).

—Raymond Deux & Ryan Millard
NinjaTrader, LLC
www.ninjatrader.com

BACK TO LIST

logo

UPDATA, SECTOR ROTATION MODEL (SRM) INDICATOR

This tip is based on Giorgos Siligardos’ article in this issue, “Applying The Sector Rotation Model.”

In the article, Siligardos introduces a macro perspective in technical trading by creating an oscillator that rises and falls with the relative dominance between bullish and bearish market sentiment. See Figure 13.

Image 13

FIGURE 13: UPDATA, SECTOR ROTATION MODEL INDICATOR. This chart shows the 75-period sector rotation model as applied to a daily chart of the S&P 500.

Financial and discretionary sectors are suggested to outperform during bullish times and are used as inputs via their ETFs. The sector ETFs of energy, utilities, and healthcare are suggested to outperform during bearish times and are used as bearish inputs. The subsequent indicator’s extremities are used to pick turning points in the aggregate market (the S&P 500 index).

The Updata code for this indicator has been added to the Updata Library and may be downloaded by clicking the Custom menu and then Indicator Library. Those who cannot access the library due to a firewall may paste the code shown here into the Updata Custom editor and save it.

PARAMETER "XLY Ticker" ˜XLY=SELECT 
PARAMETER "XLF Ticker" ˜XLF=SELECT
PARAMETER "XLE Ticker" ˜XLE=SELECT 
PARAMETER "XLU Ticker" ˜XLU=SELECT 
PARAMETER "XLP Ticker" ˜XLP=SELECT 
PARAMETER "Lookback Period" #PERIOD=75
NAME "SRM[" #PERIOD "]" ""
DISPLAYSTYLE LINE
PLOTSTYLE HISTOGRAM
@BULLELEMENT1=0
@BULLELEMENT2=0
@BEARELEMENT1=0
@BEARELEMENT2=0
@BEARELEMENT3=0
@BULL=0
@BEAR=0
@SECTORROTATIONMODEL=0  
 
FOR #CURDATE=#PERIOD TO #LASTDATE   
   @BULLELEMENT1=-1+˜XLY/HIST(˜XLY,#PERIOD)
   @BULLELEMENT2=-1+˜XLF/HIST(˜XLF,#PERIOD)
   @BEARELEMENT1=-1+˜XLE/HIST(˜XLE,#PERIOD)
   @BEARELEMENT2=-1+˜XLU/HIST(˜XLU,#PERIOD)
   @BEARELEMENT3=-1+˜XLP/HIST(˜XLP,#PERIOD)
   'AVERAGES
   @BULL=(@BULLELEMENT1+@BULLELEMENT2)/2
   @BEAR=(@BEARELEMENT1+@BEARELEMENT2+@BEARELEMENT3)/3 
   'OSCILLATOR
   @SECTORROTATIONMODEL=100*(@BULL-@BEAR)     
   @PLOT=@SECTORROTATIONMODEL      
NEXT

—Updata support team
support@updata.co.uk
www.updata.co.uk

BACK TO LIST

logo

TRADECISION, SECTOR ROTATION MODEL (SRM) INDICATOR

In “Applying The Sector Rotation Model” in this issue, author Giorgos Siligardos demonstrates two simple tools that can help to incorporate the macro perspectives of the stock market in technical analysis. Both are based on macro fundamentals, both have a technical application, and both have signals that usually precede major market reversals and highlight signals from classic technical analysis. In his article, Siligardos explains the logic of the first — the sector rotation model (SRM) — and presents a simple indicator to monitor its waves (Figure 14).

Image 14

FIGURE 14: TRADECISION, SECTOR ROTATION MODEL INDICATOR. Here is the SRM indicator plotted on an S&P 500 daily chart.

Here is the code to recreate the SRM indicator using Tradecision’s Indicator Builder.

SRM indicator:
 
{Roc look back period in trading days}
Ins
lbp:"Roc Parameter",75,10,200;
End_ins

var
Bull01:= 0;
Bull02:= 0;
Bear01:= 0;
Bear02:= 0;
Bear03:= 0;
Bear:=0;
Bull:=0;
end_var

{Roc calculation}
Bull01:= External("C", "XLY")/Ref(External("C", "XLY"),-lbp)-1;
Bull02:= External("C", "XLF")/Ref(External("C", "XLF"),-lbp)-1;
Bear01:= External("C", "XLE")/Ref(External("C", "XLE"),-lbp)-1;
Bear02:= External("C", "XLU")/Ref(External("C", "XLU"),-lbp)-1;
Bear03:= External("C", "XLP")/Ref(External("C", "XLP"),-lbp)-1;

{averages}
Bear:=(Bear01+Bear02+Bear03)/3;
Bull:=(Bull01+Bull02)/2;

{Oscillator}
return 100*(Bull-Bear);

—Yana Timofeeva, Alyuda Research
510 931-7808, sales@tradecision.com
www.tradecision.com

BACK TO LIST

logo

TRADE NAVIGATOR, SECTOR ROTATION MODEL (SRM) INDICATOR

You can recreate the custom indicator described in Giorgos Siligardos’ article in this issue, “Applying The Sector Rotation Model,” by using the following TradeSense code.

First, open the Trader’s Toolbox, click on the Functions tab and click the New button. Input the following code:

&bull01 := Close Of "XLY" / (Close.(lbp) Of "XLY").1 
&bull02 := Close Of "XLF" / (Close.(lbp) Of "XLF").1 
&bear01 := Close Of "XLE" / (Close.(lbp) Of "XLE").1 
&bear02 := Close Of "XLU" / (Close.(lbp) Of "XLU").1 
&bear03 := Close Of "XLP" / (Close.(lbp) Of "XLP").1 
&bear := (&bear01 + &bear02 + &bear03) / 3 
&bull := (&bull01 + &bull02) / 2 
100 * (&bull - &bear)
Image 1

Click the Verify button. The “Add inputs” window will pop up. Click “Add.” Change the values to the following:

Lbp = 75

When you are finished, click on the Save button, type a name for your new function, and click OK.

Now that we have the function created, go to a daily chart and go to the “Add to chart” window by clicking on the chart and typing “A” on the keyboard. Click on the Indicators tab, find the indicator in the list, and either doubleclick on it or highlight the name and click the “Add” button.

Image 1

Click on the chart and type the letter “E” to bring up the Chart Settings window. Highlight the indicator you just added and change the “type” to “histogram” under “appearance,” then click OK.

We will be providing a library called “Applying The Sector Rotation Model” that includes the custom indicator SRMind from this article. You can download a special file named “SC201208,” downloadable through Trade Navigator, to get this library.

—Michael Herman
Genesis Financial Technologies
www.TradeNavigator.com

BACK TO LIST

MICROSOFT EXCEL, SECTOR ROTATION MODEL (SRM) INDICATOR

The sector rotation model (SRM) indicator presented in Giorgos Siligardos’ article in this issue, “Applying The Sector Rotation Model,” is a simple but effective tool to help the trader visualize these forces in action.

This indicator provides an interesting concept that perhaps could be explored further by experimenting with some of the other available indexes as proxies for the market sectors.

See Figure 15 for a sample implementation.

Image 15

FIGURE 15: MICROSOFT EXCEL, SECTOR ROTATION MODEL INDICATOR. Here is a sample chart of Siligardos’ sector rotation model indicator (based on a 75-day rate of change) on the S&P 500.

The Excel spreadsheet file named “Applying SRM.xlsm” implementing this indicator can be downloaded here.

—Ron McAllister
rpmac_xltt@sprynet.com

BACK TO LIST

Originally published in the August 2012 issue of
Technical Analysis of Stocks & Commodities magazine.
All rights reserved. © Copyright 2012, Technical Analysis, Inc.

Return to Contents