//@LibraryID:897,5 //@Name:Trend Slope PA //@Description:Determine share's trend slope PA as shown on the Legend - not using Log Scale //@Returns:Number //@Width:90 //@Periodic:60 //@Env:Production // 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. // Authur: Phil Tolhurst, ShareScript Support var period = 25; // number of trading days to look back for a trend - about 6 months var dataList = ["Daily","Weekly","Monthly"]; var dataList2 = ["tds","wks","mnths"]; var trendList = ["Trend of all data","Trend of last X periods"]; var startDate = new Date(new Date()-31536000000); var endDate = getShare("UKI:UKX").getPrice().date; var useDates = 0; var trendChoice = 0; var dataSource = 0; var useIntra = 0; var trType = 0; function init(status) { if (status == Loading || status == Editing) { period = storage.getAt(0); trendChoice = storage.getAt(1); dataSource = storage.getAt(2); useIntra = storage.getAt(3); trType = storage.getAt(4); startDate = new Date(dateNumGetYear(storage.getAt(5)),dateNumGetMonth(storage.getAt(5)),dateNumGetDay(storage.getAt(5))); endDate = new Date(dateNumGetYear(storage.getAt(6)),dateNumGetMonth(storage.getAt(6)),dateNumGetDay(storage.getAt(6))); useDates = storage.getAt(7); } if (status == Adding || status == Editing) { dlg = new Dialog("Settings....",300,115); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("VAL1",10,5,100,-1,trendList,"","",trendChoice); dlg.addDropList("VAL6",10,21,100,-1,["Use period","Use dates"],"","",useDates); dlg.addDropList("VAL5",115,5,-1,-1,["Linear Scale","Log Scale"],"","",trType); dlg.addGroupBox(5,42,100,65,"Use period") dlg.addIntEdit("VAL2",10,54,-1,-1,"","Trend period",period,2,5000); dlg.addDropList("VAL4",10,72,-1,-1,dataList,"","",dataSource); dlg.addTickBox("VAL3",10,90,90,-1,"Include Intraday Data",useIntra); dlg.addGroupBox(115,42,120,65,"Use dates") dlg.addDatePicker("DP1",120,54,-1,-1, "", "Start date", startDate); dlg.addDatePicker("DP2",120,80,-1,-1, "", "End date", endDate); if (dlg.show()==Dialog.Cancel) return false; trendChoice = dlg.getValue("VAL1"); period = dlg.getValue("VAL2"); useIntra = dlg.getValue("VAL3"); dataSource = dlg.getValue("VAL4"); trType = dlg.getValue("VAL5"); startDate = dlg.getValue("DP1"); endDate = dlg.getValue("DP2"); useDates = dlg.getValue("VAL6"); storage.setAt(0, period); storage.setAt(1, trendChoice); storage.setAt(2, dataSource); storage.setAt(3, useIntra); storage.setAt(4, trType); storage.setAt(5, dateNum(startDate)); storage.setAt(6, dateNum(endDate)); storage.setAt(7, useDates); } if (useDates) setTitle((trType?"Log":"Linear")+" Trend Slope PA ("+dateToString(startDate)+" - "+dateToString(endDate)+")"); else if (trendChoice == 0) setTitle((trType?"Log":"Linear")+" Trend Slope PA ("+trendList[0]+" ("+(useIntra?"i-":"")+dataList[dataSource]+")"); else setTitle((trType?"Log":"Linear")+" Trend Slope PA ("+period+" "+(useIntra?"i-":"")+dataList2[dataSource]+")"); } function getVal(share) { if (useDates) var data = share.getPriceArrayDates(startDate,endDate); else var data = getData(share,dataSource,useIntra); if (data.length<2)return; var trendSlope; if(trendChoice==0 || useDates) { //Trend of all data period = data.length; var trendCalc = new Trend(period); for (i=0;idata[data.length-1].high?idata[0].high:data[data.length-1].high), low:(idata[0].lowdata[data.length-1].high?idata[0].high:data[data.length-1].high), low:(idata[0].low