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

resetting indicators

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

    resetting indicators

    Hi. I am still new to Ninjatrader development. The functionality of the attached indicator is to simply print arrows based on the number of variables that occur within a certain number of seconds. They are datetimes. I manually set their values because this is just one small piece of a bigger puzzle I don't have access to so that's why I am manually setting them for now:

    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    Overlay = true;
    DateTime Now = System.DateTime.Now;
    SpanThreshold = SpanThreshold.AddMilliseconds(-100000);

    UpTriangleTime=UpTriangleTime.AddMilliseconds(-100009);
    DownTriangleTime=DownTriangleTime.AddMilliseconds( 7);

    lastdowncarattime=lastdowncarattime.AddMillisecond s(5);
    lastupcarattime=lastupcarattime.AddMilliseconds(-100009);

    pricebelowbluetime=pricebelowbluetime.AddMilliseco nds(-100009);
    priceabovebluetime=priceabovebluetime.AddMilliseco nds(5);

    lastupdottime=lastupcarattime.AddMilliseconds(-100009);
    lastdowndottime=lastdowncarattime.AddMilliseconds( 777);

    yelbelowbluetime=yelbelowbluetime.AddMilliseconds(-100009);
    yelabovebluetime=yelabovebluetime.AddMilliseconds( 1);

    }

    but the indicator repaints on every bar, is there code in the wrong place?
    Attached Files

    #2
    dirtybrown,

    You should not place things in the Initialize() method like that. If you want something only run once please use if (CurrentBar == 0 && FirstTickOfBar) at the beginning of OnBarUpdate().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      dirtybrown,

      You should not place things in the Initialize() method like that. If you want something only run once please use if (CurrentBar == 0 && FirstTickOfBar) at the beginning of OnBarUpdate().
      hmm, Ok I initialized the variables like this:

      if (CurrentBar == 0 && FirstTickOfBar) {


      DateTime Now = System.DateTime.Now;
      SpanThreshold = SpanThreshold.AddMilliseconds(-100000);

      UpTriangleTime=UpTriangleTime.AddMilliseconds(-100009);
      DownTriangleTime=DownTriangleTime.AddMilliseconds( 7);

      lastdowncarattime=lastdowncarattime.AddMillisecond s(5);
      lastupcarattime=lastupcarattime.AddMilliseconds(-100009);

      pricebelowbluetime=pricebelowbluetime.AddMilliseco nds(-100009);
      priceabovebluetime=priceabovebluetime.AddMilliseco nds(5);

      lastupdottime=lastupcarattime.AddMilliseconds(-100009);
      lastdowndottime=lastdowncarattime.AddMilliseconds( 777);

      yelbelowbluetime=yelbelowbluetime.AddMilliseconds(-100009);
      yelabovebluetime=yelabovebluetime.AddMilliseconds( 1);
      return;

      }

      but still getting the repaints
      Attached Files

      Comment


        #4
        Please describe what you mean by repaints. Your draw objects are given unique names so your indicator will keep adding more and more objects.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          Please describe what you mean by repaints. Your draw objects are given unique names so your indicator will keep adding more and more objects.
          I'm running this on a 1 tick chart with a straight line printing instead of candlestick. When the new tick comes though, the indicator reprints itself on the at the top (or bottom) of the previous tick. See attachment
          Attached Files

          Comment


            #6
            You should not give each tick a new unique name for the object. You should only give it unique names as per bar.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              You should not give each tick a new unique name for the object. You should only give it unique names as per bar.
              I thought about that and tried drawing like this:

              DrawArrowUp("up1", 0, Low[0] - x, Color.Green);

              Doesn't seem to make a different for me at least. Is there another way I should be naming it?

              Comment


                #8
                Not sure I follow. When you use a static name any future calls to that same signal name will modify the old object instead of drawing a new object. If you have additional objects with other names then those will be shown as well.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  Not sure I follow. When you use a static name any future calls to that same signal name will modify the old object instead of drawing a new object. If you have additional objects with other names then those will be shown as well.
                  I only want the arrow to print when the conditions given are true. I tried to give it a dynamic name like this:


                  /DrawArrowUp("t"+ CurrentBar.ToString(), 0, Low[0] - x, Color.Green);

                  and the same thing happens, the previous print of the indicator disappears and it's redrawn on a new tick.

                  I think maybe I need to move the for loop to a lower scope

                  Comment


                    #10
                    If you are using loops it could be the cause of redrawing itself. If you want the objects to "disappear" please use RemoveDrawObject().
                    Josh P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by PhillT, Today, 02:16 PM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by Kaledus, Today, 01:29 PM
                    3 responses
                    9 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by frankthearm, Yesterday, 09:08 AM
                    14 responses
                    47 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by gentlebenthebear, Today, 01:30 AM
                    2 responses
                    13 views
                    0 likes
                    Last Post gentlebenthebear  
                    Started by PaulMohn, Today, 12:36 PM
                    2 responses
                    17 views
                    0 likes
                    Last Post PaulMohn  
                    Working...
                    X