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

cannot implicitly convert 'System.DateTime' to 'double' (CS0029)

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

    #16
    I've create the new Market Analyzer column script from the Ninjascript Editor > plus Button at the bottom > New Market Analyzer Column.

    I've copy-pasted your ExposedPlotMA and updated the code as follows:

    Click image for larger version

Name:	vmplayer_7m3PnyAL3c.png
Views:	240
Size:	362.4 KB
ID:	1164944

    'Ninjatrader.Ninjascript.Indicators.myDailyBarsPri orOHLC.priorDate' is inaccessible due to its protection level

    No doc

    I checked those posts which point at 'the correct access level: usually protected or public.'


    In your ExposedPlotMA code the variable is private only (no protected nor public add).


    Click image for larger version

Name:	vmplayer_vTdkLchoRg.png
Views:	172
Size:	33.6 KB
ID:	1164945


    My Indicator code's variable:

    Click image for larger version

Name:	vmplayer_evNW9dRl8v.png
Views:	179
Size:	17.2 KB
ID:	1164946



    How do I solve the error CS0122 in context?



    The name 'CultureInfo' does not exist in the current context

    Typos


    Must have the 'using System.Globalization;' in the #region Using declarations


    CS0103 error solved.

    Comment


      #17

      CS0122

      http://https://stackoverflow.com/a/68249310/10789707

      protected still return CS0122 'Ninjatrader.Ninjascript.Indicators.myDailyBarsPri orOHLC.priorDate' is inaccessible due to its protection level:

      Click image for larger version

Name:	vmplayer_4Lc26v3R0H.png
Views:	207
Size:	539.2 KB
ID:	1164948

      public complies without error:

      Click image for larger version

Name:	vmplayer_9kKg2u47vC.png
Views:	201
Size:	472.2 KB
ID:	1164949

      Why is your code requiring a private instead of a public?

      Why does it compile on your end with private but requires public on my end?

      What difference does it make between private and public?

      Can I go with public instead of private or will it cause potential issues?

      Comment


        #18
        Hi Chris,

        I've restarted today NT8, with the priorDate variable set to type public as:

        public Series<DateTime> priorDate;

        Upon launching the Market Analyzer saved template I got this error:

        Unhandled Exception: There was an error reflecting Type 'NinjaTrader.Ninjascript.MyDailyBarsPriorOHLC'.

        Click image for larger version

Name:	explorer_qk53WkZEfP.png
Views:	154
Size:	21.5 KB
ID:	1165138

        According to Chelsea's answer here:

        https://ninjatrader.com/support/foru...73#post1044873


        The priorDate variable should be set back to private type as:


        private Series<DateTime> priorDate;

        When I set it back to private,
        I get back the previous error CS0122 'Ninjatrader.Ninjascript.Indicators.myDailyBarsPri orOHLC.priorDate' is inaccessible due to its protection level :

        Click image for larger version

Name:	explorer_vkqa8cIt46.png
Views:	161
Size:	183.5 KB
ID:	1165140

        How to get the script to compile without errors if we need to set the variable to private?

        Or

        How to get the Market Analyzer to load without error if we need to set the variable to public?
        Attached Files

        Comment


          #19
          Hi Cormick, thanks for your reply.

          The public Series must have [XmlIgnore] as a decorator. If not, the workspace system will try to save it to the workspace file and this reflection error will come up. The access modifiers (public, private, protected) is a C# concept that is important in Object-oriented programming. See this publicly available documentation:

          Learn about Access Modifiers in C#, how to use them, what are the differences between them and what are constraints of each of them.


          Kind regards,
          -ChrisL
          Chris L.NinjaTrader Customer Service

          Comment


            #20
            Hi Chris,

            Thanks for the reply and [XmlIgnore] note, I did not know about that.

            I had the [XmlIgnore] code already set to the #region Properties code for the priorDate variable like follows:

            private Series<DateTime> priorDate;

            ...


            [Browsable(false)]
            [XmlIgnore]
            public Series <DateTime> PriorDate
            {
            get { return priorDate; }
            }
            #endregion

            I checked trying to compile again and the error CS0122 'Ninjatrader.Ninjascript.Indicators.myDailyBarsPri orOHLC.priorDate' is inaccessible due to its protection level is not solved:

            Click image for larger version  Name:	vmplayer_cY2sxErw9c.png Views:	0 Size:	190.6 KB ID:	1165205


            Did you mean to imply adding the # Properties priorDate code both to the indicator and the Market Analyzer Column Scripts?

            Or
            To the Indicator Script only?

            Or
            To the Market Analyzer Column Script only?


            From your previously TimeSeries samples NT8ExposedPlot.cs and ExposedPlotMA.cs shared on post #11 here:

            https://ninjatrader.com/support/foru...90#post1164890

            I see the #region Properties timeIndication variable is only present in the indicator script:

            NT8ExposedPlot.cs script sample Full Code:

            ExposedPlotMA.cs script sample Full Code:

            Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.


            The Xmlgnore C# page does not explain further:

            From your TimeSeries samples code I inferred the #region Properties priorDate variable was required only in the indicator code. Is that right?

            If so, what else is causing the error CS0122 'Ninjatrader.Ninjascript.Indicators.myDailyBarsPri orOHLC.priorDate' is inaccessible due to its protection level ?

            And how to solve it?

            EDIT:

            I've looked up decorators in C# here:


            Decorator pattern in C#. Full code example in C# with detailed comments and explanation. Decorator is a structural pattern that allows adding new behaviors to objects dynamically by placing them inside special wrapper objects, called decorators.


            But don't see the solution in current context.

            They do use a wrapper like so (and others):

            Click image for larger version

Name:	vmplayer_oSCbi7orEE.png
Views:	180
Size:	134.0 KB
ID:	1165214

            But those wrappers are absent from your NT8ExposedPlot.cs and ExposedPlotMA.cs samples:

            NT8ExposedPlot.cs script sample Full Code:


            ExposedPlotMA.cs script sample Full Code:

            If they're not present in your code don't we do not need them?

            If we do not need them, what else is causing the error CS0122 'Ninjatrader.Ninjascript.Indicators.myDailyBarsPri orOHLC.priorDate' is inaccessible due to its protection level ?

            And how to solve it?
            Attached Files
            Last edited by Cormick; 07-26-2021, 10:21 AM.

            Comment


              #21
              Hi Cormick, thanks for your reply.

              It looks like in "MyExposedPriorDate" you are accessing priorDate and not PriorDate (the C# code is case sensitive), that is the public property being exposed while priorDate is private to the indicator. The pastebin code is correct and should not be throwing this compile error. If you cant see where the error is in MyExposedPriorDate please share the code for this one.

              Kind regards,
              -ChrisL

              Chris L.NinjaTrader Customer Service

              Comment


                #22
                Thanks Chris,

                It worked! You rock!

                Indeed I had the priorDate typed with lowercase p in the

                CurrentText = expPriorDate.priorDate[0].ToString(CultureInfo.InvariantCulture);



                Contrary to your ExposedPlotMA sample's code line 51:

                CurrentText = expPlot.TimeIndication[0].ToString(CultureInfo.InvariantCulture);


                I corrected the MyExposedPriorDate.cs code and now it complies without error CS0122.

                MyExposedPriorDate.cs Full Code Corrected:


                Thanks a lot again!

                I'll test the Market Analyzer output and be back asap with results!

                Be well!
                Last edited by Cormick; 07-26-2021, 10:57 AM.

                Comment


                  #23
                  Hi Chris,

                  Here's the Market Analyzer Output:

                  Click image for larger version  Name:	vmplayer_jghM6V6Oht.png Views:	0 Size:	1.07 MB ID:	1165235



                  Contrary to expected, the date is today's 07/26/2021,
                  and some varying times per instrument ( for examples, GE = 21:00:00, ES = 23:00:00, ZS = 20:20:00).

                  And multiple instruments do not return the dates.

                  We are Monday.

                  So the code should return last Friday's date on the Market Analyzer Window as on the Chart:

                  I checked the chart output date for ES and other instruments and it is correct (last Friday's 07/23/2021) .

                  Click image for larger version  Name:	vmplayer_4DFSHNbHBk.png Views:	0 Size:	727.5 KB ID:	1165236

                  I also checked the PriorDay's OHLC values from the Market Analyzer's Window and they are correct (last Friday's ones).

                  Only the Markey Analyzer Window's dates are incorrect.



                  Why doesn't the Market Analyzer Window return last Friday's date as on the Chart?

                  And why multiple instruments don't return their dates on the Market Analyzer Window?


                  EDIT:

                  Here's my indicator's OnBarUpdate() code:

                  I have the logic set for non Monday/Sunday's days of week (the If() statement below) and set for Monday's/Sunday's (the Else() statement below).

                  if (Times[0][0].DayOfWeek != DayOfWeek.Sunday)
                  {
                  Values[0][0] = Open[0];
                  Values[1][0] = High[0];
                  Values[2][0] = Low[0];
                  Values[3][0] = Close[0];


                  Values[4][0] = Values[1][0] - Values[0][0];

                  Draw.Text(this, "DateTime", " " + Time[0].ToString("MMM dd yyyy"), 0, Low[0]-TickSize*2, Brushes.Pink);

                  priorDate[0] = Time[0];
                  }
                  else
                  {
                  Values[0][0] = Open[1];
                  Values[1][0] = High[1];
                  Values[2][0] = Low[1];
                  Values[3][0] = Close[1];


                  Values[4][0] = Values[1][0] - Values[0][0];

                  Draw.Text(this, "DateTime", " " + Time[0].ToString("MMM dd yyyy"), 0, Low[0]-TickSize*2, Brushes.Pink);

                  priorDate[0] = Time[0];
                  }



                  And here's again MyExposedPriorDate.cs Full Code Corrected:

                  https://pastebin.com/HDBPmRrk


                  protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
                  {
                  if (marketDataUpdate.MarketDataType == MarketDataType.Last)
                  CurrentText = expPriorDate.PriorDate[0].ToString(CultureInfo.InvariantCulture);
                  }

                  I suspected needing to separate the logic for Sundays/Mondays and Non-Sundays/Mondays weekdays in the MyExposedPriorDate.cs Market Analyzer Column script and giving different indices to solve the wrong dates issue as:

                  protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
                  {
                  if (marketDataUpdate.MarketDataType == MarketDataType.Last
                  && Times[0][0].DayOfWeek != DayOfWeek.Sunday)
                  {
                  CurrentText = expPriorDate.PriorDate[0].ToString(CultureInfo.InvariantCulture);
                  }
                  else if (marketDataUpdate.MarketDataType == MarketDataType.Last
                  && Times[0][0].DayOfWeek == DayOfWeek.Sunday)
                  {
                  CurrentText = expPriorDate.PriorDate[1].ToString(CultureInfo.InvariantCulture);
                  }
                  }

                  but the Time[0].ToString("MMM dd yyyy") index is set to zero in both the Sundays/Mondays and Non-Sundays/Mondays weekdays (If() and Else() statements) in the indicator's script—
                  and the indicator's script does return the correct Prior Date on the Chart (07/23/2021).
                  So it suggests the cause is not MyExposedPriorDate.cs index [0].
                  Thus the solution index [1] with a else if() statement for Sundays/Mondays weekdays seems not the right one.
                  Attached Files
                  Last edited by Cormick; 07-26-2021, 12:21 PM.

                  Comment


                    #24
                    Hi Cormick, thanks for your reply.

                    I must recommend you use Print() statements to print data from your script and debug your code (make sure variables are getting set when they are supposed to, make sure data is flowing the correct way, etc). The support team will not be able to spend time to write or debug code on an individual basis. The NinjaTrader Ecosystem also has developers for hire that can help create and debug custom logic:

                    Search trading apps & services to cusomize your NinjaTrader platform with trading indicators, signals and strategies.


                    Kind regards,
                    -ChrisL



                    Chris L.NinjaTrader Customer Service

                    Comment


                      #25
                      Hi Chris,

                      Thanks for the steps and hints and Print recommendation.

                      I got the date issue partially fixed by setting the calculate mode to OnBarClose instead of OnPriceChange.

                      Demo video:




                      About getting the Symbols names in the Print string method:

                      What parameter do I need to set in the Print statement to get the symbols?

                      There's no mention of the symbol parameter in the Print() documentation:

                      https://ninjatrader.com/de/support/h.../nt8/print.htm

                      I found this post about getting the symbol name but it's not for the Print string:

                      my current Print() string:

                      Print(String.Format("CurrentBar index: {0} Time[0]: {1} Open[0]: {2}, High[0]: {3} Low[0]: {4}, Close[0]: {5} State: {6} Calculate: {7}", CurrentBar, Time[0], Open[0], High[0], Low[0], Close[0], State, Calculate));
                      Last edited by Cormick; 07-27-2021, 08:18 AM.

                      Comment


                        #26
                        Hi Cormick, thanks for your reply.

                        The Instruments array holds all instruments being used by the script:



                        Kind regards,
                        -ChrisL
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #27
                          Hi Chris,

                          Thanks for the reference.

                          For some reason it does not display the Symbols Prints next to the other prints:

                          Here's what I get with

                          else if (State == State.DataLoaded)
                          {
                          //PriorDayOHLC1 = PriorDayOHLC(Close);
                          // Print all instruments which have been loaded
                          foreach (Instrument i in Instruments)
                          {
                          Print(i.FullName);
                          }
                          }


                          and (at the OnBarUpdate() end)


                          Print(String.Format("CurrentBar index: {0} Time[0]: {1} Open[0]: {2}, High[0]: {3} Low[0]: {4}, Close[0]: {5} State: {6} Calculate: {7}", CurrentBar, Time[0], Open[0], High[0], Low[0], Close[0], State, Calculate));


                          Click image for larger version  Name:	vmplayer_nSFhy1OJKB.png Views:	0 Size:	77.7 KB ID:	1165501

                          Click image for larger version  Name:	vmplayer_6cw8n1ojXX.png Views:	0 Size:	134.0 KB ID:	1165502

                          Click image for larger version  Name:	vmplayer_HK5wnYQsI7.png Views:	0 Size:	172.4 KB ID:	1165503

                          I tested:

                          Print(String.Format("Symbol: {0} CurrentBar index: {1} Time[0]: {2} Open[0]: {3}, High[0]: {4} Low[0]: {5}, Close[0]: {6} State: {7} Calculate: {8}", FullName, CurrentBar, Time[0], Open[0], High[0], Low[0], Close[0], State, Calculate));

                          But it returns error CS0103 "The name 'FullName' does not exist in the current context

                          How to get the the Symbols Prints next to the other prints?

                          For example:

                          ZW 09-21 CurrentBar index: 1 Time[0]: 26/07/2021 23:00:00 Open[0]: XXX, High[0]: YYY Low[0]: ZZZ, Close[0]: QQQ State: Realtime Calculate: OnBarClose

                          Comment


                            #28
                            I combined the 2 at the End of OnBarUpdate, in the foreach loop separately like this:

                            foreach (Instrument i in Instruments)
                            {
                            Print(i.FullName);
                            Print(String.Format("CurrentBar index: {0} Time[0]: {1} Open[0]: {2}, High[0]: {3} Low[0]: {4}, Close[0]: {5} State: {6} Calculate: {7}", CurrentBar, Time[0], Open[0], High[0], Low[0], Close[0], State, Calculate));
                            }

                            Now it's returning good enough readable prints:

                            Click image for larger version

Name:	vmplayer_Qw4l8CsoLu.png
Views:	160
Size:	110.4 KB
ID:	1165508
                            Attached Files

                            Comment


                              #29
                              I checked the Prints for RTY.

                              Click image for larger version  Name:	vmplayer_5Vqs7AyYgQ.png Views:	0 Size:	1.89 MB ID:	1165513

                              They return yesterday and the day before dates (07/27/2021 and 07/26/2021).



                              However the Market Analyzer doesn't return any date for RTY (and other symbols).

                              Furthermore, all symbols return dates in the Prints.

                              Why doesn't the Market Analyzer return the Dates present in the Prints?

                              How to get the Market Analyser return all the dates for all symbols present in the Prints?
                              Attached Files

                              Comment


                                #30
                                Hello Cormick,

                                Within the MarketAnalyzerColumn that is not displaying the date when you assign it to CurrentText, does the value have meaningful information before you assign it to CurrentText? I.E. if you print expPriorDate.PriorDate[0].ToString() before assigning to CurrentText, do you see a meaningful result in the output window?

                                If you change the datatype to string, does this help?

                                Market Analyzer DataType - https://ninjatrader.com/support/help...8/datatype.htm

                                We look forward to hearing from you.
                                JimNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by jaybedreamin, Today, 05:56 PM
                                0 responses
                                2 views
                                0 likes
                                Last Post jaybedreamin  
                                Started by DJ888, 04-16-2024, 06:09 PM
                                6 responses
                                18 views
                                0 likes
                                Last Post DJ888
                                by DJ888
                                 
                                Started by Jon17, Today, 04:33 PM
                                0 responses
                                1 view
                                0 likes
                                Last Post Jon17
                                by Jon17
                                 
                                Started by Javierw.ok, Today, 04:12 PM
                                0 responses
                                6 views
                                0 likes
                                Last Post Javierw.ok  
                                Started by timmbbo, Today, 08:59 AM
                                2 responses
                                10 views
                                0 likes
                                Last Post bltdavid  
                                Working...
                                X