Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate - multi-instrument-script

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

    OnBarUpdate - multi-instrument-script

    Hello,

    it seems that "Position.Quantity.ToString();" does not update in OnBarUpdate when using in a script with more than 1 instrument. It shows always "0", when I change the instrument in the chart then its shows the positionquantity. What does one have to add please so that its working with the instrument it is attached in the chart (or specified to any of the used instruments).

    Thank you!
    Tony

    #2
    Hello tonynt,

    This depends on where you are calling the syntax and what BarsInProgress called OnBarUpdate. Generally for multi series scripts you need to use "Positions" plural, instead of Position singular.



    Assuming you are using two difference instruments, you can reference a specific instrument using the Positions[index].

    I look forward to being of further assistance.

    Comment


      #3
      Hello,

      thank you for your reply. It works now "partially". But it does not update (in onbarupdate) my "controlvalues" with
      if (Position.MarketPosition == MarketPosition.Short)
      {if (Positions[0].Quantity>=1)
      {
      avgFillSa=Position.AveragePrice;
      ...

      I´m in a short trade but "avgFillSa" persists 0 and doesnt show the entryprice. Why?

      Thank you!
      Tony
      Last edited by tonynt; 08-16-2019, 08:35 AM. Reason: correction

      Comment


        #4
        Hello,

        after replying with this question above I found out. Its interesting that when doing a communication and asking a question very often the solution appears!
        It also has to be if(Positions[0].MarketPosition...) and avgFillSa=Positions[0].AveragePrice.

        Best regards
        Tony
        Last edited by tonynt; 08-16-2019, 08:40 AM. Reason: correction

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        43 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        21 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        30 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        50 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        40 views
        0 likes
        Last Post CarlTrading  
        Working...
        X