Support Board
Date/Time: Sun, 22 Dec 2024 12:50:26 +0000
Post From: study code running twice
[2015-04-19 16:59:24] |
dtl-saw - Posts: 79 |
When I load a new chartbook or reload the chart with these studies in them the study is run twice. I get 2 lines of "hello" in the text file and I get 2 lines of "hey dude!" in the SierraChart log (see below) Chart: F.US.EPM15 [C] 30 Min #1 | Study: write2log | hey dude! | 2015-04-19 11:41:12 Chart: F.US.EPM15 [C] 30 Min #1 | Study: write2log | hey dude! | 2015-04-19 11:41:13 I have a scheme to use files for storing relevant chart data and need to be able to read and write to a file only once on start up so that data isn't duplicated or it ruins the scheme. Do you have any suggestions to get the code to run only once or how could I code the study to ignore the second execution? Thanks #include <fstream> #include <string.h> #include "sierrachart.h" using namespace std; SCDLLName("dms_Custom_Studies") SCSFExport scsf_write2log(SCStudyGraphRef sc) { if (sc.SetDefaults) { // set the configuration and defaults sc.GraphName = "write2log"; sc.StudyDescription = ""; sc.AutoLoop = 0; sc.GraphRegion = 0; sc.FreeDLL = 1; sc.CalculationPrecedence = LOW_PREC_LEVEL; return; } string line; SCString buffer; buffer.Format("hey dude!\n"); sc.AddMessageToLog(buffer,0); } SCSFExport scsf_write2file(SCStudyGraphRef sc) { if (sc.SetDefaults) { sc.GraphName = "file_io"; sc.StudyDescription = ""; sc.AutoLoop = 0; // true sc.GraphRegion = 0; sc.FreeDLL = 1; sc.CalculationPrecedence = LOW_PREC_LEVEL; return; } ofstream ofile ("c:\\file_io\\cpp_tstx.txt", ios::out | ios::app ); if (ofile.is_open()) { ofile << "hello \n"; ofile.close(); } } |