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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        646 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        367 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        569 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X