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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        66 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        149 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        99 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        286 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X