Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by benmarkal, Yesterday, 12:52 PM
    3 responses
    22 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by helpwanted, Today, 03:06 AM
    1 response
    18 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    11 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    6 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    244 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Working...
    X