Support Board
Date/Time: Sun, 24 Nov 2024 08:58:19 +0000
Post From: Help With Building Custom Study
[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); } } |