//@Name:Fisher Transform //@Description:Transforms price to normal distribution //Author: Roger Harmer //Modified to include signal line by Phil Tolhurst, ShareScript Support /* Makes it easier to see cyclic turns. The init() function is called once. It's a place where you can do any preparation required */ var colour1 = Colour.Blue; var colour2 = Colour.Green; var colour3 = Colour.Red; var pen1 = 0; var pen2 = 0; var pen3 = 0; var width1 = 0; var width2 = 0; var width3 = 0; var lineStyle1 = 0; var lineStyle2 = 0; var lineStyle3 = 0; var firstLineOption = 1; var secLineOption = 1; var sigPeriod = 9; var sigType = 0; var sigOption = 1; var sigTypeList = ["Simple","Exponential","Weighted","Triangular","VariableVHF","VariableCMO","VIDYA"]; var sigTitleList = ["SMA","EMA","WMA","TMA","VVHF","VCMO","VIDYA"]; var sigStyle = 0; var options = 0; function init(status) { if (status==Loading || status==Editing) { colour1 = storage.getAt(0); lineStyle1 = storage.getAt(1); colour2 = storage.getAt(2); lineStyle2 = storage.getAt(3); colour3 = storage.getAt(4); lineStyle3 = storage.getAt(5); sigStyle = storage.getAt(6); options = storage.getAt(7); pen1 = Math.floor(lineStyle1/1000); width1 = lineStyle1%1000; pen2 = Math.floor(lineStyle2/1000); width2 = lineStyle2%1000; pen3 = Math.floor(lineStyle3/1000); width3 = lineStyle3%1000; sigPeriod = Math.floor(sigStyle/1000); sigType = sigStyle%1000; options = options.toString(); firstLineOption=parseInt(options.substr(0,1),10)-1; secLineOption=parseInt(options.substr(1,1),10); sigOption=parseInt(options.substr(2,1),10); } if (status==Adding || status==Editing) { do{ var dlg = new Dialog((status==Adding?"Add":"Edit")+" indicator",185,70) dlg.addOkButton(); dlg.addCancelButton(); dlg.addTickBox("VAL1",5,7,10,10,"",firstLineOption); dlg.addColLinePicker("VAL2",45,5,-1,-1,"Line 1","",colour1,pen1,width1); dlg.addTickBox("VAL3",5,27,10,10,"",secLineOption); dlg.addColLinePicker("VAL4",45,25,-1,-1,"Line 2","",colour2,pen2,width2); dlg.addColLinePicker("VAL5",45,45,-1,-1,"Signal","",colour3,pen3,width3); dlg.addTickBox("VAL6",5,47,10,10,"",sigOption); dlg.addIntEdit("VAL7",83,46,-1,-1,"","",sigPeriod,2,5000); dlg.addDropList("VAL8",125,45,55,-1, sigTypeList, "","",sigType); if (dlg.show()==Dialog.Cancel) return false; firstLineOption = dlg.getValue("VAL1"); colour1 = dlg.getValue("VAL2").colour; line1 = dlg.getValue("VAL2").pen; width1 = dlg.getValue("VAL2").width; secLineOption = dlg.getValue("VAL3"); colour2 = dlg.getValue("VAL4").colour; line2 = dlg.getValue("VAL4").pen; width2 = dlg.getValue("VAL4").width; colour3 = dlg.getValue("VAL5").colour; line3 = dlg.getValue("VAL5").pen; width3 = dlg.getValue("VAL5").width; sigOption = dlg.getValue("VAL6"); sigPeriod = dlg.getValue("VAL7"); sigType = dlg.getValue("VAL8"); }while (!sigOption && !firstLineOption && !secLineOption) lineStyle1 = pen1*1000+width1; lineStyle2 = pen2*1000+width2; lineStyle3 = pen3*1000+width3; sigStyle = sigPeriod*1000+sigType; options = ((firstLineOption+1)*100)+(secLineOption*10)+sigOption; storage.setAt(0, colour1); storage.setAt(1, lineStyle1); storage.setAt(2, colour2); storage.setAt(3, lineStyle2); storage.setAt(4, colour3); storage.setAt(5, lineStyle3); storage.setAt(6, sigStyle); storage.setAt(7, options); } if(sigOption) setTitle("Fisher Transform ("+sigPeriod+sigTitleList[sigType]+")") else setTitle("Fisher Transform"); if(firstLineOption && secLineOption && sigOption) { setSeriesColour(0,colour1); setSeriesLineStyle(0,pen1,width1); setSeriesColour(1,colour2); setSeriesLineStyle(1,pen2,width2); setSeriesColour(2,colour3); setSeriesLineStyle(2,pen3,width3); } if(firstLineOption && !secLineOption && sigOption) { setSeriesColour(0,colour1); setSeriesLineStyle(0,pen1,width1); setSeriesColour(1,colour3); setSeriesLineStyle(1,pen3,width3); } if(!firstLineOption && secLineOption && sigOption) { setSeriesColour(0,colour2); setSeriesLineStyle(0,pen2,width2); setSeriesColour(1,colour3); setSeriesLineStyle(1,pen3,width3); } if(firstLineOption && secLineOption && !sigOption) { setSeriesColour(0,colour1); setSeriesLineStyle(0,pen1,width1); setSeriesColour(1,colour2); setSeriesLineStyle(1,pen2,width2); } if(firstLineOption && !secLineOption && !sigOption) { setSeriesColour(0,colour1); setSeriesLineStyle(0,pen1,width1); } if(!firstLineOption && secLineOption && !sigOption) { setSeriesColour(0,colour2); setSeriesLineStyle(0,pen2,width2); } if(!firstLineOption && !secLineOption && sigOption) { setSeriesColour(0,colour3); setSeriesLineStyle(0,pen3,width3); } setRange(Range.CentreZero) setHorizontalLine(2); setHorizontalLine(-2); } function getGraph(share, data) { var len=8; var fish = new Array(); var fish2 = new Array(); var fishSig = new Array(); var fishSigCalc = new MA (sigPeriod,sigType) var h1 = 0; var l1 = 0; var v1 = new Array(); var v2 = new Array(); v1[len-2]=0; fish[len-2]=0; for (var i=len-1; idata[i-j].close) l1 = data[i-j].close; } v1[i] = 0.330*2*((data[i].close-l1)/(h1-l1+0.0001)-0.5)+0.67*v1[i-1]; if (v1[i]>0.99) v2[i]=0.999; else if (v1[i]<-0.99) v2[i]=-0.999; else v2[i]=v1[i]; fish[i] = 0.5*Math.log((1+v2[i])/(1-v2[i]))+0.5*fish[i-1]; fish2[i] = fish[i-1]; fishSig[i] = fishSigCalc.getNext(fish[i]); } if(firstLineOption && secLineOption && sigOption) { return [fish, fish2, fishSig]; } else if(firstLineOption && !secLineOption && sigOption) { return [fish, fishSig]; } else if(!firstLineOption && secLineOption && sigOption) { return [fish2, fishSig]; } else if(firstLineOption && secLineOption && !sigOption) { return [fish, fish2]; } else if(firstLineOption && !secLineOption && !sigOption) { return [fish]; } else if(!firstLineOption && secLineOption && !sigOption) { return [fish2]; } else if(!firstLineOption && !secLineOption && sigOption) { return [fishSig]; } }