//@Name:Sector Index //@Description:A script that allows you to add the share's sector index (or relative strength) as an indicator below the share's graph. //@Type:Historical // Care has been taken in preparing this code but it is provided without guarantee. // You are welcome to modify and extend it. Please add your name as a modifier if you distribute it. var line = [Colour.Red,Pen.Solid,2]; var baseName = ""; //epic of the base share var baseID = 46597; //ID of the base share var lookback = 250; //lookback period function init(status) { if (status == Loading || status == Editing) { line[0] = storage.getAt(0); line[1] = storage.getAt(1); line[2] = storage.getAt(2); baseID = storage.getAt(3); //get ID from storage storage.setAt(4, lookback); if (baseID!=0) baseName = getShare(baseID).getEPIC(); else baseName = ""; } if (status == Adding || status == Editing) { dlg = new Dialog("Indicator Setup",180,95); dlg.addOkButton(); dlg.addCancelButton(); dlg.addColLinePicker("COL1",50,8,-1,-1,"Line colour","",line[0],line[1],line[2]); dlg.addGroupBox(8,30,110,60,"Relative Strength"); dlg.addText(15,43,100,10,"Leave blank to not use...") dlg.addTextEdit("TE1",59,58,40,-1,"Relative to...","",baseName); //input epic of base share dlg.addIntEdit("INT1",13,-1,-1,-1,"","Lookback",lookback,2,5000); if (dlg.show()==Dialog.Cancel && status == Adding) return false; line[0] = dlg.getValue("COL1").colour; line[1] = dlg.getValue("COL1").pen; line[2] = dlg.getValue("COL1").width; baseName = dlg.getValue("TE1"); lookback = dlg.getValue("INT1"); storage.setAt(0,line[0]); storage.setAt(1,line[1]); storage.setAt(2,line[2]); storage.setAt(4, lookback); } setSeriesColour(0,line[0]); setSeriesLineStyle(0,line[1],line[2]); setRange(Range.Parent); if (baseName!="") { //list possible markets the base share could be part of var baseList = [("LSE:"+baseName),("UKI:"+baseName),("USI:"+baseName),("GER:"+baseName), ("ENXT:"+baseName),("NNM:"+baseName),("NYSE:"+baseName),("AMEX:"+baseName),("FX:"+baseName)]; //try various markets until finding the one where the base share comes from, then get the base share's ShareObj for (var i=0;i=data.length-lookback) output[i] = ((((F1/S1)*(sector.getCloseOnDate(data[i].date)/baseShare.getCloseOnDate(data[i].date)))-1)*100); } return output; }