/********************************************************* Name: TSE.Wavelet.Nowcast.Trend Analysis Type: Indicator Description: Non-decimated Haar Wavelet Trend Nowcast Indicator Used: tsewvl.dll Provided By: Trade Smart Research (c) Copyright 2001 - 2004 www.tsresearch.com *********************************************************/ var c,v,lookback,Trend, Wavelet, Sigma; /* Defining DLL */ var d = new DLL("tsewvl.dll"); /* Functions Declaration */ d.addFunction("runwvl", DLL.FLOAT, DLL.STDCALL,"RUNWVL", DLL.FLOATARRAY,DLL.INT,DLL.FLOAT); d.addFunction("getallvalues", DLL.FLOAT, DLL.STDCALL,"GETALLVALUES", DLL.INT,DLL.INT); /* Preparing parameters and array*/ function preMain() { setPriceStudy(false); setStudyTitle("Wavelet Nowcast Trend"); setCursorLabelName("Nowcast", 0); setDefaultBarStyle(PS_SOLID, 0); setDefaultBarFgColor(Color.red, 0); setDefaultBarThickness(1, 0); setPlotType(PLOTTYPE_LINE, 0); ArrayPrice = new Array(256); /* wavelet scale */ var fp1 = new FunctionParameter("Scales", FunctionParameter.NUMBER); fp1.setLowerLimit(1); fp1.setUpperLimit(8); fp1.setDefault(5); /* threshold value signal / noise */ var fp2 = new FunctionParameter("NSigma", FunctionParameter.NUMBER); fp2.setLowerLimit(1); fp2.setUpperLimit(4); fp2.setDefault(3); } function main(Scales,NSigma) { if (Scales==null) Scales=5; if (NSigma==null) NSigma=3; lookback=256; aSource=getValue("Close",0,-lookback); nBarIndex = getNumBars()+getCurrentBarIndex(); /* filling array */ if (nBarIndex >lookback) { for (x=0; x<lookback; x++) { ArrayPrice[x] = aSource[x]; } /* calling functoin in dll */ v = d.call("runwvl",ArrayPrice,8,NSigma); Wavelet =d.call("getallvalues",1,Scales); Sigma =d.call("getallvalues",2,Scales); /* Determinig trend */ if (Wavelet > NSigma * Sigma) { Trend = 1 } else { if (Wavelet < - NSigma * Sigma) { Trend = -1 } else { Trend=0 } } } else { v=0 } return Trend; } |