//@Name:Rolling Relative Strength and Additional lines //@Description:Returns the relative strength of the share against the chosen index. The starting point rolls forward as the days progress. //@Env:Production //@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. //Coded by: Richard Chiesa, ShareScript Support //Modified by: Phil Tolhurst, ShareScript Support var lookback = 250; //lookback period var baseName = "UKX"; //epic of the base share var baseID = 46597; //ID of the base share var useSector = 0; //use sector true/false var lineCol1 = Colour.Red; var lineCol2 = Colour.Blue; var lineCol3 = Colour.Green; var lineStyle1 = 0; var lineStyle2 = 0; var lineStyle3 = 0; var lineWidth1 = 0; var lineWidth2 = 0; var lineWidth3 = 0; var lineToggle1 = 0; var lineToggle2 = 0; var lineValue1 = 15; var lineValue2 = -15; var lineFlag = 0; var baseShare; var SW; var LVF; var LBUSLT function init(status) { if (status == Loading || status == Editing) { baseID = storage.getAt(0); //get ID from storage LVF = storage.getAt(1); lineCol1 = storage.getAt(2); lineCol2 = storage.getAt(3); lineCol3 = storage.getAt(4); SW = storage.getAt(5); LBUSLT = storage.getAt(6); SW = SW.toString(); lineStyle1=parseInt(SW.substr(0,1),10)-1; lineStyle2=parseInt(SW.substr(1,1),10)-1; lineStyle3=parseInt(SW.substr(2,1),10)-1; lineWidth1=parseInt(SW.substr(3,1),10)-1; lineWidth2=parseInt(SW.substr(4,1),10)-1; lineWidth3=parseInt(SW.substr(5,1),10)-1; LBUSLT = LBUSLT.toString(); lineToggle1 = parseInt(LBUSLT.substr(0,1),10)-1; lineToggle2 = parseInt(LBUSLT.substr(1,1),10)-1; useSector = parseInt(LBUSLT.substr(2,1),10)-1; lookback = parseInt(LBUSLT.substr(3,4),10); LVF = LVF.toString(); lineFlag = parseInt(LVF.substr(0,1),10)-1; lineValue1 = parseInt(LVF.substr(1,3),10); lineValue2 = parseInt(LVF.substr(4,3),10); lineFlag = (lineFlag & 4)?lineValue2=lineValue2*-1:lineValue2; lineFlag = (lineFlag & 2)?lineValue1=lineValue1*-1:lineValue1; baseName = getShare(baseID).getEPIC(); //get epic from ID } if (status == Adding || status == Editing) { dlg = new Dialog((status==Adding?"Add":"Edit")+" indicator", 320, 110); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("INT1",8,-1,-1,-1,"","Lookback",lookback,2,5000) dlg.addTextEdit("TE1",45,20,60,-1,"Base share","",baseName); //input epic of base share dlg.addColLinePicker("CL1",120,5,-1,-1,"","",lineCol1,lineStyle1,lineWidth1); dlg.addColLinePicker("CL2",120,75,-1,-1,"","",lineCol2,lineStyle2,lineWidth2); dlg.addColLinePicker("CL3",120,92,-1,-1,"","",lineCol3,lineStyle3,lineWidth3); dlg.addTickBox("TIK1",8,75,55,-1,"Draw line at ",lineToggle1); dlg.addTickBox("TIK2",8,92,55,-1,"Draw line at ",lineToggle2); dlg.addNumEdit("NUM1",60,75,-1,-1,"","",lineValue1,-99.99,99.99); dlg.addNumEdit("NUM2",60,92,-1,-1,"","",lineValue2,-99.99,99.99); dlg.addTickBox("TB1",10,35,100,-1,"Use sector index",useSector); dlg.addText(10,50,300,20,"The base share is identified by its EPIC code. If the the sctor index option is ticked the base share EPIC will be ignored. If a base share isn't found, the script will default to FTSE100"); if (dlg.show()==Dialog.Cancel) return false; lookback = dlg.getValue("INT1"); useSector = dlg.getValue("TB1"); baseName = dlg.getValue("TE1"); lineCol1 = dlg.getValue("CL1").colour; lineStyle1 = dlg.getValue("CL1").pen; lineWidth1 = dlg.getValue("CL1").width; lineCol2 = dlg.getValue("CL2").colour; lineStyle2 = dlg.getValue("CL2").pen; lineWidth2 = dlg.getValue("CL2").width; lineCol3 = dlg.getValue("CL3").colour; lineStyle3 = dlg.getValue("CL3").pen; lineWidth3 = dlg.getValue("CL3").width; lineToggle1 = dlg.getValue("TIK1"); lineToggle2 = dlg.getValue("TIK2"); lineValue1 = dlg.getValue("NUM1"); lineValue2 = dlg.getValue("NUM2"); SW = (lineStyle1+1)*100000+(lineStyle2+1)*10000+(lineStyle3+1)*1000+(lineWidth1+1)*100+ (lineWidth2+1)*10+(lineWidth3+1) lineFlag = (lineValue2<0?4:0)+(lineValue1<0?2:0) LVF = (lineFlag+1)*1000000+(lineValue1<0?lineValue1*-1000:lineValue1*1000)+(lineValue2<0?lineValue2*-1:lineValue2); LBUSLT = (lineToggle1+1)*1000000+(lineToggle2+1)*100000+(useSector+1)*10000+lookback; storage.setAt(1, LVF); storage.setAt(2, lineCol1); storage.setAt(3, lineCol2); storage.setAt(4, lineCol3); storage.setAt(5, SW); storage.setAt(6, LBUSLT); } setSeriesColour(0,lineCol1); setSeriesLineStyle(0,lineStyle1,lineWidth1); if (lineToggle1 && lineToggle2) { setSeriesColour(1,lineCol2); setSeriesLineStyle(1,lineStyle2,lineWidth2); setSeriesColour(2,lineCol3); setSeriesLineStyle(2,lineStyle3,lineWidth3); } else if (lineToggle1 && !lineToggle2) { setSeriesColour(1,lineCol1); setSeriesLineStyle(1,lineStyle1,lineWidth1); } else if (!lineToggle1 && lineToggle2) { setSeriesColour(1,lineCol2); setSeriesLineStyle(1,lineStyle2,lineWidth2); } setHorizontalLine(0); //list possible markets the base share could be part of 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