Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentDayOHL to get NetChange since Open

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

    CurrentDayOHL to get NetChange since Open

    Hi,

    I have coded a simple indicator to display the 'net change since open' for my instruments in Market Analyzer. Below is the code I have in OnBarUpdate.

    double myOpen = CurrentDayOHL().CurrentOpen[0];
    double percentChange = Math.Round(((Close[0] - myOpen) / myOpen) * 100, 2);
    PC.Set(percentChange);


    The issue I am having with the use of the CurrentDayOHLindicator is that the value returned by CurrentDayOHL().CurrentOpen[0] is the value of the Open at the time when the Market Analyzer is started. So, if I start the Analyzer at 10EST, then the value of the open is the value at 10EST and not 9:30EST.

    If I refresh the analyzer, the value of myOpen becomes the value of Open at the time the refresh is done.

    I thought the value returned by CurrentOpen would be static - Open of the day. What is the right way to use this indicator in MA.

    thanks

    #2
    Hi Vishalct,

    Thank you for posting.

    CurrentDayOHL will return the current sessions OHL. However, if those values change it will grab the current Open, High and Low from the current time, not necessarily the first bar of the session/day.

    If you are looking to get the opening bar of the session you can use Bars.FirstBarOfSession to be able to grab that data and use it for your indicator.

    See the link below on the Bars.FirstBarOfSession
    http://www.ninjatrader.com/support/h...rofsession.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Well, Bars.FirstBarOfSession has the same issue. If the list gets refreshed for some reason then the Open price becomes the Open price at the time of refresh. You can try below code at your end -

      if (Bars.FirstBarOfSession)
      myOpen = Open[0];
      double percentChange = Math.Round(((Close[0] - myOpen) / myOpen) * 100, 2);
      NC.Set(percentChange);

      Add the indicator to the Market Analyzer, let it run for a few minutes then do 'Reload Ninjascript'. After the refresh the value of the indicator will get reset.

      Comment


        #4
        Hi Vishalct,

        What kind of data you using for the indicator? E.G. Tick, minute, day?

        Please be aware that the Marker Analyzer will load 50 bars back by default. E.G. if you load a 1 minute data it will only look 50 minutes back.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Got it now. My # of bars lookback was set to 1. That was the issue.
          Thanks

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          150 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          6 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          6 views
          0 likes
          Last Post tkaboris  
          Working...
          X