Login Page - Create Account

Support Board


Date/Time: Fri, 22 Nov 2024 22:50:48 +0000



Post From: Button menu toggle

[2024-02-01 22:09:22]
ertrader - Posts: 672
Here is an example of menu button toggling.

1) Under global settings, add a customized control bar
2) Right mouse click on the control bar
3) Scroll to Advanced custom study buttons
4) Click on a button and add it to the control bar
5) Note the button number and enter this in the example study input (you can have a max of 150 buttons)
6) Once added, you can change the properties of the button...select it, the properties and you will see all the options.

#include "sierrachart.h"
#define COLOR_BABYBLUE RGB(0, 128, 255)

void SetButtonColor(SCStudyInterfaceRef& sc, int buttonNumber, int color) {
sc.SetCustomStudyControlBarButtonColor(buttonNumber, color);
}

void HandleMenuEvent(SCStudyInterfaceRef& sc, SCInputRef& input, int eventID, int buttonNumber, int colorEnabled, int colorDisabled) {
if (sc.MenuEventID == eventID) {
sc.SetCustomStudyControlBarButtonEnable(buttonNumber, 0);
bool currentState = input.GetYesNo();
input.SetYesNo(!currentState);
SetButtonColor(sc, buttonNumber, currentState ? colorDisabled : colorEnabled);
}
}

SCDLLName("MenuButtonExample")
SCSFExport scsf_MenuButtonExample(SCStudyGraphRef sc)
{
  SCInputRef Enabled             = sc.Input[0];
  SCInputRef SendOrdersToService             = sc.Input[1];
  SCInputRef Input_ACSButtonNumber             = sc.Input[15];
  SCInputRef Input_AllowCustomPropertiesForControlBarButton   = sc.Input[16];
  SCInputRef Input_ACSButtonNumber1        = sc.Input[17];
  SCInputRef Input_AllowCustomPropertiesForControlBarButton1   = sc.Input[18];
  
   if(sc.SetDefaults)
{
    sc.StudyDescription="Menu Button Example";
    sc.GraphName="Menu Button Example";

    sc.AutoLoop = true;
    sc.GraphRegion = 0;

    Enabled.Name = "Enabled";
    Enabled.SetYesNo(true);

    SendOrdersToService.Name = "Send Orders to Trade Service";    
    SendOrdersToService.SetYesNo(false);  

    Input_ACSButtonNumber.Name = "ACS Control Bar Button # for Study Enable/Disable";
    Input_ACSButtonNumber.SetInt(1);
    Input_ACSButtonNumber.SetIntLimits(1, 150);

    Input_AllowCustomPropertiesForControlBarButton.Name = "Allow Custom 'Properties' for Study Button";
    Input_AllowCustomPropertiesForControlBarButton.SetYesNo(false);

    Input_ACSButtonNumber1.Name = "ACS Control Bar Button # for Send Order Enable/Disable";
    Input_ACSButtonNumber1.SetInt(4);
    Input_ACSButtonNumber1.SetIntLimits(1, 150);

    Input_AllowCustomPropertiesForControlBarButton1.Name = "Allow Custom 'Properties' for Study Button";
    Input_AllowCustomPropertiesForControlBarButton1.SetYesNo(false);
  }

if (sc.MenuEventID != 0) {
HandleMenuEvent(sc, Enabled, Input_ACSButtonNumber.GetInt(), Input_ACSButtonNumber.GetInt(), COLOR_BABYBLUE, COLOR_RED);
HandleMenuEvent(sc, SendOrdersToService, Input_ACSButtonNumber1.GetInt(), Input_ACSButtonNumber1.GetInt(), COLOR_BABYBLUE, COLOR_RED);
}
  
  
  // if you programatically toggle the buttons rather than clicking them, here is some example code:
  
  //Enabled.SetYesNo(false);
  //sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber.GetInt(), Enabled.GetBoolean() );    
  //sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_RED);  
}  

Date Time Of Last Edit: 2024-02-01 23:46:27