Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Check the no. of trades in Ninjascript.

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

    Check the no. of trades in Ninjascript.

    Hi

    I would like to check in real time, how many trades are running in the background. Is any syntax is available for Ninjascript.

    e.g : if ( no. of trades < 2 )
    {
    Buy....
    }

    Thanks
    Imran.

    #2
    Imran, can you please clarify what you mean, trades running on the account or in the NinjaScript strategy you're currently working with?

    Comment


      #3
      Hi Bertrand

      Yes trades running on the live account. Suppose I have applied two strategies on the 100 instruments and I want to restrict the trades, on the basis of number of live trades.

      e.g : if ( no. of trades < 2 )
      {
      Buy.....
      }

      Like this but here restrict the trades on the basis of Account cash value.
      protected override void OnBarUpdate()
      {
      // Checks to see if the account has more than $25000

      if (GetAccountValue(AccountItem.CashValue) > 25000)
      // Do something;
      }
      Last edited by Imran; 09-19-2013, 04:06 AM.

      Comment


        #4
        Thanks for the clarifications, there's unfortunately no supported NinjaScript method to request this info, as the individual script would only have access per default to its own positions monitored / taken. One approach could be making a MultiSeries script out of your strategies running so one script would be working with all your instruments and thus would know its Positions



        Via the undocumented / unsupported account object you could also 'play' with this idea -

        if (FirstTickOfBar)
        track = 0;

        if (Historical == false)
        {
        foreach (Account acct in Cbi.Globals.Accounts)
        {
        if (acct.Positions != null && acct.Name == "Sim101")
        {
        PositionCollection positions = acct.Positions;

        foreach (Position pos in positions)
        track++;
        }
        }
        }

        You can then include a check to the realtime generated track variable following your account positions (here on Sim101) - however this could not be backtested then in contrast to a MultiSeries script.

        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
        331 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
        549 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        550 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X