Login Page - Create Account

Support Board


Date/Time: Tue, 06 May 2025 00:34:45 +0000



[Programming Help] - ACSIL indicator to retrieve

View Count: 273

[2025-01-16 13:32:34]
User299099 - Posts: 10
I am working on an ACSIL indicator to retrieve "AvailableFunds" and "CashBalance" and display them on the screen to calculate the real profit or loss using data from an external trading service. I have searched the documentation but haven't found how to do it. Could you please let me know how I can access those data using ACSIL?

Thank you!
[2025-01-16 16:38:53]
cmet - Posts: 690
Are you talking about an external service that is outside of your accounts linked within SC?
[2025-01-16 17:26:53]
User628480 - Posts: 114
Use sc.GetTradeAccountData()

ACSIL Interface Members - Functions: sc.GetTradeAccountData()

Example:

n_ACSIL::s_TradeAccountDataFields TradeAccountDataFields;
if (sc.GetTradeAccountData(TradeAccountDataFields, sc.SelectedTradeAccount))
{
double AccountValue = TradeAccountDataFields.m_AccountValue;
double AvailableFunds = TradeAccountDataFields.m_AvailableFundsForNewPositions
double CashBalance = TradeAccountDataFields.m_CurrentCashBalance;
}

Available data to retrieve:


struct s_TradeAccountDataFields
{
  SCString m_TradeAccount;
  uint8_t m_IsSimulated = 0;
  SCString m_CurrencyCode;
  double m_CurrentCashBalance = 0;
  uint64_t m_TransactionIdentifierForCashBalanceAdjustment = 0;
  double m_AvailableFundsForNewPositions = 0;
  double m_MarginRequirement = 0;
  double m_MarginRequirementFull = 0;
  double m_MarginRequirementFullPositionsOnly = 0;
  double m_PeakMarginRequirement = 0;
  double m_AccountValue = 0;
  double m_OpenPositionsProfitLoss = 0;
  double m_DailyProfitLoss = 0;
  double m_CalculatedDailyNetLossLimitInAccountCurrency = 0;
  double m_TrailingAccountValueAtWhichToNotAllowNewPositions = 0;
  uint8_t m_DailyNetLossLimitHasBeenReached = 0;
  uint8_t m_IsUnderRequiredMargin = 0;
  uint8_t m_IsUnderRequiredAccountValue = 0;
  uint8_t m_TradingIsDisabled = 0;
  uint8_t m_ClosePositionsAtEndOfDay = 0;
  SCString m_Description;
};

[2025-01-16 18:37:37]
User299099 - Posts: 10
Are you talking about an external service that is outside of your accounts linked within SC?

I mean that, for example, if I am connected to Rithmic, the values are not accurate when using Sierra's indicator calculations. To know exactly how much I am losing or gaining, it is necessary to query this information through the trading service. Sierra provides this data through the account balance. My idea is to develop an indicator that notifies real-time total account profits and losses, with the purpose of alerting and automatically closing trades upon reaching the predefined level.
[2025-01-16 21:03:07]
cmet - Posts: 690
Well, if the data is provided through account balance, here's the part that shows the balance and available funds without the automatic trade management.

This will just grab the data and print text on main chart pane.

#include "sierrachart.h"

SCDLLName("Funds & Cash Balance");

SCSFExport scsf_AvailableFundsCashBalance(SCStudyInterfaceRef sc)
{
SCSubgraphRef Subgraph_TextDisplay = sc.Subgraph[0];
SCInputRef Input_FontSize = sc.Input[0];
SCInputRef Input_FontColor = sc.Input[1];

if (sc.SetDefaults)
{
sc.GraphName = "Funds & Cash Balance";
sc.StudyDescription = "Display Available Funds and Cash Balance";
sc.GraphRegion = 0;
sc.AutoLoop = 0;
sc.UpdateAlways = 1;

Subgraph_TextDisplay.Name = "Text Display";
Subgraph_TextDisplay.DrawStyle = DRAWSTYLE_CUSTOM_TEXT;
Subgraph_TextDisplay.PrimaryColor = RGB(255, 255, 255);
Subgraph_TextDisplay.LineWidth = 10;
Subgraph_TextDisplay.DrawZeros = false;

Input_FontSize.Name = "Font Size";
Input_FontSize.SetInt(10);
Input_FontSize.SetIntLimits(8, 50);

Input_FontColor.Name = "Font Color";
Input_FontColor.SetColor(RGB(255, 255, 255));

return;
}

if (sc.LastCallToFunction)
{
sc.DeleteUserDrawnACSDrawing(sc.ChartNumber, 1001);
return;
}

int FontSize = Input_FontSize.GetInt();
COLORREF FontColor = Input_FontColor.GetColor();

n_ACSIL::s_TradeAccountDataFields TradeAccountData;
if (sc.GetTradeAccountData(TradeAccountData, sc.SelectedTradeAccount))
{
float AvailableFunds = static_cast<float>(TradeAccountData.m_AvailableFundsForNewPositions);
float CashBalance = static_cast<float>(TradeAccountData.m_CurrentCashBalance);
float ProfitOrLoss = CashBalance - AvailableFunds;

SCString DisplayText;
DisplayText.Format("Available Funds: %.2f Cash Balance: %.2f P/L: %.2f", AvailableFunds, CashBalance, ProfitOrLoss);

s_UseTool TextTool;
TextTool.Clear();
TextTool.ChartNumber = sc.ChartNumber;
TextTool.DrawingType = DRAWING_TEXT;
TextTool.Region = sc.GraphRegion;
TextTool.FontSize = FontSize;
TextTool.FontBold = true;
TextTool.Color = FontColor;
TextTool.Text = DisplayText;

TextTool.AddAsUserDrawnDrawing = 1;
TextTool.AllowSaveToChartbook = 1;
TextTool.LineNumber = 1001;

TextTool.BeginDateTime = 10;
TextTool.BeginValue = 90;
TextTool.UseRelativeVerticalValues = true;

sc.UseTool(TextTool);
}
}

Date Time Of Last Edit: 2025-01-16 23:48:53

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account