### Get Order Fill Price and Status Source: https://www.sierrachart.com/index.php?page=doc%2FACSILTrading.html This example demonstrates how to submit a market order, store its internal ID, and later retrieve its fill price and status after it has been processed. It shows how to use sc.BuyEntry, persist order IDs, and query order details using sc.GetOrderByOrderID. ```cpp // Enter a new order as a Buy Entry order. s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 1; NewOrder.OrderType = SCT_MARKET; int ReturnValue; ReturnValue = sc.BuyEntry(NewOrder); // Remember the internal order id if we have one into a Persistent variable int &OrderID = sc.PersistVars->Integers[0]; if (ReturnValue > 0 && NewOrder.InternalOrderID != 0) { OrderID = NewOrder.InternalOrderID; } // Once the order fills, after submitting the order, we can // determine the actual fill price with the following code. Keep in // mind that we may not obtain the fill price at this moment, but // on a subsequent call into the study function. // Get the available order data for the submitted order by using // the InternalOrderID that was assigned after calling the Order // Action function sc.BuyEntry. if (OrderID != 0) { s_SCTradeOrder TradeOrderData; int Result = sc.GetOrderByOrderID(NewOrder.InternalOrderID, TradeOrderData); if (Result != SCTRADING_ORDER_ERROR) { double FillPrice = TradeOrderData.AvgFillPrice; } int OrderStatusCode = TradeOrderData.OrderStatusCode; if (OrderStatusCode == SCT_OSC_FILLED) { // The order has completely filled } } ``` -------------------------------- ### Relational and Equality Operator Examples Source: https://www.sierrachart.com/index.php?page=doc%2Fcpp_Operators.php Provides examples of relational and equality operators evaluating to true or false. ```cpp (7 == 5) // evaluates to false. (5 > 4) // evaluates to true. (3 != 2) // evaluates to true. (6 >= 6) // evaluates to true. (5 < 5) // evaluates to false. ``` -------------------------------- ### Get Study Persistent Variable from Chart Example Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Functions.html This example demonstrates how to get a persistent float variable from a specified chart and study using GetPersistentFloatFromChartStudy. Ensure the ChartStudyReference input is correctly configured to point to the target chart and study. ```cpp SCSFExport scsf_GetStudyPersistentVariableFromChartExample(SCStudyInterfaceRef sc) { SCInputRef ChartStudyReference = sc.Input[0]; if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "Get Study Persistent Variable from Chart Example"; sc.AutoLoop = 1; ChartStudyReference.Name = "Chart Study Reference"; ChartStudyReference.SetChartStudyValues(1, 0); return; } //Get a reference to a persistent variable with key value 100 in the chart and study specified by the ChartStudyReference Input. float& FloatFromChartStudy = sc.GetPersistentFloatFromChartStudy(ChartStudyReference.GetChartNumber(), ChartStudyReference.GetStudyID(), 100); } ``` -------------------------------- ### C-like Initialization Example Source: https://www.sierrachart.com/index.php?page=doc%2Fcpp_VariablesDataTypes.php Shows how to declare an integer variable 'a' and initialize it to 0. ```cpp int a = 0; ``` -------------------------------- ### C-like Initialization Syntax Source: https://www.sierrachart.com/index.php?page=doc%2Fcpp_VariablesDataTypes.php Demonstrates the syntax for initializing a variable using the c-like method with an equal sign. ```cpp type identifier = initial_value; ``` -------------------------------- ### Get Calculation Start Index for Study Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Functions.html Retrieves the starting index for study calculations when there's a dependency on a study with an earlier start index. This function is for specialized purposes and requires Manual Looping. ```cpp int CalculationStartIndex = sc.GetCalculationStartIndexForStudy(); for (int Index = CalculationStartIndex; Index < sc.ArraySize; Index++) { float BasedOnStudySubgraphValue = sc.BaseData[InputData.GetInputDataIndex()][Index]; if (AddToZeroValuesInBasedOnStudy.GetYesNo() == 0 && BasedOnStudySubgraphValue == 0.0) { Result[Index] = 0.0; } else Result[Index] = BasedOnStudySubgraphValue + AmountToAdd.GetFloat(); } sc.EarliestUpdateSubgraphDataArrayIndex = CalculationStartIndex; ``` -------------------------------- ### Get Start Date-Time for Trading Date Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Functions.html Converts a trading date into a SCDateTime object representing the start of the trading session. Handles sessions spanning midnight. ```cpp SCDateTime TradingDate; SCDateTime SessionStartDateTime = sc.GetStartDateTimeForTradingDate(TradingDate);              ``` -------------------------------- ### Constructor Initialization Example Source: https://www.sierrachart.com/index.php?page=doc%2Fcpp_VariablesDataTypes.php Demonstrates declaring an integer variable 'a' and initializing it to 0 using constructor initialization. ```cpp int a (0); ``` -------------------------------- ### Get Session Start Time Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Functions.html Retrieves the start time of the trading day for intraday charts based on session settings. Considers evening session settings if enabled. ```cpp int StartTime = sc.SessionStartTime(); ``` -------------------------------- ### Constructor Initialization Syntax Source: https://www.sierrachart.com/index.php?page=doc%2Fcpp_VariablesDataTypes.php Illustrates the syntax for initializing a variable using the constructor method with parentheses. ```cpp type identifier (initial_value); ``` -------------------------------- ### String Declaration and Initialization Source: https://www.sierrachart.com/index.php?page=doc%2Fcpp_VariablesDataTypes.php Shows how to include the string header, declare a string variable, initialize it with a literal, and print it to the console. ```cpp // my first string #include #include using namespace std; int main () { string mystring = "This is a string"; cout << mystring; return 0; } /* Output This is a string */ ``` -------------------------------- ### Get Persistent Integer Reference Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Functions.html This example shows how to get a reference to a persistent integer variable using its key. This reference can then be used to set or retrieve the variable's value. ```cpp int& Variable = sc.GetPersistentInt(1); ``` -------------------------------- ### Create New Stop Order Example Source: https://www.sierrachart.com/index.php?page=doc%2FACSILTrading.html This example shows how to create and submit a new stop order using the s_SCNewOrder structure. Ensure OrderQuantity is set to a non-zero positive number for buy/sell entries/orders. ```cpp float BarLow = sc.Low[sc.Index]; s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 1; NewOrder.OrderType = SCT_ORDERTYPE_STOP; NewOrder.TimeInForce = SCT_TIF_DAY; NewOrder.Price1 = BarLow; ``` -------------------------------- ### Get Start of Trading Day Index Source: https://www.sierrachart.com/index.php?page=doc/ACSILProgrammingConcepts.html Retrieve the bar index corresponding to the start of the trading day in an intraday chart. This relies on session times and assumes automatic looping. ```ACSIL //Get index of start of trading day based upon Date-Time at current index. This code assumes automatic looping. SCDateTime StartDateTime = sc.GetTradingDayStartDateTimeOfBar(sc.BaseDateTimeIn[sc.Index]); int StartBarIndex = sc.GetContainingIndexForSCDateTime(sc.ChartNumber, StartDateTime); ``` -------------------------------- ### Get Trading Day Start DateTime of Bar Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Functions.html Calculates the starting Date-Time of the trading day for a given bar's SCDateTime. This is based on the Intraday Session Times settings of the chart. It also shows how to calculate the end of the trading day. ```cpp SCDateTime CurrentBarTradingDayStartDateTime = GetTradingDayStartDateTimeOfBar(BaseDateTimeIn[BarIndex]); SCDateTime CurrentBarTradingDayEndDateTime = CurrentBarTradingDayStartDateTime + 24 * HOURS - 1 * MILLISECONDS; ``` -------------------------------- ### Using sc.StorageBlock for Persistent Data Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Variables_And_Arrays.html Demonstrates how to use sc.StorageBlock for custom data storage, including defining a structure and accessing its members. ```cpp // This is the structure of our data that is to be // stored in the storage block struct s_PermData { int Number; char Text[32]; }; // Here we make a pointer to the storage block as if // it was a pointer to our structure s_PermData* PermData; PermData = (s_PermData*)sc.StorageBlock; // Here we set data using the members of our structure // This uses the memory of the storage block PermData->Number = 10; strcpy(PermData->Text, "Sample Text"); ``` -------------------------------- ### sc.SessionStartTime() Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Functions.html Gets the start time of the trading day for Intraday charts, based on the Session Times configuration. It accounts for the 'Use Evening Session' setting. ```APIDOC ## sc.SessionStartTime() ### Description Gets the start of the trading day in Intraday charts, which is determined by the Session Times set in Chart Settings. If 'Use Evening Session' is enabled, it returns the evening session start time; otherwise, it returns the regular session start time. ### Function Signature int SessionStartTime(); ### Parameters This function has no parameters. ### Return Value An integer representing the start time of the trading session. This is a Time Value. ``` -------------------------------- ### Dynamic Class Allocation Example (C++) Source: https://www.sierrachart.com/index.php?page=doc/ACSILProgrammingConcepts.html Shows how to allocate and free a class instance using C++ new and delete operators for persistent storage. Remember to free memory before DLL unload to prevent exceptions. ```cpp if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "Dynamic Memory Allocation Example (new/delete)"; sc.AutoLoop = 1; return; } //Example class class ClassA { public: int IntegerVariable; }; // Do data processing ClassA * p_ClassA = (ClassA *)sc.GetPersistentPointer(1); if(sc.LastCallToFunction) { if(p_ClassA != NULL) { delete p_ClassA; sc.SetPersistentPointer(1, NULL); } return; } if(p_ClassA == NULL) { //Allocate one instance of the class p_ClassA = (ClassA *) new ClassA; if(p_ClassA != NULL) sc.SetPersistentPointer(1, p_ClassA); else return; } int IntegerVariable = p_ClassA->IntegerVariable; return; ``` -------------------------------- ### Initialize and Use s_UseTool Structure Source: https://www.sierrachart.com/index.php?page=doc%2FACSILDrawingTools.html Demonstrates the correct way to initialize the s_UseTool structure using Clear() before setting its members and calling sc.UseTool(). This is crucial when reusing the same structure instance for multiple calls. ```cpp s_UseTool UseTool; UseTool.Clear(); // Set relevant members of UseTool here... sc.UseTool(UseTool); ``` -------------------------------- ### Get Study Data Start Index Using ID Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Functions.html Retrieves the sc.DataStartIndex from another study on the same chart using its unique ID. This is for specialized purposes. ```cpp SCInputRef StudyReference = sc.Input[0]; sc.DataStartIndex = sc.GetStudyDataStartIndexUsingID(StudyReference.GetStudyID()); ``` -------------------------------- ### Get Trade List Entry Example Source: https://www.sierrachart.com/index.php?page=doc%2FACSILTrading.html Iterates through all trades in a chart's trade list and stores them in a vector. It then accesses the ClosedProfitLoss member for each trade. ```cpp std::vector TradesList; s_ACSTrade TradeEntry; int Size = sc.GetTradeListSize(); for(int Index = 0; Index < Size; Index++) { if(sc.GetTradeListEntry(Index, TradeEntry)) TradesList.push_back(TradeEntry); } for (unsigned int TradeIndex = 0; TradeIndex < TradesList.size(); TradeIndex++) { double ProfitLoss = TradesList[TradeIndex].ClosedProfitLoss; } ``` -------------------------------- ### Basic Function Definition and Call Source: https://www.sierrachart.com/index.php?page=doc%2Fcpp_Functions.php Demonstrates how to define a simple function that performs addition and how to call it from the main function. Shows how arguments are passed and a value is returned. ```cpp // function example #include using namespace std; int addition (int a, int b) { int r; r=a+b; return (r); } int main () { int z; z = addition (5,3); cout << "The result is " << z; return 0; } /* Output The result is 8 */ ``` -------------------------------- ### Check Sierra Chart Version Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Variables_And_Arrays.html Use the sc.VersionNumber function to get the current Sierra Chart version as a string. This example checks if the version is less than 2100. ```cpp if (atoi(sc.VersionNumber().GetChars()) < 2100) { //do something } ``` -------------------------------- ### Get Chart Name Example Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Functions.html Retrieves the name of a specified chart. The name includes the symbol, timeframe, and chart number. Access is limited to charts within the same Chartbook. ```cpp SCString Chart1Name = sc.GetChartName(sc.ChartNumber); ``` -------------------------------- ### Variable Initialization and Operations Source: https://www.sierrachart.com/index.php?page=doc%2Fcpp_VariablesDataTypes.php A complete C++ program demonstrating both c-like and constructor initialization for integers, performing basic arithmetic operations, and printing the result. ```cpp // initialization of variables #include using namespace std; int main () { int a=5; // initial value = 5 int b(2); // initial value = 2 int result; // initial value undetermined a = a + 3; result = a - b; cout << result; return 0; } /* Output 6 */ ``` -------------------------------- ### Get Persistent Integer Fast Example Source: https://www.sierrachart.com/index.php?page=doc%2FACSIL_Members_Functions.html Demonstrates how to retrieve and assign values to persistent integer variables using sc.GetPersistentIntFast. The Index parameter is used as a key, ranging from 0 to 9999. ```cpp int& r_IntValue = sc.GetPersistentIntFast(0); r_IntValue = sc.Index; int& r_MenuID = sc.GetPersistentIntFast(1); ```