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

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
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by yertle, Today, 08:38 AM
    6 responses
    24 views
    0 likes
    Last Post ryjoga
    by ryjoga
     
    Started by algospoke, Yesterday, 06:40 PM
    2 responses
    24 views
    0 likes
    Last Post algospoke  
    Started by ghoul, Today, 06:02 PM
    3 responses
    15 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    46 views
    0 likes
    Last Post jeronymite  
    Started by Barry Milan, Yesterday, 10:35 PM
    7 responses
    23 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X