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
    28 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    17 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    9 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    10 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    18 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X