Sierra Chart - Programming ACSIL Custom Studies C++

Поделиться
HTML-код
  • Опубликовано: 21 окт 2024

Комментарии • 1

  • @Optimistic-Trading
    @Optimistic-Trading  Месяц назад +2

    UPDATED (9/5/24) CODE BELOW FOR COPY / PASTE...
    #include "sierrachart.h"
    SCDLLName("Limit 3x Trades Per 90 Seconds");
    SCSFExport scsf_LimitNumberOfTrades(SCStudyInterfaceRef sc) {
    // Declare static variables at the start of the function
    static SCDateTime LastResetTime = SCDateTime(0); // Initialize LastResetTime
    static int TradeCount = 0; // Persistent trade count across function calls
    static SCDateTime LastTradeTime = SCDateTime(0); // Track the time of the last trade
    // 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 if 60 seconds have passed since the last reset
    if ((CurrentTime - LastResetTime) >= SCDateTime::SECONDS(90)) {
    TradeCount = 0; // Reset TradeCount
    LastResetTime = CurrentTime; // Update LastResetTime
    }
    // Initialize position data
    s_SCPositionData PositionData;
    sc.GetTradePosition(PositionData);
    // Check if there has been a new fill since the last recorded time
    if (PositionData.LastFillDateTime > LastTradeTime) {
    TradeCount++; // Increment TradeCount
    LastTradeTime = PositionData.LastFillDateTime; // Update LastTradeTime
    }
    // Prevent new trades if the limit of 30 trades is exceeded
    if (TradeCount >= 4) {
    sc.SetTradingLockState(1); // Lock trading
    sc.AddMessageToLog("Trading locked due to exceeding trade limit.", 1);
    } else {
    sc.SetTradingLockState(0); // Unlock trading
    sc.AddMessageToLog("Trading unlocked, under trade limit.", 0);
    }
    }