Support Board
Date/Time: Sun, 02 Feb 2025 17:52:03 +0000
[User Discussion] - Ehlers Trend Extraction
View Count: 640
[2019-10-02 03:01:29] |
spoozandtwos - Posts: 3 |
Hey guys and gals, trying to get this coded for SC. Here's the EasyLanguage: Inputs:
Price((H+L)/2), Period(20), Delta(.1); Vars: gamma(0), alpha(0), beta(0), BP(0), Trend(0); beta = Cosine(360 / Period); gamma = 1 / Cosine(720*delta / Period); alpha = gamma - SquareRoot(gamma*gamma - 1); BP = .5*(1 - alpha)*(Price - Price[2]) + beta*(1 + alpha)*BP[1] - alpha*BP[2]; Trend = Average(BP, 2*Period); Plot1(Trend); Plot2(0); ...and here's what I have so far, which is essentially the BandPass filter. It's giving me NaN readings when I try to apply it to my charts. #include "sierrachart.h" SCDLLName ("Trend follower") SCSFExport scsf_Trendfollower(SCStudyInterfaceRef sc) { SCSubgraphRef Trend = sc.Subgraph[0]; SCSubgraphRef Null = sc.Subgraph[1]; SCInputRef Price = sc.Input[0]; SCInputRef Length = sc.Input[1]; SCInputRef Delta = sc.Input[2]; SCFloatArray BP = Trend.Arrays[0]; if (sc.SetDefaults) { sc.GraphName = "Trend"; sc.StudyDescription = "Main indicator"; sc.GraphRegion = 1; sc.AutoLoop = 1; sc.FreeDLL = 0; Trend.Name = "Trend follower"; Trend.DrawStyle = DRAWSTYLE_LINE; Trend.PrimaryColor = RGB(255, 255, 255); Trend.LineWidth = 2; Null.Name = "Null"; Null.DrawStyle = DRAWSTYLE_LINE; Null.PrimaryColor = RGB(255, 0, 0); Null.LineWidth = 2; Null.DrawZeros = 1; Price.Name = "Price"; Price.SetInputDataIndex(SC_HL); Length.Name = "Length"; Length.SetInt(20); Length.SetIntLimits(1, INT_MAX); Delta.Name = "Delta"; Delta.SetFloat(0.10f); Delta.SetFloatLimits(-1.00, 1.00); return; } float a1, a2, a3, a4, b1, b2, b3, b4; a1 = Delta.GetFloat(); a2 = sc.BaseData[Price.GetInputDataIndex()][sc.Index-1]; a3 = sc.BaseData[Price.GetInputDataIndex()][sc.Index-2]; a4 = sc.BaseData[Price.GetInputDataIndex()][sc.Index]; b1 = cos(360 / Length.GetInt()); b2 = 1 / cos((720*a1) / Length.GetInt()); b3 = b2 - sqrt( (b2)*(b2) - 1); BP[sc.Index] = 0.5*(1-b3)*(a4-a3) + b1*(1+b3)*BP[sc.Index-1] - b3*BP[sc.Index-2]; Trend[sc.Index] = BP[sc.Index]; Null[sc.Index] = 0; } Can anyone guess why I'm getting NaN readings, or if I'm doing anything wrong? It would be greatly appreciated, thanks! |
To post a message in this thread, you need to log in with your Sierra Chart account: