Support Board
Date/Time: Tue, 26 Nov 2024 15:44:51 +0000
[Programming Help] - Calling an External Input variable
View Count: 650
[2023-11-16 19:55:29] |
Gravity369 - Posts: 17 |
hi, How can I call an external input of a variable let's say "x" or a boolean input from an external C++ program ? regards Naga. |
[2023-11-17 01:48:04] |
User719512 - Posts: 264 |
I don't understand your question, but did you know that ChatGPT knows about c++ and even Sierra Chart questions? That route might get you answers quicker than waiting for replies on this forum. Please don't take my reply here as an indication you should not ask questions here. You wouldn't ask if you were not blocked. Lots of people here to help as we've all been there.
|
[2023-11-17 07:46:48] |
Gravity369 - Posts: 17 |
HI, Sorry for not being clear about my question. I want to run a separate C++ program that calculates Entry and Exit trades and use the trigger for trades from that program as an input into SC Study. Hope that makes sense. Naga. |
[2023-11-17 08:11:23] |
User719512 - Posts: 264 |
The best Sierra is going to do is some sort of polling to look for your triggers via the IPC (inter process communication) you design. I prob wouldn't use tcp/udp sockets for listening in a Sierra study. I suppose you could do this in a non-blocking manner, but unsure of the reliability of such solution. Does this need to be durable for if/when Sierra restarts or you close a workbook? You could use a local db like MongoDB and use it for a pub/sub pattern (or have the db hosted in Atlas for free and not have to run mongod locally). There are MongoDB libs you can use in Sierra studies. Windows supports other IPC mechanisms like memory mapped files. Just depends on what capabilities you want and the tradeoffs for each.
|
[2023-11-17 09:44:14] |
Gravity369 - Posts: 17 |
HI, Thank you for your reply. I was thinking on similar lines. I also tried CHATGPT and it came up with this answer, which I am unsure if ACSIL will Built correctly. Will try and let you know. I was pleasantly surprised when I got to know ACSIL program is available on CHATGPT. >>>>>> write a program in Sierra Chart ACSIL to take an external input from another C++ program ChatGPT Certainly! To communicate between different programs, you can use inter-process communication (IPC) methods. One commonly used method for this purpose is using named pipes. Here's an example of how you might achieve this between a Sierra Chart ACSIL program and another C++ program using named pipes: Sierra Chart ACSIL Code (Receiver): cpp Copy code #include "scsf.h" #include <iostream> #include <fstream> SCSFExport scsf_ReceiveExternalInput(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "Receive External Input"; return; } // Open a named pipe for reading std::ifstream pipe; pipe.open("/path/to/your/named_pipe", std::ios::in); if (!pipe.is_open()) { sc.AddMessageToLog("Failed to open named pipe for reading", 1); return; } while (sc.UpdateStartIndex == 0) { std::string input; std::getline(pipe, input); // Process the received input if (!input.empty()) { sc.AddMessageToLog(("Received: " + input).c_str(), 0); // Process the received input here // Example: Parse input and perform actions } sc.AddMessageToLog("Waiting for input...", 0); // Sleep for a short time to avoid busy waiting sc.Sleep(1000); // Sleep for 1 second } pipe.close(); // Close the named pipe } Replace "/path/to/your/named_pipe" with the actual path to your named pipe. C++ Code (Sender): Here's a simple example of how you might write to the named pipe from another C++ program: cpp Copy code #include <iostream> #include <fstream> int main() { std::ofstream pipe; pipe.open("/path/to/your/named_pipe", std::ios::out); if (!pipe.is_open()) { std::cerr << "Failed to open named pipe for writing" << std::endl; return 1; } // Send input to the named pipe pipe << "Your message or data here\n"; pipe.close(); // Close the named pipe return 0; } Make sure to replace "/path/to/your/named_pipe" with the actual path to the named pipe created by the Sierra Chart ACSIL code. Remember, named pipes need to have the same name and location for both processes to communicate effectively. Also, error handling, synchronization, and proper message formatting should be considered for robust communication between programs. |
[2023-11-17 15:04:37] |
Sierra_Chart Engineering - Posts: 17182 |
A simple method to accomplish this is just have the external program write to a file and then have the ACSIL study read the file. To avoid problems, with the two programs reading and writing at the same time, lock the file when writing it and then the ACSIL function cannot open the file if it is locked. And you will want to have the study update always by using sc.UpdateAlways. 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 |
[2023-11-18 00:50:38] |
Gravity369 - Posts: 17 |
Yes. This above solution was what I was looking for. Thank you. Naga. |
[2023-11-18 20:19:35] |
Sierra_Chart Engineering - Posts: 17182 |
Good.
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 |
To post a message in this thread, you need to log in with your Sierra Chart account: