Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position is static or dymanic?

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

    Position is static or dymanic?

    Dear NT,

    I can’t quite get it from the documentation, is Position length dynamic or static?

    If I understand correctly the collection is always the same length and has an element for each instrument and timeseries in the strategy? Each element only changes state of the Position object within that element, is that correct? That is, if I have a strategy with four time frames and two instruments (code in the Initialised method):


    Add(PeriodType.Minute, 1);
    Add("$CADJPY", PeriodType.Minute, 60);
    Add("$CADJPY", PeriodType.Minute, 1);

    Positions.Length would always be 3 (i.e. 0,1,2 and 3)? Is that true? However, the Trade objects within the collection change state.

    Thanks and regards,

    drolles

    #2
    Further to this, after sleeping on it, that would mean if it is static that the position’s placement in the Positions array aligns to the BarsArray one for one. I.e. the BarsArray[1][0] would align to the Positions[1] would align to the position generated by BIP==1.

    Thanks and regards,

    drolles

    Comment


      #3
      Hi Dan, it would be static, as the adding of series is static as well - i.e if you Add() a series you can't remove it later via code. In your example if the primary series would also be CADJPY the position for it would be always reported under Positions[0] and the others would be flat. If primary would be for example EURUSD, then it's position would be at index 0 and the CADJPY would be at index 1.

      Hope that helps,

      Comment


        #4
        Bertrand,

        Thanks very much for your help and reply.

        So just to check then the Positions index would always align with the BarsArray index if there is one Position index for each DataSeries?

        In the example you give, I think you mean that CADJPY 60 min would have reference of 2, the reason being that the base DataSeries would be the one on the chart / strategy analyser. That is (following your use of EURUSD),

        Instrument, timeframe, Bars Array and Positions reference
        EURUSD, 60 min, 0
        EURUSD, 1 min, 1
        CADJPY, 60 min, 2
        CADJPY, 1 min, 3

        Just checking I’ve really understood you correctly and I haven’t missed something.

        Cheers,

        drolles

        Comment


          #5
          Betrand,

          To try to be really clear what I'm trying to acheive is this:

          Code:
                                      foreach (Position p in Positions) {
                                      
                                          if (p.MarketPosition != MarketPosition.Flat) {
                                              
                                              // Need to do some work here as this will return the value
                                              // on the close of the current instrument and not the relevant instrument
                                          
                                              day_pnl += p.GetProfitLoss(Closes[x][0], PerformanceUnit.Currency);
                                              x++;
                                              
                                          }
                                          
                                      }

          Comment


            #6
            Hi Dan, I think you understood it correctly, it's just important to remember that the positions in the collection would be help for the first unique instrument index, so in your example from post 4 (assuming primary series on which the strategy is run from is not either EURUSD or CADJPY): Position for EURUSD under index 1 and the position for CADJPY under index 3, the other 1 min series (second added for the instrument) would be flat.

            Comment


              #7
              Bertrand,

              Thanks for that.

              Kind regards,

              drolles

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              633 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              364 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              105 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              567 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              568 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X