Login Page - Create Account

Support Board


Date/Time: Mon, 24 Feb 2025 18:45:04 +0000



[User Discussion] - Study: Max of a Range or Percentage of the Max of a Range

View Count: 1150

[2021-03-10 06:17:24]
PeaceFrog - Posts: 105
Hello. In advance, thank you for your time and effort in answer my question.

I’ve been looking through the available Studies and do not find a Study that will return the Maximum value from a range, like the Max formula from Excel =Max(number1,number2,etc…) or =Max(A1:A10).
In actuality, I am really looking for a Study that will return the percentage of a Maximum range, for example: =(ADXt)/MAX(ADXt:ADXt-n).

I would very much appreciate any guidance you can offer. Thank you for taking the time to respond.
[2021-03-10 07:45:52]
Flipper_2 - Posts: 57
If I understand you correctly you want a rolling max? Is it of prices or of a study?

This will do prices but if you want a study wouldn't be hard to change,




#include "sierrachart.h"

SCDLLName("HL Distance")


SCSFExport scsf_HLDist(SCStudyInterfaceRef sc)
{

  SCSubgraphRef HHLLRange = sc.Subgraph[0];

  SCInputRef HHLLPeriod = sc.Input[1];


  // Section 1 - Set the configuration variables and defaults
  if (sc.SetDefaults)
  {
    sc.GraphName = "HL Distance";

    // During development set this flag to 1, so the DLL can be rebuilt without restarting Sierra Chart. When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = 0;
    sc.AutoLoop = 1; //Automatic looping is enabled.


    HHLLRange.Name = "HH_LL_Range";
    HHLLRange.DrawStyle = DRAWSTYLE_BAR;
    HHLLRange.PrimaryColor = RGB(0, 206, 206);
    HHLLRange.LineWidth = 2;
  
    HHLLPeriod.Name = "Period for HH - LL calculation";
    HHLLPeriod.SetInt(40);


    return;
  }



  HHLLRange[sc.Index] = ((sc.GetHighest(sc.BaseDataIn[SC_HIGH], HHLLPeriod.GetInt()) - sc.GetLowest(sc.BaseDataIn[SC_LOW], HHLLPeriod.GetInt())) / sc.BaseDataIn[SC_LAST][sc.Index]) * 100;



}

[2021-03-10 18:52:39]
PeaceFrog - Posts: 105
THAT is cool! Thank you so much for your reply.

Based on my initial question, I can understand why you're asking about a rolling max and whether it’s for prices or a study. I believe that I am looking for a rolling max and am looking for the new study to be applied to an already existing Sierra Charts study (Analysis->Tools->ADX), like you can with, for example the "Input Data" field in the "Settings and Inputs" tab of the "Momentum" study when the ADX Study is already applied to the chart.

For me to clarify, it’s probably easiest if I give an example.
For the data set:
A  B      C  D     E    
1  DATE TIME    ADX  4-Bar Max ADX   Previous ADX divided by 4-Bar Max ADX
2  10-03-2020 8:10:00 AM  40  =45 =Max(B3:B6) =35/45 =C3/D2
3  10-03-2020 8:09:00 AM  35  =45 =Max(B4:B7) =40/45 =C4/D3
4  10-03-2020 8:08:00 AM  40  =45 =Max(B5:B8) =45/45 =C5/D4
5  10-03-2020 8:07:00 AM  45  =40 =Max(B6:B9) =40/40 =C6/D5
6  10-03-2020 8:06:00 AM  40  =35 =Max(B7:B10) =35/35 =C7/D6
7  10-03-2020 8:05:00 AM  35  =30 =Max(B8:B11) =30/30 =C8/D7
8  10-03-2020 8:04:00 AM  30  =25 =Max(B9:B12) =25/25 =C9/D8
9  10-03-2020 8:03:00 AM  25  
10  10-03-2020 8:02:00 AM  20  
11  10-03-2020 8:01:00 AM  15  
12  10-03-2020 8:00:00 AM  10  


I suppose I am looking for two studies, 1 that produces Column D and one that produces Column E. I hope this helps clarify.

Thank you again for your time and willingness to help. It is very much appreciated.
imageExample Data Set.PNG / V - Attached On 2021-03-10 18:51:22 UTC - Size: 20.72 KB - 243 views
Attachment Deleted.
[2021-03-10 20:48:51]
Flipper_2 - Posts: 57
Ok try this,


#include "sierrachart.h"

SCDLLName("HL Distance")


SCSFExport scsf_HLDist(SCStudyInterfaceRef sc)
{

SCSubgraphRef HLRange = sc.Subgraph[0];
SCSubgraphRef RollingMax = sc.Subgraph[1];

SCInputRef Input_SubgraphRef = sc.Input[0];
SCInputRef HHLLPeriod = sc.Input[1];



// Section 1 - Set the configuration variables and defaults
if (sc.SetDefaults)
{
sc.GraphName = "HL Distance";
sc.FreeDLL = 0;
sc.AutoLoop = 1; //Automatic looping is enabled.
sc.CalculationPrecedence = LOW_PREC_LEVEL;




  HLRange.Name = "HL_Range";
  HLRange.DrawStyle = DRAWSTYLE_BAR;
HLRange.PrimaryColor = RGB(0, 206, 206);
HLRange.LineWidth = 2;

RollingMax.Name = "RollingMax";
RollingMax.DrawStyle = DRAWSTYLE_IGNORE;
RollingMax.PrimaryColor = RGB(0, 206, 0);

Input_SubgraphRef.Name = "Subgraph Reference";
Input_SubgraphRef.SetStudySubgraphValues(0, 0);
  
  HHLLPeriod.Name = "Period for HH - LL calculation";
  HHLLPeriod.SetInt(40);


  return;
  }


SCFloatArray StudyRef;
sc.GetStudyArrayUsingID(Input_SubgraphRef.GetStudyID(), Input_SubgraphRef.GetSubgraphIndex(), StudyRef);


RollingMax[sc.Index] = sc.GetHighest(StudyRef, HHLLPeriod.GetInt());

HLRange[sc.Index] = RollingMax[sc.Index -1] / RollingMax[sc.Index];


}

Date Time Of Last Edit: 2021-03-10 20:51:29
[2021-03-15 20:40:31]
PeaceFrog - Posts: 105
Hi User925080,

First off, thank you. Thank you for taking the time to reply.

I’ve spent the last few days working on and learning from the code you shared, it’s been extremely helpful and it accomplishes what I’m looking for it to do – thank you. I should mention that I am brand new to the ASCIL, as in, this is my first experience with it, so I really appreciate your help and am going to pay-forward your good deed 3 times.

I do have another Study I’m looking to perform and I think it’s more complicated than this one and, if it’s not too much to ask, I’m wondering if you have time to have a look at it. I’ve posted it on the “General User Discussion and Programming Help” board, its title is “Study: MACD & MACD Crossover System with added New Studies” posted at 2021-03-15 20:36:12.

Again, thank you for your willingness to help. It’s very much appreciated.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account