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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    20 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    11 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    622 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    420 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    293 views
    1 like
    Last Post charlesugo_1  
    Working...
    X