Login Page - Create Account

Support Board


Date/Time: Tue, 15 Apr 2025 12:33:28 +0000



[Programming Help] - Control bar button to quickly toggle Trade symbol (e.g. to switch from mini to micro)

View Count: 266

[2024-08-23 17:52:53]
n8trading - Posts: 44
Could a button be added, assuming it doesn't already exist that I am unaware of, that we could set to be able to toggle the Trade symbol between the micro and mini contracts (NQ and MNQ for example)? This would be very convenient for my trading and likely many others.

Thank you!
[2024-08-24 20:38:48]
Sierra_Chart Engineering - Posts: 19226
This can be developed using ACSIL:
Advanced Custom Study Interface and Language (ACSIL)

Specifically refer to:
Advanced Custom Study Interaction With Menus, Control Bar Buttons, Pointer Events
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, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2024-08-25 13:08:47]
n8trading - Posts: 44
Good to know it can be done, thanks! But coding is not in my current skill-set and this would take me quite some time to figure out. I added one of the Custom Study buttons to my chart, but no idea how to properly code this function and how to assign it to that particular button. Also, there could be complexity of setting the symbol - ideally, you'd want to select the symbol from the symbol list and not manually hardcode it, and it needs to toggle back and forth between two symbols.

Could someone with experience help me with this? I'd really appreciate it!
[2024-08-26 10:56:35]
emmanuel - Posts: 62
Perhaps you can achieve the same objective by using two charts in the same chartbook. One chart for the NQ and another for the MNQ.
[2024-08-26 12:33:24]
Sierra_Chart Engineering - Posts: 19226
We marked this as programming help. Another user may be able to help you with the custom programming.
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, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2025-04-09 17:47:22]
n8trading - Posts: 44
In case anyone else finds this useful, below the latest code I have to achieve this and here is a summary of what it does:

Purpose: Toggles the Trade Symbol between mini and micro futures contracts with a single button press/release on the Control Bar in Sierra Chart.

Button Label: Displays as "Toggle Mini/Micro" on the Control Bar.

On Press:
Changes the Trade Symbol from the mini (e.g., "NQ" for Nasdaq, "GC" for Gold, "CL" for Crude Oil) to the micro version by prepending "M" (e.g., "MNQ", "MGC", "MCL").

Updates the chart’s "Currency Value Per Tick" to match the micro symbol’s settings automatically.

On Release:
Resets the Trade Symbol back to the mini (the chart’s default symbol, e.g., "NQ").

Sets the Trade Window order quantity to 1.

Updates the "Currency Value Per Tick" to match the mini symbol’s settings.

Symbol Validation:
Checks if the Trade Symbol changes successfully on both press and release.

Logs an error with a Message Log popup if the symbol fails to change (e.g., "Failed to set Trade Symbol to: MNQ").

Settings Validation:
Retrieves "Currency Value Per Tick" from the symbol’s settings dynamically (no hardcoded values).

Logs an error with a popup if the settings can’t be retrieved (e.g., "Failed to retrieve Currency Value Per Tick for symbol: MNQ").

Logging:
Records successful actions in the Message Log (e.g., "Set symbol to: MNQ on [datetime]" or "Reset symbol to: default on [datetime]").

Normal operation logs are silent (no popup) by default, but can be enabled via a "Show Log Popup for Normal Operation" study input.

Errors always trigger a Message Log popup for immediate visibility.

DLL Name: Compiles to a DLL named "Toggle MiniMicro Symbol v3.5.dll" (or similar, based on Sierra Chart’s naming).

This button streamlines trading between mini and micro contracts (like Nasdaq, Gold, and Crude Oil), ensuring accurate symbol settings and providing clear feedback on success or failure.


#include "sierrachart.h"

SCDLLName("Toggle Mini/Micro Symbol v3.5")

const int INPUT_LOG_POPUP = 0; // Index for the "Show Log Popup" input

// Function to set Trade Symbol and update Currency Value Per Tick with checks
void SetTradeSymbolAndSettings(SCStudyInterfaceRef sc, const SCString& newSymbol, const SCString& logSymbol) {
// Set the Trade Symbol
sc.TradeAndCurrentQuoteSymbol = newSymbol;

// Check if the symbol was set successfully
if (sc.TradeAndCurrentQuoteSymbol != newSymbol) {
SCString errorMsg = "Failed to set Trade Symbol to: ";
errorMsg += newSymbol.IsEmpty() ? "default" : newSymbol;
sc.AddMessageToLog(errorMsg, 1); // Popup for error
return; // Exit early if symbol didn't change
}

// Determine which symbol's settings to use
SCString settingsSymbol = newSymbol.IsEmpty() ? sc.Symbol : newSymbol;

// Get the Currency Value Per Tick from the symbol settings
double currencyValuePerTick = sc.GetSymbolDataValue(SYMBOL_DATA_CURRENCY_VALUE_PER_TICK, settingsSymbol);
if (currencyValuePerTick > 0) {
sc.CurrencyValuePerTick = currencyValuePerTick; // Update chart's Currency Value Per Tick
} else {
// Fallback in case the symbol data isn’t available
SCString errorMsg = "Failed to retrieve Currency Value Per Tick for symbol: ";
errorMsg += settingsSymbol;
sc.AddMessageToLog(errorMsg, 1); // Popup for error
return; // Exit early if settings couldn't be retrieved
}

// Log the successful action without popping up the log by default
SCString action = newSymbol.IsEmpty() ? "Reset" : "Set";
SCString message = action + " symbol to: " + logSymbol + " on ";
SCString dateTimeStr = sc.DateTimeToString(sc.GetCurrentDateTime(), 0);
message += dateTimeStr;
int popup = sc.Input[INPUT_LOG_POPUP].GetYesNo(); // Check the input setting
sc.AddMessageToLog(message, popup); // Use input to control popup (default 0)
}

// Main study function
SCSFExport scsf_ToggleMiniMicroSymbol(SCStudyInterfaceRef sc) {
if (sc.SetDefaults) {
sc.GraphName = "Toggle Mini/Micro Symbol";
sc.StudyDescription = "Toggles the Trade Symbol between mini and micro, updating Currency Value Per Tick. Errors will trigger a log popup.";
sc.AutoLoop = 0; // Manual execution mode
sc.SetCustomStudyControlBarButtonText(0, "Toggle Mini/Micro");

// Set up the input for controlling log popup, defaulting to No
sc.Input[INPUT_LOG_POPUP].Name = "Show Log Popup for Normal Operation";
sc.Input[INPUT_LOG_POPUP].SetYesNo(0); // Default to 0 (no popup for normal logs)

return;
}

static bool isButtonPressed = false;

// Button press event
if (sc.PointerEventType == SC_ACS_BUTTON_ON && !isButtonPressed) {
SCString currentSymbol = sc.Symbol; // Mini chart symbol (e.g., "NQ")
SCString microSymbol = SCString("M") + currentSymbol; // Micro version (e.g., "MNQ")

SetTradeSymbolAndSettings(sc, microSymbol, microSymbol);
isButtonPressed = true;
}
// Button release event
else if (sc.PointerEventType == SC_ACS_BUTTON_OFF && isButtonPressed) {
SetTradeSymbolAndSettings(sc, "", "default"); // Reset to mini (chart symbol)
sc.TradeWindowOrderQuantity = 1; // Set order quantity to 1
isButtonPressed = false;
}
}

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

Login

Login Page - Create Account