Support Board
Date/Time: Sun, 24 Nov 2024 06:52:21 +0000
[Programming Help] - Help With Building Custom Study
View Count: 219
[2024-06-19 22:51:41] |
limitlesstrevor - Posts: 3 |
I am trying to build a custom study that will send post data to a python script when a trade I entered or exited on Sierra chart, and I am getting error codes when I try to build it. These are the error codes: C:\SierraChart\ACS_Source\chickwasodpasda.cpp(34): error C3680: cannot concatenate user-defined string literals with mismatched literal suffix identifiers C:\SierraChart\ACS_Source\chickwasodpasda.cpp(34): note: Concatenating suffix 'type' with suffix 'entry' C:\SierraChart\ACS_Source\chickwasodpasda.cpp(34): error C3680: cannot concatenate user-defined string literals with mismatched literal suffix identifiers C:\SierraChart\ACS_Source\chickwasodpasda.cpp(34): note: Concatenating suffix 'type' with suffix 'symbol' C:\SierraChart\ACS_Source\chickwasodpasda.cpp(34): error C3680: cannot concatenate user-defined string literals with mismatched literal suffix identifiers C:\SierraChart\ACS_Source\chickwasodpasda.cpp(34): note: Concatenating suffix 'type' with suffix 'price' C:\SierraChart\ACS_Source\chickwasodpasda.cpp(34): error C3688: invalid literal suffix 'type'; literal operator or literal operator template 'operator ""type' not found C:\SierraChart\ACS_Source\chickwasodpasda.cpp(51): error C3680: cannot concatenate user-defined string literals with mismatched literal suffix identifiers C:\SierraChart\ACS_Source\chickwasodpasda.cpp(51): note: Concatenating suffix 'type' with suffix 'exit' C:\SierraChart\ACS_Source\chickwasodpasda.cpp(51): error C3680: cannot concatenate user-defined string literals with mismatched literal suffix identifiers C:\SierraChart\ACS_Source\chickwasodpasda.cpp(51): note: Concatenating suffix 'type' with suffix 'symbol' C:\SierraChart\ACS_Source\chickwasodpasda.cpp(51): error C3680: cannot concatenate user-defined string literals with mismatched literal suffix identifiers C:\SierraChart\ACS_Source\chickwasodpasda.cpp(51): note: Concatenating suffix 'type' with suffix 'entry_price' C:\SierraChart\ACS_Source\chickwasodpasda.cpp(51): error C3680: cannot concatenate user-defined string literals with mismatched literal suffix identifiers C:\SierraChart\ACS_Source\chickwasodpasda.cpp(51): note: Concatenating suffix 'type' with suffix 'exit_price' C:\SierraChart\ACS_Source\chickwasodpasda.cpp(51): error C3680: cannot concatenate user-defined string literals with mismatched literal suffix identifiers C:\SierraChart\ACS_Source\chickwasodpasda.cpp(51): note: Concatenating suffix 'type' with suffix 'points' C:\SierraChart\ACS_Source\chickwasodpasda.cpp(51): error C3688: invalid literal suffix 'type'; literal operator or literal operator template 'operator ""type' not found This is the code in the file I selected: #include "sierrachart.h" #include "scstructures.h" SCDLLName("HTTP POST Example") // Global variables to track trade entry and exit float tradeEntryPrice = 0.0f; // Use 'f' for float literals bool inTrade = false; // Custom study function SCSFExport scsf_HTTPPOSTExample(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "HTTP POST Example"; sc.AutoLoop = 1; return; } // Define the URL of your Flask application endpoint SCString URL = "http://127.0.0.1:5000/trade"; // Replace with your server's IP and port // Fetch the symbol SCString symbol = sc.GetChartSymbol(sc.ChartNumber); // Get trade position data s_SCPositionData PositionData; if (!sc.GetTradePosition(PositionData)) { // Handle error if unable to get position data sc.AddMessageToLog("Failed to get trade position data", 1); return; } // Check if there is an open position if (PositionData.PositionQuantity != 0 && !inTrade) { tradeEntryPrice = static_cast<float>(PositionData.AveragePrice); // Explicitly cast to float inTrade = true; // Construct the POST data for entry SCString POSTData = "{ "type": "entry", "symbol": "" + symbol + "", "price": "" + std::to_string(tradeEntryPrice) + "" }"; // Headers (if needed) SCString Headers = "Content-Type: application/json"; // Make the HTTP POST request for entry sc.MakeHTTPRequest(POSTData + Headers); // Log the result SCString logMessage = "HTTP POST Entry result: "; sc.AddMessageToLog(logMessage, 0); } // Check if the position is closed if (PositionData.PositionQuantity == 0 && inTrade) { float tradeExitPrice = static_cast<float>(sc.Close[sc.Index]); // Example: Exit using the current close price inTrade = false; // Calculate profit or loss in points float profitLossPoints = tradeExitPrice - tradeEntryPrice; // Construct the POST data for exit SCString POSTData = "{ "type": "exit", "symbol": "" + symbol + "", "entry_price": "" + std::to_string(tradeEntryPrice) + "", "exit_price": "" + std::to_string(tradeExitPrice) + "", "points": "" + std::to_string(profitLossPoints) + "" }"; // Headers (if needed) SCString Headers = "Content-Type: application/json"; // Make the HTTP POST request for exit sc.MakeHTTPRequest(POSTData + Headers); // Log the result SCString logMessage = "HTTP POST Exit result: "; sc.AddMessageToLog(logMessage, 0); } } Would love some help with what I need to change in the code to fix this, thanks! |
[2024-06-19 23:49:29] |
limitlesstrevor - Posts: 3 |
C:\SierraChart\ACS_Source\bruhplease.cpp(12): error C3680: cannot concatenate user-defined string literals with mismatched literal suffix identifiers C:\SierraChart\ACS_Source\bruhplease.cpp(12): note: Concatenating suffix 'type' with suffix 'symbol' C:\SierraChart\ACS_Source\bruhplease.cpp(12): error C3688: invalid literal suffix 'type'; literal operator or literal operator template 'operator ""type' not found C:\SierraChart\ACS_Source\bruhplease.cpp(14): error C3688: invalid literal suffix 'price'; literal operator or literal operator template 'operator ""price' not found C:\SierraChart\ACS_Source\bruhplease.cpp(18): error C3688: invalid literal suffix 'entry_price'; literal operator or literal operator template 'operator ""entry_price' not found C:\SierraChart\ACS_Source\bruhplease.cpp(22): error C3688: invalid literal suffix 'exit_price'; literal operator or literal operator template 'operator ""exit_price' not found Now I just have these errors, with the following code: #include "sierrachart.h" #include "scstructures.h" #include <sstream> #include <string> #include <iomanip> SCDLLName("HTTP POST Example") // Helper function to construct JSON string SCString constructJSON(const std::string& typeStr, const char* symbolStr, float priceVal, float entryPriceVal = 0.0f, float exitPriceVal = 0.0f) { std::stringstream ss; ss << "{ "type": "" << typeStr << "", "symbol": "" << symbolStr << """; if (priceVal != 0.0f) { ss << ", "price": "" << std::fixed << std::setprecision(2) << priceVal << """; } std::string entryPriceString; if (entryPriceVal != 0.0f) { entryPriceString = ", "entry_price": "" + std::to_string(entryPriceVal) + """; } std::string exitPriceString; if (exitPriceVal != 0.0f) { exitPriceString = ", "exit_price": "" + std::to_string(exitPriceVal) + """; } ss << entryPriceString << exitPriceString; ss << " }"; return SCString(ss.str().c_str()); // Convert std::string to SCString } // Global variables to track trade entry and exit float tradeEntryPrice = 0.0f; // Use 'f' for float literals bool inTrade = false; // Custom study function SCSFExport scsf_HTTPPOSTExample(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "HTTP POST Example"; sc.AutoLoop = 1; return; } // Define the URL of your Flask application endpoint SCString URL = "http://127.0.0.1:5000/trade"; // Replace with your server's IP and port // Fetch the symbol SCString symbol = sc.GetChartSymbol(sc.ChartNumber); // Get trade position data s_SCPositionData PositionData; if (!sc.GetTradePosition(PositionData)) { // Handle error if unable to get position data sc.AddMessageToLog("Failed to get trade position data", 1); return; } // Check if there is an open position if (PositionData.PositionQuantity != 0 && !inTrade) { tradeEntryPrice = static_cast<float>(PositionData.AveragePrice); // Explicitly cast to float inTrade = true; // Construct the POST data for entry SCString POSTData = constructJSON("entry", symbol.GetChars(), tradeEntryPrice); // Headers (if needed) SCString Headers = "Content-Type: application/json"; // Make the HTTP POST request for entry sc.MakeHTTPRequest(POSTData + Headers); // Log the result SCString logMessage = "HTTP POST Entry result: "; sc.AddMessageToLog(logMessage, 0); } // Check if the position is closed if (PositionData.PositionQuantity == 0 && inTrade) { float tradeExitPrice = static_cast<float>(sc.Close[sc.Index]); // Example: Exit using the current close price inTrade = false; // Calculate profit or loss in points float profitLossPoints = tradeExitPrice - tradeEntryPrice; // Construct the POST data for exit SCString POSTData = constructJSON("exit", symbol.GetChars(), tradeEntryPrice, tradeExitPrice, profitLossPoints); // Headers (if needed) SCString Headers = "Content-Type: application/json"; // Make the HTTP POST request for exit sc.MakeHTTPRequest(POSTData + Headers); // Log the result SCString logMessage = "HTTP POST Exit result: "; sc.AddMessageToLog(logMessage, 0); } } |
To post a message in this thread, you need to log in with your Sierra Chart account: