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

UpTick or DownTick

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

    UpTick or DownTick

    On a tick chart , is there a direct way in indicator code to find out if the last tick was up or was down?
    Or any example of code doing that please?

    Or do I need to temporarily store the value of the prior tick then compare with the current tick?

    #2
    Hello,

    Thank you for the question.

    This would depend, if you are on a 1 tick chart, you could compare the Close[0] is greater or less than the Close[1]. This is just saying to compare the close of the current bar to the close of the last bar. This would work as an indicator on a 1 tick chart.

    For greater times such as a 100 tick chart, more logic would be required to either Add a 1 tick series and use logic to check this, or to use live market data ticks and logic.

    There are multiple ways to accomplish this depending on what the intended use would be. If you can provide more detail on the timeframe it would be used with or where it would be applied, I can provide a more specific example.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      It would normally be something like a 70 tick chart.

      So there isn't something like Close[0].Tick[1].CompareTo( Close[0].Tick[0] ) ? 'Down' : 'Up' ;

      Based on code from the Heiken-Ashi indicator, I can check on each tick if the bar is still a bull bar or a bear bar. It checks if the y-coordinate of the bar is smaller or larger than where it was at the open of the bar using ChartControl.GetYByValue

      But I'd like to compare tick by tick not just compared to the open of the current bar.

      Comment


        #4
        Hello,

        For tick by tick on any series, you could use OnMarketData or an added series.

        A couple of examples would be:

        Code:
        double lastTick;
        protected override void OnMarketData(MarketDataEventArgs e)
        {
        	if(e.MarketDataType == MarketDataType.Last)
        	{
        		if(e.Price > lastTick)
        		{
        			Print("Up");	
        		} 
        		else if(e.Price < lastTick)
        		{
        			Print("Down");
        		}
        		lastTick = e.Price;
        	}
        }
        This would take each incoming last tick and compare it to the previous tick.

        Another way woud be to add a 1 tick series, the statement below could be consolidated into a statement similar to the one you provided:
        Close[0].Tick[1].CompareTo( Close[0].Tick[0] ) ? 'Down' : 'Up' ;

        Code:
        protected override void Initialize()
        {
        	Add(PeriodType.Tick, 1);
        }
        
        protected override void OnBarUpdate()
        {
        	if(BarsInProgress == 1)
        	{
        		if(CurrentBars[1] >0)
        		{
        			if(Closes[1][0] > Closes[1][1])
        			{
        				Print("Up");	
        			}
        			else if(Close[0] < Close[1])
        			{
        				Print("down");	
        			}
        		}
        	}
        }
        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by jclose, Today, 09:37 PM
        0 responses
        5 views
        0 likes
        Last Post jclose
        by jclose
         
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        10 responses
        1,413 views
        0 likes
        Last Post Traderontheroad  
        Started by firefoxforum12, Today, 08:53 PM
        0 responses
        11 views
        0 likes
        Last Post firefoxforum12  
        Started by stafe, Today, 08:34 PM
        0 responses
        11 views
        0 likes
        Last Post stafe
        by stafe
         
        Started by sastrades, 01-31-2024, 10:19 PM
        11 responses
        169 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X