Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

hi i'm gettin this error in log

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

    hi i'm gettin this error in log

    hi my indicator works fine but i'm getting the below error when i trace orders and also in log. why?



    Failed to call method 'Initialize' for indicator 'SpreadValue': 'Add' method only accepts positive 'period' values, but was -1 Min

    Code:
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Line, "SPREAD"));
                
                   Add(SecondInstrument, BarsPeriods[0].Id, BarsPeriods[0].Value);
    
                Overlay                = false;
            }
            
            private double a,b,c,d,e=0;
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                
                if (CurrentBarArray[0] > 0 && CurrentBarArray[1] > 0)
                {
                    if (BarsInProgress > 0) 
                    {
                
                if(CurrentBars[0] ==1)            
                    
                {
                a = CurrentDayOHL(BarsArray[0]).CurrentOpen[0];
                b = CurrentDayOHL(BarsArray[1]).CurrentOpen[0];
                }
                
                if( b > 0 && a >0)
                {
                    c = (Closes[0][0]/a)-1;
                    d = (Closes[1][0]/b)-1;
                    e = (c - d)*50000;    
                }
    
                SPREAD.Set(e);
                
                    }
                }
            }

    #2
    Hello calhawk01,

    Thanks for your post.

    The reason for the error is because of how you are adding your additional dataseries. The use of BarsPeriods[0].Id, BarsPeriods[0].Value is not recommended in Initialize because it does not perform consistently, as you have observed. Most of the time it would work and eventually, through the number of passes in initialize, it does seem to work but it will generate the errors you have observed on occasion.

    It is recommended to use hard coding of the Value and ID.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    574 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    332 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    553 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X