Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Comparing prices on successive ticks

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

    Comparing prices on successive ticks

    Hi guys

    With CalculateOnBarClose = true, the price at the current bar can be compared with that of the previous bar, as in:

    Close[0] > Close[1]

    However, with CalculateOnBarClose = false, is it possible to make the same comparison with successive tick values, such as:

    Price this tick > Price previous tick ?

    If this is possible, how would this be coded?

    (Just to add that I'd be using ordinary range bars for my entry conditions. I'd use the above to code a mathematical function to define a trailing stop.)

    Thanks in advance for your help.
    Last edited by arbuthnot; 05-26-2012, 03:32 PM.

    #2
    If there isn't anything in ninja, you could always assign a variable the current price, which on the next bar, would always be the previous price

    That would be faster also.

    edit: assign at the end of OnBarUpdate when you are done using it, and 1st time through default it to something reasonable..

    Originally posted by arbuthnot View Post
    Hi guys

    With CalculateOnBarClose = true, the price at the current bar can be compared with that of the previous bar, as in:

    Close[0] > Close[1]

    However, with CalculateOnBarClose = false, is it possible to make the same comparison with successive tick values, such as:

    Price this tick > Price previous tick ?

    If this is possible, how would this be coded?

    (Just to add that I'd be using ordinary range bars for my entry conditions. I'd use the above to code a mathematical function to define a trailing stop.)

    Thanks in advance for your help.
    Last edited by sledge; 05-26-2012, 04:05 PM.

    Comment


      #3
      Sledge's solution is better (IMO), but you could also add a 1-tick data series for the instrument and do Closes[1-tick][0] > Closes[1-tick][1]

      Comment


        #4
        Originally posted by arbuthnot View Post
        Hi guys

        With CalculateOnBarClose = true, the price at the current bar can be compared with that of the previous bar, as in:

        Close[0] > Close[1]

        However, with CalculateOnBarClose = false, is it possible to make the same comparison with successive tick values, such as:

        Price this tick > Price previous tick ?

        If this is possible, how would this be coded?

        (Just to add that I'd be using ordinary range bars for my entry conditions. I'd use the above to code a mathematical function to define a trailing stop.)

        Thanks in advance for your help.
        With COBC = false, the current price is always Close[0], so to compare the current price to the previous price, you just need to save the price to a class variable, then compare on the next tick, the price that you saved on the last tick.

        Code:
        private double previousPrice = 0; //declare and initialize a class variable
        Code:
         
        if (Close[0] > previousPrice) {// do stuff} //compare current price to saved price
        previousPrice = Close[0]; // save current price to compare on next tick

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        67 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        36 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        59 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X