//@Name:JKHL //@Description:JK HiLo Index, as described in Stocks & Commodities Magazine, October 2011. //@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 var indexList = ["FT30","FTSE100","FTSE250","FTSE350","FTSE All-Share","NYSE","Nasdaq","AMEX"]; var listList = [List.FT30,List.FTSE100,List.FTSE250,List.FTSE350,List.FTSEAllShare,List.NYSE,List.NASDAQ,List.AMEX]; var listNum = 0; var baseShare; var NH = []; var NL = []; var NS = []; var JKHL = []; var col1 = Colour.DarkGreen; var style1 = 0; var width1 = 0; var lookback = 250; var resetFile = false; function init(status) { if (status == Loading || status == Editing) { listNum = storage.getAt(0); col1 = storage.getAt(1); style1 = storage.getAt(2); width1 = storage.getAt(3); } if (status == Adding || status == Editing) { var dlg = new Dialog("New 250td Highs/Lows", 220, 115); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1",8,-1,90,-1,indexList,"","",listNum); dlg.addTickBox("TB1",8,-1,150,-1,"Reset stored values",false); dlg.addColLinePicker("LN1",8,-1,-1,-1,"","",col1,style1,width1); dlg.addText(8,57,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.addText(8,85,180,26,"Tick the Reset option to delete previously stored values.") if (dlg.show()==Dialog.Cancel) return false; listNum = dlg.getValue("DL1"); resetFile = dlg.getValue("TB1"); col1 = dlg.getValue("LN1").colour; style1 = dlg.getValue("LN1").pen; width1 = dlg.getValue("LN1").width; storage.setAt(0, listNum); storage.setAt(1, col1); storage.setAt(2, style1); storage.setAt(3, width1); } //if the reset option has been selected delete all content from the dat file. if (resetFile) { var F = new File(); F.open("/Output/JKHL.dat",File.WriteMode); F.close(); } var startTime = new Date(); //starts the timer var baseList = getList(listList[listNum]); //gets the list of shares var list = []; NH = []; //array of new highs NL = []; //array of new lows NS = []; //array of number of instruments trading at each point in time //check if data file exists, if not create it and enter 14 lines of zeros var F = new File(); try { F.open("/Output/JKHL.dat",File.ReadMode); } catch (e) { F.open("/Output/JKHL.dat",File.WriteMode); } finally { F.close(); } //open the file again and read the NH & NL line for the selected index F = new File(); F.open("/Output/JKHL.dat"); var line; var fullLine = []; var lineNum = -1; for (var i=0;line = F.readLine();i++) { if (line[0]=="@") //@ indicates the beginning of a new set of data { lineNum++; fullLine[lineNum] = line; } else { fullLine[lineNum] += line; } } F.close(); //check the header data of each line and load it in the NH, NL & NS arrays if it matches var iNH; var iNL; var iNS; for (i=0;ibaseShare.length) baseShare = list[i]; } //calculate the values of the new highs, new lows and number of shares for eash day of the list's history var j, n, isHigh, isLow; for (i=0;ibaseShare[j].dateNum) j++; j++; isHigh, isLow; for (var k=1;k=Math.max(k-(lookback-1),0);n--) { if (list[i][n].close>list[i][k].close) isHigh = false; if (list[i][n].close=0) { var F = ma1.getNext(E); var G = (F>=2.15||F<=0.4)?F:1; var H = NH[i] / (NH[i]+NL[i]); if (isNaN(H)) H = 0; if (H>=0) { var I = ma2.getNext(H); if (ignoreCount>=lookback) JKHL[i] = G*I*100; else ignoreCount++; } } } for (i=0;ibaseShare[j].dateNum) j++; for (var i=0;ibaseShare[j].dateNum) { j++;i--; } else { outputJKHL[i] = outputJKHL[i-1]; } } catch(e) { outputJKHL[i] = 0; } } return outputJKHL; }