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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      549 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X