Login Page - Create Account

Support Board


Date/Time: Mon, 23 Dec 2024 23:45:08 +0000



Post From: Calculate only on closing Tick

[2015-10-14 22:07:51]
KhaosTrader - Posts: 128
Hi,

I am writing up some code that marks bar patterns. I wrote a test project (shown below), just to illustrate that I can mark red bars. However, this logic is run every single tick I think, which is a waste of CPU time. In easylanguage they have a condition where u can check if its the closing tick of the bar, so that you only need to run the logic one time per bar, I don't see how to do this in the Sierra Chart code...

Also I find that I must put "Marker[cur]= 0;" rather than "Marker[cur-1]= 0;" to make it work, which doesn't seem logical to me. This statement is on the 3rd line or so at the bottom of the example.

My code example is here below:


  SCSFExport scsf_Calculator(SCStudyGraphRef sc)
{
  // Section 1 - Set the configuration variables
  
  SCSubgraphRef Marker = sc.Subgraph[0];
  // This section is only run once. Refer to documentation for further details.
  if (sc.SetDefaults)
  {
    // Set the configuration and defaults
    
    sc.GraphName = "Calculator";
    
    sc.StudyDescription = "Insert study description here.";
    
    sc.AutoLoop = 1; // true
    sc.FreeDLL = 1;
    
    sc.GraphRegion = 0;
    
    
    
    Marker.Name = "Dot Marker";
    Marker.PrimaryColor = RGB(102,255,102); // Optionally, you may predefine your graph's colors
    Marker.DrawStyle= DRAWSTYLE_POINT;
    Marker.PrimaryColor = RGB(255,255,255);
    Marker.LineWidth = 3;
    Marker.DrawZeros = false;
    

    return;
  }

  // Section 2 - Data processing
  int cur = sc.Index;
  
  
  Marker[cur]= (sc.BaseDataIn[SC_LOW][cur-1] - 2*sc.TickSize);
  
  //if(sc.GetBarHasClosedStatus(sc.Index-1) == BHCS_BAR_HAS_CLOSED)
//  {
    
    if( sc.Open[cur-1] > sc.Close[cur-1])
    //if (Range > 0.0f)
    {
    
      Marker[cur-1]= (sc.BaseDataIn[SC_LOW][cur-1] - 2*sc.TickSize);
      
      
    }
    {
      Marker[cur]= 0;
  
    }

}