Login Page - Create Account

Support Board


Date/Time: Tue, 26 Aug 2025 05:23:03 +0000



Post From: Custom Study Compiles and Loads, but Function Never Executes (No Logging or Orders)

[2025-08-05 08:37:56]
User431178 - Posts: 763

#include "sierrachart.h"
SCDLLName("Log Test")

SCSFExport scsf_DebugAutoTrade(SCStudyInterfaceRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "DEBUG: AutoTrade Trigger";
    sc.StudyDescription = "Minimal example to test auto trading and logging.";
    sc.AutoLoop = 1;
    sc.GraphRegion = 0;
    sc.UpdateAlways = 1;
    return;
  }

  if (sc.Index == 0)
  {
    sc.AddMessageToLog("Study initialized.", 0);
  }

  // Just to confirm this is firing every bar
  sc.AddMessageToLog("Tick update", 0);

  // Dummy trade entry once at index 100
  if (sc.Index == 100)
  {
    s_SCNewOrder order;
    order.OrderType = SCT_ORDERTYPE_MARKET;
    order.OrderQuantity = 1;
    order.TextTag = "Test Entry";

    sc.BuyEntry(order);
    sc.AddMessageToLog("Sent BuyEntry at index 100", 0);
  }
}

Try using the remote compiler with this code, it compiles and does what it is meant to.

Unless you use Trade Menu: AutoTrade System Replay Backtest (Trade menu) it is unlikely that the replay will include bar index 5, and trades are not executed during recalculation, so I changed "if (sc.Index == 5)" to "if (sc.Index == 100)". Try it and check the outcome (you can add the Bar Numbering study to check that your replay includes the specified bar).


SendOrdersToTradeService is set to Yes

You mean it's set to no (correct for sim), the deafult value, as you are not explicitly setting it here.


Do yourself a favor and look at the various study and trading system examples in the ACS_Source folder of your SC installation.
You will probably find that you save some time and headaches by using/modifying the examples, compared to relying on LLM for coding.