Login Page - Create Account

Support Board


Date/Time: Thu, 06 Mar 2025 04:18:20 +0000



[Programming Help] - Inaccurate OHLC data in custom study

View Count: 579

[2022-01-26 19:34:31]
opmetal - Posts: 70
I noticed a bug in my code the other day and have narrowed it down to a very basic test case of unable to read OHLC data. The OHLC values that are displayed in the Message Log are not correct. For example, the Open price is always zero. I noticed this first on "Range per bar - true (in ticks)" bars and got the same on minute charts. What am I doing wrong? Thank you.

test code:
-----------------------------------------------------------------

#include "sierrachart.h"

SCDLLName("ohlc_test")

SCSFExport scsf_OHLCtest(SCStudyInterfaceRef sc)
{

  if (sc.SetDefaults)
  {
    sc.GraphName = "ohlc_test";
    sc.GraphRegion = 0;
    sc.AutoLoop = 1;

    return;
  }


  SCString DataString;

  DataString.Format("current bar: Open:%f High:%f Low:%f Close:%f", sc.FormatDateTime(sc.BaseDateTimeIn[sc.Index]).GetChars(), sc.Open[sc.Index], sc.High[sc.Index], sc.Low[sc.Index], sc.Close[sc.Index]);
  sc.AddMessageToLog(DataString, 0);


}
[2022-01-26 19:50:58]
User907968 - Posts: 834
DataString.Format("current bar: Open:%f High:%f Low:%f Close:%f", sc.FormatDateTime(sc.BaseDateTimeIn[sc.Index]).GetChars(), sc.Open[sc.Index], sc.High[sc.Index], sc.Low[sc.Index], sc.Close[sc.Index]);

The problem is 'sc.FormatDateTime(sc.BaseDateTimeIn[sc.Index]).GetChars()' - you are missing the %s after 'current bar:', so instead the const char* value is trying to be read as a float.
[2022-01-26 19:55:33]
opmetal - Posts: 70
Thank you! What a silly mistake.

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

Login

Login Page - Create Account