Login Page - Create Account

Support Board


Date/Time: Fri, 26 Apr 2024 14:40:34 +0000



Study write to file problem with SC 996

View Count: 1763

[2013-07-13 21:00:12]
ChrisH - Posts: 10
I've written studies that send results to a text file.

These studies work fine with SC 912 using Whatcom compiler. With SC 996 using MinGW/G++ they no longer work. A basic sample with comments is below:


#include "sierrachart.h"
#include <iostream> //Appears to have been already included with MinGW & generates errors
#include <fstream> //Appears to have been already included with MinGW & generates errors

using namespace std;

SCDLLName("KAI TEST")

SCSFExport scsf_KAI_TEST(SCStudyGraphRef sc) {
  SCString Buffer;
  ofstream DataFile; //If I remove the iostream/fstream includes, this fails as not defined
  
  if (sc.SetDefaults) {
    sc.GraphName = "KAI Test Study";
    sc.StudyDescription = "KAI Test Study";
    sc.GraphRegion = 0;
    sc.AutoLoop = 1;
    sc.FreeDLL = 0;

    return;
  }

  DataFile.open ("C:\\KAI_TEST.TXT", ios::out | ios::app);
  Buffer.Format("%s,%f\n",sc.Symbol.GetChars(), sc.Close[sc.Index]);
  DataFile << Buffer.GetChars();
  DataFile.close();
  }
}

[2013-07-13 22:27:14]
Sierra Chart - Max - Posts: 5596
I do see an issue the compilation. Also a quick look at the code shows that there is an extra "}" at the end.

The following code does compile and output to the file.

#include <fstream>
#include "sierrachart.h"

SCDLLName("KAI TEST")

SCSFExport scsf_KAI_TEST(SCStudyGraphRef sc)
{
if (sc.SetDefaults)
{
sc.GraphName = "KAI Test Study";
sc.StudyDescription = "KAI Test Study";
sc.GraphRegion = 0;
sc.AutoLoop = 1;
sc.FreeDLL = 0;

return;
}

SCString Buffer;
std::ofstream DataFile("D:\\KAI_TEST.TXT", std::ofstream::out | std::ofstream::app);

Buffer.Format("%s,%f\n",sc.Symbol.GetChars(), sc.Close[sc.Index]);
DataFile << Buffer.GetChars();
DataFile.close();

}



Also please look at the provided Write Bar Data To File study source code found inside of Studies6.cpp scsf_WriteBarDataToFile in the ACS_Source folder within your Sierra Chart installation folder.


Sierra Chart Support
Date Time Of Last Edit: 2013-07-13 22:59:38

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

Login

Login Page - Create Account