Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

1 Bar Delay, when using Multiple DataSeries

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

    1 Bar Delay, when using Multiple DataSeries

    Hi,
    My code has 15 Data Series Loaded, & I'm trying to make it more efficient by having the main method only run on 1 iteration of the code, and not on every dataseries.

    Right now, if i move the main method into something like
    if (BarsInProgress == 0)
    {
    Main Method();
    }

    or
    if (BarsInProgress == 15) // ie the Last DataSeries
    {
    Main Method();
    }

    Then it will cause a delay in the Signal output.
    > So right now my only option is to have it run on every DataSeries , which is unnecessary
    ​​

    Is there a solution to this?
    Thanks in advance :-)

    Code:
            
            private bool runOnce = true;
            private int LastBarsArray = 0;​
    
            protected override void OnBarUpdate()
            {
    
                if (runOnce)
                {
                    var totalDataSeries = BarsArray.Length; // Get the total number of data series loaded
                    LastBarsArray = totalDataSeries - 1;
                    runOnce = false;
                }
    
                if (BarsInProgress != 0)
                {
                    UpdateSeries();
                    GetPrices();
    
                    Main_LogicA(); // The Signal is Fine, if i put the Main Methods Here. But it Runs on every DataSeries (ie 10+ )
                    Main_LogicB();
               }
    
    
                if (BarsInProgress == LastBarsArray)
                 {
                    Main_LogicA(); // If I Put the Main Method at the end of the OnBarUpdate. Then it Causes  the output Signal to delay by 1 bar
                    Main_LogicB();
                  }​
    
                      
            }​​
    
    private void Main_LogicA()
    {
    
    // Print the BarsInProgress index and the current close price for the series
    Print("BarsInProgress: " + BarsInProgress + " | CurrentBar: " + CurrentBar + " | Close Price: " + Closes[BarsInProgress][0]);
    
    }
    
    output
    BarsInProgress: 1 | CurrentBar: 20718 | Close Price: 1.08894
    BarsInProgress: 2 | CurrentBar: 20718 | Close Price: 0.85164
    BarsInProgress: 3 | CurrentBar: 20718 | Close Price: 1.48824
    BarsInProgress: 7 | CurrentBar: 20718 | Close Price: 0.96846​
    Last edited by yertle; 06-09-2024, 09:42 PM.

    #2
    Hello yertle,

    Thank you for your inquiry.

    OnBarUpdate() will still run for every data series added to the script. However, to prevent further processing from occurring, the suggested solution would be to have something like:

    Code:
    //prevent further processing unless the primary data series is being updated
    if (BarInProgress != 0)
    return;
    This would prevent further processing from occurring on any series that isn't the primary data series of the script.

    Calling your method when BIP != 0 (as it is currently being called in your code) would cause your method to be called for every added data series except the primary series.

    Please let us know if you have any further questions.

    Comment


      #3
      Perfect.
      Thank you

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      670 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      379 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      111 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      575 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      582 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X