Login Page - Create Account

Support Board


Date/Time: Tue, 18 Jun 2024 15:58:29 +0000



Post From: How to have a study starting from a clicked location on the chart?

[2020-12-06 08:53:17]
User139950 - Posts: 4
This is my resettable version of the Cumulative Delta Bars Study:


SCSFExport scsf_CumulativeDeltaBarsTickVolumeReset(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Open = sc.Subgraph[SC_OPEN];
  SCSubgraphRef High = sc.Subgraph[SC_HIGH];
  SCSubgraphRef Low = sc.Subgraph[SC_LOW];
  SCSubgraphRef Close = sc.Subgraph[SC_LAST];
  SCSubgraphRef OHLCAvg = sc.Subgraph[SC_OHLC_AVG];
  SCSubgraphRef HLCAvg = sc.Subgraph[SC_HLC_AVG];
  SCSubgraphRef HLAvg = sc.Subgraph[SC_HL_AVG];

  SCInputRef ResetAtSessionStart = sc.Input[0];
  SCInputRef ResetAtBothSessionStarts = sc.Input[1];

  int& ResetID = sc.GetPersistentInt(1);
  int& MenuID_Set = sc.GetPersistentInt(2);
  int& MenuID_Clear = sc.GetPersistentInt(3);

  if (sc.SetDefaults)
  {
    sc.GraphName = "Resettable Cumulative Delta Bars - Up/Down Tick Volume";

    sc.MaintainAdditionalChartDataArrays = 1;
    sc.AutoLoop = 0;//Manual looping

    sc.ValueFormat = 0;
    sc.GraphDrawType = GDT_CANDLESTICK;

    Open.Name = "Open";
    Open.DrawStyle = DRAWSTYLE_LINE;
    Open.PrimaryColor = RGB(0,255,0);
    Open.SecondaryColor = RGB(0,255,0);
    Open.SecondaryColorUsed = true;
    Open.DrawZeros = true;

    High.Name = "High";
    High.DrawStyle = DRAWSTYLE_LINE;
    High.PrimaryColor = RGB(0,128,0);
    High.DrawZeros = true;

    Low.Name = "Low";
    Low.DrawStyle = DRAWSTYLE_LINE;
    Low.PrimaryColor = RGB(255,0,0);
    Low.SecondaryColor = RGB(255,0,0);
    Low.SecondaryColorUsed = true;
    Low.DrawZeros = true;

    Close.Name = "Close";
    Close.DrawStyle = DRAWSTYLE_LINE;
    Close.PrimaryColor = RGB(128,0,0);
    Close.DrawZeros = true;

    OHLCAvg.Name = "OHLC Avg";
    OHLCAvg.DrawStyle = DRAWSTYLE_IGNORE;
    OHLCAvg.PrimaryColor = COLOR_GREEN;
    OHLCAvg.DrawZeros = true;

    HLCAvg.Name = "HLC Avg";
    HLCAvg.DrawStyle = DRAWSTYLE_IGNORE;
    HLCAvg.PrimaryColor = COLOR_GREEN;
    HLCAvg.DrawZeros = true;

    HLAvg.Name = "HL Avg";
    HLAvg.DrawStyle = DRAWSTYLE_IGNORE;
    HLAvg.PrimaryColor = COLOR_GREEN;
    HLAvg.DrawZeros = true;

    ResetAtSessionStart.Name = "Reset at Start of Trading Day";
    ResetAtSessionStart.SetYesNo(true);

    ResetAtBothSessionStarts.Name = "Reset at Both Session Start Times";
    ResetAtBothSessionStarts.SetYesNo(false);
    
    ResetID = -1;
    MenuID_Set = -1;
    MenuID_Clear = -1;

    return;
  }
  
  // add the menu command when study is added
  if (sc.UpdateStartIndex == 0)
  {
    MenuID_Set = sc.AddACSChartShortcutMenuItem(sc.ChartNumber, "Set Delta Reset");
    MenuID_Clear = sc.AddACSChartShortcutMenuItem(sc.ChartNumber, "Clear Delta Reset");
    
    if (MenuID_Set < 0 || MenuID_Clear < 0)
    {
      sc.AddMessageToLog("Add ACS Chart Shortcut Menu Item failed", 1);
    }
  }
  
  // remove the menu command when study is removed
  if (sc.LastCallToFunction)
  {
    sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, MenuID_Set);
    sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, MenuID_Clear);
  }

  // receive menu event
  if (sc.MenuEventID != 0 && sc.MenuEventID == MenuID_Set)
  {
    // get idx for resetting
    ResetID = sc.ActiveToolIndex;
    
    // initiate recalculation
    sc.UpdateStartIndex = 0;
  }
  if (sc.MenuEventID != 0 && sc.MenuEventID == MenuID_Clear)
  {
    // clear idx for resetting
    ResetID = -1;
    
    // initiate recalculation
    sc.UpdateStartIndex = 0;
  }

  for (int Index = sc.UpdateStartIndex; Index < sc.ArraySize; Index++)
  {
    bool Reset = false;

    if (Index == 0 || Index == ResetID)
    {
      Reset = true;
    }
    else if (ResetAtBothSessionStarts.GetYesNo() != 0)
    {
      SCDateTime PriorStartOfPeriod = sc.GetStartOfPeriodForDateTime(sc.BaseDateTimeIn[Index - 1], TIME_PERIOD_LENGTH_UNIT_DAYS, 1, 0, 1);

      SCDateTime StartOfPeriod = sc.GetStartOfPeriodForDateTime(sc.BaseDateTimeIn[Index], TIME_PERIOD_LENGTH_UNIT_DAYS, 1, 0, 1);

      if (StartOfPeriod != PriorStartOfPeriod)
      {
        Reset = true;
      }
    }
    else if (ResetAtSessionStart.GetYesNo() != 0)
    {
      SCDateTime PriorStartOfPeriod = sc.GetStartOfPeriodForDateTime(sc.BaseDateTimeIn[Index - 1], TIME_PERIOD_LENGTH_UNIT_DAYS, 1, 0, 0);

      SCDateTime StartOfPeriod = sc.GetStartOfPeriodForDateTime(sc.BaseDateTimeIn[Index], TIME_PERIOD_LENGTH_UNIT_DAYS, 1, 0, 0);

      if (StartOfPeriod != PriorStartOfPeriod)
      {
        Reset = true;
      }
    }

    sc.CumulativeDeltaTickVolume(sc.BaseDataIn, Close, Index, Reset);

    Open[Index] = Close.Arrays[0][Index];
    High[Index] = Close.Arrays[1][Index];
    Low[Index] = Close.Arrays[2][Index];

    sc.CalculateOHLCAverages(Index);
  }
}