//@LibraryID:1262,0 //@Name:Price Bounce MA //@Description:Returns 1 if the price has drop to or recently bounced off the MA //@Returns:Number //@Width:60 //@Update:Periodic,60 var maType = 0; var period = 20; var dataSource = 0; var dataList = ["Daily","Weekly","Monthly"]; var maTitleList = ["SMA","EMA","WMA","TMA","VVHF","VCMO","VIDYA"]; var maList = ["Simple","Exponential","Weighted","Triangular","VariableVHF","VariableCMO","VIDYA"]; var useIntra = 0; function init(status) { if (status == Loading || status == Editing) { dataSource = storage.getAt(0); maType = storage.getAt(1); period = storage.getAt(2); useIntra = storage.getAt(3); } if (status == Adding || status == Editing) { dlg = new Dialog("Settings",200,90); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1",8,-1,-1,-1,dataList,"","",dataSource); dlg.addDropList("DL2",8,-1,-1,-1,maList,"","",maType); dlg.addIntEdit("INT1",8,-1,-1,-1,"","MA period",period,2,1000); dlg.addTickBox("VAL2",8,-1,130,-1,"use latest intraday data (daily only)", useIntra); if (dlg.show()==Dialog.Cancel) return false; dataSource = dlg.getValue("DL1"); maType = dlg.getValue("DL2"); period = dlg.getValue("INT1"); useIntra = dlg.getValue("VAL2"); storage.setAt(0, dataSource); storage.setAt(1, maType); storage.setAt(2, period); storage.setAt(3, useIntra); } setTitle("Price bounce off MA ("+period+","+maTitleList[maType]); } function getVal(share) { if (dataSource == 0) { var data = share.getPriceArray(period+20); if (useIntra==1) { var idata = share.getIBarArray(0,86400); if (idata!=undefined && idata.length==1 && new Date().getDate()==idata[0].date.getDate() && new Date().getDate()!=data[data.length-1].date.getDate()) { var tclose = share.getIClose(); var topen = share.getIOpen(); data[data.length]={open:(topen==null?idata[0].open:topen),high:idata[0].high,low:idata[0].low,close:(tclose==null?share.getIMid():tclose),volume:idata[0].volume}; } } } if (dataSource == 1) var data = share.getWeeklyBarArray(period+20); if (dataSource == 2) var data = share.getMonthlyBarArray(period+20); if (data == undefined || data.length < period+20) return; var ma = new MA(period,maType); var maValues = new Array(); for (var i=0;i 0.2) i-=1; while (isClose == true) { perc = 100*(data[i].close-maValues[i])/maValues[i]; if (perc>0 && perc<0.2) count += 1; else isClose = false; i-=1; } if (count > 0 && perc > 0.5) return 1; return 0; }