Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get Chart Trader account selection from indicator code.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • bltdavid
    replied
    Originally posted by omribidi View Post
    But it shows the data only after I do "reload ninjascript"' any idea work to fix this issue so it will reload auto after changing the account?

    Try calling this function wherever you happen to need the
    current account from chart trader,

    Code:
    private Account ChartTrader_GetAccount()
    {
        if (ChartControl == null)
            return null;
    
        ChartControl.Dispatcher.InvokeAsync((Action)(() =>
        {
            return ChartControl.OwnerChart.ChartTrader.Account;
        }));
    }

    *untested*

    Leave a comment:


  • omribidi
    replied
    What "NinjaTrader_AlanP​" uploaded works!
    But it shows the data only after I do "reload ninjascript"' any idea work to fix this issue so it will reload auto after changing the account?
    Last edited by omribidi; 01-22-2025, 11:06 AM.

    Leave a comment:


  • omribidi
    replied
    Hello,
    Has someone managed to cause "Position Display Indicator" to select a user automatically?
    please help​

    Leave a comment:


  • Only Juanpa
    replied
    Yo ​What´s going on? pls helpClick image for larger version

Name:	image.png
Views:	949
Size:	85.1 KB
ID:	1293490

    Leave a comment:


  • NinjaTrader_Gaby
    replied
    Hello DavidHP,

    Please see the attached.

    If you have any further questions, please let me know!
    Attached Files

    Leave a comment:


  • DavidHP
    replied
    Originally posted by NinjaTrader_Gaby View Post
    Hello DavidHP,

    Instead of getting the account from OnBarUpdate(), you should get the account in State.DataLoaded. This should work as long as your script is added to the chart and the ChartControl is not null. Getting the account from OnBarUpdate() would likely cause an object reference error if you are trying to do something with the account from State.DataLoaded but you haven't grabbed the actual account from OnBarUpdate() yet.

    Please let me know if you have any further questions.
    Perhaps you could give an example.
    I've tried adding to the dataloaded several different ways and each give errors.

    Leave a comment:


  • NinjaTrader_Gaby
    replied
    Hello DavidHP,

    Instead of getting the account from OnBarUpdate(), you should get the account in State.DataLoaded. This should work as long as your script is added to the chart and the ChartControl is not null. Getting the account from OnBarUpdate() would likely cause an object reference error if you are trying to do something with the account from State.DataLoaded but you haven't grabbed the actual account from OnBarUpdate() yet.

    Please let me know if you have any further questions.

    Leave a comment:


  • DavidHP
    replied
    Originally posted by NinjaTrader_Gaby View Post
    Hello DavidHP,

    Thank you for your response.

    The PositionDisplayIndicator uses the account chosen in the 'Properties' of the indicator. Right-click on the chart > Indicators > click on the Indicator > you can select the account on the right side (Properties section).

    You can however integrate the code from PrintChartTraderSelectedAccount into this indicator. You can get the account from State.DataLoaded, as long as your script is added to a chart and you are checking that the ChartControl is not null.

    Please let me know if you have any other questions.
    The section in the State.DataLoaded has the code I indicated:
    Code:
    lock (Account.All)
    account = Account.All.FirstOrDefault(a => a.Name == AccountName);​​
    When I integrate the code from the (PrintChartTraderSelectedAccount.zip) the account name "PRINTS" in the Output Window as in the original indicator.
    However when I try to pass the code to the 'account' I etiher get Object reference error or a CBI error.
    It seems the code in the (PrintChartTraderSelectedAccount.zip) is in OnBarUpdate but State.DataLoaded is read before that and is of a differnt type.

    Perhaps I'm not 'integrating' it properly?
    What am I missing?

    Thanks for your suggestions.

    Leave a comment:


  • NinjaTrader_Gaby
    replied
    Hello DavidHP,

    Thank you for your response.

    The PositionDisplayIndicator uses the account chosen in the 'Properties' of the indicator. Right-click on the chart > Indicators > click on the Indicator > you can select the account on the right side (Properties section).

    You can however integrate the code from PrintChartTraderSelectedAccount into this indicator. You can get the account from State.DataLoaded, as long as your script is added to a chart and you are checking that the ChartControl is not null.

    Please let me know if you have any other questions.

    Leave a comment:


  • DavidHP
    replied
    Originally posted by NinjaTrader_Gaby View Post
    Hello DavidHP,

    Thank you for your post.

    Can you clarify what you mean by "trying to find the chart name"? The code Alan provided demonstrates getting the name of the selected account from the Chart Trader from an indicator.
    I have the following indicator loaded.
    This indicator provides a customizable text box which displays a position’s UnRealized PnL, Realized PnL of a selected account, and the overall cash value of the account.

    It does not seem to work unless I manually insert the account name i.e. "Sim101" or "Playback101" into the code.

    Here is the code on lines 73 -74
    Code:
                    lock (Account.All)
                        account = Account.All.FirstOrDefault(a => a.Name == AccountName);​
    To get it to detect the PNL I must change the code from "AccountName" to the account on the chart manually, otherwise it does nothing.

    I thought maybe I could use the code from this indicator (PrintChartTraderSelectedAccount.zip) to be able to automatically get the account name instead of needing to manually change the code each time I changed accounts.

    Is that possible?​

    Leave a comment:


  • NinjaTrader_Gaby
    replied
    Hello DavidHP,

    Thank you for your post.

    Can you clarify what you mean by "trying to find the chart name"? The code Alan provided demonstrates getting the name of the selected account from the Chart Trader from an indicator.

    Leave a comment:


  • DavidHP
    replied
    Originally posted by NinjaTrader_AlanP View Post

    I have put together an indicator which will print to the output window what account is selected in the chart trader account drop down.

    Please let us know if you need further assistance.
    I loaded this indicator on a chart and it detects the account in the chart trader window
    However, I am trying to find the chart name in an indicator.
    I am using the code shown in another thread.
    This is the code:
    Code:
                    lock (Account.All)
                        myAccount = Account.All.FirstOrDefault(a => a.Name == AccountName);​
    How do I get the 'AccountName to reflect the account shown in the Chart Account dropdown?

    If I hard code the name i.e. "Sim101" the account name is correct but using 'AccountName' does not work.
    Thanks

    Leave a comment:


  • anon84
    replied
    Originally posted by TickTaker View Post
    Heh, any chance you have this for nt 7?
    Code:
    Panel panel = (Panel)ChartControl.Controls["pnlChartTrader"];
    
    if (panel != null && panel.Controls["ctrChartTraderControl"] != null)
    {
         ComboBox comboAccount = (ComboBox)panel.Controls["ctrChartTraderControl"].Controls["cboAccount"];
         NinjaTrader.Cbi.Account AccountObject = (NinjaTrader.Cbi.Account)comboAccount.SelectedItem;
         Print("Selected Account: " + AccountObject.Name);
    }

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    Hello TickTaker,

    There is no sample for this in NT7 and may be possible however not supported.

    Please let us know if you need further assistance.

    Leave a comment:


  • TickTaker
    replied
    Heh, any chance you have this for nt 7?

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by SalmaTrader, 07-07-2026, 10:26 PM
0 responses
35 views
0 likes
Last Post SalmaTrader  
Started by CarlTrading, 07-05-2026, 01:16 PM
0 responses
20 views
0 likes
Last Post CarlTrading  
Started by CaptainJack, 06-17-2026, 10:32 AM
0 responses
13 views
0 likes
Last Post CaptainJack  
Started by kinfxhk, 06-17-2026, 04:15 AM
0 responses
19 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Started by kinfxhk, 06-17-2026, 04:06 AM
0 responses
21 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Working...
X