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

OnPriceChange ?

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

    OnPriceChange ?

    Hi,

    On daily chart, which function is called every tick the price changes?
    for example, while I'm connected to live data stream, I want to Print("Tick") every time
    the price changes on the chart .
    Last edited by bassam; 11-07-2013, 02:48 PM.

    #2
    Hello bassam,

    While, there is nothing inside of NinjaTrader that will only update when the price as changed you may use the CalculateOnBarClose (COBC) set to false so that you can see price action on every Tick as it is coming in and then use a variable to store what the last price was to tell when there is a change for example:

    Code:
    double priceChange = 0;
    
    protected override void Initialize()
    {
           CalculateOnBarClose = false;
    }
    
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    	if(Close[0] != priceChange)
            {
                    Print("Tick");
                    priceChange = Close[0];
            }
    }
    JCNinjaTrader Customer Service

    Comment


      #3
      Thanks JC for your response.

      It's not exactly what I'm looking for, in my indicator there is a line that starts from Close[0] , every time the price changes the line falls behind the price, so I have to redraw the line again by mouse click event.

      Now I want that to be automatic ( no need to click the chart every time for update), so every time the price changes the line got redrawn again from new Close[0] position ( CalculateOnClose should be True).
      Last edited by bassam; 11-07-2013, 03:57 PM.

      Comment


        #4
        Hello bassam,

        The snippet I sent was just an example of how you could check to see if the price has changed and Print out in the Output window "Tick" when this happens.

        Could you clarify what you mean by your line falls behind the price? Do you mean that the line is not updating when the price changes?
        JCNinjaTrader Customer Service

        Comment


          #5
          yes exactly, the line is not updating when the price changes. It's not supposed to update on its own
          as I have a mouse click event handler, and every time I click the chart the line gets updated.

          On daily chart, the close price ( when you are connected to live data feed) changes every tick and the change displays on the price marker.

          Now, I want to catch this event to use it to update the line position.

          Hope it's clear.

          Edit:
          I suspect I have to use Close[-1] (Close[0] is last save data (yesterday)), but I'm not able to test that as Simulation feed connection does not change anything on the chart even after reopening it.

          Comment


            #6
            Hello Bassam,

            Thank you for your response.

            In this case you would set CalculateOnBarClose to false so that the OnBarUpdate() method is called on each tick.

            For information on CalculateOnBarClose please visit the following link: http://www.ninjatrader.com/support/h...onbarclose.htm

            Please let me know if I may be of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Christopher_R, Today, 12:29 AM
            0 responses
            6 views
            0 likes
            Last Post Christopher_R  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            166 responses
            2,235 views
            0 likes
            Last Post sidlercom80  
            Started by thread, Yesterday, 11:58 PM
            0 responses
            3 views
            0 likes
            Last Post thread
            by thread
             
            Started by jclose, Yesterday, 09:37 PM
            0 responses
            7 views
            0 likes
            Last Post jclose
            by jclose
             
            Started by WeyldFalcon, 08-07-2020, 06:13 AM
            10 responses
            1,415 views
            0 likes
            Last Post Traderontheroad  
            Working...
            X