Login Page - Create Account

Support Board


Date/Time: Sun, 12 Jan 2025 09:49:04 +0000



Post From: How to set condition to trigger email?

[2016-10-23 09:53:38]
Sierra Chart Engineering - Posts: 104368
We finally have a good example for you. We created a new study in Sierra Chart called "Volume at Price Threshold Alert V2".

Below is the source code for it.

If you can find any sample on how to retrieve the value based on different levels, that should be enough for me to understand the programming structures. Once I know on what variable and structure to be used, I should able to handle the rest of coding.

This should be a big help for what you want to do.


SCSFExport scsf_VolumeAtPriceThresholdAlertV2(SCStudyInterfaceRef sc)
{
  SCInputRef ComparisonMethod = sc.Input[0];
  SCInputRef VolumeThreshold = sc.Input[1];
  SCInputRef AlertNumber = sc.Input[2];

  if (sc.SetDefaults)
  {
    // Set the configuration and defaults
    sc.GraphName = "Volume At Price Threshold Alert V2";

    sc.GraphRegion = 0;    
    sc.AutoLoop = 0;//Manual looping
    sc.ValueFormat = sc.BaseGraphValueFormat;

    sc.FreeDLL = 0;

    sc.MaintainVolumeAtPriceData = 1; // true

    
    for (int SubgraphIndex = 0; SubgraphIndex < SC_SUBGRAPHS_AVAILABLE; ++SubgraphIndex)
    {
      SCString SubgraphName;
      SubgraphName.Format("Trigger %d", SubgraphIndex);

      sc.Subgraph[SubgraphIndex].Name = SubgraphName;
      sc.Subgraph[SubgraphIndex].PrimaryColor = RGB(255, 128, 0);
      sc.Subgraph[SubgraphIndex].DrawStyle = DRAWSTYLE_SQUARE_OFFSET_LEFT_BODY;
      sc.Subgraph[SubgraphIndex].LineWidth = 8;
      sc.Subgraph[SubgraphIndex].DrawZeros = 0;
    }


    ComparisonMethod.Name = "Comparison Method";
    ComparisonMethod.SetCustomInputStrings("Bid Volume;Ask Volume;Total Volume;Number of Trades;Ask Volume Bid Volume Difference;");
    ComparisonMethod.SetCustomInputIndex(2);

    VolumeThreshold.Name = "Volume Threshold";
    VolumeThreshold.SetInt(100);

    AlertNumber.Name = "Volume Alert Number";
    AlertNumber.SetAlertSoundNumber(0);
    
    sc.ValueFormat = VALUEFORMAT_INHERITED;

    return;
  }
      
  //This is an indication that the volume at price data does not exist
  if ((int)sc.VolumeAtPriceForBars->GetNumberOfBars() < sc.ArraySize)
    return;

  SCString AlertMessage;
  bool EnableAlerts = sc.IsFullRecalculation == 0 && !sc.DownloadingHistoricalData;

  for (int BarIndex = sc.UpdateStartIndex; BarIndex < sc.ArraySize; BarIndex++)
  {
    int AvailableSubgraphIndex = 0;

    //Reset all subgraph values
    for (int SubgraphIndex = 0; SubgraphIndex < SC_SUBGRAPHS_AVAILABLE; ++SubgraphIndex)
      sc.Subgraph[SubgraphIndex].Data[BarIndex] = 0;


    s_VolumeAtPriceV2 *p_VolumeAtPrice = NULL;
    int NumberOfPricesAtBarIndex = sc.VolumeAtPriceForBars->GetSizeAtBarIndex(BarIndex);

    for (int PriceIndex = 0; PriceIndex < NumberOfPricesAtBarIndex; ++PriceIndex)
    {
      if (!sc.VolumeAtPriceForBars->GetVAPElementAtIndex(BarIndex, PriceIndex, &p_VolumeAtPrice))
        continue;

      float Price = p_VolumeAtPrice->PriceInTicks * sc.TickSize;

      // Check if condition has been met
      //Bid Volume;Ask Volume;Total Volume;Number of Trades;Ask Volume Bid Volume Difference;
      int ComparisonMethodIndex = ComparisonMethod.GetIndex();
      bool ConditionMet = false;
      unsigned int VolumeThresholdValue = VolumeThreshold.GetInt();

      if (ComparisonMethodIndex == 0)
      {
        if (p_VolumeAtPrice->BidVolume >= VolumeThresholdValue)
          ConditionMet = true;

      }
      else if (ComparisonMethodIndex == 1)
      {
        if (p_VolumeAtPrice->AskVolume >= VolumeThresholdValue)
          ConditionMet = true;
      }
      else if (ComparisonMethodIndex == 2)
      {
        if (p_VolumeAtPrice->Volume >= VolumeThresholdValue)
          ConditionMet = true;
      }
      else if (ComparisonMethodIndex == 3)
      {
        if (p_VolumeAtPrice->NumberOfTrades >= VolumeThresholdValue)
          ConditionMet = true;
      }
      else if (ComparisonMethodIndex == 4)
      {
        int AskVolumeBidVolumeDifference = p_VolumeAtPrice->AskVolume - p_VolumeAtPrice->BidVolume;
        int VolumeThresholdSigned = VolumeThreshold.GetInt();

        if (AskVolumeBidVolumeDifference > 0 && VolumeThresholdSigned > 0 && AskVolumeBidVolumeDifference >= VolumeThresholdSigned)
          ConditionMet = true;
        else if (AskVolumeBidVolumeDifference < 0 && VolumeThresholdSigned < 0 && AskVolumeBidVolumeDifference <= VolumeThresholdSigned)
          ConditionMet = true;

      }

      if (ConditionMet )
      {
        sc.Subgraph[AvailableSubgraphIndex][BarIndex] = Price;

        if (AvailableSubgraphIndex < SC_SUBGRAPHS_AVAILABLE - 1)
          ++AvailableSubgraphIndex;

        if (EnableAlerts && AlertNumber.GetAlertSoundNumber() > 0 && BarIndex == sc.ArraySize - 1)
        {

          sc.SetAlert(AlertNumber.GetAlertSoundNumber() - 1 , "Volume threshold triggered");
        }
      }
    }
  }
}

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:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

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: 2016-10-23 10:03:48