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

draw.text question

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

    draw.text question

    Hello-

    One chart has 1 series but multiple time frames.

    Let's say I have time frame 1 and time frame 2. The bars of TF1 are visible, TF2 are not visible. My indicator calculates a value for TF2, but I want to print it on my chart a few ticks above or below the visible TF1 bars.

    Is there a way to do this?

    Thank you.

    #2
    Hello imalil,

    Thanks for your post.

    Yes, what you would need to do in your indicator is add the 2nd data series so that the data is available to the indicator (FYI- the indicator would only know of the charts primary series so even though you may show two data series the indicator only know of the first (primary) data series on the chart).

    Once the data is added, you can then reference the added data by either BarsArray[1] or plurals of OHLC, such as Opens[1], Highs[1], Lows[1], Closes[1] to calculate your value.

    Finally then to print on the primary series you would need to use BarsInProgress = 0 so that the Draw.Text is properly aligned with the charts primary series. Here is a short example to further clarify:

    if (BarsInProgress !=0 ) return; // only process based on primary series

    double myCalcValue = Highs[1][0] - Lows[1][0] / TickSize; // number of ticks in secondary data series bar

    Draw.Text(this, "myText"+CurrentBar, myCalcValue.ToString(), 0, High[0]+ 5 * TickSize); // show the calculated value 5 ticks above the high on the primary series


    References:







    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for this information, it's making sense. But I think I need to give more detail on my setup just so there's no confusion.

      On 1 chart I have 3 time frames with 1 instrument:
      TF1 (primary with visible bars) 100 tick bars
      TF2 200 tick bars (not visible)
      TF3 300 tick bars (not visible)

      The indicator I am using is loaded on the chart 3 times: 1 for TF1, 1 for TF2, 1 for TF3. It calculates unique values for each TF.

      The indicator for TF1 of course prints perfectly above or below its bars.

      On TF2 and TF3, am I supposed to modify the indicator for each of these TF? So I will essentially have 3 indicators that are the same except for the print changes you mentioned earlier?

      On what TF's indicator do I load the changes you sent earlier?

      Multiple TF is new to me; sorry for the beginner question.

      I hope this is clearer.

      Thank you.

      Comment


        #4
        Hello imalil,

        Thanks for your reply.

        To accomplish your goal of printing on the 100 tick chart, you would have to create a multi-time frame indicator that adds the 200 tick bars and 300 tick bars and then references the data from those series for whatever calculations you make then use the Draw.Text() in the BarsInProgress = 0 section to print on the charts 100 tick bars.

        You would not need to add the 200 & 300 tick bars to the chart as they are added into the indicator. You would only need one instance of this indicator.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks. So using your example:

          if (BarsInProgress !=0 ) return; // only process based on primary series

          double myCalcValue = 200; // number of ticks in secondary data series bar
          double myCalcValue2 = 300; // number of ticks in third data series bar

          Draw.Text(this, "myText"+CurrentBar, myCalcValue.ToString(), 0, High[0]+ 5 * TickSize); // show the calculated value 5 ticks above the high on the primary series

          Draw.Text(this, "myText"+CurrentBar, myCalcValue2.ToString(), 0, High[0]+ 15 * TickSize); // show the calculated value 15 ticks above the high on the primary series

          Since I'm guessing there is an error, Please tell me where it is.

          Thank you for your help.

          Comment


            #6
            Hello imalil,

            Thanks for your reply.

            You would need to change the tagname on the 2nd instance as otherwise one will be replaced by the other as they may have the same tagname if shown on the same bar.

            So from "myText"+CurrentBar to perhaps "myTexta"+CurrentBar
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hello-
              I never finished this because I started doing other things.
              I have a multi time frame chart, 100, 200, 300 tick bars.

              The primary data series is a 100 tick bar chart. Here's what I have so far:
              else if (State == State.Configure)
              {
              AddDataSeries(BarsPeriodType.Tick, (200));
              AddDataSeries(BarsPeriodType.Tick, (300));
              }
              in OnBarUpdate():
              if (BarsInProgress !=0 ) return;
              double Var1 = first value to print;
              double Var2 = second value to print;
              double Var3 = third value to print;
              My goal is to print each of these variables via draw.text on the multi time frame chart whenever my conditions are true for each data series.

              For example:
              if (my conditions are true for data series 2)
              Print Var1, Var2, Var3 via draw.text for data series 2. (which will have a unique color)

              Same goes for data series 1 and 3.

              I do not know how to identify in my if and print statements whether I'm referring to data series 1, 2 or 3.
              How do I call a specific data series in an if and print statement?

              Thank you.

              Comment


                #8
                Originally posted by imalil View Post
                Hello-
                I never finished this because I started doing other things.
                I have a multi time frame chart, 100, 200, 300 tick bars.

                The primary data series is a 100 tick bar chart. Here's what I have so far:


                in OnBarUpdate():






                My goal is to print each of these variables via draw.text on the multi time frame chart whenever my conditions are true for each data series.

                For example:
                if (my conditions are true for data series 2)
                Print Var1, Var2, Var3 via draw.text for data series 2. (which will have a unique color)

                Same goes for data series 1 and 3.

                I do not know how to identify in my if and print statements whether I'm referring to data series 1, 2 or 3.
                How do I call a specific data series in an if and print statement?

                Thank you.
                BarsInProgress? Just in the manner that you have already used it, but filtering for 1, 2 or 3 instead of 0?

                Comment


                  #9
                  if (BarsInProgress !=0 ) return; is there because I want to print all data series above/below the primary bars. This was my first question of this thread.

                  Are you saying I should copy/paste three instances of identical code with "if BarsInProgress==0 or if BarsInProgress ==1 or if BarsInProgress ==2" in front of it, give each data series unique variables and print those?

                  I know this is basic stuff, but I've never done multi time frame before and I don't know how to do it.

                  Thank you.

                  Comment


                    #10
                    Originally posted by imalil View Post
                    if (BarsInProgress !=0 ) return; is there because I want to print all data series above/below the primary bars. This was my first question of this thread.

                    Are you saying I should copy/paste three instances of identical code with "if BarsInProgress==0 or if BarsInProgress ==1 or if BarsInProgress ==2" in front of it, give each data series unique variables and print those?

                    I know this is basic stuff, but I've never done multi time frame before and I don't know how to do it.

                    Thank you.
                    You can do that, or you can be more efficient, and use a switch statement.

                    Comment


                      #11
                      I'll provide a little more clarity in case I get NT CSR to respond.

                      I have a very long and involved indicator that produces many values which are printed above and below the bars of many tick time frames. One data series per chart. I have no problem with this. As long as I'm working with one data series, I can get things to print where I want above/below the bars.

                      My goal is to have a chart with three data series: same instrument, different tick sizes. I want these data series to run the exact same indicator and print only three or less of my indicator's values above/below the primary data series' bars.

                      If the primary data series' print conditions are true, I want draw text to print the three values above/below the primary data series bars.

                      If the second data series' print conditions are true, I want draw text to print the three values above/below the primary data series bars.

                      If the third data series' print conditions are true, I want draw text to print the three values above/below the primary data series bars.

                      So far I have:

                      else if (State == State.Configure)
                      {
                      AddDataSeries(BarsPeriodType.Tick, (200));
                      AddDataSeries(BarsPeriodType.Tick, (300));
                      }
                      in OnBarUpdate():
                      Quote:
                      if (BarsInProgress !=0 ) return;
                      Quote:
                      double Var1 = first value to print;
                      Quote:
                      double Var2 = second value to print;
                      Quote:
                      double Var3 = third value to print;

                      If I write "if (BarsInProgress ==1)," for example, it will check my second data series, but when I get to "if (BarsInProgress !=0 ) return;" it won't print.

                      Keep in mind this indicator is extremely long; I'm calculating many values before I get to Var1-3.

                      It's not making sense to me how I can run the same code for three data series on one chart and print it how I want it to print.

                      I'd appreciate any help.
                      Thank you.

                      Comment


                        #12
                        Hello imalil,

                        Thanks for your posts.

                        Using a quick example, let's say that you want to know the current value of a 10 period SMA on each of the 3 data series (chart bars 100tick, added 200 tick and added 300 tick).

                        if (CurrentBars[0] < 10 || CurrentBars[1] < 10 || CurrentBars[2] < 10) // do not proceed until 10 bars in each series has been loaded for the SMAs
                        return;

                        if (BarsInProgress !=0 ) return; // process on the chart bars call because we want to draw on the chart.

                        Draw.Text(this, "myTexta"+CurrentBar, SMA(Closes[0], 10)[0].ToString(), 0, High[0]+ 5 * TickSize); // show the SMA from the 100tick series 5 ticks above the high on the primary series(Chart bars)

                        Draw.Text(this, "myTextb"+CurrentBar, SMA(Closes[1], 10)[0].ToString(), 0, High[0]+ 10 * TickSize); // show the SMA from the 200 tick series 10 ticks above the high on the primary series (Chart bars)

                        Draw.Text(this, "myTextc"+CurrentBar, SMA(Closes[2], 10)[0].ToString(), 0, High[0]+ 16 * TickSize); // show the SMA from the 300 tick series 15 ticks above the high on the primary series (Chart bars)


                        Closes[0] is the close price series of the chart bars, Closes[1] is the 200 tick, Closes[2] is the 300 tick. When the chart bars call OnBarUpdate, the code will process and will pull the current value of the 10 period SMA of each data series to then print on the chart above the current bar on the chart.

                        Please note I have shown using SMA in this manner for clarity of the example, in normal use I would have created a local instance according to best practices here: https://ninjatrader.com/support/help..._practices.htm

                        The helpguides section on MultiTimeFrame is the best guide for understanding how to code for MT, here is the link: https://ninjatrader.com/support/help...nstruments.htm
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          You have:
                          if (BarsInProgress !=0 ) return;
                          That line says in English: "if the BarsInProgress is 1, 2, or any other number that is not zero, do not process any further lines after this line." i.e., "if this tick comes from anything other than the primary bar series on the chart, stop processing and wait for the next tick."

                          So, of course, the program does as you have instructed. Start by getting the logic of your statements in order. After that, the code is somewhat trivial to write. If you want to process ticks from other bar series, then do not write an earlier instruction that says to not process those ticks.

                          Comment


                            #14
                            Hello imalil and koganam,

                            To clarify, I am responding to how to print on the chart bars. I apologize for any confusion created.

                            As I do not know what calculations you (imalil) are performing it may very well be that you do need to perform as Koganam has advised. If your calculations require processing on each tick of each series then certainly you would want to separate by BarsInprogress

                            if BarsInProgress ==0)
                            {
                            ....various calculations only when BIP = 0
                            Place all of your drawtext calls here

                            Draw.Text for the BIP=0 calculation results
                            Draw.Text for the BIP=1 calculation results
                            Draw.Text for the BIP =2 calculation results
                            }
                            if (BarsInProgress == 1)
                            {
                            ... various calculations only when BIP = 1
                            }
                            ifBarsInProgress == 2)
                            {
                            various calculations only when BIP =2
                            }
                            Paul H.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks for all the info, Paul and koganam.

                              This indicator uses OnMarketData and OnBarUpdate. All the code is set to process on bar close.

                              I'm calculating many values before I get to the value I want. I realize I should be using more classes and methods, but my focus is only on getting the right value, not on efficiency. The resulting code is very long. I plan to clean it up later.

                              It has always worked fine on a single data series. And this is why I loaded the indicator three separate times on my MTF chart. It resulted in printing in bad areas of the chart and is why I started this thread in the first place.

                              It's feeling like I have to either load it three times or paste it three different times, making it three times longer than it is. I'm reading about switch but I'm a long way off from being able to use it.

                              I noticed in Paul's MACrossover indicator you use many switch statements. Is my indicator of a similar type?

                              Thank you.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by mmenigma, Yesterday, 03:25 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by kujista, Today, 05:44 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post kujista
                              by kujista
                               
                              Started by ZenCortexCLICK, Today, 04:58 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post ZenCortexCLICK  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              172 responses
                              2,281 views
                              0 likes
                              Last Post sidlercom80  
                              Started by Irukandji, Yesterday, 02:53 AM
                              2 responses
                              18 views
                              0 likes
                              Last Post Irukandji  
                              Working...
                              X