//@Name:Forex Index //@Description:Returns the USD or EUR index based on a basket of other currencies. // 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 var forexList = ["US Dollar Index","Euro Index"]; var forexNum = 0; var lineCol = Colour.Red; var lineWidth = 1; var lineStyle = 0; var indexData = []; function init(status) { //clear(); if (status == Loading || status == Editing) { forexNum = storage.getAt(0); lineCol = storage.getAt(1); lineStyle = storage.getAt(2); lineWidth = storage.getAt(3); } if (status == Adding || status == Editing) { var dlg = new Dialog("Forex Index", 220, 55); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1",8,10,90,-1,forexList,"","",forexNum); dlg.addColLinePicker("LN1",110,10,-1,-1,"","",lineCol,lineStyle,lineWidth); if (dlg.show()==Dialog.Cancel) return false; forexNum = dlg.getValue("DL1"); lineCol = dlg.getValue("LN1").colour; lineStyle = dlg.getValue("LN1").pen; lineWidth = dlg.getValue("LN1").width; storage.setAt(0, forexNum); storage.setAt(1, lineCol); storage.setAt(2, lineStyle); storage.setAt(3, lineWidth); } setSeriesColour(0, lineCol); setSeriesLineStyle(0,lineStyle,lineWidth); setTitle(forexList[forexNum]); var pairs = []; var ratios = []; var constant; if (forexNum==0) { pairs[0] = getShare("FX:EURUSD").getCloseArray(); pairs[1] = getShare("FX:USDJPY").getCloseArray(); pairs[2] = getShare("FX:GBPUSD").getCloseArray(); pairs[3] = getShare("FX:USDCAD").getCloseArray(); pairs[4] = getShare("FX:USDSEK").getCloseArray(); pairs[5] = getShare("FX:USDCHF").getCloseArray(); ratios = [-0.576,0.136,-0.119,0.091,0.042,0.036]; constant = 50.14348112; } else if (forexNum==1) { pairs[0] = getShare("FX:EURUSD").getCloseArray(); pairs[1] = getShare("FX:GBPEUR").getCloseArray(); pairs[2] = getShare("FX:EURJPY").getCloseArray(); pairs[3] = getShare("FX:EURCHF").getCloseArray(); pairs[4] = getShare("FX:EURSEK").getCloseArray(); ratios = [0.3155,-0.3056,0.1891,0.1113,0.0785]; constant = 34.38805726; } var dlength; for (var i=0;i