Login Page - Create Account

Support Board


Date/Time: Thu, 28 Nov 2024 22:51:15 +0000



Post From: How to set ChartRegion of study correctly?

[2023-03-21 23:44:24]
User92573 - Posts: 530
Hi John

No its not working as described. Here are two versions of code, one setting the region inside the defaults and the other outside.

The regions are:

0 = Main Graph region or region 1 visually.
1 = Next region or actually region 2 visually etc etc.

When I place the study a second time irrespective of where I set the Regions it display in the next subgraph, not the same or designated. As usual its probably me but here is the code and screenshots related to V1 and V2.


// I realise this is an SMA in region 1 the second region of the chart but it's simple.

#include "sierrachart.h"
#include "scconstants.h"

SCDLLName("SMA_Test_V1")


SCSFExport scsf_SMA_Test_V1(SCStudyGraphRef sc)
{
  
  //ARRAYS
  SCSubgraphRef Subgraph_SMA = sc.Subgraph[0];
  //INPUTS
  SCInputRef Input_SMA_Length = sc.Input[0];

  if (sc.SetDefaults)
  {
    // Set the configuration and defaults
    
    sc.GraphName = "Moving Average Example - Region 1";
    
    sc.StudyDescription = "I'll insert this twice and see if it stays in region 1";
    
    sc.AutoLoop = 1; // true
    sc.FreeDLL = 1;
    
    sc.GraphRegion = 1; // Below main chart
    
    Subgraph_SMA.Name = "Simple Moving Average";
    Subgraph_SMA.PrimaryColor = RGB(0,0,255); // Blue
    Subgraph_SMA.LineStyle = LINESTYLE_SOLID;
    
    Input_SMA_Length.Name = "Moving Average Length";
    Input_SMA_Length.SetInt(10);
    
    return;
  }
  
  
  // Do Processing

  
  // Set the index of the first array element to begin drawing at
  sc.DataStartIndex = Input_SMA_Length.GetInt() - 1;  

  sc.SimpleMovAvg(sc.Close, Subgraph_SMA, Input_SMA_Length.GetInt());

}




.... and with the Set GraphRegion outside:


// I realise this is an SMA in region 1 the second region of the chart but it's simple.

#include "sierrachart.h"
#include "scconstants.h"

SCDLLName("SMA_Test_V2")


SCSFExport scsf_SMA_Test_V2(SCStudyGraphRef sc)
{
  
  //ARRAYS
  SCSubgraphRef Subgraph_SMA = sc.Subgraph[0];
  //INPUTS
  SCInputRef Input_SMA_Length = sc.Input[0];

  if (sc.SetDefaults)
  {
    // Set the configuration and defaults
    
    sc.GraphName = "Moving Average Example - Region 1";
    
    sc.StudyDescription = "I'll insert this twice and see if it stays in region 1";
    
    sc.AutoLoop = 1; // true
    sc.FreeDLL = 1;
    
    //sc.GraphRegion = 1; // Below main chart
    
    Subgraph_SMA.Name = "Simple Moving Average";
    Subgraph_SMA.PrimaryColor = RGB(0,0,255); // Blue
    Subgraph_SMA.LineStyle = LINESTYLE_SOLID;
    
    Input_SMA_Length.Name = "Moving Average Length";
    Input_SMA_Length.SetInt(10);
    
    return;
  }
  
  
  // Do Processing
  
  sc.GraphRegion = 1; // Below main chart

  
  // Set the index of the first array element to begin drawing at
  sc.DataStartIndex = Input_SMA_Length.GetInt() - 1;  

  sc.SimpleMovAvg(sc.Close, Subgraph_SMA, Input_SMA_Length.GetInt());

}




2 Screen shots, one for each follow.


As always, many thanks for the support.
Date Time Of Last Edit: 2023-03-21 23:44:45
imageV1 study added twice.png / V - Attached On 2023-03-21 23:43:40 UTC - Size: 27.4 KB - 98 views
imageV2 study added twice.png / V - Attached On 2023-03-21 23:44:02 UTC - Size: 27.52 KB - 94 views