Login Page - Create Account

Support Board


Date/Time: Sun, 11 May 2025 05:31:19 +0000



Post From: Custom Study Help - s_SCOrderFillData OrderFillData.Quantity

[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