Login Page - Create Account

Support Board

Date/Time: Wed, 29 May 2024 00:19:48 +0000

[Programming Help] - ACSIL -> Open and write into a text file....

View Count: 4504

[2018-09-02 18:32:10]
fraalbe - Posts: 12
Hi, Is there a possibility to open and write into a textfile? I don't want the log file, but a new separate text file.

[2018-09-06 11:07:32]
fraalbe - Posts: 12
Hi, Is there a possibility to open and write into a textfile? I don't want the log file, but a new separate text file.

[2018-09-07 00:45:39]
User553714 - Posts: 184
Whilst you cannot use the console (cin or cout) within SC, you can use text files within SC as you normally would in any C++ programme, I use them extensively;
[2019-12-15 19:41:02]
User275592 - Posts: 97

could you send to this request an example of code

I'm starting writing acsil programs and it would be of great help !
[2019-12-17 03:53:40]
User553714 - Posts: 184
This is a quick example of outputting to a text file; there are a lot of subtleties when using text files escpecially when you set sc.UpdateAlways equal to 1; at that stage you really need to understand the way SC constantly returns into applied studies. I suggest that you keep compiling over and over with differently set paramters to see their effect if you're just starting out and try not to have too much data loaded when testing things.

The study below will only print to file during a live or replay session; if you press stop on the replay the file will be deleting (ie on recalculation) and re-created so press pause if you want to see the results first; this behaviour can off course be changed depending on what you are trying to do.

You might want to download a Notepad++ plugin that updates the textfile in real time so you can see file changes as they occur; I use DocumentMonitor but I am not sure that plugin is still available to Notepad++.

Also don't forget to create the required folder and change the outputfile1 string accordingly for your SC instal location.

SCSFExport scsf_TextFiles(SCStudyInterfaceRef sc)

  int& FileTest1 = sc.GetPersistentInt(1);
  string outputfile1, outputfile2;
  ofstream myfile1, myfile2;

  // SetDefaults
  if (sc.SetDefaults)
    sc.GraphName = "1.TextFiles";
    sc.StudyDescription = "Text File use.";
    sc.GraphRegion = 0;
    sc.AutoLoop = 1;
    //sc.UpdateAlways = 1;
    FileTest1 = 0;

  // SPECIAL CASES - often used
  int Index = sc.Index;
  float OpenPrice = sc.BaseData[SC_OPEN][Index];
  float HighPrice = sc.BaseData[SC_HIGH][Index];
  float LowPrice = sc.BaseData[SC_LOW][Index];
  float LastPrice = sc.BaseData[SC_LAST][Index];

  //Declare file location string
  outputfile1 = "C:\\SierraChartB0\\TextFiles\\Debugging.txt";

  // DebuggingLog
  if (Index == 0 && FileTest1 == 0)
    myfile1.open(outputfile1, ios::out | ios::trunc);          // Only create the file if it dosen't exist
    myfile1 << "Start Debug logging..." << endl;

  if ( sc.IsFullRecalculation != 1 )                // Only append to file when there is no full-recalculation
    myfile1.open(outputfile1, ios::out | ios::app);

  myfile1 << "Debug log, " << Index << ", " << OpenPrice << ", " << HighPrice << ", " << LowPrice << ", " << LastPrice << endl;

[2019-12-17 10:06:02]
User907968 - Posts: 804
If it is any help, there are also functions within the sc structure that you can use for working with external files.


[2019-12-19 20:40:41]
User275592 - Posts: 97
Thank you for your messages and Help !
Sierrachart great platform great support great community !
[2019-12-20 12:59:36]
User275592 - Posts: 97

keep trying to understand how all that works .... ("you really need to understand the way SC constantly returns into applied studies")

Do you have any suggestion of books, youtube videos or website to help me understand the principles of programming in acsil ?

like ACSIL for dummies ;-) (not C or C++ those ones are ok for me

Thank you for your help

[2019-12-23 05:40:19]
User553714 - Posts: 184
I don't think there are any books on ACSIL and there is only the documentation that SC supplies; I suggest you have a repeated read of the ACSILProgrammingConcepts and the docs in general;
ACSIL Programming Concepts
Working with ACSIL Arrays and Understanding Looping

Another good source of ACSIL info is the ACS_Source folder inside the SierraChart base folder. You can open all the example studies in VisualStudio/Notepad++ and then search for the ACSIL
functions you are trying to use to see examples of their use; unfortunately I often found that many of the SC functions have not been used in any of the example studies.

Like you one of the biggest hurdles I had when I started using ACSIL is understanding the SC development environment.
SC to me is like a Windows App and continues to run and monitor message streams one of which you might think of as the studies (functions) applied to your charts.
If you have written any Windows programmes and worked with the Windows Message stream then you will probably better understand where I'm coming from.

SC executes your code/study multiple times for every chart bar period.
For example if you have a 1min chart with 20,000 minutes of data loaded then your study/code will run at least 20,000 times during a replay;
in fact it runs much more than that as you can see for yourself if you run replays and play around with that simple text file study I incl further up;
From the text file results you can see that for a 1min chart for example, during a replay the study will return and a line will be added to the text file many times for each Index.
This is because there is a LOT of time/data in 1min so although you can't generally see it displayed on a 1min chart SC is still calculating the Study Values on a sub 1min Index level and usually many times per second. To some extent the number of times the study returns will depend on the GlobalSettings>>General>>ChartUpdateIntervalInMS setting you use, the speed of your computer and size/speed of your study etc.

If you don't set UpdateAlways = 1 then SC will stop running your studies when there is no new data IE.. when there is no replay running or when you're not in live data mode.
If you do set UpdateAlways = 1 then SC continues to run your studies even without new data.
For example you would want to use UpdateAlways if you want to use many ACSIL functions on a static chart which is neither in Live mode or Replay; ASCIL Scroll functions or ACS buttons linked to your ACSIL code will only continue to work outside Live or Replay modes if UpdateAlways is true.

Hope that helps some, Goodluck...
[2019-12-23 08:38:32]
User275592 - Posts: 97
thank you for your complete message It is of great help for me

I started digging the acs-source directory some days ago :-)

With your help, no doubt i will be lucky
[2019-12-24 19:08:42]
Sierra Chart Engineering - Posts: 104368
The most efficient way to use ACSIL is manual looping:
Working with ACSIL Arrays and Understanding Looping: Manual Looping/Iterating
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:

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: 2019-12-24 19:09:39
[2020-07-17 09:02:14]
gfx2trade - Posts: 48
hi everyone,

I am quite happy with this...

void iMessageToFile(SCStudyInterfaceRef sc, SCString myText) {
  int FileHandle;
  int myTextLength = myText.GetLength() + 2; // +2 to count for \\
  unsigned int BytesWritten = 0;
  // Directory must exists
  SCString outputfile = "C:\\Trading\\Plateforme\\Log\\Sierra\\TextLogFile.txt";
  sc.OpenFile(outputfile, n_ACSIL::FILE_MODE_OPEN_TO_APPEND, FileHandle);
  myText = myText + "\r\n";
  sc.WriteFile(FileHandle, myText, myTextLength, &BytesWritten);


hope it helps
Date Time Of Last Edit: 2020-07-17 09:03:28
[2020-07-17 09:52:55]
gfx2trade - Posts: 48
ended up with ...

void iMessageToFile(SCStudyInterfaceRef sc, SCString myText) {

  SCDateTimeMS DateTimeMS , DateTimeMSRefChart;   
  unsigned int BytesWritten = 0;
  int FileHandle;
  int myTextLength = 0;
  SCString DateTimeString = sc.DateTimeToString(sc.CurrentSystemDateTime,FLAG_DT_COMPLETE_DATETIME_MS);
  myText = DateTimeString + "|" + myText;
  myText = sc.Symbol + "|" + myText;
  myTextLength = myText.GetLength() + 2; // +2 to count for \\
  // Directory must exists
  SCString outputfile = "C:\\Trading\\Plateforme\\Log\\Sierra\\TextLogFile.txt";
  sc.OpenFile(outputfile, n_ACSIL::FILE_MODE_OPEN_TO_APPEND, FileHandle);
  myText = myText + "\r\n";
  sc.WriteFile(FileHandle, myText, myTextLength, &BytesWritten);

[2023-03-10 08:48:46]
BenjFlame - Posts: 306
Super easy:

SCString DebugMessage;
DebugMessage = "A string line. \n"

std::ofstream myfile;
myfile.open("C:\\Users\\user\\Desktop\\debugMessages.txt", std::ios::app); // Appends new lines
myfile << DebugMessage;

Date Time Of Last Edit: 2023-03-10 08:51:03

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


Login Page - Create Account