Login Page - Create Account

Support Board


Date/Time: Thu, 28 Nov 2024 22:45:16 +0000



[Programming Help] - How to set ChartRegion of study correctly?

View Count: 1247

[2018-08-08 19:38:27]
User517260 - Posts: 97
Dear Sir, I use srting

sc.GraphRegion = 1;

for study to set study to second region. But if I already have 3 or 4 regions with other studies - my study with sc.GraphRegion = 1; is automatically sets to the latest region number + 1. So, If user of my indicator will apply it to chart - he can not to see markers of my indicator in second region, because my study outputs markers to 5th or 6th region. How could I set default chart region correctly? Thanks. Best regards, Alex.
[2018-08-09 05:13:48]
Sierra Chart Engineering - Posts: 104368
What you will want to do is set sc.GraphRegion = 1; below the sc.SetDefaults code block.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2018-08-09 06:37:31]
User517260 - Posts: 97
Thanks, it works good now. Wish you a good day!
[2023-03-20 11:01:36]
User92573 - Posts: 530
Dear Support

My ascil default code sets the sc.GraphRegion as described but when the study is added it's placement is still the last study region + 1 as
opposed to over the existing study.


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

    sc.GraphName = "My_Study";

    sc.ValueFormat = VALUEFORMAT_INHERITED;
    sc.AutoLoop = 1;
    sc.GraphRegion = 1; // if there is already a study in region 1 or 2 etc the study is still being placed in last study + 1?
    sc.CalculationPrecedence = LOW_PREC_LEVEL;

Any thoughts as to why this might be?

Many thanks.
[2023-03-20 17:21:28]
John - SC Support - Posts: 36350
Read post #2 above. The solution is in there.
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2023-03-21 08:54:26]
User92573 - Posts: 530
I've already done that and it did not work.

When I said, as described, I was poorly referring to the fact that I'd followed the suggestion in "Post #2" as well as what I'd placed in the code section of my message above.


return;

// def section above

}

// Do data processing

sc.GraphRegion = 1; // does not place the study in the subgraph below the main chart.


I tried the method suggested but it did not place the study as sett out in my code.

Many thanks.
[2023-03-21 21:03:45]
John - SC Support - Posts: 36350
In the code snippet you show in Post #4 the "sc.GraphRegion = 1" is inside the sc.SetDefaults code block. Hence the reason why we assumed that you did not move it out.

But, if it is outside that block, then it should be putting your study into Region #2. Is it putting your study in the region with the Main Price Graph? Or are you saying that it is putting it into the next available region (like Region 3 or 4, etc.)?
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[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
[2023-03-22 14:29:10]
John - SC Support - Posts: 36350
Your Version 1 will not do what you want, you would need to use Version 2.

When we copy and compile your Version 2, it works as we expect. It will only allow the study to be put into Region #2 (sc.GraphRegion = 1). When we try to change the region, it forces it back to 2. When we add 2 copies of the study, they are both drawn in the same region (verified by changing the color and size of the lines).

We do not know why this is not working for you. Your version 2 should only draw that study into Region #2 as you have it defined.
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2023-03-24 11:46:03]
User92573 - Posts: 530
Hi John,

Well I don't know what to say. Recompiled and working. I've no idea why I was getting inconsistent results. I use NP++ and a local compiler so maybe I had set something incorrectly? Anyway all working.

As always many thanks for support for assistance.

Great Platform. Great support. Many thanks.
[2023-03-24 22:45:29]
John - SC Support - Posts: 36350
We are glad you got it working.
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2023-03-29 17:47:00]
User92573 - Posts: 530
Hi John,

I'm not sure if this post is monitored any longer?

There is an unfortunate side-effect and I wonder if there is a solution?

Setting the region this way, unlike setting it in defaults causes the region height to be completely reset. Not an issue on one chart but laborious with a large number of charts.

I there any way to stop the method advised (V2) from completely resetting the study regions height when added to an existing pre-set region?

Many thanks.
Date Time Of Last Edit: 2023-03-29 17:47:56

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

Login

Login Page - Create Account