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

Tick chart indicator

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

    Tick chart indicator

    Hi I am trying to program a basic indicator that draws a random visual (In this case a down arrow) whenever 3 bars are produced in the same minute on a tick chart. When I use the indicator on historical data it does not plot anything. Any help would be appreciated. Here's the code:

    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    Overlay = true;
    PriceTypeSupported = false;
    }


    protected override void OnBarUpdate()
    {
    if (ToTime(Time[0]) - ToTime(Time[2]) < 100);
    {
    DrawArrowDown(CurrentBar.ToString(), true, 0, High[0] + TickSize, Color.Blue);
    }
    }

    #2
    HowardM, you can't just subtract 100 from a ToTime value, because Time is not base 100. You'll have to manipulate the DateTime values to do what you want.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hi Austin, thanks for your help. I wasn't subtracting 100 from ToTime() I was subtracting the two different integer values returned from two different ToTime() functions and checking to see if the difference was less than the value of 100, which would indicate that the associated time difference fell within 1 minute.

      Comment


        #4
        Howard, either way, ToTime is not a valid comparison for times at all. Let's say, for example, the current bar is midnight (00:00:00am) and the previous bar is 11:59:59PM. If you subtract the previous bar from the current bar, you'll get a time of -235959, which is clearly not a valid time.

        You will still have to work with the actual DateTime objects to compare the times.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Ok so let me see if I understand this correctly. ToTime() is a function that returns an integer value correct? According to Ninja's help guide you can use the integer value returned from ToTime() to make comparisons with constant integer values. For example the ToTime() help guide says:


          Examples

          // Only trade between 7:45 AM and 1:45 PM
          if (ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 134500)
          {
          // Strategy logic goes here
          }


          so in the above example Ninja is using ToTime and comparing it to an integer value. Why then can't I simply subtract the two integer values returned from two different ToTime() functions. It's simply the subtraction of two different integers correct?

          In regards to your example, that would be the only time where a negative value would be produced. After those 3 minutes during midnight, calculations will make logical sense again but that is not problematic anyway because it would not be breaking any logical/calculation rules anyway and I would disregard signals generated during those times anyway.

          Comment


            #6
            Howard, ToTime() is used to compare two times when one of the times does not change.

            I will say this again, you will have to manipulate and use the actual DateTime objects like this:
            Code:
            OnBarUpdate()
            {
              if (CurrentBar < 3) return;
            
              if (Time[0] < Time[2].AddMinutes(1))
                 DrawDot("dot" + CurrentBar, false, 0, Low[0] - TickSize, Color.Green);
            }
            AustinNinjaTrader Customer Service

            Comment


              #7
              Austin, thanks a lot for your help. Turns out my original code was actually correct. All I needed was the line:

              if (CurrentBar < 3) return;

              basically both your code and mine do the same thing, the above line was the missing piece.
              Thanks again

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by helpwanted, Today, 03:06 AM
              1 response
              14 views
              0 likes
              Last Post sarafuenonly123  
              Started by Brevo, Today, 01:45 AM
              0 responses
              11 views
              0 likes
              Last Post Brevo
              by Brevo
               
              Started by aussugardefender, Today, 01:07 AM
              0 responses
              6 views
              0 likes
              Last Post aussugardefender  
              Started by pvincent, 06-23-2022, 12:53 PM
              14 responses
              244 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              9 responses
              387 views
              1 like
              Last Post Gavini
              by Gavini
               
              Working...
              X