Login Page - Create Account

Support Board


Date/Time: Mon, 07 Oct 2024 21:44:58 +0000



[Programming Help] - Button menu toggle

View Count: 2468

[2021-01-25 03:01:34]
ertrader - Posts: 670
I'm trying to add a button to the menu which enables or disables (yes/no) a selection in a study. Does anyone know how to do this with ACSIL?

I've been able to get the following code to enable or disable a study, however, when I try to add a second button, the two buttons get linked/combined so they toggle back and forth rather than independently working. I used different variables for the second button but they were still combined when toggled.

This comes from the study: AutomatedTradeManagementBySubgraph.cpp

Does anyone know how to add a button for anything other than enabling/disabling a study?

The button on the far right (ES) of the first image works to enable or disable the ES study. I also want to have another button to enable/disable longs. The second image is where you add the button to the control menu.

This is all done through the customize control bar options.


if (sc.IsFullRecalculation)//Is full recalculation
{
  // set ACS Tool Control Bar tool tip
  sc.SetCustomStudyControlBarButtonHoverText(Input_ACSButtonNumber.GetInt(), "Trade Enable/Disable");

// set Custom Study Control Bar button text if the input to allow custom properties is not true. Otherwise, rely upon what the user sets.
  if (!Input_AllowCustomPropertiesForControlBarButton.GetYesNo())
  sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber.GetInt(), "TCCI");
      
  sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber.GetInt(), Enabled.GetBoolean() );

}

// Wait for an event to enable study if not already enabled
if (sc.MenuEventID == Input_ACSButtonNumber.GetInt())
{
  const int ButtonState = (sc.PointerEventType == SC_ACS_BUTTON_ON) ? 1 : 0;
  Enabled.SetYesNo(ButtonState);
      
}

Date Time Of Last Edit: 2021-01-25 03:46:29
imageScreenshot from 2021-01-24 22-36-40.png / V - Attached On 2021-01-25 03:37:14 UTC - Size: 18.11 KB - 427 views
imageScreenshot from 2021-01-24 22-40-00.png / V - Attached On 2021-01-25 03:40:18 UTC - Size: 67.44 KB - 371 views
[2021-01-25 03:08:27]
ertrader - Posts: 670
This code compiles but does NOT work as intended for the second button...the buttons toggle back and forth rather than work independently. It is an example of my thinking how this may have worked. In this case, I am attempting to create 2 buttons: One to enable/disable the study, the second to enable/disable to go long. Once I get this working, I will also add another button for shorts.

// Study enable button
if (sc.IsFullRecalculation)//Is full recalculation
{
// set ACS Tool Control Bar tool tip
sc.SetCustomStudyControlBarButtonHoverText(Input_ACSButtonNumber.GetInt(), "Trade CCI Enable/Disable");
sc.SetCustomStudyControlBarButtonHoverText(Input_ACSButtonNumber1.GetInt(), "Trade Long");      

// set Custom Study Control Bar button text if the input to allow custom properties is not true. Otherwise, rely upon what the user sets.
if (!Input_AllowCustomPropertiesForControlBarButton.GetYesNo())
sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber.GetInt(), "TCCI");
      
if (!Input_AllowCustomPropertiesForControlBarButton1.GetYesNo())      
sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber1.GetInt(), "Long");      

sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber.GetInt(), Enabled.GetBoolean() );
sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber1.GetInt(), Long.GetBoolean() );      

}
// Wait for an event to enable study if not already enabled
if (sc.MenuEventID == Input_ACSButtonNumber.GetInt() || sc.MenuEventID == Input_ACSButtonNumber1.GetInt())
{
const int ButtonState = (sc.PointerEventType == SC_ACS_BUTTON_ON) ? 1 : 0;
Enabled.SetYesNo(ButtonState);
      
const int ButtonState1 = (sc.PointerEventType == SC_ACS_BUTTON_ON) ? 1 : 0;
Long.SetYesNo(ButtonState1);    
}

Date Time Of Last Edit: 2021-01-25 03:51:12
[2021-01-25 08:46:29]
User907968 - Posts: 821
Hi,
Only 1 ACS button can be active at a time, which is why they appear to toggle, there is some information here:
Advanced Custom Study Interaction With Menus, Control Bar Buttons, Pointer Events: Maintaining Multiple On States For Advanced Custom Study Control Bar Buttons
Don't think a specific code example is provided, so if you want some help just write.
[2021-01-25 19:50:17]
ertrader - Posts: 670
Thank you... seems like an odd limitation. For now will probably duplicate the chart until there is a better way. I'm trying to stay within ACSIL ... I know it can be done outside with c++ but really liked this functionality until I ran into the limitations. If you or anyone else has a code example that would be very helpful!
[2021-01-26 17:18:01]
ertrader - Posts: 670
After experimenting further, these calls are quite unreliable for getting/setting button status. Unfortunately, I had to remove all code. Will probably have to code outside of SC to get what I'm trying to do.
[2021-01-27 08:12:36]
User907968 - Posts: 821
I'm trying to stay within ACSIL
Sure, this is no problem.

A simple example based on post #2, using color to indicate button state and setting input state accordingly.


  if (sc.IsFullRecalculation)//Is full recalculation
  {
    // set ACS Tool Control Bar tool tip
    sc.SetCustomStudyControlBarButtonHoverText(Input_ACSButtonNumber.GetInt(), "Trade CCI Enable/Disable");
    sc.SetCustomStudyControlBarButtonHoverText(Input_ACSButtonNumber1.GetInt(), "Trade Long");

    // set Custom Study Control Bar button text if the input to allow custom properties is not true. Otherwise, rely upon what the user sets.
    if (!Input_AllowCustomPropertiesForControlBarButton.GetYesNo())
      sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber.GetInt(), "TCCI");

    if (!Input_AllowCustomPropertiesForControlBarButton1.GetYesNo())
      sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber1.GetInt(), "Long");

    // set buttons to disabled i.e. not pushed in state
    sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber.GetInt(), 0);
    sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber1.GetInt(), 0);

    // set button color to show enabled / disabled state
    if (Enabled.GetYesNo())
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_GREEN);
    else
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_RED);

    if (Long.GetYesNo())
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_GREEN);
    else
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_RED);
  }

  if (sc.MenuEventID != 0)
  {
    if (sc.MenuEventID == Input_ACSButtonNumber.GetInt())
    {
      // reset button to disabled i.e. not pushed in state
      sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber.GetInt(), 0);

      if (Enabled.GetYesNo())
      {
        // change state of input to disabled and set color accordingly
        Enabled.SetYesNo(0);
        sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_RED);
      }
      else
      {
        // change state of input to disabled and set color accordingly
        Enabled.SetYesNo(1);
        sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_GREEN);
        
      }

    }
    else if (sc.MenuEventID == Input_ACSButtonNumber1.GetInt())
    {
      sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber1.GetInt(), 0);

      if (Long.GetYesNo())
      {
        Long.SetYesNo(0);
        sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_GREEN);
      }
      else
      {
        Long.SetYesNo(1);
        sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_RED);
      }
    }
  }

[2021-01-28 05:51:05]
ertrader - Posts: 670
Great...thank you yes this seems to be working much better! Is there any way to make the buttons work so when you press them they work without clicking the recalc button too? I see it is coded that way but it adds an unnecessary click and status.
Date Time Of Last Edit: 2021-01-28 06:36:10
[2021-01-28 06:18:48]
ertrader - Posts: 670
I was able to get close... there is a slight delay after clicking the button but not a big deal at all. Here is your code with study enable/disable, long enable/disable and short enable/disable. I used sc.FlagFullRecalculate = 1 to force a recalc after pushing the button. Maybe there is a better way but this does work.

You rock!!

  if (sc.IsFullRecalculation)//Is full recalculation
  {

    // set ACS Tool Control Bar tool tip
    sc.SetCustomStudyControlBarButtonHoverText(Input_ACSButtonNumber.GetInt(), "Trade CCI Enable/Disable");
    sc.SetCustomStudyControlBarButtonHoverText(Input_ACSButtonNumber1.GetInt(), "Trade Long");
    // set Custom Study Control Bar button text if the input to allow custom properties is not true. Otherwise, rely upon what the user sets.

    if (!Input_AllowCustomPropertiesForControlBarButton.GetYesNo())
     sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber.GetInt(), "TCCI");
    if (!Input_AllowCustomPropertiesForControlBarButton1.GetYesNo())
     sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber1.GetInt(), "Long");
    if (!Input_AllowCustomPropertiesForControlBarButton2.GetYesNo())
     sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber2.GetInt(), "Short");   
    // set buttons to disabled i.e. not pushed in state
    sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber.GetInt(), 0);
    sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber1.GetInt(), 0);
    sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber2.GetInt(), 0);     
    // set button color to show enabled / disabled state

    if (Enabled.GetYesNo())
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_GREEN);
    else
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_RED);
    if (Long.GetYesNo())
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_GREEN);
    else
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_RED);
    if (Short.GetYesNo())
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber2.GetInt(), COLOR_GREEN);
    else
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber2.GetInt(), COLOR_RED);   
  }
  if (sc.MenuEventID != 0)
  {
    if (sc.MenuEventID == Input_ACSButtonNumber.GetInt())
    {
     // reset button to disabled i.e. not pushed in state
     sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber.GetInt(), 0);
     if (Enabled.GetYesNo())
     {
      // change state of input to disabled and set color accordingly
      Enabled.SetYesNo(0);
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_RED);
     }
     else
     {
      // change state of input to disabled and set color accordingly
      Enabled.SetYesNo(1);
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_GREEN);
     }
      sc.FlagFullRecalculate = 1;
    }
    else if (sc.MenuEventID == Input_ACSButtonNumber1.GetInt())
    {
      sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber1.GetInt(), 0);
      if (Long.GetYesNo())
      {
        Long.SetYesNo(0);
        sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_GREEN);
      }
      else
      {
        Long.SetYesNo(1);
        sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_RED);
      }
      sc.FlagFullRecalculate = 1;
    }
    else if (sc.MenuEventID == Input_ACSButtonNumber2.GetInt())
    {
     sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber2.GetInt(), 0);
     if (Short.GetYesNo())
     {
      Short.SetYesNo(0);
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber2.GetInt(), COLOR_GREEN);
     }
     else
     {
      Short.SetYesNo(1);
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber2.GetInt(), COLOR_RED);
     }
      sc.FlagFullRecalculate = 1;    
    }    
  }

Date Time Of Last Edit: 2021-01-29 12:47:22
[2021-01-28 09:29:11]
User907968 - Posts: 821
there is a slight delay after clicking the button
Maybe relates to chart update interval and/or market data - General Settings Window: Chart Update Interval (Global Settings >> General Settings >> General >> Update Intervals)

sc.FlagFullRecalculate is probably not necessary, it is just a way of circumventing the chart update delay. Assuming that you are handling the button press event before the main body of code, the changes due to the button press will be effective right away.
[2021-01-28 12:43:07]
ertrader - Posts: 670
It does work much better with it. I tried with and without sc.FlagFullRecalculate = 1 and it works to update the button without having to click the Recalc button. I tried setting the chart update interval to 25...still had to click recalc which I have as a button. Kept the version with sc.FlagFullRecalculate = 1 for now.
Date Time Of Last Edit: 2021-01-28 12:56:17
imageScreenshot from 2021-01-28 07-42-17.png / V - Attached On 2021-01-28 12:43:03 UTC - Size: 14.68 KB - 354 views
[2021-01-28 13:13:00]
User907968 - Posts: 821
Changing the chart update interval alone doesn't necessarily make any difference, as if no market data is received then there is no chart update.

You could take a look at sc.UpdateAlways, which will cause the study to update according to the chart update interval whether new data is received or not - ACSIL Interface Members - Variables and Arrays: sc.UpdateAlways

In any case, if you have a solution that you are happy with, then it's all good.
[2021-01-29 16:23:49]
ertrader - Posts: 670
I'm testing the following with no requirement for sc.IsFullRecalculation and this is working much better. It updates the buttons instantly with no delays! Also, added a button for enabling/disabling sending to trade service. So now, can switch on and off anything without going into the study.

    

// set ACS Tool Control Bar tool tip
    sc.SetCustomStudyControlBarButtonHoverText(Input_ACSButtonNumber.GetInt(), "Trade Study Enable/Disable");
    sc.SetCustomStudyControlBarButtonHoverText(Input_ACSButtonNumber1.GetInt(), "Trade Long");
    sc.SetCustomStudyControlBarButtonHoverText(Input_ACSButtonNumber2.GetInt(), "Trade Short");
    sc.SetCustomStudyControlBarButtonHoverText(Input_ACSButtonNumber3.GetInt(), "Send");
    // set Custom Study Control Bar button text if the input to allow custom properties is not true. Otherwise, rely upon what the user sets.

    if (!Input_AllowCustomPropertiesForControlBarButton.GetYesNo())
     sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber.GetInt(), "TCCI");
    if (!Input_AllowCustomPropertiesForControlBarButton1.GetYesNo())
     sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber1.GetInt(), "Long");
    if (!Input_AllowCustomPropertiesForControlBarButton2.GetYesNo())
     sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber2.GetInt(), "Short");   
    if (!Input_AllowCustomPropertiesForControlBarButton3.GetYesNo())
     sc.SetCustomStudyControlBarButtonText(Input_ACSButtonNumber3.GetInt(), "Send");   
    // set buttons to disabled i.e. not pushed in state
    sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber.GetInt(), 0);
    sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber1.GetInt(), 0);
    sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber2.GetInt(), 0);     
    sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber3.GetInt(), 0);     
    // set button color to show enabled / disabled state

    if (Enabled.GetYesNo())
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_GREEN);
    else
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_RED);
  
    if (Long.GetYesNo())
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_GREEN);
    else
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_RED);
  
    if (Short.GetYesNo())
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber2.GetInt(), COLOR_GREEN);
    else
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber2.GetInt(), COLOR_RED);   
  
    if (SendOrdersToService.GetYesNo())
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber3.GetInt(), COLOR_GREEN);
    else
     sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber3.GetInt(), COLOR_RED);   

  if (sc.MenuEventID != 0)
  {
    if (sc.MenuEventID == Input_ACSButtonNumber.GetInt())
    {
     // reset button to disabled i.e. not pushed in state
     sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber.GetInt(), 0);
     if (Enabled.GetYesNo())
     {
      // change state of input to disabled and set color accordingly
      Enabled.SetYesNo(0);
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_RED);
     }
     else
     {
      // change state of input to disabled and set color accordingly
      Enabled.SetYesNo(1);
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber.GetInt(), COLOR_GREEN);
     }

    }
    else if (sc.MenuEventID == Input_ACSButtonNumber1.GetInt())
    {
      sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber1.GetInt(), 0);
      if (Long.GetYesNo())
      {
        Long.SetYesNo(0);
        sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_GREEN);
      }
      else
      {
        Long.SetYesNo(1);
        sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber1.GetInt(), COLOR_RED);
      }

    }
    else if (sc.MenuEventID == Input_ACSButtonNumber2.GetInt())
    {
     sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber2.GetInt(), 0);
     if (Short.GetYesNo())
     {
      Short.SetYesNo(0);
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber2.GetInt(), COLOR_GREEN);
     }
     else
     {
      Short.SetYesNo(1);
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber2.GetInt(), COLOR_RED);
     }

    }  
    else if (sc.MenuEventID == Input_ACSButtonNumber3.GetInt())
    {
     sc.SetCustomStudyControlBarButtonEnable(Input_ACSButtonNumber3.GetInt(), 0);
     if (SendOrdersToService.GetYesNo())
     {
      SendOrdersToService.SetYesNo(0);
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber3.GetInt(), COLOR_GREEN);
     }
     else
     {
      SendOrdersToService.SetYesNo(1);
      sc.SetCustomStudyControlBarButtonColor(Input_ACSButtonNumber3.GetInt(), COLOR_RED);
     }
  
    }    
  }

Date Time Of Last Edit: 2021-02-04 23:21:56
[2022-01-17 18:36:26]
ertrader - Posts: 670
This code has been working OK for the last few months. However, for this one study, I routinely see 80-200 MS calculation times across all contracts I trade (ES,YM,NQ,GC,CL) despite many attempts to optimize. It still worked...but for such a small amount of code, very high calc times. (there is more to the study than above but this section is the performance issue)

Additional discussion:
Code optimization

In the last 2 weeks, in updating my chartbooks, I noticed new chartbooks had significantly better calculation times (6-10 MS) for the IDENTICAL setup. This occurred even without recompiling my custom study.

After testing several possible scenarios (recompiling, different references etc), the only difference was a new chartbook. So, I duplicated my previous chartbooks (right mouseclick on the chart and duplicate) to new ones and now all are 10 MS or less for calculation times! And this same improvement is across two different installations with two different order routing services (this should not have any impact but is good for comparison)

Key takeaway: Something about recent release chartbooks (SC V2345 is what I tested) are much more efficient when calling this code, even without recompiling.
Date Time Of Last Edit: 2022-01-17 19:39:50
[2024-01-21 23:31:29]
ertrader - Posts: 670
Here is an updated optimized version I am testing. So far, the optimization is working quite well reducing calculation times to 0 ms. We will see.

For my latest version, I am Enabling/Disabling trading and Enabling/Disabling sending to trading service. (not long, short or the other TCCI option)


1) Add the following prior to the SCDLLName call:

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);
}
}
2) Replace all the other menu code with:

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);
}

Date Time Of Last Edit: 2024-01-21 23:47:05
[2024-02-01 22:09:22]
ertrader - Posts: 670
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

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

Login

Login Page - Create Account