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 Set() info from OnMarketData() ??

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

    How to Set() info from OnMarketData() ??

    Hello,

    I have a price value that I retrieve from the OnMarketData() method that is the exact price of the first tick that occurs at market open(7:30am(mst)). This price is used as an exact/true market opening price. Which amazingly can be up to around a 4-5 tick difference between the true open and the open price that occurs by simply utilizing a synchronized PC clock.

    However, my problem comes in when I try to use the Set() method to keep this value for historical purposes. My indicator plots just fine as long as I am using real-time info and was connected prior to market open(7:30), but if I try to add the indicator later or look at historical charts, I cannot see view the indicator at all.

    Can I use the Set() method to save values from the OnMarketData() method?

    insomniac

    #2
    I believe so.

    Do you mean something like:

    Code:
    OnMarketData()
    {
    if (e.MarketDataType == MarketDataType.Last) myDataSeries.Set(e.Price);
    }
    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      I believe so.

      Do you mean something like:

      Code:
      OnMarketData()
      {
      if (e.MarketDataType == MarketDataType.Last) myDataSeries.Set(e.Price);
      }
      Yes, except I have to throw in:

      Code:
      OnMarketData()
              {
                  if (needOpenPrice)
                  {
                      if (e.MarketDataType == MarketDataType.Last)
                      {
                          if (ToTime(e.Time) == 73000)
                          {
                              needOpenPrice = false;
                              myDataSeries.Set(e.Price);
                          }
                      }
                  }
              }
      However I cannot seem to get it to show historically. I have even tried to Set() it within the OnBarUpdate()

      insomniac

      Comment


        #4
        I forgot, you must set the value in OnBarUpdate() since when this method is called, if you don't set it, it is internally reset.

        Declare a variable in the scope of the indicator, set the value of this variable in OnMarketData() then pas this variable in the .Set() method in OnBarUpdate().
        RayNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Ray View Post
          I forgot, you must set the value in OnBarUpdate() since when this method is called, if you don't set it, it is internally reset.

          Declare a variable in the scope of the indicator, set the value of this variable in OnMarketData() then pas this variable in the .Set() method in OnBarUpdate().
          I have tried this, but I still can't seem to get it to stick.

          insomniac

          Comment


            #6
            Then you will need to debug it as for sure that would work.

            You can work backwards, just declare a variable and se its value at declaration time, then assign this variable to .Set() in OnBarUpdate(). You will see that it works as expected.
            RayNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Ray View Post
              Then you will need to debug it as for sure that would work.

              You can work backwards, just declare a variable and se its value at declaration time, then assign this variable to .Set() in OnBarUpdate(). You will see that it works as expected.
              I don't know if I am just an idiot or what, but I can't get this to work. I am starting to believe it has to do with the fact that I have to throw in the following:

              if (ToTime(e.Time) == 73000)
              daysOpen = e.Price;

              When I am running live w/real-time data feed it works just fine. But when looking back at previous days, nothing shows up at 7:30am, and if I remove the indicator at any time, even during live connections, I can reapply the indicator and it does not show. So the only way to keep the indicator showing on the chart is to stay connected to the data feed.

              Essentially all I need is the same indicator as CurrentDayOHL(), but instead of grabbing and setting the Open Price using:

              if (Bars.SessionBreak)
              currentOpen = Open[0];

              I need it to grab and set the Open Price using OnMarketData() at exactly 7:30am.

              insomniac

              Comment


                #8
                For clarification -

                OnMarketData() and OnMarketDepth() are only called in real-time NOT against historical data.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Ray View Post
                  For clarification -

                  OnMarketData() and OnMarketDepth() are only called in real-time NOT against historical data.
                  Ray,

                  Ok, so I certainly do not want to give you sh!t, but I spoke of this very thing in my first post and my second post. So why have I been ripping my hair out for something that cannot be done, but was given suggestions on how to do it, even when I kept saying that I couldn't get it to work. As you re-read my posts, you will see that I consistently referred to Historical Charts, and in my very first post I mention that I have it working just fine in real-time.

                  I am disappointed.


                  Originally posted by insomniac View Post
                  However, my problem comes in when I try to use the Set() method to keep this value for historical purposes. My indicator plots just fine as long as I am using real-time info and was connected prior to market open(7:30), but if I try to add the indicator later or look at historical charts, I cannot see view the indicator at all.
                  Originally posted by insomniac View Post
                  However I cannot seem to get it to show historically. I have even tried to Set() it within the OnBarUpdate()

                  Comment


                    #10
                    Sorry, I did not mean to disapoint you, it was not my intention. I overlooked that piece of information and should not have.
                    RayNinjaTrader Customer Service

                    Comment


                      #11
                      Well since I don't know how to take no for an answer. Would someone be willing to help me out with coding this indicator to actually do what I am looking for it to do. I am sure that there has got to be a way to have the indicator use System.IO to Write/Read from a text file that will start to accumulate historical Opening tick prices, as I run the indicator each day, and then it can read from the file and process each past day to Set() the value of the opening price for my charts.

                      insomniac

                      Comment


                        #12
                        You could contact a consultant.

                        RayNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by GLFX005, Today, 03:23 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post GLFX005
                        by GLFX005
                         
                        Started by XXtrader, Yesterday, 11:30 PM
                        2 responses
                        11 views
                        0 likes
                        Last Post XXtrader  
                        Started by Waxavi, Today, 02:10 AM
                        0 responses
                        6 views
                        0 likes
                        Last Post Waxavi
                        by Waxavi
                         
                        Started by TradeForge, Today, 02:09 AM
                        0 responses
                        14 views
                        0 likes
                        Last Post TradeForge  
                        Started by Waxavi, Today, 02:00 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post Waxavi
                        by Waxavi
                         
                        Working...
                        X