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

Array access issue | values are not valid even though set properly |NT 8

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

    Array access issue | values are not valid even though set properly |NT 8

    I am writing my first indicator and kind of stuck on accessing values from two arrays which is holding buy and sell signalspecific to each bar.
    i.e. like Close array i want to maintain a LongSignal & ShortSignal array specific to each bar. below is my script snippet; have defined LongSignal & ShortSignal as double array & for every bar they get initialized at the start on onBarUpdate with 0. later on these values get reset if my buy/sell condition meets with 1.
    am sure i am making very basic mistake here, any help would be appreciated.

    my final intent is to have these signal array exposed to a strategy.

    OUTPUT FOR LOG WINDOW;
    6/23/2019 12:39:47 PM NinjaScript SHORT INDICATOR: CurrentBar=5179- 100/100
    My CODE;
    protected override void OnBarUpdate()
    {
    LongSingle[CurrentBar]= 0; // initialize with 0 at the bar start,
    ShortSignal[CurrentBar]=0; // initialize with 0.at the bar start,

    if(SOME CONDITION ) {
    LongSignal[CurrentBar]= 0; // set LongSignal for current bar to 0.
    ShortSignal[CurrentBar]=1; // set LongSignal for current bar to 1.

    Log("SHORT INDICATOR: CurrentBar="+CurrentBar+"-"+LongSignal[CurrentBar].ToString()+"/"+ShortSignal[CurrentBar],LogLevel.Information);

    // below also does not work
    // Log("SHORT INDICATOR: CurrentBar="+CurrentBar+"-"+LongSignal.GetValueAt(CurrentBar).ToString()+"/"+ShortSignal.GetValueAt(CurrentBar),LogLevel. Info rmation);
    }
    }

    #region Properties

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> LongSignal
    {
    get { return Values[0]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> ShortSignal
    {
    get { return Values[0]; }
    }
    #endregion

    Last edited by [email protected]; 06-23-2019, 10:59 AM.

    #2
    Hello [email protected],

    I would recommend Printing to the output window instead of calling Log() to write to the log.



    What code have you used to declare the LongSignal and ShortSignal arrays?

    If you are using an array that does not dynamically expand, you would have to predict how many new bars are going to form while the script is running in real-time. A List is like an array but is dynamically expandable.

    .GetValueAt() does not work with C# arrays. This is something that is NinjaScript specific to DataSeries for getting a bar value.


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      i was able to figure this out myself. believe one need to initialize arrays in dataload block. does ninja allow printing logs in a file per strategy ? i dont like viewing log in OOB log window, it would be nice to able to see logs in a file (one file per strategy)

      Comment


        #4
        BTW for anyone still accessing this in search spelling errors will drive you nuts in code or when you print to output window

        LongSingle[CurrentBar]= 0; // initialize with 0 at the bar start, (should be LongSignal)
        ShortSignal[CurrentBar]=0; // initialize with 0.at the bar start,

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Haiasi, Today, 06:53 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by ScottWalsh, Today, 06:52 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by ScottW, Today, 06:09 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by ftsc2022, 10-25-2022, 12:03 PM
        5 responses
        256 views
        0 likes
        Last Post KeyonMatthews  
        Started by Board game geek, 10-29-2023, 12:00 PM
        14 responses
        244 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Working...
        X