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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        67 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        36 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        60 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X