Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Did Price Tick up or Tick down

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

    Did Price Tick up or Tick down

    I'm really new to programming and I'm looking for some example code that will help me determine if price has ticked up or ticked down.

    I know it's possible and probably a very simple solution but I'm struggling to understand working with tick data .vs more of the Onbar Close stuff.

    Does anyone have an example? I'm assuming it's something like getting the current price and saving that into a variable, then at some point requesting that price again and comparing the two. Am I even close?

    Thank you, any and all help is really appreciated.

    #2
    Hello jkosnikowski,

    Thanks for the post and welcome to the NinjaTrader forum.

    To check if the price has ticked up or down your indicator will need its calculation mode set to Calculate.OnEachTick. This means that the OnBarUpdate method will run on each incoming tick.

    Code:
    Calculate = Calculate.OnEachTick;
    Now to store a variable between calls to OnBarUpdate, set up a variable at the class level.

    Code:
    public class MyIndicator : Indicator
    {
    	private double myPrice = 0;
    ...
    Now in OnBarupdate, you can check if the variable is different from the last OnBarupdate:

    Code:
    protected override void OnBarUpdate()
    		{
    			if(myPrice != Close[0])
    			{
    				Print("Current price (Close[0] is different from the last recorded price (myPrice))");
    				myPrice = Close[0];
    			}
    		}
    I have attached my example indicator to this post. Please see this help guide page for instructions on importing it:


    Please let us know if we may be of any further assistance.
    Attached Files

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    24 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    120 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    63 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    45 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X