Login Page - Create Account

Support Board


Date/Time: Fri, 14 Mar 2025 18:24:56 +0000



Post From: must recalculate the study to see correct values?

[2022-06-25 23:57:12]
User133994 - Posts: 80
User431178,

Excellent suggestions. I remember having issues with precedence before...so I'm familiar with that. Why didn't I think of that!? Thanks a lot!!

sc.CalculationPrecedence = VERY_LOW_PREC_LEVEL


^^^ finally fixed it ^^^ (LOW wasn't enough; and yes, I did need to re-order the studies as I was referencing some that were below the one I was having issues with)

Also, I tried using GetArraySize and that kindof worked (before switching to VERY_LOW...); but again, the study only painted for live data bars not ones that were already on the chart (historical) without having to recalc manually.

Bottom line: use VERY_LOW_PREC_LEVEL and make sure your referenced studies are *above* this dynamic HH/LL study.

Thanks so much for all your help!!!

For those who want to use a *dynamically* calculated HighestHigh and LowestLow, here is the full working code [enjoy]:


/*******
input a: Input_Study1/Input_Study1Subgraph--this is the study for which you want to calculate the HH or LL
input b: Input_Lookback/Input_LookbackSubgraph--this is the study that tells you how many bars back to look
for a HH or LL; it can change based on time/period/other; For example, use the wave count: i.e. how many bars
were in the last down wave? And then use that count to determine the HH/LL; and on the next wave you use the
next bar count (which is different from prior bar count). Thus, you have a HH/LL based on wave bar counts,
not a fixed number.

output HH/LL: The HH (or LL) output won't be exactly the highest high (or lowest) of the last 5 bars, but will
vary based on the number entered for "input b".
********/

//{{{ Indicator Name: generic dynamicHHLL
SCSFExport scsf_DynamicHHLL(SCStudyInterfaceRef sc)
{

  SCSubgraphRef Subgraph_HH = sc.Subgraph[0];
  SCSubgraphRef Subgraph_LL = sc.Subgraph[1];

  SCInputRef Input_Study1 = sc.Input[0];
  SCInputRef Input_Study1Subgraph = sc.Input[1];

  SCInputRef Input_Lookback = sc.Input[4];
  SCInputRef Input_LookbackSubgraph = sc.Input[5];

  SCInputRef Input_DetailedLogging = sc.Input[8];

  // Set configuration variables
  //{{{
  if (sc.SetDefaults)
  {
    // Set the configuration and defaults
   sc.CalculationPrecedence = VERY_LOW_PREC_LEVEL;  

    sc.GraphName = "DynHHLL v 0.19";
    sc.GraphRegion = 4;
    
    // Set the Length input and default it to 30
Input_Lookback.Name = "Input Study to determine Lookback Range";
    Input_Lookback.SetStudyID(100);
    
    Input_LookbackSubgraph.Name = "Lookback Study Subgraph";
    Input_LookbackSubgraph.SetSubgraphIndex(0);

    Subgraph_HH.Name = "DynHighestHigh";
    Subgraph_HH.DrawStyle = DRAWSTYLE_LINE;
    Subgraph_HH.PrimaryColor = RGB(0,255,0);

    Subgraph_LL.Name = "DynLowestLow";
    Subgraph_LL.DrawStyle = DRAWSTYLE_LINE;
    Subgraph_LL.PrimaryColor = RGB(0,255,255);

    Input_Study1.Name = "Input Study 1";
    Input_Study1.SetStudyID(11);

    Input_Study1Subgraph.Name = "Study 1 Subgraph";
    Input_Study1Subgraph.SetSubgraphIndex(0);

    Input_DetailedLogging.Name = "Detailed Logging (for debugging)";
    Input_DetailedLogging.SetYesNo(1);

    sc.AutoLoop = 1;
    
    return;
  }
  //}}}
  
  //reset some persistent variables
  int& r_LastLookback = sc.GetPersistentInt(1);
  int& LastLogMessageIdentifier =sc.GetPersistentInt(2);
  float curHighestHigh = 0.0;
  float curLowestLow = 0.0;
  
  if (sc.IsFullRecalculation) //Is full recalculation
  {
   LastLogMessageIdentifier = 0;
   r_LastLookback = 1;
  }

  if(sc.GetBarHasClosedStatus()==BHCS_BAR_HAS_CLOSED){
   //reset on each new bar also
   LastLogMessageIdentifier = 0;
   curHighestHigh = 0.0;
   curLowestLow = 0.0;
  }

//{{{ Don't run indicator in these conditions

if(sc.GetBarHasClosedStatus()==BHCS_BAR_HAS_NOT_CLOSED)
return; //do not do any processing if the bar at our current index has not closed

//}}}

  // Get the subgraph specified with the Study 1
  // Subgraph input from the study specified with
  // the Input Study 1 input.
  SCFloatArray Study1Array;
  sc.GetStudyArrayUsingID(Input_Study1.GetStudyID(),Input_Study1Subgraph.GetSubgraphIndex(),Study1Array);

  SCFloatArray LookbackStudyArray;
  sc.GetStudyArrayUsingID(Input_Lookback.GetStudyID(),Input_LookbackSubgraph.GetSubgraphIndex(),LookbackStudyArray);


  int lookback = 5;
  SCString DebugString;

  lookback = static_cast<int>(LookbackStudyArray[sc.Index]);

  //ensure lookback is positive at all times
  if (lookback <= 0){
   lookback = 1;
   r_LastLookback = 1;
  }else if(r_LastLookback <= 0){
   lookback = 5;
   r_LastLookback = 5;
  }else{
   r_LastLookback = lookback;
  }

  if (Input_DetailedLogging.GetYesNo() && LastLogMessageIdentifier != 1)
  {
   LastLogMessageIdentifier = 1;
   DebugString.Format("lookback == : %d", lookback);
   sc.AddMessageToLog(DebugString, 0);
  }

  float hhanswer = 0.0;
  float llanswer = 0.0;

  if (Input_DetailedLogging.GetYesNo() && LastLogMessageIdentifier != 2)
  {
   LastLogMessageIdentifier = 2;
  DebugString.Format("sc.Index == : %f", sc.Index);
  sc.AddMessageToLog(DebugString, 0);

  DebugString.Format("Study1Array[sc.Index] == : %f", Study1Array[sc.Index]);
  sc.AddMessageToLog(DebugString, 0);
  }

  hhanswer =sc.GetHighest(Study1Array, lookback);
  llanswer =sc.GetLowest(Study1Array, lookback);


  if (Input_DetailedLogging.GetYesNo() && LastLogMessageIdentifier != 3)
  {
   LastLogMessageIdentifier = 3;
  DebugString.Format("hhanswer == : %f", hhanswer);
  sc.AddMessageToLog(DebugString, 0);
  DebugString.Format("llanswer == : %f", llanswer);
  sc.AddMessageToLog(DebugString, 0);
  }

  
  Subgraph_HH[sc.Index] = hhanswer;
  
  Subgraph_LL[sc.Index] = llanswer;
  
}
//}}}

Thanks again.
Date Time Of Last Edit: 2022-06-25 23:59:24