Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple symbol synchronicity

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

    Multiple symbol synchronicity

    Is it correct that it's possible to trade several symbols on one chart, with the BarsInProgess field indicating which of the charts is being referenced in the OnBarUpdate() method? i.e.the OHLC all apply to the chart which is active (as defined by BarsInProgress), so that if I want to keep track of the spread between the close of the top chart and the close of the second chart the following might work:

    Code:
    double spread = 0;
    double topClose = 0;
    double secondClose = 0;
    
    protected override void OnBarUpdate(){
      if (BarsInProgress == 0) topClose = Close[0];
      if (BarsInProgress == 1) secondClose = Close[0];
      spread = topClose - secondClose;
    }
    Last edited by kaydgee; 08-31-2012, 08:15 AM.

    #2
    Hello kaydgee,
    The current code you are using wont work as either topClose or secondClose will be 0 (zero) at any point of time.

    You can follow any of the below steps to calculate the spread.

    Using BarsInProgress
    Code:
    double spread = 0;
    if (BarsInProgress == 0)
    	spread = Close[0] - Closes[1][0];
    else if (BarsInProgress == 1)
    	spread = Closes[0][0] - Close[0];
    Not using BarsInProgress
    Code:
    double spread = Closes[0][0] - Closes[1][0];
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Sorry, inadvertently I made my edit after you replied. I don't know if your comment still applies given that I'm not resetting topClose and secondClose to 0 on every OnBarUpdate.

      Comment


        #4
        Hello kaydgee,
        Yes, it would work, but I would still make a check that both the fields have non-zero values.

        Code:
        double spread = 0;
        double topClose = 0;
        double secondClose = 0;
        
        protected override void OnBarUpdate(){
         {
          if (BarsInProgress == 0) topClose = Close[0];
          if (BarsInProgress == 1) secondClose = Close[0];
         
        if (topClose == 0 || secondClose == 0) return;  // we do not have enough information to calculate the spread 
         spread = topClose - secondClose;
        }
        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        639 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        366 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        107 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        569 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        572 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X