//@Name:New Highs minus New Lows //@Description:Returns the New Highs/Lows market graph with separate high and low histograms. // 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: Philip Tolhurst, ShareScript Support var indexList = ["FT30","FTSE100","FTSE250","FTSE350","FTSE All-Share","LSE Shares","DJ Industrials","Nasdaq 100","S&P 500","NYSE","Nasdaq","US Shares"]; var listList = [List.FT30,List.FTSE100,List.FTSE250,List.FTSE350,List.FTSEAllShare,List.LSEShares,List.DJ30,List.NASDAQ100,List.US500,List.NYSE,List.NASDAQ,List.USShares]; var listNum = 0; var baseShare; var NH = []; var NL = []; var outputCol = Colour.Blue; var downCol = Colour.Red; var dOption = 0; var lookback = 250; var outputOption = 0; var clearDatFile = false; function init(status) { //clear(); if (status == Loading || status == Editing) { listNum = storage.getAt(0); outputCol = storage.getAt(1); lookback = storage.getAt(2); dOption = storage.getAt(3); downCol = storage.getAt(4); outputOption = storage.getAt(5); } if (status == Adding || status == Editing) { var dlg = new Dialog("New Highs - New Lows", 220, 145); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("VAL1",5,5,90,-1,indexList,"","",listNum); dlg.addIntEdit("VAL2",5,22,-1,-1,"","lookback",lookback,2,5000); dlg.addColPicker("VAL3",18,39,-1,-1,"","Bar Colour",outputCol); dlg.addTickBox("VAL4",5,58,10,-1,"",dOption); dlg.addColPicker("VAL5",18,56,-1,-1,"","Down Colour",downCol); dlg.addTickBox("VAL6",5,73,70,-1,"Output as a line.",outputOption); dlg.addText(8,94,180,26,"Note: the indicator will take a few minutes to calculate, it will then store the calculated values reducing the processing times of all successive uses."); dlg.addTickBox("VAL7",5,125,75,-1,"Clear stored values",clearDatFile); if (dlg.show()==Dialog.Cancel) return false; listNum = dlg.getValue("VAL1"); lookback = dlg.getValue("VAL2"); outputCol = dlg.getValue("VAL3"); dOption = dlg.getValue("VAL4"); downCol = dlg.getValue("VAL5"); outputOption = dlg.getValue("VAL6"); clearDatFile = dlg.getValue("VAL7"); storage.setAt(0, listNum); storage.setAt(1, outputCol); storage.setAt(2, lookback); storage.setAt(3,dOption); storage.setAt(4,downCol); storage.setAt(5,outputOption); } 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 compatible or if 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++; //isHigh, isLow; 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