Login Page - Create Account

Support Board


Date/Time: Wed, 15 Jan 2025 13:57:31 +0000



Post From: USER DISCUSSION: PLEASE HELP A COMPUTER RETARD TRANSLATE SIX LINES OF TRADESTATION CODE

[2017-06-19 13:54:17]
michelh - Posts: 159
Hi All,

So this is quite embarrassing.

I was reading an Ehlers article on a simple method of detrending. Since I want to learn about cycles, I thought it would be good to see what my detended data sets look like. To find the document, please put the following into google "ehlers the joy of detrending" - it is the first result. It looked really interesting and he goes further to make a trend-ambivalent AO - but I am just interested in the first detrend bit.

The six lines of tradestation code for the detrender are:

Inputs: Price((H+L)/2);
Vars:  Detrend(0);
Value1 = Price + .088*Value1[6];
Value2 = Value1 – Value1[6] + 1.2*Value2[6] - .7*Value2[12];
Detrend = Value2[12] – 2*Value2[6] + Value2;
Plot1(Detrend, “Detrend”);

I have studied the ASCIL documentation and found the courage to try this.

The compiler error I get is:

error: stray '\226' in program Det[sc.Index] = V2[sc.Index - 12] – (2 * V2[sc.Index - 6]) + V2[sc.Index]; ^ detrend.cpp: In function 'void scsf_EhlersDetrend(SCStudyInterfaceRef)': detrend.cpp:42:59: error: expression cannot be used as a function Det[sc.Index] = V2[sc.Index - 12] – (2 * V2[sc.Index - 6]) + V2[sc.Index];

If you have ten minutes to spare and can spot my error, that would be appreciated.


--------------------------------------------------------------

#include "sierrachart.h"
// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("EhlersDetrend")

//From Stocks & Commodities V. 18:7 (20-29): Optimal Detrending by John F. Ehlers

SCSFExport scsf_EhlersDetrend(SCStudyInterfaceRef sc)
{
  // Set the configuration variables

SCSubgraphRef Det = sc.Subgraph[0];
SCFloatArrayRef V1 = Det.Arrays[0];
SCFloatArrayRef V2 = Det.Arrays[1];

SCInputRef InputData = sc.Input[0];

  if (sc.SetDefaults)
  {

    sc.GraphName = "EhlersDetrend";
    sc.StudyDescription = "Ehlers Detrend";
    sc.AutoLoop = 1; // true
    // During development set this flag to 1, so the DLL can be rebuilt without restarting Sierra Chart. When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = 1;
    sc.GraphRegion = 0;

    InputData.Name = "Input Data";
    InputData.SetInputDataIndex(SC_HL);

Det.Name = "Detrend";
    Det.DrawStyle = DRAWSTYLE_LINE;      // Look in scconstants.h for other draw styles
    Det.PrimaryColor = RGB(0, 128, 0);    // Green
    Det.SecondaryColor = RGB(255,0,0);
    Det.LineWidth = 3;

    return;
  }

  V1[sc.Index] = sc.BaseDataIn[SC_HL][sc.Index] + (.088 * V1[sc.Index - 6]);
  V2[sc.Index] = V1[sc.Index] - V1[sc.Index - 6] + V2[sc.Index - 6] - (0.7 * V2[sc.Index - 12]);
  Det[sc.Index] = V2[sc.Index - 12] – (2 * V2[sc.Index - 6]) + V2[sc.Index];

return;
}


Thanks!
attachmentdetrend.cpp - Attached On 2017-06-19 13:50:37 UTC - Size: 1.45 KB - 412 views