It was written sometime ago but still very applicable today. Please enjoy it!

Code:

```
# PINTO_SectorsOverlay
# Emulation of the PerfChart: S&P Sector ETFs
# http://stockcharts.com/freecharts/perf.php?[SECT]
# Updated on May/22/2012
declare upper;
input ShowOverlay = yes;
input pivot = 180; ### bars
input length = 4;
input displace = 3;
input SnP500 = "SPY";
input Cyclicals = "XLY";
input Technology = "XLK";
input Industrials = "XLI";
input Materials = "XLB";
input Energy = "XLE";
input Staples = "XLP";
input HealthCare = "XLV";
input Utilities = "XLU";
input Financials = "XLF";
def BasePrice = WildersAverage(open , length)[-length + displace];
def SnP500Price = WildersAverage(open(SnP500) , length)[-length + displace];
def CyclicalsPrice = WildersAverage(open(Cyclicals) , length)[-length + displace];
def TechnologyPrice = WildersAverage(open(Technology) , length)[-length + displace];
def IndustrialsPrice = WildersAverage(open(Industrials), length)[-length + displace];
def MaterialsPrice = WildersAverage(open(Materials) , length)[-length + displace];
def EnergyPrice = WildersAverage(open(Energy) , length)[-length + displace];
def StaplesPrice = WildersAverage(open(Staples) , length)[-length + displace];
def HealthCarePrice = WildersAverage(open(HealthCare) , length)[-length + displace];
def UtilitiesPrice = WildersAverage(open(Utilities) , length)[-length + displace];
def FinancialsPrice = WildersAverage(open(Financials) , length)[-length + displace];
def barNumber = if barNumber() > pivot then barNumber() else 1;
def BaseOpen = if barNumber == 1 then basePrice else BaseOpen[1];
def SnP500Open = if barNumber == 1 then SnP500Price else SnP500Open[1];
def CyclicalsOpen = if barNumber == 1 then CyclicalsPrice else CyclicalsOpen[1];
def TechnologyOpen = if barNumber == 1 then TechnologyPrice else TechnologyOpen[1];
def IndustrialsOpen = if barNumber == 1 then IndustrialsPrice else IndustrialsOpen[1];
def MaterialsOpen = if barNumber == 1 then MaterialsPrice else MaterialsOpen[1];
def EnergyOpen = if barNumber == 1 then EnergyPrice else EnergyOpen[1];
def StaplesOpen = if barNumber == 1 then StaplesPrice else StaplesOpen[1];
def HealthCareOpen = if barNumber == 1 then HealthCarePrice else HealthCareOpen[1];
def UtilitiesOpen = if barNumber == 1 then UtilitiesPrice else UtilitiesOpen[1];
def FinancialsOpen = if barNumber == 1 then FinancialsPrice else FinancialsOpen[1];
def Multiplier = BaseOpen;
plot dot = if barNumber() == pivot then BaseOpen else Double.NaN;
dot.SetDefaultColor(Color.WHITE);
dot.SetStyle(Curve.POINTS);
dot.SetLineWeight(5);
plot basePriceToPlot = if ShowOverlay then BasePrice - (BasePrice - BaseOpen) + Multiplier * (BasePrice - BaseOpen) / BaseOpen else Double.NaN;
basePriceToPlot.SetDefaultColor(Color.WHITE);
AddLabel(ShowOverlay, " " + GetUnderlyingSymbol() + " ", Color.WHITE);
basePriceToPlot.SetLineWeight(2);
plot SnP500PriceToPlot = if ShowOverlay then SnP500Price - (SnP500Open - BaseOpen) + Multiplier * (SnP500Price - SnP500Open) / SnP500Open else Double.NaN;
SnP500PriceToPlot.SetDefaultColor(Color.RED);
AddLabel(ShowOverlay, " SnP500 ", Color.RED);
plot CyclicalsPriceToPlot = if ShowOverlay then CyclicalsPrice - (CyclicalsOpen - BaseOpen) + Multiplier * (CyclicalsPrice - CyclicalsOpen) / CyclicalsOpen else Double.NaN;
CyclicalsPriceToPlot.SetDefaultColor(Color.VIOLET);
AddLabel(ShowOverlay, " Cyclicals ", Color.VIOLET);
plot TechologyPriceToPlot = if ShowOverlay then TechnologyPrice - (TechnologyOpen - BaseOpen) + Multiplier * (TechnologyPrice - TechnologyOpen) / TechnologyOpen else Double.NaN;
TechologyPriceToPlot.SetDefaultColor(Color.GREEN);
AddLabel(ShowOverlay, " Techology ", Color.GREEN);
plot IndustrialsPriceToPlot = if ShowOverlay then IndustrialsPrice - (IndustrialsOpen - BaseOpen) + Multiplier * (IndustrialsPrice - IndustrialsOpen) / IndustrialsOpen else Double.NaN;
IndustrialsPriceToPlot.SetDefaultColor(Color.MAGENTA);
AddLabel(ShowOverlay, " Industrials ", Color.MAGENTA);
plot MaterialsPriceToPlot = if ShowOverlay then MaterialsPrice - (MaterialsOpen - BaseOpen) + Multiplier * (MaterialsPrice - MaterialsOpen) / MaterialsOpen else Double.NaN;
MaterialsPriceToPlot.SetDefaultColor(Color.CYAN);
AddLabel(ShowOverlay, " Materials ", Color.CYAN);
plot EnergyPriceToPlot = if ShowOverlay then EnergyPrice - (EnergyOpen - BaseOpen) + Multiplier * (EnergyPrice - EnergyOpen) / EnergyOpen else Double.NaN;
EnergyPriceToPlot.SetDefaultColor(Color.YELLOW);
AddLabel(ShowOverlay, " Energy ", Color.YELLOW);
plot StaplesPriceToPlot = if ShowOverlay then StaplesPrice - (StaplesOpen - BaseOpen) + Multiplier * (StaplesPrice - StaplesOpen) / StaplesOpen else Double.NaN;
StaplesPriceToPlot.SetDefaultColor(Color.DARK_GREEN);
AddLabel(ShowOverlay, " Staples ", Color.DARK_GREEN);
plot HealthCarePriceToPlot = if ShowOverlay then HealthCarePrice - (HealthCareOpen - BaseOpen) + Multiplier * (HealthCarePrice - HealthCareOpen) / HealthCareOpen else Double.NaN;
HealthCarePriceToPlot.SetDefaultColor(Color.PLUM);
AddLabel(ShowOverlay, " HealthCare ", Color.PLUM);
plot UtilitiesPriceToPlot = if ShowOverlay then UtilitiesPrice - (UtilitiesOpen - BaseOpen) + Multiplier * (UtilitiesPrice - UtilitiesOpen) / UtilitiesOpen else Double.NaN;
UtilitiesPriceToPlot.SetDefaultColor(Color.ORANGE);
AddLabel(ShowOverlay, " Utilities ", Color.ORANGE);
plot FinancialsPriceToPlot = if ShowOverlay then FinancialsPrice - (FinancialsOpen - BaseOpen) + Multiplier * (FinancialsPrice - FinancialsOpen) / FinancialsOpen else Double.NaN;
FinancialsPriceToPlot.SetDefaultColor(Color.PINK);
AddLabel(ShowOverlay, " Financials ", Color.PINK);
```