Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with account Leeloo

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

    Problem with account Leeloo

    Hello,

    I have a problem with my code which works very well on Sim account. It bug with an LL account (Leeloo connected to Ritmic)
    I get an error message : Unhandled exception



    After research, the following instruction is the problem: Acct.Positions.Count

    Thanks for your help.




    My code is :
    protected void Button1Click(object sender, RoutedEventArgs e)
    {

    xAlselector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
    quantitySelector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlQuantitySelector") as NinjaTrader.Gui.Tools.QuantityUpDown;

    Account Acct = Account.All.FirstOrDefault(x => x.Name == xAlselector.SelectedAccount.ToString());


    if (Acct.Positions.Count>=0) { OpenBuy(quantitySelector.Value); /*for (int n=1; n<=quantitySelector.Value; n++) AddStopLoss(1);*/ return;}
    else {DisplayInfo("Not Possible because Position Already Open !!!",Brushes.Red); return;}
    }


    #2
    Hello jodu49,

    The line below is redundant:
    Account Acct = Account.All.FirstOrDefault(x => x.Name == xAlselector.SelectedAccount.ToString());

    You could use:
    private Account Acct;

    Acct = xAlselector.SelectedAccount;

    You will need to check that xAlselector are Acct are not null.

    if (xAlselector != null)
    {
    Acct = xAlselector.SelectedAccount;
    }

    if (Acct != null)
    {
    if (Acct.Positions.Count>=0)
    {
    }
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thank you very much, it works very well!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      156 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      90 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      140 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      130 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X