Login Page - Create Account

Support Board


Date/Time: Sun, 24 Nov 2024 08:24:20 +0000



[Programming Help] - [PROGRAMMING HELP] ACSIL compare SCDateTime

View Count: 359

[2024-06-07 10:59:00]
aknsyu71@gmail - Posts: 54
This code for comparing date and time gives me an error message I cannot figure whats wrong?
    
SCDateTime IndexDateTime = sc.BaseDateTimeIn[i];
SCDateTime MySCDateTime(2000, 1, 1, 12, 0, 0);
if (IndexDateTime == MySCDateTime.GetDateTimeYMDHMS(2024,5,3,13,30,0))    SummerTime[i] = sc.Close[i];

AK_NEWS.cpp:45:55: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
45 | if (IndexDateTime == MySCDateTime.GetDateTimeYMDHMS(2024,5,3,13,30,0)) SummerTime = sc.Close;
[2024-06-07 23:06:56]
ondafringe - Posts: 284
I'm guessing it has something to do with the way you declared SummerTime[] and/or the "i" variable.
[2024-06-08 21:22:56]
Tony - Posts: 516
It would be much easier for other users to help, if you could clarify:

1, what you are trying to achieve;

2, more complete information, i.e. how did you declare SummerTime?
Date Time Of Last Edit: 2024-06-08 21:26:28
[2024-06-11 08:29:18]
aknsyu71@gmail - Posts: 54
this is the full code, Summertime is a subgraph to highlight the bar at a datetime whilest i is sc.Index

#include "sierrachart.h"
SCDLLName("AK_NEWS")
SCSFExport scsf_AK_NEWS(SCStudyInterfaceRef sc)
{
  SCSubgraphRef SummerTime = sc.Subgraph[0];
  
  if (sc.SetDefaults)
  {
    sc.GraphName = "NEWS highlight";
    sc.FreeDLL = 1;
    sc.GraphRegion = 0;
    sc.AutoLoop = 0;
    sc.ValueFormat = 0;
    sc.ScaleRangeType = SCALE_INDEPENDENT;

    SummerTime.Name = "Summer Time";
    SummerTime.DrawStyle = DRAWSTYLE_COLOR_BAR;
    SummerTime.PrimaryColor = RGB(255, 0, 255);
    SummerTime.DrawZeros = false;
  }
  
  int i = sc.Index;
  for (int i = sc.UpdateStartIndex; i < sc.ArraySize; i++)
  {
    SCDateTime IndexDateTime = sc.BaseDateTimeIn[i];
    SCDateTime MySCDateTime(2000, 1, 1, 12, 0, 0);
    if (IndexDateTime == MySCDateTime.GetDateTimeYMDHMS(2024,5,3,13,30,0))    SummerTime[i] = sc.Close[i];
  }
}[/i][/i][/i]

Date Time Of Last Edit: 2024-06-11 08:29:51
[2024-06-11 09:16:36]
User431178 - Posts: 541

if (IndexDateTime == MySCDateTime.GetDateTimeYMDHMS(2024,5,3,13,30,0)) SummerTime[i] = sc.Close[i];

should be


if (IndexDateTime == MySCDateTime.SetDateTimeYMDHMS(2024,5,3,13,30,0)) SummerTime[i] = sc.Close[i];

cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
This is referring to the fact that GetDateTimeYMDHMS expects references to int values (lvalue references), whereas you are passing in temporary (rvalues) int.

Working with the SCDateTime Variables and Values: GetDateTimeYMDHMS()
Working with the SCDateTime Variables and Values: SetDateTimeYMDHMS()


You could also just construct the SCDateTime object in place and skip the set function altogether.


if (IndexDateTime == SCDateTime(2024, 5, 3, 13, 30, 0)) SummerTime[i] = sc.Close[i];

Date Time Of Last Edit: 2024-06-11 09:18:38
[2024-06-11 09:27:31]
aknsyu71@gmail - Posts: 54
Thank you so much for your time. So obvoius and easy once explained.

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

Login

Login Page - Create Account