Login Page - Create Account

Support Board


Date/Time: Sat, 18 May 2024 20:19:50 +0000



Post From: Study Angle Reset

[2017-06-14 08:03:00]
Neo - Posts: 198
My trouble with your implementation is that it only skips the calculation at the start of the session, and will still look back at data from the previous day. So a gap day creates a big skew, especially when looking at the cumulative result( See image below- Green vs Yellow( my version)

I have taken your advice and implemented the changes myself. The only trouble is the performance is poor. Could you make any comments on how I could improve this?


#include "sierrachart.h"

SCDLLName("StudyAngleReset");


SCSFExport scsf_StudyAngle(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Angle = sc.Subgraph[0];
  SCSubgraphRef ZeroLine = sc.Subgraph[1];
  
  SCInputRef InInputData = sc.Input[0];
  SCInputRef InLength = sc.Input[1];
  SCInputRef InValuePerPoint = sc.Input[2];
  SCInputRef ResetAtSessionStart = sc.Input[3];
  
  if (sc.SetDefaults)
  {
    // xx
    
    sc.GraphName = "Study Angle";
    sc.AutoLoop = 1;
    
    // xx
    sc.FreeDLL = 0;
    
    Angle.Name = "Angle";
    Angle.DrawStyle = DRAWSTYLE_LINE;
    Angle.PrimaryColor = RGB(0,255,0);
    Angle.DrawZeros= false;
    
    ZeroLine.Name = "Zero Line";
    ZeroLine.DrawStyle = DRAWSTYLE_LINE;
    ZeroLine.PrimaryColor = RGB(255,0,255);
    ZeroLine.DrawZeros= true;
    
    InInputData.Name = "Input Data";
    InInputData.SetInputDataIndex(0);
    
    InLength.Name = "Length";
    InLength.SetInt(10);
    InLength.SetIntLimits(1,MAX_STUDY_LENGTH);
    
    InValuePerPoint.Name = "Value Per Point";
    InValuePerPoint.SetFloat(1.0f);

    ResetAtSessionStart.Name = "Reset at Start of Trading Day";
    ResetAtSessionStart.SetYesNo(0);
    
    return;
  }
  
  int Length = InLength.GetInt();
  
  sc.DataStartIndex = Length;
  
  if (InValuePerPoint.GetFloat() == 0.0f)
    InValuePerPoint.SetFloat(0.01f);
  
  SCDateTime NextSessionStart = sc.GetTradingDayStartDateTimeOfBar(sc.BaseDateTimeIn[sc.DataStartIndex - 1]) + 1*DAYS;

  if (sc.DataStartIndex == 0)
  {
    Angle[0] = 0;
  }
  
  for (int Index = max(sc.DataStartIndex, 1); Index < sc.ArraySize; Index++)
  {
    if (ResetAtSessionStart.GetYesNo() != 0)
    {
      SCDateTime IndexDateTime = sc.BaseDateTimeIn[Index];
      SCDateTime LengthDateTime = sc.BaseDateTimeIn[Index - Length];

      if (IndexDateTime >= NextSessionStart || (LengthDateTime < NextSessionStart - 1 * DAYS || LengthDateTime >= NextSessionStart))
      {
        Angle[Index] = 0;

        NextSessionStart = sc.GetTradingDayStartDateTimeOfBar(IndexDateTime) + 1*DAYS;
      }
      else
      {
        SCFloatArrayRef InData = sc.BaseData[InInputData.GetInputDataIndex()];

        float BackValue = InData[Index - Length];
        float CurrentValue = InData[Index];

        float PointChange = (CurrentValue - BackValue) / InValuePerPoint.GetFloat();

        Angle[Index] = (float)(atan2((double)PointChange, (double)Length) * 180.0 / M_PI);
      }
    }
    else
    {

          SCFloatArrayRef InData = sc.BaseData[InInputData.GetInputDataIndex()];

          float BackValue = InData[Index - Length];
          float CurrentValue = InData[Index];

          float PointChange = (CurrentValue - BackValue) / InValuePerPoint.GetFloat();

          Angle[Index] = (float)(atan2((double)PointChange, (double)Length) * 180.0 / M_PI);

    }
  }  
}

Date Time Of Last Edit: 2017-06-14 08:11:50
imagestudyanglereset.png / V - Attached On 2017-06-14 08:11:29 UTC - Size: 119.59 KB - 295 views
Attachment Deleted.
Attachment Deleted.