Login Page - Create Account

Support Board


Date/Time: Wed, 05 Mar 2025 04:13:37 +0000



Post From: create a custom C++ class that manages trade/logic

[2022-01-09 02:57:07]
User133994 - Posts: 80
Can I do this now:

struct some_struct
{
some_struct() = default;
some_struct(SCStudyInterfaceRef sc)
void some_func(const SCDateTimeMS& when);
void record_ID(int a){ Target2OrderIDstop = a;};
void example_using_sc_inside(){sc.SupportTradingScaleIn = true;};
private:
std::unordered_map<SCDateTimeMS, s_SCTradeOrder> something;
int Target2OrderIDstop;

}

const std::int32_t some_struct_pkey = 1;

SCSFExport scsf_some_study(SCStudyInterfaceRef sc)
{

some_struct* ss = reinterpret_cast<some_struct*>(sc.GetPersistentPointer(some_struct_pkey));

if (ss == nullptr)
sc.SetPersistentPointer(some_struct_pkey, new some_struct(sc));

if (sc.SetDefaults)
{

// Do something...

}
//sent order in...
// now record attached order id
ss->record_ID(12356173);
ss->example_using_sc_inside();
// Do something...
if(sc.LastCallToFunction)

delete ss;
}

So, is the syntax for my record_ID function correct? Can I safely assume that the value of Target2OrderIDstop persists across calls to the study? Therefore, it appears I don't need to use sc.GetPersistentInt(11) anymore--since the class (struct) is persistent, right?


What about the example_using_sc_inside() function--just trying to use the "sc" object that was passed via the constructor--is that correct? Or do I need to add a member to the struct that gets assigned the sc, object? (please reply with example code if possible)

Again, many thanks!