Login Page - Create Account

Support Board


Date/Time: Sat, 04 May 2024 15:13:23 +0000



Post From: sc.SetChartWindowState is active across workbooks

[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