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

Need help with Drawing text

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

    Need help with Drawing text

    I'm a beginner with ninjaTrader, and I am trying to draw text/verticalLine/... on the prev bar on the chart but I see notning

    protectedoverridevoid OnBarUpdate()
    {
    if (CurrentBar == 1)
    {
    //DrawVerticalLine("tag1", 1, Color.Blue);
    DrawText("tag1", "AAA", 1, High[1], Color.Black);
    }
    }

    What am I doing wrong?
    Thanks



    #2
    Your condition CurrentBar == 1 is incorrect, since this paints only on bar #1.

    Should read:

    if
    (CurrentBar < 1)
    return;
    DrawText("tag1", "AAA", 1, High[1], Color.Black);

    Comment


      #3
      Originally posted by NinjaTrader_Dierk View Post
      Your condition CurrentBar == 1 is incorrect, since this paints only on bar #1.

      Should read:

      if (CurrentBar < 1)
      return;
      DrawText("tag1", "AAA", 1, High[1], Color.Black);

      Thanks,

      What is the correct syntax for drawing only on bar no.5?

      if (CurrentBar < 5)
      return;
      DrawVerticalLine("tag1", 5, Color.Blue);

      or is there another alternative?

      Comment


        #4
        Do you mean the 5th bar of the left of the chart or the 5 bars back from the current bar (which is the right most bar)?

        If the latter, then your code is correct.

        Comment


          #5
          Thanks for the help,
          Another question if I am in a for loop and I want to get the low value of index bar ago (low[index]), do I need every time in the loop do the check: if (CurrentBar < index) ?
          Note: if I don't do the check I get Error to the Log.

          What Is the correct syntax for this problem?

          Example:
          protectedoverridevoid OnBarUpdate()
          {
          for (int i = 25; i >= 0; i--)
          {
          if (CurrentBar < i)
          continue;
          Print(Low[i]);
          }
          }

          Comment


            #6
            Your approach is fine. You also could do:
            protectedoverridevoid OnBarUpdate()
            {
            if (CurrentBar < 25)
            return;


            for
            (int i = 25; i >= 0; i--)
            {
            Print(Low[i]);
            }
            }

            Comment


              #7
              Typical non-programmer question

              Hello
              As far as I understand the code :

              if (CurrentBar < 1)
              return;
              DrawText(
              "tag1", "AAA", 1, High[1], Color.Black);

              should plot a triple A at the high of the lastbut one bar ,but I can't get no plot. What am I doing wrong?
              regs
              Jojo

              Comment


                #8
                That code works as expected. Please check your log tab for any other errors you may have in your indicator.

                The code below for sure works as is.

                protected override void OnBarUpdate()
                {
                if (CurrentBar < 1)
                return;
                DrawText("tag1", "AAA", 1, High[1], Color.Black);
                }
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Sorry but I did as described , compiles with no errors. Do I miss something like declaring a font or something like this ?
                  regs

                  Comment


                    #10
                    Works as expected

                    Hi jojojo,

                    It works as outlined. Attached is an indicator that demonstrates this. You can import it via the Control Center window, File > Utilities > Import NinjaScript.
                    Attached Files
                    RayNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Ray
                      But please consider this one .It's quite identical , that's what's driving me mad.
                      Attached Files

                      Comment


                        #12
                        That's pretty clear. You need to apply different (!) tag names for different drawing objects:
                        Code:
                                protected override void OnBarUpdate()
                                {
                                    if (CurrentBar < 1)
                                        return;
                                    DrawText("tag1", "AAA", 1, High[1], Color.Black);
                                    
                                    if (CurrentBar < 5)
                                        return;
                                    DrawVerticalLine("[SIZE=4][B][COLOR=Red]tag2[/COLOR][/B][/SIZE]", 5, Color.Blue);
                                }

                        Comment


                          #13
                          Ok you can call me goofy

                          Comment


                            #14
                            Hello (still goofin around)
                            Another one : How can I plot this (example AAA)at the current price(at the right or left side) , so that the plot is moving up and down with the incoming ticks like a cursor?

                            regs
                            Jojo

                            Comment


                              #15
                              How about:
                              DrawText("tag1", "AAA", 1, Close[0], Color.Black);

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by PaulMohn, Today, 12:36 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post PaulMohn  
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              38 views
                              0 likes
                              Last Post love2code2trade  
                              Started by alifarahani, Today, 09:40 AM
                              2 responses
                              14 views
                              0 likes
                              Last Post alifarahani  
                              Started by junkone, Today, 11:37 AM
                              3 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by frankthearm, Yesterday, 09:08 AM
                              12 responses
                              44 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X