Login Page - Create Account

Support Board


Date/Time: Wed, 01 May 2024 19:39:18 +0000



Post From: A problem with the milliseconds of the Times and Sales function

[2018-09-17 00:07:39]
User210074 - Posts: 63
I have a problem with the milliseconds of times and sales.


#include <iostream>
#include <string>
#include <fstream>
#include "sierrachart.h"
SCDLLName("TNS");
SCSFExport scsf_TNS(SCStudyGraphRef sc) {
  SCInputRef OutputFile = sc.Input[0];
  if(sc.SetDefaults)
  {
    sc.GraphName="TNS";
    sc.StudyDescription="Time and sales memory";
    sc.FreeDLL = 1;
    sc.GraphRegion = 0;
    OutputFile.Name = "The storage link";
    SCString OutputFileDefaultName;
    OutputFileDefaultName.Format("H:\\Trading\\Plateforme\\SierraChart\\Data\\TNS\\%s.txt", sc.Symbol.GetSubString(2,0).GetChars());
    OutputFile.SetString(OutputFileDefaultName);
    return;
  }
  std::ofstream file(OutputFile.GetString(), std::ios_base::app );
  if (!file) {
    SCString Buffer;
    Buffer.Format("Unable to open file %s", OutputFile.GetString());
    sc.AddMessageToLog(Buffer, 1);
    return;
   }
  if (sc.Index == sc.ArraySize-1)
  {
    __int64& LastProcessedSequence = sc.GetPersistentInt64 (1);
    SCTimeAndSalesArray TimeSales;
    sc.GetTimeAndSales(TimeSales);
    if (TimeSales.Size() == 0)
      return;
    if (LastProcessedSequence != 0)
    {
      for (int TSIndex = 0; TSIndex < TimeSales.Size() ; ++TSIndex)
      {
        if(TimeSales[TSIndex].Sequence < LastProcessedSequence)
          continue;
        if (TimeSales[TSIndex].Type == SC_TS_BID || TimeSales[TSIndex].Type == SC_TS_ASK )
        {
          int ValueFormat = sc.BaseGraphValueFormat;
          SCString formatString = " Date[ %i%02i%02i %02i%02i %02i.%03i ]";
          SCDateTime TradeDateTime = TimeSales[TSIndex].DateTime;
          TradeDateTime += sc.TimeScaleAdjustment;
          int Year, Month, Day, Hour, Minute, Second;
          DATETIME_TO_YMDHMS(TradeDateTime, Year, Month, Day, Hour, Minute, Second);

         SCString BarDataString;
          BarDataString.Format(formatString,
          Year, Month, Day, Hour, Minute, Second, TimeSales[TSIndex].DateTime.GetMilliSecond());
          file << BarDataString << std::endl;
        }
      }
    }
    LastProcessedSequence = TimeSales[TimeSales.Size()-1 ].Sequence;
  }
}

When I tried to build the dll, I got this error message
"
H:\Trading\Plateforme\SierraChart\ACS_Source\TNS.cpp(58): error C2039: 'GetMilliSecond': is not a member of 'SCDateTimeMS'
h:\trading\plateforme\sierrachart\acs_source\scdatetime.h(1022): note: see declaration of 'SCDateTimeMS'".
I look at the documentation of the "SCDateTimeMS" function.
I find a solution to build my dll with the function "DATETIME_TO_YMDHMS_MS". It's good it works.


#include "sierrachart.h"
#include "scdatetime.h"
#include "scstudyfunctions.h"
#include <iterator>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <chrono>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <list>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
SCDLLName("TNS_Modif");
SCSFExport scsf_TNS_Modif(SCStudyGraphRef sc) {
  SCInputRef OutputFile = sc.Input[0];

  if(sc.SetDefaults){
    sc.GraphName="TNS_Modif";
    sc.StudyDescription="Time and sales";
    sc.GraphRegion = 0;
    //sc.AutoLoop=true;
    sc.FreeDLL=1;
    OutputFile.Name = "The storage link";
    SCString OutputFileDefaultName;
    OutputFileDefaultName.Format("H:\\Trading\\Plateforme\\SierraChart\\Data\\TNS\\%s.txt", sc.Symbol.GetSubString(2,0).GetChars());
    OutputFile.SetString(OutputFileDefaultName);
  }
  std::ofstream file(OutputFile.GetString(), std::ios_base::app );
  if (!file) {
    SCString Buffer;
    Buffer.Format("Unable to open file %s", OutputFile.GetString());
    sc.AddMessageToLog(Buffer, 1);
    return;
   }
//Only do this processing on the last bar

  
  if (sc.Index == sc.ArraySize-1)
  {
    __int64& LastProcessedSequence = sc.GetPersistentInt64 (1);
    SCTimeAndSalesArray TimeSales;
    sc.GetTimeAndSales(TimeSales);
    if (TimeSales.Size() == 0)
      return;
    if (LastProcessedSequence != 0)
    {
      for (int TSIndex = 0; TSIndex < TimeSales.Size() ; ++TSIndex)
      {
        if(TimeSales[TSIndex].Sequence < LastProcessedSequence)
          continue;
        if (TimeSales[TSIndex].Type == SC_TS_BID || TimeSales[TSIndex].Type == SC_TS_ASK )
        {
          int ValueFormat = sc.BaseGraphValueFormat;
          SCString formatString = " Date[ %i%02i%02i %02i%02i %02i.%03i ]";
          SCDateTime TradeDateTime = TimeSales[TSIndex].DateTime;
          TradeDateTime += sc.TimeScaleAdjustment;
          int Year, Month, Day, Hour, Minute, Second, MilliSecond;
          DATETIME_TO_YMDHMS_MS(TradeDateTime, Year, Month, Day, Hour, Minute, Second, MilliSecond);
         SCString BarDataString;
          BarDataString.Format(formatString,Year, Month, Day, Hour, Minute, Second, MilliSecond);
          file << BarDataString << std::endl;
        }
      }
    }
    LastProcessedSequence = TimeSales[TimeSales.Size()-1 ].Sequence;
  }

}

But by comparing the data of the file and that of the times and sales window, I see that I have a big problem.
The milliseconds of the date do not match.
What does it take for the milliseconds to match?