Login Page - Create Account

Support Board


Date/Time: Thu, 25 Apr 2024 02:13:08 +0000



sc.SetChartWindowState is active across workbooks

View Count: 635

[2019-09-05 13:10:29]
User462086 - Posts: 188
Hello, I'm trying to bring 2 background charts to the foreground with a hotkey.

The code below works fine unless there's more than one chartbook open that's using the code and has the same chart numbers, in which case it will cycle through the other open chartbooks' charts.

Edit: The documentation states: "The sc.SetChartWindowState function is used to minimize, restore or maximize the chart specified by the ChartNumber parameter in the same Chartbook containing the chart the study instance is applied to."

How do I restrict this function and the keypress to only the active chartbook?

Many thanks!!



#include "sierrachart.h"

SCDLLName("ShowCharts")

bool keydown(int key){
return (GetKeyState(key) & 0x100) != 0;
}

SCSFExport scsf__ShowCharts(SCStudyInterfaceRef sc)
{
  SCInputRef chartNum_1 = sc.Input[0];
  SCInputRef chartNum_2 = sc.Input[1];

  if (sc.SetDefaults)
  {
    sc.GraphName = "ShowCharts";
    sc.GraphRegion = 0; // main price graph
    sc.AutoLoop = 0; //Automatic looping is disabled.
    
    chartNum_1.Name = "Chart number to show";
    chartNum_1.SetInt(2);
    
    chartNum_2.Name = "Chart number to show";
    chartNum_2.SetInt(3);  
    
    return;
  }
  
  // show charts when 'CTRL' is pressed
  
  bool pressed = keydown(VK_CONTROL);
  
  if( pressed ){
    
    if(chartNum_1.GetInt()>0){
      sc.SetChartWindowState(chartNum_1.GetInt(),CWS_MINIMIZE);
      sc.SetChartWindowState(chartNum_1.GetInt(),CWS_RESTORE);
    }
    if(chartNum_2.GetInt()>0){
      sc.SetChartWindowState(chartNum_2.GetInt(),CWS_MINIMIZE);
      sc.SetChartWindowState(chartNum_2.GetInt(),CWS_RESTORE);
    }
  }
}


Date Time Of Last Edit: 2019-09-05 13:13:13
[2019-09-05 15:21:44]
Sierra Chart Engineering - Posts: 104368
Definitely the sc.SetChartWindowState function only applies to the same Chartbook containing the chart the study instance is applied to. This has been verified.
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
[2019-09-05 15:33:37]
User462086 - Posts: 188
Thank you for the speedy response. Tomorrow, I will check if a keypress is detected by all open chartbooks and report back.
[2019-09-05 15:35:48]
User462086 - Posts: 188
In the meantime, is there a better way to bring a background chart in a chartbook to the foreground?
[2019-09-05 18:02:49]
Sierra Chart Engineering - Posts: 104368
I will check if a keypress is detected by all open chartbooks
No this is definitely not going to be the case.
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
[2019-09-06 10:35:51]
User462086 - Posts: 188
Thank you for the heads-up regarding the keypress' scope. Guess the only thing left that can be done is to continue experimenting with it this weekend and report back on Monday.
[2019-09-07 08:15:30]
User462086 - Posts: 188
A key press IS detected by background (open but not active) chartbooks' studies, even when using Sierra Chart's variables (ie, not the generic code used in the first post).

Compile and put the code below into several open chartbooks, assign a unique number to the 'Chartbook Number" input, and press/hold the 'Control' key while data is streaming into all chartbooks, or all chartbooks are replaying. Each background chartbook using the study will write to the message log eventually.

The only way to filter out the background chartbooks is to use 'sc.ChartWindowIsActive' AND make sure the chart with the study on it is indeed the active chart. This effectively stops the background chartbooks from executing the code triggered by the keypress.

Ideally, a variable 'sc.ChartbookIsActive' could be used so the user isn't required to click on a chart to make it active before pressing the hotkey.

Many thanks!!

Edit: using SC v1983



#include "sierrachart.h"

SCDLLName("Test_Keypress")

SCSFExport scsf__Test_Keypress(SCStudyInterfaceRef sc)
{
  SCString DebugMessage;
  
  SCInputRef cbNum = sc.Input[0];
  
  if (sc.SetDefaults)
  {
    sc.GraphName = "Test_Keypress";
    sc.GraphRegion = 0; // main price graph
    sc.AutoLoop = 0; //Automatic looping is disabled.
    
    sc.ReceiveKeyboardKeyEvents = 1;
    sc.SupportKeyboardModifierStates = 1;
    
    cbNum.Name = "Chartbook Number";
    cbNum.SetInt(1);
    
    return;
  }
  
  if( sc.IsKeyPressed_Control ){ // use 'sc.ChartWindowIsActive && sc.IsKeyPressed_Control' to filter background chartbooks
    DebugMessage.Format(" Chartbook %d ", cbNum.GetInt() );
    sc.AddMessageToLog(DebugMessage, 0);
  }
}



Date Time Of Last Edit: 2019-09-07 08:30:58
[2019-09-07 09:39:59]
Sierra Chart Engineering - Posts: 104368
Yes that is true you will have to check sc.ChartWindowIsActive. What we meant is that when there is a keyboard event through the variable like sc.KeyboardKeyEventCode, only the active chart is going to have the studies on it called and be able to detect that.

But as other charts are updating and you are continuing to hold a control key, then yes they can detect that control key state.
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
Date Time Of Last Edit: 2019-09-07 09:57:44

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

Login

Login Page - Create Account