Login Page - Create Account

Support Board


Date/Time: Sun, 05 May 2024 11:48:43 +0000



[Programming Help] - Help with Study - but attached working Keltner Channels with Hull MID

View Count: 1067

[2020-06-18 19:38:13]
User463534 - Posts: 3
Hi!
I know it is posted that custom programming questions will not be answered by staff and I’m hoping that users on here would be willing to lend a hand to a new SC member. In researching my compilation errors and questions I see coding questions are answered here by users so I know this is the right place to ask. Attached also is a working copy of double Keltner channel with Hull MA Mid - its just not how I want it and I'm trying to code it also to better stadards.

I recently moved over to SC in an effort to automate a strategy with I run manually but on an alert trigger basis. I'm stuck trying to build a really simple visual indicator, a hull MA with 2 sets of ATR bands whose values are necessary for my risk and trailing components of the system. I figured coding this simple indicator would be a logical first step in my endeavors, but i seem to be thoroughly stuck at what I would assume be a simple header or syntax type error in my code.

What is coded are double ATR bands (length, average type selectable, multiplier selectable) wrapped +- around a hull moving average (price type, length selectable). This was standard in my other platform by using 2 Keltner channels and its a visual match to part of the strategy. I easily coded the double version and bactestable strategy in my other plaform but I'm not having much luck here.

I found many coding examples in the ACS folder that closely match, read most of the ASCIL guides and extensively attempted this myself – there is a lot of information and many examples which is why it is driving me nuts that I can’t get this to work as I intend it to.
I successfully, created the indicator using a user example here that just uses the unnamed SC arrays for inputs and subgraphs , but I can't get the price type or separate int input value for the ATR length to work ( currently it is set up to be the same as the Hull length which does indeed work). I also could not get a user selectable price type functionality to work either (select, open, close, OHCL4, etc) - it is currently set to last which is OK. So it works based on an example of ATR Bands and the hull mid was added but i need to get a couple of features to work better.

I also took it upon myself per the ACSIL Interface Members - sc.Input Array: Using References to Inputs best practices to add proper naming conventions to the array variables, but it just fails to compile with errors such as
'SC' was not declared in this scope
SCInputRef HULL_LENGTH = SC.INPUT[0];

It seems these would be very easy to fix. The code is there, and what isn't working on the SC array version is commented out. And the other attached version V4 was my attempt at taking the working unnamed version of the code , and simply just renaming the variable properly but that doesn't compile. Any help looking this over would be greatly appreciated. I get and understand all of the Studies*.cpp examples. I don't get how this matches the examples but doesn't' compile or why my original version won't compile if I add a couple of additional inputs. I'm stumped and appreciate any help! the platform and look forward to trading in it.

Thanks!
NOTE: V2_2 is the working unnamed variable version that needs the inputs for price type and ATR length added. V4 is my attempt at taking the working vs 2_2 and naming the variables properly
attachmentDTEK_V2_2_HULL_DOUBLE_KELTNER_BANDS.cpp - Attached On 2020-06-18 19:32:19 UTC - Size: 5.68 KB - 229 views
attachmentDTEK_V3_HULL_DOUBLE_KELTNER_BANDS.cpp - Attached On 2020-06-18 19:32:28 UTC - Size: 5.94 KB - 225 views
[2020-06-19 00:04:27]
Flipper - Posts: 65
You have a few small errors

'SC' was not declared in this scope
SCInputRef HULL_LENGTH = SC.INPUT[0];

ACSIL Interface Members Structure have lower case sc not upper SC like you used. You had them lower case in the first study and for some reason changed it in the second one.
so all your subgraph and input decelerations referenced nothing.

Then you had a syntax error in the all of the band calculations with a missing closing bracket.



// The top of every source code file must include this line
#include "sierrachart.h"


/*****************************************************************************

  This file contains Sierra Chart custom study template functions and example functions.
  
  For reference, please refer to the Advanced Custom Study Interface
  and Language documentation on the Sierra Chart website.
  
*****************************************************************************/

//*****************************************************************************
// 06/22/13. ATRBands Version 1.0. In response to Sierra support forum question
// ATR Bands
// Compiled with MSVS 2010 Pro with SC v990 headers.
// Tested with SC v990
// Support Forum user: StevieD
//******************************************************************************
// BASED ON ABOVE STUDY BUT SIGNIFICANTLY CHANGED

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("DTEK DOUBLE HULL MID ATR BANDS")

SCSFExport scsf_DTEK_V3_HULL_DOUBLE_KELTNER_BANDS(SCStudyGraphRef sc)
{
  // Section 1 - Set the configuration variables
  SCSubgraphRef Hull_AVG = sc.Subgraph[0];
  SCSubgraphRef ATR_CALC_VALUE = sc.Subgraph[1];
  SCSubgraphRef BAND_A_UPPER = sc.Subgraph[2];
  SCSubgraphRef BAND_A_LOWER = sc.Subgraph[3];
  SCSubgraphRef BAND_B_UPPER = sc.Subgraph[4];
  SCSubgraphRef BAND_B_LOWER = sc.Subgraph[5];

  SCInputRef HULL_PRICE = sc.Input[0];
  SCInputRef HULL_LENGTH = sc.Input[1];
  SCInputRef ATR_AVG_TYPE = sc.Input[2];
  SCInputRef ATR_BAND_A_MULT = sc.Input[3];
  SCInputRef ATR_BAND_B_MULT = sc.Input[4];


  if (sc.SetDefaults)
  {
    // Set the configuration and defaults

    sc.GraphName = "HULL_WITH_DOUBLE_ATR_BANDS";
    sc.StudyDescription = "HULL_WITH_DOUBLE_ATR_BANDS";


    // 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 = 1;

    sc.GraphRegion = 0;
    sc.ValueFormat = VALUEFORMAT_INHERITED;

    Hull_AVG.Name = "HULL MID AVG";
    Hull_AVG.PrimaryColor = COLOR_GREEN;
    Hull_AVG.DrawStyle = DRAWSTYLE_LINE;
    Hull_AVG.LineWidth = 2;

    // Named but ignored. For tool value window only.
    // This study draws on the main price graph, not a region.
    // Unless ATR value is similar to price scale, chart will distort, as it should.
    ATR_CALC_VALUE.Name = "ATR Value";
    ATR_CALC_VALUE.DrawStyle = DRAWSTYLE_IGNORE;

    BAND_A_UPPER.Name = "OUTER BAND A UPPER";
    BAND_A_UPPER.PrimaryColor = RGB(255, 165, 0);
    BAND_A_UPPER.DrawStyle = DRAWSTYLE_LINE;
    //sc.Subgraph[2].LineStyle = LINESTYLE_DASH;
    BAND_A_UPPER.LineWidth = 1;

    BAND_A_LOWER.Name = "OUTER BAND A LOWER";
    BAND_A_LOWER.PrimaryColor = RGB(169, 169, 169);
    BAND_A_LOWER.DrawStyle = DRAWSTYLE_LINE;
    //sc.Subgraph[3].LineStyle = LINESTYLE_DASH;
    BAND_A_LOWER.LineWidth = 1;

    BAND_B_UPPER.Name = "INNER BAND B UPPER";
    BAND_B_UPPER.PrimaryColor = RGB(169, 169, 169);
    BAND_B_UPPER.DrawStyle = DRAWSTYLE_LINE;
    //sc.Subgraph[4].LineStyle = LINESTYLE_DASH;
    BAND_B_UPPER.LineWidth = 1;

    BAND_B_LOWER.Name = "INNER BAND B LOWER";
    BAND_B_LOWER.PrimaryColor = RGB(205, 92, 92);
    BAND_B_LOWER.DrawStyle = DRAWSTYLE_LINE;
    //sc.Subgraph[5].LineStyle = LINESTYLE_DASH;
    BAND_B_LOWER.LineWidth = 1;

    //INPUTS
    HULL_PRICE.Name = "HULL PRICE TYPE";
    HULL_PRICE.SetInputDataIndex(SC_LAST);

    HULL_LENGTH.Name = "HULL AVG Length";
    HULL_LENGTH.SetInt(30);
    HULL_LENGTH.SetIntLimits(1, 600);
    HULL_LENGTH.SetDescription("MA Length.<br>\
                  Displays as the Mid-Band and used to calculate ATR value.");

    ATR_AVG_TYPE.Name = "ATR CALCULATION AVERAGE TYPE";
    ATR_AVG_TYPE.SetMovAvgType(MOVAVGTYPE_WEIGHTED);
    ATR_AVG_TYPE.SetDescription("AVG TYPE USED TO COMPUTE ATR.<br>\
                  Can be diffent than average type");

    //sc.Input[2].Name = "ATR LOOKBACK CALC LENGTH";
    //sc.Input[2].setInt(30);
    //sc.Input[2].SetIntLimits(1,50);
    //sc.Input[2].SetDescription("AVG TYPE USED TO COMPUTE ATR. <br>\
                  Can differ from Hull Length if desired <br\
                  I always find this useful to separate ATR calc Length from MID");

    ATR_BAND_A_MULT.Name = "OUTER BANDS Multiplier";
    ATR_BAND_A_MULT.SetFloat(2.0);
    ATR_BAND_A_MULT.SetFloatLimits(0.1f, 10.0f);
    ATR_BAND_A_MULT.SetDescription("OUTER Band MULT - example 2.0 is HULL AVG +- 2.0 * ATR <br>\
                    rounded to neares tick size");

    ATR_BAND_B_MULT.Name = "INNER BANDS Multiplier";
    ATR_BAND_B_MULT.SetFloat(1.5);
    ATR_BAND_B_MULT.SetFloatLimits(0.1f, 10.0f);
    ATR_BAND_B_MULT.SetDescription("INNER Band MULT - example 1.5 is MID +- 1.5 * ATR <br>\
                    rounded to neares tick size");

    sc.AutoLoop = 1; // true

    return;
  }

  // Section 2 - Do data processing

  sc.DataStartIndex = HULL_LENGTH.GetInt();

  sc.HullMovingAverage(sc.BaseData[HULL_PRICE.GetInputDataIndex()], Hull_AVG, HULL_LENGTH.GetInt());
  //sc.MovingAverage(sc.BaseDataIn[SC_LAST],sc.Subgraph[0],sc.Input[1].GetMovAvgType(),sc.Input[0].GetInt());

  sc.ATR(sc.BaseDataIn, ATR_CALC_VALUE, HULL_LENGTH.GetInt(), ATR_AVG_TYPE.GetMovAvgType());

  //OUTBAND UPPER BAND
  BAND_A_UPPER[sc.Index] = sc.RoundToTickSize((Hull_AVG[sc.Index] + ATR_CALC_VALUE[sc.Index] * ATR_BAND_A_MULT.GetFloat()), sc.TickSize);
  //OUTBERBAND UPLOWER BAND
  BAND_A_LOWER[sc.Index] = sc.RoundToTickSize((Hull_AVG[sc.Index] - ATR_CALC_VALUE[sc.Index] * ATR_BAND_A_MULT.GetFloat()), sc.TickSize);
  //INNERBAND UPPER BAND
  BAND_B_UPPER[sc.Index] = sc.RoundToTickSize((Hull_AVG[sc.Index] + ATR_CALC_VALUE[sc.Index] * ATR_BAND_B_MULT.GetFloat()), sc.TickSize);
  //INNERBAND LOWER BAND
  BAND_B_LOWER[sc.Index] = sc.RoundToTickSize((Hull_AVG[sc.Index] - ATR_CALC_VALUE[sc.Index] * ATR_BAND_B_MULT.GetFloat()), sc.TickSize);

}

[2020-06-19 00:10:37]
Flipper - Posts: 65
Let me know if that is actually the fix you were after.

(just a tip all those UPPER CASE variable names make it hard to read too) ; )
[2020-06-19 04:00:55]
User463534 - Posts: 3
Thank you very much for the prompt response! That indeed was exactly what I needed help with!

I'm not sure how I overlooked the 'SC' vs 'sc' syntax discrepancy during my copy and paste job from my previous version. I'm so glad it's fixed - as though I spent a lot of time trying to find the solution myself (and learned a lot of nice features and coding ideas for future reference in the process), I just couldn't find the error and knew it be be something obvious for someone experienced. Also per your suggestions on readability, I also changed my variable naming conventions and removed the all caps per your suggestion.


I really appreciate you taking the time to help me. TI'll make sure to contribute and pay forward the help once I get a better grasp on the platform.

Have a good one!

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

Login

Login Page - Create Account