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

SQLite Sample Code

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

    SQLite Sample Code

    Hi,
    Can anyone help me with a sample code for connecting SQLite DB with NinjaTrader.

    I want to pick some values from DB for my calculations and then write to DB after the calculations.

    #2
    Hello,

    Thank you for the question.

    If you are asking how to access your own database that uses SQLite, you would likely need to just use google to find relevant help for C# in general as this is not something NinjaTrader support would document. Here is one example showing some basic implementations in C#: http://blog.tigrangasparian.com/2012...in-c-part-one/

    If you instead are trying to access the NinjaTrader.sdf file to do custom database operations, I would not have any information on how to do that as that is not a documented item. I did try searching the forum for this topic but was unable to locate any relevant topics related to this.

    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      A big thanq for the timely response. I went through the article and have a few more queries after trying out the sample you provided.

      I downloaded the two files .dll and .xml but do not know where to place them in NT. I referenced the .dll file from the Download folder and also the using statement but once I try creating a variable of the class, it always reports an error

      The type 'System.Data.Common.DbConnection' is defined in an assembly that is not referenced.

      My Sample code is

      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using System.Linq;
      using System.Data;
      using System.Data.SQLite;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Gui.Chart;

      namespace NinjaTrader.Indicator
      {
      /// <summary>
      ///
      /// </summary>
      [Description("")]
      public class DayX : Indicator
      {
      #region Variables
      // Wizard generated variables

      // User defined variables (add any user defined variables below)
      private SQLiteConnection sql_con;
      .......
      I have not completed the code but you might understand what I am trying to do.

      I have downloaded the sqlite-netFx35-setup-bundle-x86-2008-1.0.98.0.exe package from the SQLite portal.
      Last edited by SurenForex; 10-12-2015, 11:41 PM. Reason: Adding further information

      Comment


        #4
        Thank you for the support. Just to update viewers who read this thread , I was able to resolve the issue by adding the appropriate System.Data reference which was located in my

        C:\Windows\Microsoft.NET\Framework\v2.0.50727\Syst em.Data.DLL

        Comment


          #5
          Sorry again but got stuck further. So continue to keep this thread going.

          My Indicator compiles without any issues but while attaching it to the chart gives me an error

          Could not load file or assembly 'System.Data.SQLite, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The system cannot find the file specified.

          I am using a Win 7 machine and NT7 , so can you shed some light on this error.

          Comment


            #6
            Hello,

            Thank you for the reply.

            This would be outside what I can really assist with but I can provide some steps to try to get this working in NInjaTrader.

            First, I searched the sqlite-netFx35-setup-bundle-x86-2008-1.0.98.0.exe, this is a 32 bit release but they also have a 64 bit release. NinjaTrader is both 32 and 64 bit but not at the same time, if you downloaded the x86 version you would have to use the 32 bit NinjaTrader. Otherwise download the 64 bit version to use that with 64 bit NinjaTrader.

            Additionally make sure to copy all required dll's into the Documents\NinjaTrader 7\bin\Custom folder when you reference them.

            With System.Data, there is a 4.5 version and 3.5 version, you would need the 3.5 version which should be in the folder: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5 or C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\ Profile\Client

            I did try referencing the file from the 64 bit version and copied both the System.Data.SQLite.dll and System.Data.dll into the custom folder and then referenced them.

            After doing so I restarted, then used the code you supplied. I was able to see the indicator can be compiled and added to a chart with no errors at this point but that is hardly saying this works. You would need to try and see if everything works as expected.

            Regarding third party assemblies, any standard .net assembly would normally be intended to be referenced in a C# project, in this case because this is not a standard C# project not all assemblies you find may work. Most would need tested to see if they can be used with NinjaTrader.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            23 views
            0 likes
            Last Post algospoke  
            Started by ghoul, Today, 06:02 PM
            3 responses
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            45 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            22 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            181 views
            0 likes
            Last Post jeronymite  
            Working...
            X