Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position and multiple strategies

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

    Position and multiple strategies

    Is there a way to get information regarding the account positions?

    I ask this because I run two strategies at the same time and I don't want both strategies to conflict with each other. So if I'm long with strategy A, then all signals in strategy B (long or short) should be ignored). And vice versa.

    I've read information that there is Strategy Position and Account Position. So basically strategy B does not know that strategy A is long. But if I was able to get data about the account then I would know if there is already a position open or not.
    Last edited by siroki; 10-12-2014, 12:15 PM.

    #2
    Hello siroki,

    Thank you for your post.

    It is unsupported but the code below is an example of how to pull the account positions:
    Code:
    foreach (Account acct in Cbi.Globals.Accounts)
    {
    if (acct.Positions != null)
    {
    PositionCollection positions = acct.Positions;
    foreach (Position pos in positions)
    {
    Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
    }
    }

    Comment


      #3
      Thank you so much for your help Patrick!

      Comment


        #4
        Compile error on position sizing

        The name 'Equity' does not exist in the current context.
        The name 'StartEquity' does not exist in the current context.

        Note that I imported and compiled an archive, but the 2 scripts included did not list position sizing methods.

        Is it likely that i should replace Equity and Start Equity with Ninjascript 'AccountSize' and another method?

        I have minimal programming skills so I have included the code below for your perusal.


        // Position sizing calculations

        NShares = MinSize;
        if (RoundPS && RoundTo > 0)
        NShares = (int)Math.Floor((double)MinSize/RoundTo);

        if (Math.Abs(PSParam) > 0 && (Equity - StartEquity) > 0)
        NShares = (int)(0.5 * (1 + Math.Sqrt(Math.Pow((2 * NShares - 1), 2.0) + 8 * (Equity - StartEquity)/Math.Abs(PSParam))));

        if (RoundPS && RoundTo > 0)
        NShares = NShares * RoundTo;

        if (RoundPS && RoundTo > 0)
        NShares = (int)Math.Floor((double)NShares/RoundTo) * RoundTo;

        NShares = Math.Max(NShares, MinSize);
        NShares = Math.Min(NShares, SizeLimit);

        Comment


          #5
          Hello Nullid,

          Thank you for your post.

          Equity and StartEquity are doubles that need to be declared at some point in your code and assigned a value.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          77 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          45 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          27 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          32 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          63 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X