Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 10:33:06 +0000



Post From: Code help, using a string instead of a constant

[2023-08-28 16:29:00]
j4ytr4der_ - Posts: 938
I have it working for historical bars, but I can't get it to work for the current updating bar. As far as I understand it should be calculating correctly for all bars up to the last one but for some reason it isn't. Don't know what I'm missing.



#include "sierrachart.h"
SCDLLName("Multi Formula All Bars")
/*==================================================================================*/
SCSFExport scsf_TestProj(SCStudyInterfaceRef sc)
{
  sc.MaintainVolumeAtPriceData = 1;

  if (sc.SetDefaults)
  {
    sc.GraphName = "Multi Formula All Bars";
    sc.GraphRegion = 2;
    sc.AutoLoop = 0;
    sc.ValueFormat = VALUEFORMAT_INHERITED;
    sc.ScaleRangeType = SCALE_AUTO;
    sc.GlobalDisplayStudySubgraphsNameAndValue = 1;
    sc.DisplayStudyInputValues = 0;
    sc.HideDLLAndFunctionNames = 1;
    
    for (auto i = 0; i < 4; ++i)
    {
      sc.Input[i].Name.Format("s%d", i);
      sc.Input[i].SetString("");

      sc.Subgraph[i].Name.Format("s%d", 1);
      sc.Subgraph[i].DrawStyle = DRAWSTYLE_POINT;
      sc.Subgraph[i].LineWidth = 4;
    }

    return;
  }

  bool ParseAndSetFormula = sc.IsFullRecalculation;

  for (int InputIndex = 0; InputIndex < 4; InputIndex++) // Loop through each input
  {
    const char* Formula = sc.Input[InputIndex].GetString(); // Grab the formula for the chosen input

    for (int BarIndex = sc.UpdateStartIndex; BarIndex < sc.ArraySize; BarIndex++)
    {
      double FormulaOutput{ 0.0 };

      if (BarIndex == 0)
        FormulaOutput = sc.EvaluateGivenAlertConditionFormulaAsDouble(BarIndex, ParseAndSetFormula, Formula); // Evaluate the formula
      else
        FormulaOutput = sc.EvaluateGivenAlertConditionFormulaAsDouble(BarIndex, 0, ""); // Evaluate the formula

      sc.Subgraph[InputIndex][BarIndex] = (float)FormulaOutput; // Return the formula result in a subgraph
    }
  }
}