NexusFi: Find Your Edge


Home Menu

 





GetAccountValue in an Indicator


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Mindset with 4 posts (0 thanks)
    2. looks_two MXASJ with 2 posts (1 thanks)
    3. looks_3 steve2222 with 2 posts (0 thanks)
    4. looks_4 TimeTrade with 2 posts (1 thanks)
    1. trending_up 10,328 views
    2. thumb_up 3 thanks given
    3. group 7 followers
    1. forum 14 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
Mindset's Avatar
 Mindset 
Singapore
 
Experience: Intermediate
Platform: NT
Broker: ib
Trading: MES
Posts: 365 since Sep 2009
Thanks Given: 90
Thanks Received: 292

Can anyone provide a code snippet to get the value of a specified account in an Indicator.
It's a doddle in a strategy but I require it in an indicator and can't seem to get it


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Thanks Mike. Godspeed.
The Elite Circle
Penalties in Budapest, Peace Deadline in Tehran: Arsenal …
Prediction Markets & Event Contracts
Saylors 41-Month HODL Breaks: Strategy Sells 32 BTC as $ …
Prediction Markets & Event Contracts
Peace Deal Forward Curve: May 22%, June 51%, December 81 …
Prediction Markets & Event Contracts
CME Raises Energy Futures Margins After Iran-War Volatil …
Commodities
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
10 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #3 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 649 since Aug 2009
Thanks Given: 320
Thanks Received: 623


Have you tried adding following declaration to your indicator code:

using NinjaTrader.Cbi;
using NinjaTrader.Strategy;


Reply With Quote
  #4 (permalink)
 
Mindset's Avatar
 Mindset 
Singapore
 
Experience: Intermediate
Platform: NT
Broker: ib
Trading: MES
Posts: 365 since Sep 2009
Thanks Given: 90
Thanks Received: 292

Thanks Gregid - tried that - makes no difference seemingly.


Started this thread Reply With Quote
  #5 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


Mindset View Post
Can anyone provide a code snippet to get the value of a specified account in an Indicator.
It's a doddle in a strategy but I require it in an indicator and can't seem to get it

I recall that question on the NT Forums being answered by support staff as 'the info wasnt available to indicators' ... I made a request that it should ... I have yet to see any of my requests showup in NT

Jon


Writing to you from the wonderful province of Ontario, Canada. Home to the world's biggest natural negative ion generator, the Niagara Falls, and to those that dare to know how to go over it in a barrel. SALUTE!
Reply With Quote
  #6 (permalink)
 
Mindset's Avatar
 Mindset 
Singapore
 
Experience: Intermediate
Platform: NT
Broker: ib
Trading: MES
Posts: 365 since Sep 2009
Thanks Given: 90
Thanks Received: 292

Displaying account equity and margin in Market Analyzer - NinjaTrader Support Forum

They must have an awfully long list of stuff to add to NT - it's rare to get anything actually done about these requests.
Just think a trading platform where you can't get access to your account balances in an indicator.....must have taken some designing that.


Started this thread Reply With Quote
  #7 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 801

Don't know if it helps but I run a custom method in a risk management strat that looks at global PnL (and a bunch of other things). Here is the method code. The variables should be pretty easy to figure out. If not I can point you to the full strat over in the Elite section.

 
Code
                            
#region AccountMonitor()
private void AccountMonitor()
// Custom method to monitor the cash account balance. This should be considered as a LAST line of defense and not a suggested way to monitor session P&L.
// Note this is tied to the 5 min bar series.
{//Open AccountMonitor()
 
buyingpower GetAccountValue(AccountItem.BuyingPower);
realPnL GetAccountValue(AccountItem.RealizedProfitLoss);
cashValue GetAccountValue(AccountItem.CashValue);
 
switch(
acctType)
{
case(
AccountType.CashValue):
{
currentAccountValue GetAccountValue(AccountItem.CashValue);
break;
}
case(
AccountType.BuyingPower):
{
currentAccountValue GetAccountValue(AccountItem.BuyingPower);
break;
}
}
if (
BarsInProgress == && FirstTickOfBar && printCurrentAccountValue)
{
Print(
DateTime.Now " " Account.Name " Current Account Value: $" Math.Round(currentAccountValue2));
 
/*
//You can use this code block to see what type of account information your provider supports
Print(Account.Name + " Buying Power: $" + buyingpower);
Print(Account.Name + " Realized P&L: $" + realPnL);
Print(Account.Name + " Cash Value: $" + cashValue);
*/
}
 
if (
BarsInProgress == && applyAccountMonitor && currentAccountValue == 0)
{
Print(
DateTime.Now " ERROR: AccountMonitor() returns 0 for CurrentAccountValue");
if (
alertsWindowAlert("accountzero"NinjaTrader.Cbi.Priority.Medium"CurrentAccountValue = 0""Alert1"10Color.YellowColor.White);
}
 
if (
BarsInProgress == && applyAccountMonitor && FirstTickOfBar)
{
 
if (
currentAccountValue <= openingAccountValue -((maxAccountLoss/100)*openingAccountValue))// Note this is tied to the 5 min bar series
{
Print(
"");
Print(
"!!!!FLATTEN EVERYTHING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Print(
DateTime.Now " SYSTEM MONITOR: Global Loss Limit Exceeded!");
Print(
"Opening Account value: $" openingAccountValue);
Print(
"Current Account Value: $" currentAccountValue); 
if (
alertsWindowAlert("globalloss"NinjaTrader.Cbi.Priority.High"Global Loss Limit Exceeded""triple_klaxon.wav"10Color.RedColor.White);
if (
logAlertsLog("SystemMonitor: Global Loss Limit Exceeded"NinjaTrader.Cbi.LogLevel.Error);
Print(
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Print(
"");
GetFlat();
}
}
}
//Close Account Monitor
#endregion 


Reply With Quote
Thanked by:
  #8 (permalink)
 
Mindset's Avatar
 Mindset 
Singapore
 
Experience: Intermediate
Platform: NT
Broker: ib
Trading: MES
Posts: 365 since Sep 2009
Thanks Given: 90
Thanks Received: 292

MXASJ - thanks, but you still run into the issue that GetAccountValue() simply doesn't exist in an indicator - only in a strategy for some bizarre reason.


Started this thread Reply With Quote
  #9 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 801


Mindset View Post
MXASJ - thanks, but you still run into the issue that GetAccountValue() simply doesn't exist in an indicator - only in a strategy for some bizarre reason.

Yep. Global PnL is my workaround. There are some other "Utility" methods in Ninja that don't work in both Strats and Indis. PrintWithTimeStamp(), for example, only works in Strats IIRC.


Reply With Quote
  #10 (permalink)
 
d1g1talfr3ak's Avatar
 d1g1talfr3ak 
Huntsville AL/USA
 
Experience: Beginner
Platform: NinjaTrader
Trading: Stocks, Futures
Posts: 24 since Nov 2011
Thanks Given: 31
Thanks Received: 46



Mindset View Post
MXASJ - thanks, but you still run into the issue that GetAccountValue() simply doesn't exist in an indicator - only in a strategy for some bizarre reason.

I have several indicators that have needed info only available in the strategy... I just have the strat pass the info to the indicator.

This code is in my EquityCurve Indicator

 
Code
		public void setEC(double val)
		{
			this.ec = val;
			this.Update();
		}
		
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            PlotEC.Set(ec);
        }
And then in the strategy, in the OnBarUpdate:

 
Code
			ecInd.setEC(Performance.AllTrades.TradesPerformance.Currency.CumProfit);


Follow me on X Reply With Quote




Last Updated on May 31, 2012


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts