Support Board
Date/Time: Wed, 22 Jan 2025 15:52:46 +0000
[Programming Help] - A problem with the milliseconds of the Times and Sales function
View Count: 1575
[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? |
[2018-09-17 00:38:56] |
Sierra Chart Engineering - Posts: 104368 |
Use this function where second is lowercase: GetMillisecond But by comparing the data of the file and that of the times and sales window, I see that I have a big problem. We do not provide programming help. We do not know exactly what you are referring to. The millisecond component of the time and sales data is going to match the millisecond component of individual trades within an Intraday data file for the same symbol and trade.The milliseconds of the date do not match. What does it take for the milliseconds to match? So we really do not know what you are referring to or how you are coming to that conclusion and we do not do code analysis. That is totally outside the scope of our support. Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2018-09-17 00:40:13
|
[2018-09-17 06:56:22] |
Cavalry3162 - Posts: 523 |
we found it that the milliseconds arent really milliseconds but more like a counter.. see attached screenshot.. its impossible to get ascending times like this.. that happens with rithmic and cqg the same way so it aint data feed related. |
2018-09-17_02-54-40.png / V - Attached On 2018-09-17 06:55:51 UTC - Size: 67.91 KB - 335 views |
[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
|
Error1.PNG / V - Attached On 2018-09-17 09:03:48 UTC - Size: 151.7 KB - 347 views Error2.PNG / V - Attached On 2018-09-17 09:03:59 UTC - Size: 153.63 KB - 420 views |
[2018-09-18 00:58:43] |
User210074 - Posts: 63 |
Good evening, it's good, I understood where the problem comes from. I will try to do a correction function. I search the function of the "s_TimeAndSales" in the site to get the number of trade. When I run a search with the word "s_TimeAndSales". I only find that "https://search.sierrachart.com/?q=s_TimeAndSales&submitted=true" and there is nothing. it's to do a function that will look like that "int NumberTrade = (int)TimeSales[TSIndex].NumTrade;" |
[2018-09-18 14:34:25] |
User210074 - Posts: 63 |
Thank you for your help, I managed to correct the problem. It works properly. is the TSIndex, is the number of time and sales records stored in the data / trade service settings? Is the number the maximum limit for each "TIME AND SALES" of each future feed provider? Is it possible to start the "TIME AND SALES" at index 0, when loading the study? This is to have the "TIME AND SALES" complete of the day, after a reload. Date Time Of Last Edit: 2018-09-18 14:49:37
|
[2018-09-18 21:18:57] |
Sierra Chart Engineering - Posts: 104368 |
You need to refer to the documentation here: sc.GetTimeAndSales() Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
[2018-09-26 18:40:02] |
User61576 - Posts: 445 |
Thank you for your help, I managed to correct the problem. It works properly.
i will be more than happy if you could share you working solution and explain what was the issue. it will help us all learnthanks! |
To post a message in this thread, you need to log in with your Sierra Chart account: