Login Page - Create Account

Support Board


Date/Time: Tue, 22 Apr 2025 13:03:14 +0000



Post From: possible to attach a control bar button to a particular study?

[2025-01-21 20:35:57]
n8trading - Posts: 44
Perfect, thank you! I'm quite impressed with ChatGPT even though it made a lot of mistakes and we had to go through several interations. Here is the final code which should work for any mini/micro symbol pair where the micro symbol simply has a "M" prepended to it, in case any one is interested.


#include "sierrachart.h"

SCDLLName("Toggle Mini/Micro Symbol")

// Function to change the trade symbol
void SetTradeSymbol(SCStudyInterfaceRef sc, const SCString& newSymbol) {
sc.TradeAndCurrentQuoteSymbol = newSymbol; // Set Trade Symbol
}

// Function to set order quantity
void SetOrderQuantity(SCStudyInterfaceRef sc, int quantity) {
sc.TradeWindowOrderQuantity = quantity; // Set order quantity to the specified value
}

// Main study function
SCSFExport scsf_ToggleMiniMicroSymbol(SCStudyInterfaceRef sc) {
static bool isButtonPressed = false;

if (sc.SetDefaults) {
sc.GraphName = "Toggle Mini/Micro Symbol";
sc.StudyDescription = "Toggles the Trade Symbol between Mini and Micro based on button press and release.";
sc.AutoLoop = 0; // Manual execution mode

// Set the button text for the custom study button
sc.SetCustomStudyControlBarButtonText(0, "Toggle Mini/Micro");

return;
}

// Detect button press event (SC_ACS_BUTTON_ON)
if (sc.PointerEventType == SC_ACS_BUTTON_ON) {
// Only change the symbol when the button is pressed
if (!isButtonPressed) {
SCString currentSymbol = sc.Symbol; // Get the current chart symbol
SCString microSymbol = "M"; // Start with "M" for the micro version
microSymbol.Append(currentSymbol); // Append the current symbol to "M"

SetTradeSymbol(sc, microSymbol); // Set the trade symbol to the micro version
isButtonPressed = true;
}
}
// Detect button release event (SC_ACS_BUTTON_OFF)
else if (sc.PointerEventType == SC_ACS_BUTTON_OFF) {
// Null the TradeAndCurrentQuoteSymbol and set order quantity to 1 when button is released
if (isButtonPressed) {
SetTradeSymbol(sc, ""); // Null the symbol when switching back to default
SetOrderQuantity(sc, 1); // Set the order quantity to 1
isButtonPressed = false;
}
}
}

Date Time Of Last Edit: 2025-01-21 22:21:54