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

How to identify Live candle with Calculate.OnBarClose is set ?

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

    How to identify Live candle with Calculate.OnBarClose is set ?

    How to get hold of Live forming candle with setting is ( Calculate.OnBarClose) because here in this case Close[0] is already closed bar.
    So is there any way to get the hold of Live forming candle and access all the values like : Open, Close, High, Low ?














    #2
    Hello yogeshdhan78,

    Thanks for your post.

    Running an indicator or strategy with Calculate.OnBarClose means that the strategy will only process and calculate values on the close of a bar.

    To have the indicator/strategy process more frequently, you could consider setting the Calculate mode to OnPriceChange or OnEachTick. OnPriceChange means the script will process with each change in price. OnEachTick means that the script will process for each incoming tick.

    See this help guide for more information: https://ninjatrader.com/support/help.../calculate.htm

    Or, you could consider adding an additional data series to the script, such as a 1 Tick series, and print out values from that added series.

    See the help guide documentation below for more information.
    AddDataSeries: https://ninjatrader.com/support/help...dataseries.htm
    Working with Multi-Timeframe/Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm
    PriceSeries: https://ninjatrader.com/support/help...riceseries.htm

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      Pratically I don't see any difference between OnEachTick and OnPriceChange because price is changing on every tick by few cents then how it is different than OnEachTick ?

      Thanks

      Comment


        #4
        Also How to identify Live Bar ( Forming Bar ) from Click of a button instead of going to the OnBarUpdate() method ?
        Like : Close[Bars.count() - 1] or something else.
        Also it is required to get Open, Close, High, Low for the Live Bar without going to the method OnBarUpdate().
        do you provide any method what gives the Color of the live forming Bar ( Green / RED ) ?



        Comment


          #5
          Hello yogeshdhan78,

          Thanks for your notes.

          Calculate.OnPriceChange means that OnBarUpdate() will process once for each price change. If there were two ticks in a row with the same price, the second tick would not trigger OnBarUpdate(). This can improve performance if calculations are only needed when new values are possible.

          Calculate.OnEachTick means that OnBarUpdate() will process on every single tick that comes in.

          To access Open, High, Low, or Close values from the currently forming bar, you would use Calculate.OnPriceChange or Calculate.OnEachTick along with Open[0], High[0], Low[0], or Close[0] within the OnBarUpdate() method.

          To access the values for the most recently closed bar, you could use Calculate.OnPriceChange or Calculate.OnEachTick and call the PriceSeries you would like to access with a barsAgo value of 1. For example, Open[1], High[1], Low[1], or Close[1].

          To access the most current Open, High, Low, or Close values on the currently forming bar, Calculate.OnEachTick should be used along with passing a barsAgo value of 0 to the PriceSeries you are accessing to get the values for each live tick. For example, Open[0], High[0], Low[0], or Close[0].

          See the help guide pages below.
          Open: https://ninjatrader.com/support/helpGuides/nt8/open.htm
          High: https://ninjatrader.com/support/helpGuides/nt8/high.htm
          Low: https://ninjatrader.com/support/helpGuides/nt8/low.htm
          Close: https://ninjatrader.com/support/help.../nt8/close.htm

          "do you provide any method what gives the Color of the live forming Bar ( Green / RED ) ?"

          To detect an up bar (green) in a NinjaScript, you would create a condition that checks if (Close[0] > Open[0]). To detect a down bar (red) in a NinjaScript, you would create a condition that checks if (Close[0] < Open[0]).


          Let us know if we may assist further.
          Last edited by NinjaTrader_BrandonH; 03-17-2022, 02:32 PM.
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            Also How to identify Live Bar ( Forming Bar ) from Click of a button instead of going to the OnBarUpdate() method ?

            Bars LiveBar = Bars.Count(Bars.Count - 1);
            Print("LiveBar time" + LiveBar.Time + " Close " + LiveBar.Close );

            Print(" Live Bar" + Time[Bars.Count - 1] + " Close " + Close[Bars.Count - 1]);

            I want to access Live Bar onClick of a button or somewhere else in the class but not in the OnBarUpdate() method.
            When I tried above code it is giving me an error.
            Can you please help ??


            Thanks.

            Comment


              #7
              Hello yogeshdhan78,

              Thanks for your note.

              Time[Bars.Count - 1] would refer to the first bar on the chart. Since the click of a button is not a NinjaScript bar event, using Time[0] will result in the first bar on the chart or an error. You would need to surround code like Time[0] with TriggerCustomEvent to bring that code up to speed with the current processing.

              You could also consider using GetValueAt() with an index like Count.

              The easiest code is:
              Code:
              Print(Time.GetValueAt(Count-1));
              The cleanest code is:
              Code:
              TriggerCustomEvent(o =>
              {
                  Print(Time[0]);
              },null);
              See the help guide pages below for more information:

              GetValueAt: https://ninjatrader.com/support/help...getvalueat.htm
              OnRender: https://ninjatrader.com/support/help...8/onrender.htm
              TriggerCustomEvent: https://ninjatrader.com/support/help...ustomevent.htm
              Time: https://ninjatrader.com/support/help...eries_time.htm

              Let us know if we may assist further.
              Brandon H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by merzo, 06-25-2023, 02:19 AM
              10 responses
              823 views
              1 like
              Last Post NinjaTrader_ChristopherJ  
              Started by frankthearm, Today, 09:08 AM
              5 responses
              15 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              43 views
              0 likes
              Last Post jeronymite  
              Started by yertle, Today, 08:38 AM
              5 responses
              16 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by adeelshahzad, Today, 03:54 AM
              3 responses
              19 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X