Login Page - Create Account

Support Board


Date/Time: Wed, 01 May 2024 21:05:44 +0000



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

[2018-09-17 09:07:53]
User210074 - Posts: 63
Thank you for your message.
I made the corrections you told me.
It works very well.
But, when I compare the TNS of the file and that of the window.
I still have the same problem. For some unknown reason, I have an additional line identical to the previous one in the test file.
I put a picture.
Is this normal?
Is this an error of my code?


#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\\1_%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 = " %i/%02i/%02i %02i:%02i:%02i: %03i , %i";
          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,TSIndex);
          file << BarDataString << std::endl;
        }
      }
    }
    LastProcessedSequence = TimeSales[TimeSales.Size()-1 ].Sequence;
  }

}

Date Time Of Last Edit: 2018-09-17 09:09:13
imageError1.PNG / V - Attached On 2018-09-17 09:03:48 UTC - Size: 151.7 KB - 314 views
imageError2.PNG / V - Attached On 2018-09-17 09:03:59 UTC - Size: 153.63 KB - 320 views