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 beginner

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

    #16
    Thank you. New question on multi time frame:

    If I call a moving average on "if(BarsInProgress == 1)" timeframe, will the lines of this moving average show on my primary time frame chart?

    And how do I call this moving average in my program? Just "SMA(10)" under OnBarUpdate does not work.

    Comment


      #17
      Hello,

      Thank you for the reply.

      If I call a moving average on "if(BarsInProgress == 1)" timeframe, will the lines of this moving average show on my primary time frame chart?
      Unfortunately not, Calling a indicator would not add the indicator at all but only provide you with a Value when you call it. To visualize what Values that indicator is producing, you would need to Plot that data.

      You could do this either by adding the secondary series to the indicator its self (in its code) and Plot the values based on that secondary series, or if you are working in an Indicator that calls another indicator, the calling indicator could Plot the data as well.

      In either case, you need to set up a Plot and assign data to that Plot for it to be visualized.


      To call any indicator, you would use its name so the syntax you have provided is correct for the actual Call of the indicator or:

      Code:
      SMA(20)
      To get the Value, you need to specify a BarsAgo or:

      Code:
      SMA(20)[0]
      or

      Code:
      double mySmaPrice = SMA(20)[0];

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #18
        Next question;

        My code is drawing two rectangles on the primary chart from calculations on "BarsInProgress == 1"
        The rectangles are disappearing after a certain time period when a recalculation is done and new rectangles appear.
        How can I code this so these drawing objects remain on the chart? I cannot find help on this.

        Comment


          #19
          Hello,

          To retain objects they would need unique tag names. By the description, it sounds like you are only using 1 tag for each rectangle or 2 total tags.

          The most simple way to make a unique tag would be to append the bar number to the string or:

          "MyTagName" + CurrentBar

          This would ensure a new object is added for each new bar.


          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #20
            Thanks. To try to simplify my question, what I am trying to do is having a line show on my 1000 tick primary chart calculated starting from the close of a 45 minute bar ending at the close of the next 45 bar on my "if (BarsInProgress) ==1" background chart.

            If I use "tag1" + CurrentBar in DrawLine() in the 45 min background chart the line shows up from one close to next close on the 1000 tick primary chart, not from close to close on the 45 min background chart. This has me puzzled.

            Comment


              #21
              My last post was confusing. The line I am speaking of is a horizontal line, beginning at the close of a 45 min bar and ending at the close of the next 45 min bar. The line is a midpoint of a range established by 45 minutes.

              Comment


                #22
                Here is a code snippet: I have substituted "Count" for "CurrentBar" but line is still not showing on primary chart. It does work on a 45 min chart by itself.


                Add(PeriodType.Minute, 45);

                if(BarsInProgress == 1)
                {
                double x = (High[0] + Low[0] + Close[0]) / 3;

                DrawLine("mytag" + Count, true, 0, x, -1, x, Color.White, DashStyle.Dash, 4);
                }

                Comment


                  #23
                  Hello,
                  I do see a horizontal line plotting on the 1000 tick chart when testing the code snippet on my end. It appears to only last for one bar on the Tick chart. Can you verify if you see the same and also what you are expecting?
                  I have attached a picture of my chart with how the horizontal lines appear on my end.

                  I look forward to your reply.
                  Attached Files
                  Cody B.NinjaTrader Customer Service

                  Comment


                    #24
                    Thanks. Yes I can verify that is what I see too, but not what I was expecting. What I was trying for was a horizontal line 45 minutes long on the primary chart representing the pivot point of a 45 minute range.

                    Strangly enough, if an arbitrary number like -199 is placed in the endBarsAgo pararameter like:

                    DrawLine("tag1" + Count, true, 0, x, -199, x, Color.White, DashStyle.Dash, 4);

                    in the "if(BarsInProgress ==1" code, the line appears in the primary chart but with no control of its ending.

                    Comment


                      #25
                      Hello,
                      To have the DrawLine go through the entire time period of the secondary data series you will want to set the start and end times of the line to be the time of the current bar and the time of the next bar.

                      I have provided an example below of how you can do this:
                      Code:
                      protected override void Initialize()
                      {
                      	Add(PeriodType.Minute, 45);
                      	Overlay				= true;
                      	
                      }
                      protected override void OnBarUpdate()
                      {
                      	if(BarsInProgress == 1)
                      	{ 
                      	double x = (High[0] + Low[0] + Close[0]) / 3;
                      
                      	DrawLine("mytag" + CurrentBar, true, Times[1][0], x, Times[1][-1], x, Color.Black, DashStyle.Dash, 4);
                      	}
                      }
                      For more information on Times please see the following link: http://ninjatrader.com/support/helpGuides/nt7/times.htm
                      Cody B.NinjaTrader Customer Service

                      Comment


                        #26
                        Thanks, your post was very helpful.

                        To synchronize with a fellow trader I need "Times [1][-1]", (The first 45 min bar) to start or end at 00000 or some 45 minute start thereafter that would cause a historical bar to start at 00000. For example 6:45. Right now the start is 15 minutes early.

                        Is this possible?
                        Last edited by Pete77; 10-05-2016, 12:27 PM.

                        Comment


                          #27
                          I have a new question:

                          I have a horizontal line, create by code in the if( BarsInProgress = =1) area that appears on the primary chart. The Y value of this line will change periodically.

                          I would like to set an alarm when price goes above this line. Lets call this line's value x. This would be an audio alarm which I would call in the secondary area.

                          I assume I should maybe make value "x" a DataSeries object. Can a y value be DataSeries object?

                          If so in my primary variables region I will assign "private DataSeries myDataSeries;"

                          But I am at a total loss how and where to initialize this, and cannot find any examples for same.

                          Thanks for any help.
                          Last edited by Pete77; 10-12-2016, 12:39 PM.

                          Comment


                            #28
                            Hello,

                            Thank you for the question.

                            assume I sould maybe make value "x" a DataSeries object. Can a y value be DataSeries object?
                            Let us assume that value x is a DataSeries, in this case the Close prices and value y is a double or the lines Y price.

                            To detect a Cross of prices, you could use the existing CrossAbove or CrossBelow methods.


                            Code:
                            double myYPrice = 2000;
                            if (CrossAbove(Closes[1], myYPrice, 1))
                            {
                               Alert(....);
                            }
                            You could also form an if statement using only Prices to detrmine if one is greater than the other:

                            Code:
                            double myYPrice = 2000;
                            if (Closes[1][0] > myYPrice)
                            {
                               Alert(....);
                            }
                            If you wanted to make the Y prices a DataSeries, that would also be acceptible as the Cross methods also support this, or you could use Prices once again :

                            Code:
                            if (CrossAbove(Closes[1], MyYDataSeries, 1))
                            {
                               Alert(....);
                            }
                            Code:
                            if (Closes[1][0] > MyYDataSeries[0])
                            {
                               Alert(....);
                            }

                            I look forward to being of further assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #29
                              New question:

                              I am not able to use data series "Closes" in this case. I will try to explain better.

                              What I am trying to do is create an alarm when prices close above the top line of a rectangle in my secondary "if BarsInProgress == 1" chart.

                              This rectangle is the length of a 45 min bar so there is no Closes during the length of this rectangle except in the primary 1 minute chart.

                              I am at a loss of how to identify price in the secondary chart or carry the y value of the line to the primary chart. Any ideas would be appreciated.

                              Comment


                                #30
                                Hello,

                                If you are setting the rectangle using a price, you already know the target price which could be saved as a variable for later use. You would need to set that price to a variable where you create the rectangle.


                                A very simple example of storing a value to use between the BarsInProgress logic would be as follows:


                                private double storedPrice = 0;
                                protected override void OnBarUpdate()
                                {
                                if(BarsInProgress == 0)
                                {
                                storedPrice = Close[0]; // or a price you set the rectangle at.
                                }
                                else if (BarsInProgress == 1)
                                {
                                if(Close[0] > storedPrice) //bar closed greater than the stored price.
                                }
                                }

                                I look forward to being of further assistance.
                                JesseNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by usazencort, Today, 01:16 AM
                                0 responses
                                1 view
                                0 likes
                                Last Post usazencort  
                                Started by kaywai, 09-01-2023, 08:44 PM
                                5 responses
                                603 views
                                0 likes
                                Last Post NinjaTrader_Jason  
                                Started by xiinteractive, 04-09-2024, 08:08 AM
                                6 responses
                                22 views
                                0 likes
                                Last Post xiinteractive  
                                Started by Pattontje, Yesterday, 02:10 PM
                                2 responses
                                21 views
                                0 likes
                                Last Post Pattontje  
                                Started by flybuzz, 04-21-2024, 04:07 PM
                                17 responses
                                230 views
                                0 likes
                                Last Post TradingLoss  
                                Working...
                                X