Login Page - Create Account

Support Board


Date/Time: Thu, 17 Apr 2025 23:58:21 +0000



Post From: Control bar button to quickly toggle Trade symbol (e.g. to switch from mini to micro)

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