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 6,575 views
    2. thumb_up 3 thanks given
    3. group 7 followers
    1. forum 14 posts
    2. attach_file 0 attachments




 
Search this Thread

GetAccountValue in an Indicator

  #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: 291

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?
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Exit Strategy
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
38 thanks
NexusFi site changelog and issues/problem reporting
27 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #3 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 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: 291

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: 291

Displaying account equity and margin in Market Analyzer - [AUTOLINK]NinjaTrader[/AUTOLINK] 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: 800

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: 291

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: 800


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 Twitter Reply With Quote




Last Updated on May 31, 2012


© 2024 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 - Privacy Policy - Downloads - Top
no new posts