Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MT Programmer new to NT, tips please?

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

    MT Programmer new to NT, tips please?

    Hi, I am an experienced programmer, having done MT4 for several years (and C++ a long time ago).

    I have a NT indicator I am trying to convert to MT, and wondered if someone would be willing to give me a couple tips on some base class members I do not understand.

    Hoping in the affirmative, I'll start with this:

    Inside the class are some member functions that look like this:

    [Browsable(false)]
    [XmlIgnore]
    public DataSeries aboveR1
    {
    get
    {
    return base.Values[1];
    }
    }

    [Browsable(false)]
    [XmlIgnore]
    public DataSeries aboveS1
    {
    get
    {
    return base.Values[5];
    }
    }

    [Browsable(false)]
    [XmlIgnore]
    public DataSeries belowR1
    {
    get
    {
    return base.Values[2];
    }
    }

    [Browsable(false)]
    [XmlIgnore]
    public DataSeries belowS1
    {
    get
    {
    return base.Values[6];
    }
    }

    [Browsable(false)]
    [XmlIgnore]
    public DataSeries midLOW
    {
    get
    {
    return base.Values[4];
    }
    }

    [Browsable(false)]
    [XmlIgnore]
    public DataSeries midUP
    {
    get
    {
    return base.Values[3];
    }
    }

    [Browsable(false)]
    [XmlIgnore]
    public DataSeries r2
    {
    get
    {
    return base.Values[0];
    }
    }

    [Browsable(false)]
    [XmlIgnore]
    public DataSeries s2
    {
    get
    {
    return base.Values[7];
    }
    }


    First off, I do not know what the "DataSeries" type returns exactly, and secondly what all the indexed "base.Values[]" mean.

    Could someone explain this to me please, or maybe if you can send me the definition of the base class I could figure it out (?)

    Thank you in advance!

    PS: If there is a link to a tutorial / manual that explains all this well, please don't hesitate to send :-)

    #2
    Welcome to our forums here - for getting starting coding in the C# based NinjaScript, please consider reviewing those tutorials -



    Our DataSeries class is explained here - http://www.ninjatrader.com/support/h...ries_class.htm

    The Values one here - http://www.ninjatrader.com/support/h...nt7/values.htm

    For more advanced references samples and tips, please check into -

    Comment


      #3
      Values[] followup

      Thank you for the links.

      Have read over them a bit, especially the Values array / objects.

      Understand DataSeries now well enough... but when it references base.Values[?], still not sure what that would be referencing.

      Of course my mind is still trying to do a MT4 conversion :-)

      Comment


        #4
        The Values array is a collection holding the values calculated for the indicators, the plots added in the Initialize only determine how those should be visualized - this is basically the 'link' from the plot characteristics to the actual values plotted then.

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          The Values array is a collection holding the values calculated for the indicators, the plots added in the Initialize only determine how those should be visualized - this is basically the 'link' from the plot characteristics to the actual values plotted then.
          Ok, I think I get that. But then the code I listed, calling base.Values[1].... The base class is "indicator". Aren't there some rules for what Values[] holds for that base class?

          Or am I not quite getting it?

          Comment


            #6
            Those objects would hold double values.

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              Those objects would hold double values.
              Yes, I know, but WHAT values?

              Ah... or is base.Values[1] just referring to the inherited class (my ind) Values array?

              Comment


                #8
                That's correct DerkWehler.

                Comment


                  #9
                  muy gracias senior

                  Will see how far I can get on that. Appreciate the help.

                  Comment


                    #10
                    So far so good

                    Hello any readers:

                    Things are coming along. I think I am understanding much of the coding.

                    But a brief question on this code snippet:

                    protected override void OnBarUpdate()
                    {
                    double item;
                    double num;
                    double num1;
                    if (base.CurrentBar == 0)
                    {
                    item = base.Close[0];
                    }
                    else
                    {
                    item = base.Close[0] * 0.2 + 0.8 * base.Close[1];
                    }
                    ...

                    Unlike MT, which runs through a loop for each bar, I am assuming OnBarUpdate gets called for each bar on the chart..(?)

                    So when it says:

                    if (base.CurrentBar == 0)
                    {
                    item = base.Close[0];
                    }
                    else
                    {
                    item = base.Close[0] * 0.2 + 0.8 * base.Close[1];
                    }

                    Is that saying "if the bar we are working on is the open candle ("base.CurrentBar == 0" means the right-most open candle I assume, or is it the one that just closed?), then set:

                    item = Close price of open (or most recently closed) candle

                    else set

                    item = Close price of right-most candle * 20% + Close price of previous candle * 80%

                    --OR--

                    Does base.Close[0] here refer to the close of whatever candle we are working on?

                    In other words, if OnBarUpdate is called for each candle, and the one it's currently working on is the 10th candle from the right, then does base.Close[0] refer to THAT candle, and base.Close[1] refer to the 11th candle from the right?

                    PS: I am not sure how to get this editor to respect the tabs in my code when I paste it. Is there a trick?

                    Comment


                      #11
                      DerkWehler, glad to hear you're moving along nicely - OnBarUpdate() is called for each bar on the chart from left to right, so CurrentBar = 0 is the first bar on the left and not the rightmost one.

                      What Close[0] is depends on your CalculateOnBarClose setting for the script (for realtime processing) -



                      With this setting to 'true' you're processing the currently last closed candle, and not the developing right most one - this can only be accessed with 'false' and the [0] index. In this scenario then an index of [1] would mean the last completed candle.

                      In backtesting / historical data this would always be 'true'.

                      Comment


                        #12
                        Originally posted by NinjaTrader_Bertrand View Post
                        DerkWehler, glad to hear you're moving along nicely - OnBarUpdate() is called for each bar on the chart from left to right, so CurrentBar = 0 is the first bar on the left and not the rightmost one.

                        What Close[0] is depends on your CalculateOnBarClose setting for the script (for realtime processing) -



                        With this setting to 'true' you're processing the currently last closed candle, and not the developing right most one - this can only be accessed with 'false' and the [0] index. In this scenario then an index of [1] would mean the last completed candle.

                        In backtesting / historical data this would always be 'true'.
                        Ok, I understand that, and have this setting:

                        base.set_CalculateOnBarClose(true);

                        So, calculating from the left, and it is on the 5th bar from the left at the moment, base.Close[0] refers to the close price of the current (5th from left) bar then?

                        And base.Typical[1] refers to the previous (4th bar from left) bar's typical price, (high + low + close) / 3 ? Or does it refer to the 6th bar from the left?

                        Comment


                          #13
                          You are correct in understanding, and index of 1 would mean one bar back. We would not supporting looking into the 'future' with indexing.

                          Comment


                            #14
                            Originally posted by NinjaTrader_Bertrand View Post
                            You are correct in understanding, and index of 1 would mean one bar back. We would not supporting looking into the 'future' with indexing.
                            Makes sense!

                            Thanks again Bertrand!

                            Probably will yet have a couple more questions, but that should get me translating most of it. :-)

                            Comment


                              #15
                              You're welcome, best of luck on the conversions.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              596 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              343 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              556 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              554 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X