Login Page - Create Account

Support Board


Date/Time: Tue, 14 May 2024 22:47:51 +0000



Post From: Error wth remote build

[2019-07-30 10:05:03]
User148625 - Posts: 2
THanks! Here is the code


//#include <scstudyfunctions.h>
#include "sierrachart.h"



// For reference, refer to this page:
// Advanced Custom Study Interface and Language (ACSIL)

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

//This is the basic framework of a study function. Change the name 'TemplateFunction' to what you require.


SCSFExport scsf_OR(SCStudyInterfaceRef sc)
{
  SCSubgraphRef HighOfDay = sc.Subgraph[0];
  SCSubgraphRef LowOfDay = sc.Subgraph[1];

  SCInputRef Input_StartTime = sc.Input[0];
  SCInputRef Input_EndTime = sc.Input[1];
  SCInputRef Input_NumberDaysToCalculate = sc.Input[2];
  SCInputRef Input_UseLineStopTime = sc.Input[3];
  SCInputRef Input_Version = sc.Input[4];
  SCInputRef Input_LineStopTimeInput = sc.Input[5];
  SCInputRef Input_DisplayHighLowIncrementally = sc.Input[6];

  SCInputRef Input_InputDataHigh = sc.Input[7];
  SCInputRef Input_InputDataLow = sc.Input[8];
  SCInputRef Input_FridayEveningExtendsIntoSunday = sc.Input[9];

  if (sc.SetDefaults)
  {
    sc.GraphName      = "High/Low for Time Period - Extended";
    sc.GraphRegion      = 0;
    sc.AutoLoop        = 0;
    
    HighOfDay.Name = "High";
    HighOfDay.DrawStyle = DRAWSTYLE_STAIR_STEP;
    HighOfDay.PrimaryColor = RGB(0,255,0);
    HighOfDay. DrawZeros = false;
    
    LowOfDay.Name = "Low";
    LowOfDay.DrawStyle = DRAWSTYLE_STAIR_STEP;
    LowOfDay.PrimaryColor = RGB(255,0,255);
    LowOfDay.DrawZeros = false;

    Input_StartTime.Name = "Start Time";
    Input_StartTime.SetTime(0);

    Input_EndTime.Name = "End Time";
    Input_EndTime.SetTime(SECONDS_PER_DAY - 1);
  
    Input_NumberDaysToCalculate.Name= "Number Of Days To Calculate";
    Input_NumberDaysToCalculate.SetInt(120);

    Input_UseLineStopTime.Name = "Use Line Stop Time";
    Input_UseLineStopTime.SetYesNo(false);

    Input_LineStopTimeInput.Name = "Line Stop Time";
    Input_LineStopTimeInput.SetTime(SECONDS_PER_DAY - 1);

    Input_DisplayHighLowIncrementally.Name = "Display High Low Incrementally";
    Input_DisplayHighLowIncrementally.SetYesNo( true);

    Input_InputDataHigh.Name = "Input Data High";
    Input_InputDataHigh.SetInputDataIndex(SC_HIGH);

    Input_InputDataLow.Name = "Input Data Low";
    Input_InputDataLow.SetInputDataIndex(SC_LOW);

    Input_FridayEveningExtendsIntoSunday.Name = "Friday Evening Extends Into Sunday";
    Input_FridayEveningExtendsIntoSunday.SetYesNo(false);

    Input_Version.SetInt(2);

    return;
  }
    
    SCSFExport scsf_HighLowForTimePeriodExtendedLines(SCStudyInterfaceRef sc)
{
  SCSubgraphRef HighOfDay = sc.Subgraph[0];
  SCSubgraphRef LowOfDay = sc.Subgraph[1];

  SCInputRef Input_StartTime = sc.Input[0];
  SCInputRef Input_EndTime = sc.Input[1];
  SCInputRef Input_NumberDaysToCalculate = sc.Input[2];
  SCInputRef Input_UseLineStopTime = sc.Input[3];
  SCInputRef Input_Version = sc.Input[4];
  SCInputRef Input_LineStopTimeInput = sc.Input[5];
  SCInputRef Input_DisplayHighLowIncrementally = sc.Input[6];

  SCInputRef Input_InputDataHigh = sc.Input[7];
  SCInputRef Input_InputDataLow = sc.Input[8];
  SCInputRef Input_FridayEveningExtendsIntoSunday = sc.Input[9];

  if (sc.SetDefaults)
  {
    sc.GraphName      = "High/Low for Time Period - Extended";
    sc.GraphRegion      = 0;
    sc.AutoLoop        = 0;
    
    HighOfDay.Name = "High";
    HighOfDay.DrawStyle = DRAWSTYLE_STAIR_STEP;
    HighOfDay.PrimaryColor = RGB(0,255,0);
    HighOfDay. DrawZeros = false;
    
    LowOfDay.Name = "Low";
    LowOfDay.DrawStyle = DRAWSTYLE_STAIR_STEP;
    LowOfDay.PrimaryColor = RGB(255,0,255);
    LowOfDay.DrawZeros = false;

    Input_StartTime.Name = "Start Time";
    Input_StartTime.SetTime(0);

    Input_EndTime.Name = "End Time";
    Input_EndTime.SetTime(SECONDS_PER_DAY - 1);
  
    Input_NumberDaysToCalculate.Name= "Number Of Days To Calculate";
    Input_NumberDaysToCalculate.SetInt(120);

    Input_UseLineStopTime.Name = "Use Line Stop Time";
    Input_UseLineStopTime.SetYesNo(false);

    Input_LineStopTimeInput.Name = "Line Stop Time";
    Input_LineStopTimeInput.SetTime(SECONDS_PER_DAY - 1);

    Input_DisplayHighLowIncrementally.Name = "Display High Low Incrementally";
    Input_DisplayHighLowIncrementally.SetYesNo( true);

    Input_InputDataHigh.Name = "Input Data High";
    Input_InputDataHigh.SetInputDataIndex(SC_HIGH);

    Input_InputDataLow.Name = "Input Data Low";
    Input_InputDataLow.SetInputDataIndex(SC_LOW);

    Input_FridayEveningExtendsIntoSunday.Name = "Friday Evening Extends Into Sunday";
    Input_FridayEveningExtendsIntoSunday.SetYesNo(false);

    Input_Version.SetInt(2);

    return;
  }

  if (Input_Version.GetInt() == 1)
  {

    Input_InputDataHigh.SetInputDataIndex(SC_HIGH);
    Input_InputDataLow.SetInputDataIndex(SC_LOW);

    Input_Version.SetInt(2);
  }

  if (Input_NumberDaysToCalculate.GetInt() <= 0)
    Input_NumberDaysToCalculate.SetInt(10000);

  Input_StartTime.GetDateTime();
  Input_EndTime.GetDateTime();


  if (Input_StartTime.GetTime() <= Input_EndTime.GetTime()
    
    && (Input_StartTime.GetTime() < sc.StartTimeOfDay && Input_EndTime.GetTime() > sc.StartTimeOfDay)
    )
  {
    Input_StartTime.SetTime(sc.StartTimeOfDay);

    //Check if the start time is now greater than or equal to the end time in which case move the end time forward by 30 minutes from the start time.
    if (Input_StartTime.GetTime() >= Input_EndTime.GetTime())
    {
      Input_EndTime.SetTime(Input_StartTime.GetTime() + 30 * 60);
    }
  }
  
  float & HighOfPeriod = sc.GetPersistentFloat(1);
  float & LowOfPeriod = sc.GetPersistentFloat(2);

  SCDateTime DaysToCalculateStartDateTime = sc.GetTradingDayStartDateTimeOfBar(sc.BaseDateTimeIn[sc.ArraySize - 1]) - (Input_NumberDaysToCalculate.GetInt() - 1);

  // Loop through chart bars starting at the Update Start Index
  for (int Index = sc.UpdateStartIndex; Index < sc.ArraySize; Index++ )
  {

    SCDateTime CurrentBarDateTime = sc.BaseDateTimeIn[Index];

    SCDateTime PreviousBarDateTime = sc.BaseDateTimeIn[max(0, Index - 1)];

    SCDateTime StartDateTimeOfCurrentIndex = sc.GetTradingDayStartDateTimeOfBar(CurrentBarDateTime);
    SCDateTime StartDateTimeOfPreviousIndex = sc.GetTradingDayStartDateTimeOfBar(PreviousBarDateTime);

    bool NeedReset = StartDateTimeOfCurrentIndex != StartDateTimeOfPreviousIndex
      || Index == 0;

    if (sc.BaseDateTimeIn[Index] < DaysToCalculateStartDateTime)
      continue;

    SCDateTime StartDateTime ;
    SCDateTime EndDateTime ;

    StartDateTime = CurrentBarDateTime.GetDate();
    EndDateTime = CurrentBarDateTime.GetDate();

    StartDateTime.SetTime(Input_StartTime.GetTime());
    EndDateTime.SetTime(Input_EndTime.GetTime());

    bool TimesAreReversed = false;
    if (Input_StartTime.GetTime() > Input_EndTime.GetTime())
    {
      TimesAreReversed = true;
      if (CurrentBarDateTime.GetTimeInSeconds() < Input_StartTime.GetTime())
      {
        StartDateTime -= DAYS;
      }
      else
      {
        EndDateTime += DAYS;
      }
    }

    if(TimesAreReversed && Input_FridayEveningExtendsIntoSunday.GetYesNo())
    {
      SCDateTime TradingDayDate(sc.GetTradingDayDate(CurrentBarDateTime));
      int DayOfWeek = TradingDayDate.GetDayOfWeek();
      if (DayOfWeek == MONDAY)//DayOfWeek == SUNDAY ||
      {
        StartDateTime -= 2 * DAYS;
        NeedReset = false;
      }

    }

    //reset
    if (NeedReset)
    {
      HighOfPeriod = -FLT_MAX;
      LowOfPeriod = FLT_MAX;    
    }


    bool OutsideTimeRange = true;
    if (CurrentBarDateTime >= StartDateTime && CurrentBarDateTime <= EndDateTime)
    {
      OutsideTimeRange = false;

      if (HighOfPeriod < sc.BaseData[Input_InputDataHigh.GetInputDataIndex()][Index])
        HighOfPeriod = sc.BaseData[Input_InputDataHigh.GetInputDataIndex()][Index];

      if (LowOfPeriod > sc.BaseData[Input_InputDataLow.GetInputDataIndex()][Index])
        LowOfPeriod = sc.BaseData[Input_InputDataLow.GetInputDataIndex()][Index];
    }


    SCDateTime NoDrawEndDateTime;
    if (Input_UseLineStopTime.GetYesNo())
    {
      NoDrawEndDateTime.SetDateTime(EndDateTime.GetDate() , Input_LineStopTimeInput.GetTime());

      if (CurrentBarDateTime >= NoDrawEndDateTime)
      {
        HighOfPeriod = -FLT_MAX;
        LowOfPeriod = FLT_MAX;
      }
    }

    // Set/update all values for current day
    int BackIndex = Index;
    while(true && HighOfPeriod != -FLT_MAX)
    {
      if(BackIndex < 0)
        break;

      SCDateTime IndexDateTime = sc.BaseDateTimeIn[BackIndex];

      if(!OutsideTimeRange && IndexDateTime < StartDateTime)
        break;

      HighOfDay[BackIndex] = HighOfPeriod;
      LowOfDay[BackIndex] = LowOfPeriod;


      if (OutsideTimeRange || Input_DisplayHighLowIncrementally.GetYesNo())
        break;

      BackIndex--;

      if(sc.UpdateStartIndex != 0)
        sc.EarliestUpdateSubgraphDataArrayIndex = BackIndex;
    }
  }

}