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

Multi time frame basic use error

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

    Multi time frame basic use error

    I was experiencing calling an indicator with a different input off of an indicator. For some reason I couldn't get it to work even with the simplest code. The anticipated result is just two panels on the chart window (an ES 09-12 Weekly).

    A1 - The indicator that calls:
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Overlay = false;
    Add(PeriodType.Day, 1);
    }
    protected override void OnBarUpdate()
    {
    Plot0.Set(Close[0]);
    A2(BarsArray[1],1);
    }

    A2 - The indicator that is being called:
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Overlay = false;

    }
    protected override void OnBarUpdate()
    {
    Plot0.Set(Close[0]);

    }

    #2
    savekad, is there any error returned in the Control Centers log tab as the study is applied? So the base chart that adds the script is your weekly chart?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi, sorry for the delay.

      No, there are no errors on the log.
      Yes, the base chart is Week.

      I'm using the free Kinetick End-of-Day free data feed and I've noticed it can't supply me with 60 min bars data for some reason.

      Comment


        #4
        Thanks, the free Kinetick End of Day connection would not provide intraday data, it would offer daily intervals and higher only.

        Plotting daily data on a weekly chart would not be a useful setup, as the plotting would be limited by the primary bars timestamps, so I would suggest you add a weekly series and plot this from the daily chart.

        With an OnBarUpdate() in A1 changed to :

        if (BarsInProgress != 0 || CurrentBars[0] < 0 || CurrentBars[1] < 0)
        return;

        Plot0.Set(A2(BarsArray[1])[0]);
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I've even simplified it a bit more and still - Output is empty.

          A1:

          protected override void Initialize()
          {
          Overlay = false;
          Add(PeriodType.Week, 1);
          }
          protected override void OnBarUpdate()
          {
          if (BarsInProgress != 0 || CurrentBars[0] < 0 || CurrentBars[1] < 0) return;
          A2(BarsArray[1]);
          }


          A2:

          protected override void Initialize()
          {
          Overlay = false;
          }
          protected override void OnBarUpdate()
          {
          Print("A2 OBU invoked.");
          }

          Base chart is of a Day period type.

          Comment


            #6
            Can you please clarify what you expect to see from -

            A2(BarsArray[1]);

            Did you try with my supplied code sample that would actually set a value to plot?
            BertrandNinjaTrader Customer Service

            Comment


              #7
              I expected to see prints at the Output window that says "A2 OBU invoked." for every A2 OBU call for each bar of the BarsArray[1] was passed to it.

              About your suggestion, I had to change:

              Plot0.Set(A2(BarsArray[1])[0]);

              to:

              Plot0.Set(A2(BarsArray[1], 1)[0]);

              in order for it to compile but even afterwards, result was the same - only one plot on the chart.

              So... Any idea why nothing prints? I'm clearly missing some basic thing here.

              Comment


                #8
                Since you never request a value from the method, it would not be called - as such you don't see your embedded prints - try for example -

                double test = A2(BarsArray[1])[0];

                Without plotting anything...it should trigger your prints, as A2 bar update would be called then.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Oh, OK. I'll try that.

                  Might as well worth adding it to your great Help article at:

                  Comment


                    #10
                    Couldn't get it to work. Please take a look at the attached scripts.
                    Attached Files

                    Comment


                      #11
                      Please just try accessing a double value from your called script, like I provided in my example call.

                      The variable here you try to access was never exposed to be accessed by another script.

                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        DAMN! you were totally right!

                        Sorry for not sticking with the original case I presented. It's just that the whole plotting this is unfamiliar to me as I only use horizontal lines and prints in my indicators.

                        From the tests I made I found out that by calling Update(), I was able to invoke the OBU of the remote indicator even without accessing a variable. Same thing is what made your instruction work - calling a var is basically activating its get property which suppose to include a call to Update().

                        Please verify or correct the statements I've made.

                        Comment


                          #13
                          You are welcome and correct - the Update() would be needed here to ensure the called script OBU() is called before the variable is returned, so it's up to date. If you expore or access a series this would not be needed. The reason is that NT's internal model is optimized to avoid any unneeded calls for performance.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Bertrand, thank you for all your help.

                            I have another issue. Is there any reason why I'm able to see prints but not horizontal lines using the following script?

                            A1

                            protected override void Initialize()
                            {
                            Overlay = true;
                            Add(PeriodType.Day, 1);
                            }
                            protected override void OnBarUpdate()
                            {
                            if (BarsInProgress == 0)
                            {
                            Print("A1 OBU invoked on CurrentBar " + CurrentBar);
                            Print(" ");
                            }
                            if (BarsInProgress == 1)
                            {
                            A2(BarsArray[1]).Update();
                            }
                            }


                            A2

                            protected override void Initialize()
                            {
                            Overlay = true;
                            }
                            protected override void OnBarUpdate()
                            {
                            Print("A2 OBU invoked on CurrentBar " + CurrentBar);
                            DrawHorizontalLine("line1", 1400.00, Color.Blue);
                            DrawHorizontalLine("line2", Close[0], Color.Blue);
                            Print(" ");
                            }
                            Attached Files

                            Comment


                              #15
                              You're welcome, only strategies could Add other indicators for display purposes - http://www.ninjatrader.com/support/f...ead.php?t=3228

                              You just call a value from an indicator, you could not add other indicators through your script.
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by funk10101, Today, 09:43 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post funk10101  
                              Started by pkefal, 04-11-2024, 07:39 AM
                              11 responses
                              37 views
                              0 likes
                              Last Post jeronymite  
                              Started by bill2023, Yesterday, 08:51 AM
                              8 responses
                              44 views
                              0 likes
                              Last Post bill2023  
                              Started by yertle, Today, 08:38 AM
                              6 responses
                              26 views
                              0 likes
                              Last Post ryjoga
                              by ryjoga
                               
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              24 views
                              0 likes
                              Last Post algospoke  
                              Working...
                              X