Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 05:11:36 +0000



Post From: Keyboard shortcut that will allow me to copy the ticker from a chart?

[2024-04-02 23:56:58]
User584005 - Posts: 27
I was able to write a script that saves the ticker to a text file and i can use other apps to get the ticker. However the file just constantly updates what whichever chart the study is on. Does anyone know of a way I can force this script to run only when i want it to. Maybe something like stamping a marker on the chart will tell it to export that ticker symbol to the file.
#include "sierrachart.h"

SCDLLName("CopyTickerToClipboardDLL") // This line names your DLL

SCSFExport scsf_CopyTickerSymbolToFile(SCStudyInterfaceRef sc)
{
if (sc.SetDefaults)
{
sc.GraphName = "Copy Ticker Symbol To File";
sc.StudyDescription = "Writes the chart's ticker symbol to a text file.";

sc.GraphRegion = 0;
sc.UpdateAlways = false;
sc.AutoLoop = false;
return;
}

// Main code execution
SCString tickerSymbol = sc.Symbol;

// Specify the path to the text file
SCString filePath = "C:\\SierraChart\\SierraChartInstance_2\\SymbolOutput.txt";

// Open file stream
std::ofstream outputFile(filePath.GetChars(), std::ios::out);
if(outputFile.is_open())
{
outputFile << tickerSymbol.GetChars();
outputFile.close();

// Optionally, log to Sierra Chart Message Log
SCString logMessage;
logMessage.Format("Ticker Symbol %s written to file.", tickerSymbol.GetChars());
sc.AddMessageToLog(logMessage, 0);
}
}