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

Dionysus New Year Present – Ninja & Excel

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

    Hello Branpo,

    Thank you for your patience.

    It looks like your issues stem from the fact that your indicator doesn't assign the plot values in OnBarUpdate() by reading an individual value from the .csv and assigning that value to Value[0] but instead loops through the CSV in your SetPlotTK() method and assigns the values there after the fact.

    The upshot of this is that your strategy would be processing data which does not have plot value set. For example, your strategy processes historical bars 1-200, then indicator sets plot values for past bars. Since the strategy already processed those bars, it would not see the plot value and would not be included in its calculations.

    You'd need to modify the indicator to read the values from the CSV one at a time and assign them to Value[0] in OnBarUpdate in order for the strategy to be able to access those values properly.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      Is there a way to grab executions as they happen throughout the day and use the BigMikeExcel solution to write the executions to an excel file?

      I am aware of the ability to export executions by right-clicking the executions grid and clicking export but I would like to automate an excel spreadsheet with executions. Currently, the BigMikeExcel indicator seems like the best solution to achieve this but I am not an avid programmer.

      Thank you in advance for any help related to this matter!

      Comment


        Hello Triggertrader,

        Thank you for your post.

        You'd need to subscribe to the account updates, grab execution updates as they come in, and then write the execution information to a file. Here's a link to our help guide on the Account object that has good examples of how to subscribe to Execution updates:



        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          Originally posted by NinjaTrader_Kate View Post
          Hello Branpo,

          Thank you for your patience.

          It looks like your issues stem from the fact that your indicator doesn't assign the plot values in OnBarUpdate() by reading an individual value from the .csv and assigning that value to Value[0] but instead loops through the CSV in your SetPlotTK() method and assigns the values there after the fact.

          The upshot of this is that your strategy would be processing data which does not have plot value set. For example, your strategy processes historical bars 1-200, then indicator sets plot values for past bars. Since the strategy already processed those bars, it would not see the plot value and would not be included in its calculations.

          You'd need to modify the indicator to read the values from the CSV one at a time and assign them to Value[0] in OnBarUpdate in order for the strategy to be able to access those values properly.

          Please let us know if we may be of further assistance to you.
          Thank you for your Time to find the error in my script.
          Is it possible that you assist me with changing the algo to update the algo?
          Maybe you can tell me some "framework" to start with? I really dont think i can manage it by myself. I stupid thing is i built several indicators in that way without checking them in the Strategy section i was assuming if they are displayed correctly they'll work in the strategies too.
          Thank you very much!
          Last edited by Branpo; 11-02-2019, 05:17 AM.

          Comment


            Hello Branpo,

            Thank you for your note.

            Just to be clear, in platform support, we do not create/write strategies, we do not provide debugging services. We also cannot provide programming education services. If you would like the strategy created or edited for you, we can provide references to 3rd party programmers who could meet your needs.

            However, I'd encourage you to take a look at the SampleStreamReader example here:



            You could modify your logic to do the reading from the file and assign the resulting value of BW to the plot in on bar update instead of in a separate method like this shows here, where it matches the date to the bar information and then prints the appropriate values.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              Hello Kate,

              thank you very much for your help.
              just in case im not able to do it in my own can you provide me with a link to some third party programmers?
              and can u give me an estimation what a fair price for an indicator like that would be?

              thanks again

              Comment


                Hello,

                This is Patrick from the NinjaTrader Business Development team responding on behalf of my colleague.

                You can search our extensive library of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more:
                You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third-party services for NinjaTrader, all pricing and support information will need to be obtained through the consultant.

                Let me know if I may be of further assistance

                The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem, LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

                Comment


                  Hi Guys,

                  im trying to read from a File that is called ZRTK.csv.
                  If i acces it with path = NinjaTrader.Core.Globals.UserDataDir + "APData" + "TK" + "ZR"+ "TK"+".csv";
                  it works properly.
                  Now i want to automaticly switch to another file if i change the Master instrument.
                  I tried it with
                  path = NinjaTrader.Core.Globals.UserDataDir + "APData\" + "TK\" +(string)Instrument.MasterInstrument.Name + "TK.csv";
                  or
                  path = NinjaTrader.Core.Globals.UserDataDir + "APData\" + "TK\" +Instrument.MasterInstrument.Name + "TK.csv";

                  but that crashes my indicator.
                  Masterinstrument was ZR 01-20.

                  Trace:
                  2019-11-21 21:45:48:315 ERROR: Indicator 'Terminkurve': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.
                  2019-11-21 21:45:48:320 ERROR: Error on getting/setting property 'PaintPriceMarkers' for NinjaScript 'Terminkurve': Exception has been thrown by the target of an invocation.
                  2019-11-21 21:45:48:320 ERROR: Unable to create instance of NinjaScript 'Terminkurve'. Most likely either the implementation no longer exists, there is no default constructor defined, the default constructor does not work correctly, or the 'OnStateChange' implementation for State=SetDefaults is flawed: System.InvalidOperationException: 'DrawHorizontalGridLines' cannot be set from this state. Please see the Help Guide article on 'DrawHorizontalGridLines' for more information. at NinjaTrader.NinjaScript.IndicatorBase.set_DrawHori zontalGridLines(Boolean value) at NinjaTrader.NinjaScript.IndicatorBase.CopyTo(Ninja Script ninjaScript) at NinjaTrader.Gui.NinjaScript.IndicatorRenderBase.Co pyTo(NinjaScript ninjaScript) at NinjaTrader.NinjaScript.NinjaScript.Clone()
                  2019-11-21 21:45:48:320 ERROR: Failed to restore Indicator 'NinjaTrader.NinjaScript.Indicators.Backtesting.Te rminkurve'. Most likely (a) the implementation changed or (b) one or more properties have been renamed or removed or (c) the custom assembly which implements this Indicator no longer is there.

                  If i use If i acces it with path = NinjaTrader.Core.Globals.UserDataDir + "APData" + "TK" + "ZR"+ "TK"+".csv"; theres no entry in the trace file


                  I then switched to
                  case State.Configure:
                  SymNewSchool=(string)Instrument.MasterInstrument.N ame;
                  path = (string)NinjaTrader.Core.Globals.UserDataDir + "APData\" + "TK\" + SymNewSchool+ "TK"+".csv";

                  Now it doesnt crash anymore and doesnt produce an Trace output.
                  But it still doesnt work because it doesnt show anything.

                  So I added if (!File.Exists(path))
                  {
                  // If file does not exist, let the user know
                  Print("File does not exist.");
                  Print(SymNewSchool);
                  Print((string)NinjaTrader.Core.Globals.UserDataDir + "APData\" + "TK\" + SymNewSchool+ "TK"+".csv");
                  return;
                  }

                  which returns me
                  File does not exist.
                  ZR
                  C:\Users\dboeh\OneDrive\Dokumente\NinjaTrader 8\APData\TK\ZRTK.csv

                  which is the correct path in which the file is located.

                  Can you tell me what i did wrong? And how it is done wright?
                  Thanks a lot
                  Branpo
                  Last edited by Branpo; 11-21-2019, 03:28 PM.

                  Comment


                    Hello Branpo,

                    Thank you for your post.

                    Where are you setting the path variable? If you're setting it before State.DataLoaded, I would expect you to get an error - you can't access the Instrument class prior to that point or you'll run into what you're experiencing. See the Instrument class in the help guide here:



                    Try setting the path variable in State == State.DataLoaded and you should avoid that error.

                    Please let us know if we may be of further assistance to you.
                    Kate W.NinjaTrader Customer Service

                    Comment


                      Thanks a lot Kate!
                      That helped to solve the Problem

                      Comment


                        Hi.
                        I've been reading all the posts about connecting with Exceland I've some doubts. First of all, what I want is to get some data from an Excel Worksheet and use it in NinjaTrader 8 at the beginning of the strategy to modify some parameters of the strategy.

                        I've modified BigMikeExcel as follows:

                        public class IJFMExcelFase : Indicator
                        {
                        #region Variables
                        // Wizard generated variables
                        private int myInput0 = 1; // Default setting for MyInput0
                        // User defined variables (add any user defined variables below)
                        private string excelFile = @"E:\USUARIOSJFM\JORGE\BOLSA\2020\ESTRATEGIAS\A TR MERCADOS\ATR 2020.xlsx";
                        private string excelSheetName = "DATOS";
                        private bool workSheetFound = false;
                        private bool excelOpen=false;
                        private string fullFileName;
                        private string simpleFileName;
                        Excel.Application excelApp;
                        Excel._Workbook excelWorkBook;
                        Excel._Worksheet excelSheet;
                        Excel.Range excelRange;
                        private int rowCount = 1;
                        private int temp;
                        #endregion

                        protected override void OnBarUpdate()
                        {
                        if (excelOpen == false)
                        {
                        SetUpSpreadsheet();
                        }

                        private void SetUpSpreadsheet()
                        {
                        OpenWorkbook(excelFile);
                        excelSheet = (Excel._Worksheet)FindSheet(excelWorkBook, excelSheetName);
                        if (excelSheet == null)
                        {
                        Alert("openError", Priority.High, "Error opening spreadsheet - check indicator parameters", "Alert1.wav", 10, Brushes.Firebrick, Brushes.Gold);
                        }
                        try
                        {
                        // Get the range of cells we want to format into an object
                        excelRange = excelSheet.get_Range("B3","G3");

                        FaseYM = ((excelSheet.Cells[3,2] as Excel.Range).Value.ToString());
                        FaseAntYM = ((excelSheet.Cells[3,3] as Excel.Range).Value.ToString());
                        }
                        catch
                        {
                        Alert("Exception formatting Excel", Priority.High, "Error opening spreadsheet - check indicator parameters", "Alert1.wav", 10, Brushes.Firebrick, Brushes.Gold);
                        }

                        }

                        #region Properties
                        [Description("")]
                        public string FaseYM
                        {
                        get { return FaseYM; }
                        set { FaseYM = value; }
                        }
                        [Description("")]
                        public string FaseAntYM
                        {
                        get { return FaseAntYM; }
                        set { FaseAntYM = value; }
                        }
                        #endregion

                        Now, I don't know where to call the indicator. Do I have to declare it as an Indicator?:

                        private NinjaTrader.NinjaScript.Indicators.IJFMExcelFase EXC1;

                        And then call it from OnStateChange()?:

                        else if (State == State.DataLoaded)
                        {
                        EXC1 = IJFMExcelFase();
                        Print("Fase: " + EXC1.FaseYM);
                        Print("FaseAnt: " + EXC1.FaseAntYM);

                        Doing this NT crashes in this point. I've to shutdown it. There is no message in the output window showing an error, but the program stops.

                        I've proved other solutions but I always have the same problem. I don't know if the problem is in the indicator or how I call it. If someone can help me it'd be fine.

                        Thank you very much

                        Best regards
                        Last edited by Espartano; 07-06-2020, 10:24 PM.

                        Comment


                          Hello Espartano,

                          Thank you for your note.

                          The example you've pulled this from is unsupported by NinjaTrader. We would suggest trying Visual Studio to help you debug this and having it break on unhandled exceptions. Here's a publicly available link from Microsoft that goes over setting up the debugger to break on unhandled exceptions that may assist with this:

                          This post has been updated to reflect *the experience while using Visual Studio 2015.* If you have spent any time coding, odds are that you have had to deal with Exception Handling. In Visual Studio, when exceptions are thrown or end up unhandled,


                          I understand you've had questions over email regarding how to read Excel data through the interop libraries. Those questions would be best answered by community members as we do not support the interop libraries.

                          If any community members here on the forums would be willing to demonstrate using the interop libraries to read the spreadsheet that may be helpful as well.

                          Please let us know if we may be of further assistance to you.
                          Kate W.NinjaTrader Customer Service

                          Comment


                            Dear Kate,

                            Thank you for your reply. I don't have any problem to post my in the link of Visual Studio.

                            Yes, I've been trying to solve this question via email and I know these questions aren't supported by NT. I was only trying to find another traders that perhaps could help me.

                            Reading the 10 pages of this link, I thought this was possible, as I've seen several posts talking about this problem, writing modified codes, adding files, …. My problem is refereed to Interop libraries, not to debugging, indeed.

                            Furthermore, I began this thread with Jesse a month ago. This was part of the reply on 02/06/20:

                            “Reading files using a streamreader is a C# concept so we only have the one sample but you can find more information about this by searching online for "C# streamreader" or "C# read file" or even "C# read text file". There is also a post about using excel directly that you can find on the forum however because that is an external reference that is not really something our support can assist with.
                            https://ninjatrader.com/support/foru...96-ninja-excel

                            This weekend I replied Jesse with the same post I've written here, and, instead of Jesse, Chelsea replied to it this Monday:
                            “As a heads up, connecting to Excel is not officially supported by the NinjaTrader Support team.
                            Some community members have some unsupported code in a discussion on the forums I am linking below.
                            http://www.ninjatrader.com/support/f...t=36938&page=7

                            So, If some member of the Technical Service recommend me a threat (twice), I think I can read and write in it.

                            Now, you send me a new suggestion. Ok, is the third member that has attended me in this matter. I’ve to remember also, that Jim participated in it this week. 4 members (I never asked it), no solutions and a lot of time wasted by me and by your team.

                            It seems like a little madness world.

                            I’ll rewrite the post wherever you want. No problem. Be happy.

                            Best regards

                            Jorge Flores

                            PD Sincerely, I’ve seeng the link you has suggested me and I think there is less easy I find a solution than here.

                            Comment


                              Hi,

                              Finally I've been able, by myselsf, to read data of an Escel sheet inside my strategy.

                              It makes what I wanted.

                              Thank you Kate.

                              Comment


                                Hi,
                                I am struggling with this Error all day
                                I tried everything possible and I have no success
                                If somebody had the same issue will be very happy if I get some advice

                                Please check the screenshots for more information

                                Even if I add Microsoft.Office.Interop.Excel.dll in the NinjaTrader 8\bin\Custom folder, I still get the first error message... without referencing the dll...

                                The second screenshot is after importing your example indicator called Excel8
                                It is strange that after importing it I can compile but get a lot of errors during the import... And of course the indicator is not working after that...
                                Attached Files
                                Last edited by vlaladim; 08-02-2020, 02:23 PM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by algospoke, Today, 06:40 PM
                                0 responses
                                9 views
                                0 likes
                                Last Post algospoke  
                                Started by maybeimnotrader, Today, 05:46 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post maybeimnotrader  
                                Started by quantismo, Today, 05:13 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post quantismo  
                                Started by AttiM, 02-14-2024, 05:20 PM
                                8 responses
                                168 views
                                0 likes
                                Last Post jeronymite  
                                Started by cre8able, Today, 04:22 PM
                                0 responses
                                10 views
                                0 likes
                                Last Post cre8able  
                                Working...
                                X