How do you get account info?

Questions about MultiCharts .NET and user contributed studies.
Talky_Zebra
Posts: 45
Joined: 07 Mar 2024
Has thanked: 13 times
Been thanked: 1 time

How do you get account info?

Postby Talky_Zebra » 13 Mar 2024

I would like to access Account details. I have tried making a simple indicator and attaching it to a chart connected and getting data from my broker.

See the attached code sample and the attached image. I have tried numerous fields: Name, ID, Equity, etc. Nothing is returned.

I have also tried TradeProfiles but cannot seem to get the syntax correct. I have tried a few variations based on snippets here on the forum but have not gotten it to work.

Direction on how to get Account equity, balance, name, etc very much appreciated.

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.TradeManager; using PowerLanguage.Function; namespace PowerLanguage.Indicator{ public class test4 : IndicatorObject { public test4(object _ctx):base(_ctx){} private Account account; protected override void Create() { } protected override void StartCalc() { Output.Clear(); } protected override void CalcBar(){ Output.WriteLine("Account info: {0}", account.Equity); } }
Attachments
AccountInfo.JPG
(123.46 KiB) Not downloaded yet

Talky_Zebra
Posts: 45
Joined: 07 Mar 2024
Has thanked: 13 times
Been thanked: 1 time

Re: How do you get account info?

Postby Talky_Zebra » 13 Mar 2024

After wrestling with this a bit more, I was able to get the name of the Account and the other TradeProfiles info. But, I need the Balance and the Equity. How do I get this?

FYI, it is an Demo account with OANDA, if that matters.

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.TradeManager; using PowerLanguage.Function; namespace PowerLanguage.Indicator{ public class test4 : IndicatorObject { public test4(object _ctx):base(_ctx){} private ITradingProfile tp; protected override void Create() { } protected override void StartCalc() { Output.Clear(); } protected override void CalcBar(){ tp = TradeManager.TradingProfiles[1]; string name = tp.Name; string acc = tp.Accounts[0]; Output.WriteLine("Account info: {0}, {1}", name, acc); } } }

Talky_Zebra
Posts: 45
Joined: 07 Mar 2024
Has thanked: 13 times
Been thanked: 1 time

Re: How do you get account info?

Postby Talky_Zebra » 14 Mar 2024

Ah HA! I finally cracked this. I really wish the docs were a bit more clear with more examples.

But finally I was able to extract Balance and Equity from account information. Here is a first cut at it. I am sure I can smooth it out somewhat, but it may be helpful for others.

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.TradeManager; using PowerLanguage.Function; namespace PowerLanguage.Indicator{ public class test4 : IndicatorObject { public test4(object _ctx):base(_ctx){} private ITradingProfile tp; private ITradingData td; string tp_account; int tp_profiles_count; Account account; int bars; string trading_account_name; protected override void Create() { } protected override void StartCalc() { bars = Bars.FullSymbolData.Count; tp_account = ""; tp_profiles_count = -1; trading_account_name = "DEMO Account"; Output.WriteLine("account items: ", TradeManager.TradingData.Accounts.Items.Count().ToString()); Output.Clear(); } protected override void CalcBar(){ if(bars == Bars.FullSymbolData.Count) return; if(tp_profiles_count == -1){ tp_profiles_count = TradeManager.TradingProfiles.Count(); for(int i = 1; i < tp_profiles_count; i++){ if(TradeManager.TradingProfiles[i].Accounts[0] == trading_account_name) { tp = TradeManager.TradingProfiles[i]; tp_account = TradeManager.TradingProfiles[i].Accounts[0]; Output.WriteLine("i: {0}, account name: {1}", i.ToString(), tp_account); break; } } td = TradeManager.TradingData; Account account = td.Accounts.Items[0]; if(tp_account == account.Name) { Output.WriteLine("Accounts ID: {0}, Name: {1}, Balance: {2}, Equity: {3}, OpenPL: {4}, Available to trade: {5}", account.ID, account.Name, account.Balance.ToString(), account.Equity.ToString(), account.OpenPL.ToString(), account.AvailableToTrade.ToString() ); } } bars = Bars.FullSymbolData.Count; } } }


Return to “MultiCharts .NET”