Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 20:49:39 +0000



Executing external programs on various events

View Count: 545

[2023-07-10 17:21:11]
User166108 - Posts: 73
Hi support,

Is there any way to execute external programs when an order gets filled or the position is otherwise updated?

I think the answer is "no, write your own plugin" which is fine but I just want to make sure of that.

If the answer is "no", is there a list of events anywhere or do we need to infer changes by maintaining last position size?

Thanks.
[2023-07-10 21:07:41]
John - SC Support - Posts: 36344
Yes you can through the Alerts functionality:
General Settings Window: Run Program When This Alert Triggered (Global Settings >> General Settings >> Alerts >> Alert Settings)

You can set a specific alert, for an order fill. Refer to the following:
Global Trade Settings Windows: Play Alert When Order Filled (Global Settings >> General Trade Settings >> Notifications)
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2023-07-10 22:58:02]
User166108 - Posts: 73
That looks close to what I need, but does the alert pass any parameters? I want to do something different when position=0 vs position!=0
[2023-07-11 13:32:03]
John - SC Support - Posts: 36344
The alert does not pass any parameters. You would have to have two different alerts each calling different programs to do what you want.
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2023-07-11 14:04:15]
JohnR - User831573 - Posts: 306
Hope you don't mind my tagging on to this thread. I too have been contemplating how to connect SC to another program within the MSFT structure. Before retiring, I was around a lot of 'infrastructure' DB, MSG, WebApp. So I get the functionality of it. So, for my small project, would it be better to use the Event structure of C# & C++ as the method to connect or would a Messaging technology be better, have less issues? I might be partial, but seems like the ability to have the programs execute async of each other could be a good thing.
Maybe it would be simpler to implement since I don't have to worry C# / C++ exchanges. Just initialize & or connect to a queue and then put / get messages.

Pointers to places to get smarter or replies here would be greatly appreciated.

Retired (Old) self taught C++/C# -- past structured coder
JohnR
[2023-07-12 20:12:52]
User166108 - Posts: 73
JohnR, I wrote this to solve my problem, maybe you can use it as a starting point.

I also have a trade copier that I built.


#include "boost/format.hpp"
#include "boost/lexical_cast.hpp"
#include "boost/process.hpp"
#include "boost/process/windows.hpp"
#include "sierrachart.h"
#include <limits>

namespace bp = boost::process;

SCDLLName("Chart events plugin");

class ChartEvents
{
private:
double m_lastPosition = 0;

static void executeProgram(SCStudyInterfaceRef sc, std::string command,
std::vector<std::string> args)
{
SCString logMessage;
logMessage.Append("Executing command: ");
logMessage.Append(command.c_str());
logMessage.Append(" ");
for (auto const &arg : args)
{
logMessage.Append(arg.c_str());
logMessage.Append(" ");
}
sc.AddMessageToLog(logMessage, 0);
boost::process::spawn(command, boost::process::args(args),
bp::std_out > "output.log", bp::std_err > "error.log",
boost::process::windows::hide);
}

public:
void processPosition(SCStudyInterfaceRef sc, std::string const &pythonPath,
std::string const &onPositionChanged,
double currentPosition)
{
if (m_lastPosition == currentPosition)
return;

m_lastPosition = currentPosition;

if (onPositionChanged == "Unset" || onPositionChanged.empty())
return;

executeProgram(sc, pythonPath,
{onPositionChanged, sc.Symbol.GetChars(),
boost::lexical_cast<std::string>(currentPosition)});
}
};

SCSFExport scsf_ChartEvents(SCStudyInterfaceRef sc)
{
SCInputRef Input_PythonPath = sc.Input[0];
SCInputRef Input_OnPositionChange = sc.Input[1];

try
{
if (sc.SetDefaults)
{
sc.GraphName = "Chart events";
sc.StudyDescription = "Execute programs on chart events";
sc.GraphRegion = 0;
sc.FreeDLL = 1;
sc.AutoLoop = 0;

Input_PythonPath.Name = "Path to Python executable";
Input_PythonPath.SetString("");

Input_OnPositionChange.Name = "onPositionChangeCommand";
Input_OnPositionChange.SetDescription(
"Execute on position change: <your input> <current position>");
Input_OnPositionChange.SetString("");
}
else
{
auto ptr = (ChartEvents *)sc.GetPersistentPointer(1);
if (!ptr)
{
delete ptr;
ptr = new ChartEvents();
sc.SetPersistentPointer(1, ptr);
}

s_SCPositionData position;
sc.GetTradePosition(position);
ptr->processPosition(sc, Input_PythonPath.GetString(),
Input_OnPositionChange.GetString(),
position.PositionQuantity);

if (sc.LastCallToFunction)
{
auto ptr = (ChartEvents *)sc.GetPersistentPointer(1);
delete ptr;
sc.SetPersistentPointer(1, nullptr);
}
}
}
catch (std::exception const &e)
{
sc.AddMessageToLog(e.what(), 1);
}
}

[2023-07-14 09:53:55]
Sierra_Chart Engineering - Posts: 17198
Parameters are passed when running a program when an alert is triggered:
General Settings Window: Run Program When This Alert Triggered (Global Settings >> General Settings >> Alerts >> Alert Settings)
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-07-16 19:47:01]
User166108 - Posts: 73
Ah too late, my plugin works sufficiently for me. Plus, I'm not sure of the format of various messages from your link above, is that listed somewhere? I might end up switching to it later when I need more events.

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

Login

Login Page - Create Account