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 chbruno, Today, 04:10 PM
          0 responses
          3 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          6 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by frslvr, 04-11-2024, 07:26 AM
          9 responses
          127 views
          1 like
          Last Post caryc123  
          Working...
          X