Login Page - Create Account

Support Board


Date/Time: Fri, 03 May 2024 09:58:52 +0000



[Programming Help] - ACSIL not detecting last bar on a friday

View Count: 438

[2021-03-16 15:45:27]
grantx - Posts: 244
This code prints an arrow above the first bar of the day and last bar of the day. Works for all days of the week but Friday.
Why does it not pick up the last bar on Friday? The arrow that should be on Fridays bar gets printed on Mondays first bar.


SCSFExport scsf_Indicate_Day_Start_End_Bars(SCStudyInterfaceRef sc)
{
  SCSubgraphRef ArrowDown = sc.Subgraph[0];
  SCSubgraphRef ArrowUp = sc.Subgraph[1];
  if (sc.SetDefaults)
  {
    sc.GraphName = "Highlight start and end bars";
    sc.GraphRegion = 0;
    sc.DisplayStudyName = 0;
    sc.DisplayStudyInputValues = 0;
    sc.Subgraph[0].DisplayNameValueInDataLine = false;
    sc.Subgraph[1].DisplayNameValueInDataLine = false;
    sc.Subgraph[2].DisplayNameValueInDataLine = false;
    sc.AutoLoop = 0; //No automatic looping

    ArrowUp.Name = "End";
    ArrowUp.DrawStyle = DRAWSTYLE_ARROW_DOWN;
    ArrowUp.PrimaryColor = RGB(255, 255, 255);  // red
    ArrowUp.LineWidth = 2; //Width of arrow
    ArrowUp.DrawZeros = 0;

    ArrowDown.Name = "Start";
    ArrowDown.DrawStyle = DRAWSTYLE_ARROW_DOWN;
    ArrowDown.PrimaryColor = RGB(255, 0, 0);  // red
    ArrowDown.LineWidth = 2; //Width of arrow
    ArrowDown.DrawZeros = 0;
  }
  SCDateTimeMS InStartTime;
  SCDateTimeMS InEndTime;
  InStartTime = sc.StartTime1;
  InEndTime = sc.StartTime2;
  
  for (int BarIndex = sc.UpdateStartIndex; BarIndex < sc.ArraySize - 1; ++BarIndex)
  {    
    //Wait for the last bar to close
    if (sc.GetBarHasClosedStatus(BarIndex) != BHCS_BAR_HAS_CLOSED)
      return;

    int StartIndex;
    int EndIndex;
    if (BarIndex != 0)
    {
      SCDateTime startTime;
      SCDateTime EndDateTime;

      startTime.SetTime(sc.StartTime1);
      EndDateTime.SetTime(sc.EndTime1);
      SCDateTime timeDifference = EndDateTime - startTime - 1;

      SCDateTime TradingDayStartDateTime = sc.GetTradingDayStartDateTimeOfBar(sc.BaseDateTimeIn[BarIndex]);
      SCDateTime CurrentBarTradingDayEndDateTime = TradingDayStartDateTime + timeDifference;

      if (CurrentBarTradingDayEndDateTime.IsMonday())
      {
        CurrentBarTradingDayEndDateTime.SubtractDays(3);
      }
      
      EndIndex = sc.GetNearestMatchForSCDateTime(sc.ChartNumber, CurrentBarTradingDayEndDateTime);
      StartIndex = sc.GetFirstIndexForDate(sc.ChartNumber, TradingDayStartDateTime.GetDate());

      ArrowDown[StartIndex] = sc.High[StartIndex];
      ArrowUp[EndIndex] = sc.High[EndIndex];

    }
  }
}

Date Time Of Last Edit: 2021-03-16 15:46:18

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account