//@Name:New Highs/Lows Lines //@Description:Returns the New Highs/Lows market graph as a pair of indicators // 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 indexList = ["FT30","FTSE100","FTSE250","FTSE350","FTSE All-Share","LSE Shares","NYSE","Nasdaq","AMEX","US 500"]; var listList = [List.FT30,List.FTSE100,List.FTSE250,List.FTSE350,List.FTSEAllShare,List.LSEShares,List.NYSE,List.NASDAQ,List.AMEX,List.US500]; var listNum = 0; var baseShare; var NH = []; var NL = []; var upCol = Colour.Blue; var downCol = Colour.Red; var lookback = 250; var clearDatFile = false; var upStyle = 0; var downStyle = 0; var upWidth = 0; var downWidth = 0; function init(status) { //clear(); if (status == Loading || status == Editing) { listNum = storage.getAt(0); upCol = storage.getAt(1); downCol = storage.getAt(2); lookback = storage.getAt(3); upWidth = storage.getAt(4); upStyle = storage.getAt(5); downWidth = storage.getAt(6); downStyle = storage.getAt(7); } if (status == Adding || status == Editing) { var dlg = new Dialog("New 250td Highs/Lows", 220, 125); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1",8,-1,90,-1,indexList,"","",listNum); dlg.addIntEdit("INT1",8,-1,-1,-1,"","lookback",lookback,2,5000); dlg.addColLinePicker("COL1",8,-1,-1,-1,"","New Highs",upCol,upStyle,upWidth); dlg.addColLinePicker("COL2",8,-1,-1,-1,"","New Lows",downCol,downStyle,downWidth); dlg.addText(8,77,180,26,"Note: the indicator will take a few minutes to calculate, it will however store the calculated values reducing the processing times of all successive uses.") dlg.addTickBox("TB1",5,108,75,-1,"Clear stored values",clearDatFile); if (dlg.show()==Dialog.Cancel) return false; listNum = dlg.getValue("DL1"); lookback = dlg.getValue("INT1"); upCol = dlg.getValue("COL1").colour; downCol = dlg.getValue("COL2").colour; upWidth = dlg.getValue("COL1").width; upStyle = dlg.getValue("COL1").pen; downWidth = dlg.getValue("COL2").width; downStyle = dlg.getValue("COL2").pen; clearDatFile = dlg.getValue("TB1"); storage.setAt(0, listNum); storage.setAt(1, upCol); storage.setAt(2, downCol); storage.setAt(3, lookback); storage.setAt(4, upWidth); storage.setAt(5, upStyle); storage.setAt(6,downWidth); storage.setAt(7,downStyle); } var startTime = new Date(); //starts the timer var baseList = getList(listList[listNum]); //gets the list of shares var list = []; NH = []; NL = []; //check if data file exists, if not create it and enter 14 lines of zeros var F = new File(); try { F.open("/Output/NewH-NewL.dat",File.ReadMode); //this next bit is to delete the dat file of the older verion of the script, which is no longer compatble var lineTest = F.readLine(); if (lineTest[2]!="@" || clearDatFile) { F.close(); F.open("/Output/NewH-NewL.dat",File.WriteMode); } } catch (e) { F.open("/Output/NewH-NewL.dat",File.WriteMode); //for (var x=0;x= baseShare.length, all the data has already been calculated, so break the loop if (j>=baseShare.length) break; //shift forward j if the share's data history begins after the that of the base share. while (list[i][0].dateNum>baseShare[j].dateNum) j++; for (var k=1;kbaseShare[j].dateNum) { k--; continue; } if (list[i][k].dateNum=Math.max(k-(lookback-1),0);n--) { if (list[i][n].close>=list[i][k].close) isHigh = false; if (list[i][n].close<=list[i][k].close) isLow = false; if (!isHigh && !isLow) break; } if (isHigh) NH[j]++; if (isLow) NL[j]--; } } for (i=0;ibaseShare.length) { while (data[i].dateNumbaseShare[j].dateNum) { j++; } } for (i;i