Support Board
Date/Time: Sun, 11 May 2025 01:30:41 +0000
[Programming Help] - Custom Study Help - s_SCOrderFillData OrderFillData.Quantity
View Count: 317
[2024-09-04 19:33:29] |
MmmDeion - Posts: 4 |
I'll keep this as quick and efficient as possible. I'm looking to create a custom study to limit my trading (contract count 1, including entries/exits/flattens) to less than 3 trades every 120 seconds. However, I'm having a heck of a time trying to get the OrderFillData.Quantity to return the proper count. It seems to limit me to only 1x trade every 120 seconds. I know I'm not pulling the order quantity count correctly, but can't seem to figure out where I'm going wrong. Any help is sincerely appreciated!! My current CPP code is the following: #include "sierrachart.h"
SCDLLName("Revised 308pm"); // Function to limit the number of trades SCSFExport scsf_LimitNumberOfTrades(SCStudyInterfaceRef sc) { // Static variables to retain values across function calls static int TradeCount = 0; static SCDateTime LastResetTime = sc.CurrentSystemDateTime; // Default settings for the study if (sc.SetDefaults) { sc.GraphName = "Limit Number of Trades"; sc.AutoLoop = 1; // Enable auto-looping return; } // Get the current system time SCDateTime CurrentTime = sc.CurrentSystemDateTime; // Reset the trade count at the start of a new time period (e.g., hourly) if ((CurrentTime - LastResetTime) >= SCDateTime::SECONDS(120)) { TradeCount = 0; LastResetTime = CurrentTime; } // Get order fills s_SCOrderFillData OrderFillData; int NumOrderFills = OrderFillData.Quantity; for (int i = 0; i < NumOrderFills; i++) { sc.GetOrderFillEntry(i, OrderFillData); if (OrderFillData.FillDateTime > LastResetTime) { TradeCount++; } } // Prevent new trades if the limit is exceeded if (TradeCount >= 3) { sc.SetTradingLockState(1); // Lock trading } else { sc.SetTradingLockState(0); // Unlock trading } } Date Time Of Last Edit: 2024-09-04 19:33:52
|
[2024-09-04 20:02:44] |
User948037 - Posts: 15 |
Why not just use the position data? s_SCPositionData PositionData;
sc.GetTradePosition(PositionData); int PositionQuantity = PositionData.PositionQuantity; |
[2024-09-05 12:56:00] |
MmmDeion - Posts: 4 |
That was exactly what I was looking for. Thank you very much!
|
To post a message in this thread, you need to log in with your Sierra Chart account: