//@Name:Intraday Compare //@Description:Calculates the difference or the ratio between the share and the base share. You must have the intraday graph set to start with full period. //@Type:Intraday // 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 useRatio = 0; var LineCol = 255; var LineStyle = 0; var LineWidth = 0; var changeBase; function init(status) { if (status == Loading || status == Editing) { useRatio = storage.getAt(0); LineCol = storage.getAt(1); LineStyle = storage.getAt(2); LineWidth = storage.getAt(3); } if (status == Adding || status == Editing) { dlg = new Dialog((status==Adding?"Add":"Edit")+" indicator", 220, 80); dlg.addOkButton(); dlg.addCancelButton(); dlg.addTextEdit("TE1",45,-1,60,-1,"Base share","","UKI:UKX"); dlg.addColLinePicker("CL1",120,5,-1,-1,"","",LineCol,LineStyle,LineWidth) dlg.addTickBox("TB1",10,-1,100,-1,"Ratio instead of difference",useRatio); dlg.addText(10,43,170,35,"The base share is identified as EXCH:EPIC. Use UKI for UK indicies, LSE for LSE shares, GER for the DAX and ENXT for the CAC. If base share isn't found, the script will default to FTSE100"); if (dlg.show()==Dialog.Cancel) return false; useRatio = dlg.getValue("TB1"); baseName = dlg.getValue("TE1"); LineCol = dlg.getValue("CL1").colour; LineStyle = dlg.getValue("CL1").pen; LineWidth = dlg.getValue("CL1").width; storage.setAt(0, useRatio); storage.setAt(1, LineCol); storage.setAt(2, LineStyle); storage.setAt(3, LineWidth); //set change base to true (which will be reset after the first call of getGraph() changeBase = true; } setSeriesColour(0,LineCol); setSeriesLineStyle(0,LineStyle,LineWidth); try { globalBaseShare = getShare(baseName); } catch (e) { globalBaseShare = getShare("UKI:UKX"); } var F = new File(); try { F.open("/Output/IntraComp.cfg",File.ReadMode); } catch (e) { F.open("/Output/IntraComp.cfg",File.WriteMode); } finally { F.close(); } } function getGraph(share, data) { var baseShare = globalBaseShare; //the first time getGraph gets called, the base share ID gets stored with the main share ID if (changeBase) { var F = new File(); F.open("/Output/IntraComp.cfg"); var line; var items = []; var entryExists = false for (var i=0;line = F.readLine();i++) { items[i] = line.split(","); //if an entry for the share exists, amend it with the new base share if (items[i][0] == share.getShareScopeID() && items[i][1] == share.getShareNum()) { items[i][2] = baseShare.getShareScopeID(); items[i][3] = baseShare.getShareNum(); entryExists = true; } } F.close(); //if an entry for the share doesn't exist create a new entry if (!entryExists) items[items.length] = [share.getShareScopeID(),share.getShareNum(),baseShare.getShareScopeID(),baseShare.getShareNum()]; F.open("IntraComp.cfg",File.WriteMode); for (i=0;i0;i--) { if (data[i].dateNum != date) { var baseRawData = baseShare.getIBarArrayOnDate(data[i].date,fixedPeriod); if (baseRawData == undefined || baseRawData.length==0) baseRawData = nullArray(fixedPeriod,share.getMarket()); baseData = baseRawData.concat(baseData); date = data[i].dateNum; } } //Calcualtes the Intraday comparison line if (baseData[0].close==null) output[0] = null; else if (!useRatio) output[0] = data[0].close - baseData[0].close; else output[0] = data[0].close / baseData[0].close; for (var m=1;m