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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    82 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    43 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    56 views
    0 likes
    Last Post CarlTrading  
    Working...
    X