Support Board
Date/Time: Sat, 23 Nov 2024 17:43:10 +0000
Post From: Python for Sierra Chart
[2014-01-09 23:45:45] |
onnb - Posts: 662 |
the best way to do this depends on your specific circumstances but sticking as much possible to your code... what is happening is that the study function is like OnBarUpdate from NT. It gets called repeatably for any given bar. So the code here get called many times within the first bar encountered that starts at 16:15 or later if (sc.Subgraph[0][sc.Index-1]==0 && sc.Subgraph[0][sc.Index]==1) { sc.SaveChartImageToFile = 1; sc.AddMessageToLog("Printed file",true); } The simplest way I can think of to leave the rest of your approach intact and still get this to print just once would be to add a condition that you are on bar close for the study to process. That way the study only processes once. You would add this like so: if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED) { return; } SCDateTime Print_Time(sc.BaseDateTimeIn[sc.Index].GetDate(),Time1.GetTime() );//Set the print time for each day. SCDateTime Current_Time(sc.BaseDateTimeIn[sc.Index].GetDate(),sc.BaseDateTimeIn[sc.Index].GetTime());//Get the current time sc.Subgraph[0][sc.Index]=0; //Flag signal if (Current_Time>=Print_Time) { sc.Subgraph[0][sc.Index]=1; //attempt to flag Print time so it only prints once per day } else return; //I want it to print/save at the change of state if (sc.Subgraph[0][sc.Index-1]==0 && sc.Subgraph[0][sc.Index]==1) { sc.SaveChartImageToFile = 1; sc.AddMessageToLog("Printed file",true); } else return; hope this helps |