NexusFi: Find Your Edge


Home Menu

 





MySQL & Ninja


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one dsraider with 8 posts (8 thanks)
    2. looks_two ejtrader with 5 posts (5 thanks)
    3. looks_3 Big Mike with 4 posts (1 thanks)
    4. looks_4 shodson with 1 posts (0 thanks)
    1. trending_up 8,846 views
    2. thumb_up 14 thanks given
    3. group 5 followers
    1. forum 18 posts
    2. attach_file 1 attachments




 
Search this Thread

MySQL & Ninja

  #1 (permalink)
dsraider
New York, NY
 
Posts: 142 since Dec 2009
Thanks Given: 41
Thanks Received: 87

Hey All,

I've written code so that one of my indicators can write directly to MySQL. The following works fine with a simple Windows Form I created but prints

"Error on calling 'OnBarUpdate' method for indicator '[indicator]' on bar 0: AssemblyResolveEvent handlers cannot return Assemblies loaded for reflection only."

in my output window when attempting to use with Ninja. I've been through this, and other, forums and can't find the answer.

 
Code
                            
//create a MySQL connection with a query string 
                    
MySqlConnection connection = new MySqlConnection("Server=server;Database=database;Port=port;Uid=userid;Password=password"); 

                    
//create a MySQL insert command with a query string 
                    
string myInsertQuery String.Format ("INSERT INTO table (column1, column2) values ('value1', 'value2')"); 
                    
MySqlCommand command = new MySqlCommand(myInsertQuery); 

                    
command.Connection connection
                    
connection.Open(); 

                    
//insert info 
                    
command.ExecuteNonQuery(); 
                 
                    
//close the connection 
                    
connection.Close(); 
Thanks,
DS

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NexusFi Journal Challenge - April 2024
Feedback and Announcements
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Request for MACD with option to use different MAs for fa …
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
58 thanks
Battlestations: Show us your trading desks!
55 thanks
NexusFi site changelog and issues/problem reporting
48 thanks
What percentage per day is possible? [Poll]
31 thanks
GFIs1 1 DAX trade per day journal
29 thanks

  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,322 since Jun 2009
Thanks Given: 33,143
Thanks Received: 101,477


Sorry I don't have specific advise on the error. But I played with mysql db collection from Ninja a few years ago, here are some tips based on what I remember:

1) Don't create/destroy the connection OnBarUpdate. Instead just open it once, and close it once.

2) Don't write (INSERT) on every OnBarUpdate or OnMarketData. Instead use some sort of array or collection and write every 'x' ticks or every 'x' seconds. If you are timestamping, you can generate the timestamp within the collection or array so that when written it will retain the original timestamp.

I was able to record a dozen or more instruments at the tick level doing this, using a remote mysql server on my local network.

I have since deleted the code (by accident) so can't post, sorry.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
The following user says Thank You to Big Mike for this post:
  #4 (permalink)
dsraider
New York, NY
 
Posts: 142 since Dec 2009
Thanks Given: 41
Thanks Received: 87

Interesting, Mike. Will give these tips a whirl.

Thanks.

Reply With Quote
  #5 (permalink)
dsraider
New York, NY
 
Posts: 142 since Dec 2009
Thanks Given: 41
Thanks Received: 87

Afraid moving things around resulted in:

Error on calling 'OnStartUp' method for indicator '[indicator]': AssemblyResolveEvent handlers cannot return Assemblies loaded for reflection only. and

Error on calling 'OnTermination' method for indicator '[indicator]': AssemblyResolveEvent handlers cannot return Assemblies loaded for reflection only.

Oh Ninja. Why must you be so cruel...?

Reply With Quote
  #6 (permalink)
 ejtrader 
Portland, OR
 
Experience: Intermediate
Platform: Sierra Chart
Trading: ES
Posts: 269 since Jan 2011
Thanks Given: 327
Thanks Received: 180

This thread should help in this space.



I am also looking for very similar but trying to use sqlserver ( or sql CE) with an intention of using certain other plug-ins in the future. Have to see how it goes.

dsraider - if you can find a solution using mySQL - can you post the result as well?

Thanks.

Reply With Quote
The following 3 users say Thank You to ejtrader for this post:
  #7 (permalink)
dsraider
New York, NY
 
Posts: 142 since Dec 2009
Thanks Given: 41
Thanks Received: 87

FIXED!!

I have absolutely no idea whatsoever why this worked but all I had to do was remove the System.Data.dll reference to .NET 4.0 and replace with with the same one from 2.0.

I am now happily writing to MySQL. Hope this helps anyone who's going through the same thing.

Mike, will still gladly take your advice on where to put what. I hadn't even thought of that so thanks again.

DS

Reply With Quote
The following 2 users say Thank You to dsraider for this post:
  #8 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,322 since Jun 2009
Thanks Given: 33,143
Thanks Received: 101,477

Glad to hear it. I was using NT 6.5 and it was about 3 years ago, using 5 year old hardware, so I am sure you can record a 100+ tick level instruments using an efficient method.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #9 (permalink)
 ejtrader 
Portland, OR
 
Experience: Intermediate
Platform: Sierra Chart
Trading: ES
Posts: 269 since Jan 2011
Thanks Given: 327
Thanks Received: 180

dsraider - Very Nice. Would you please post the full sample code if possible?

I tried the other thread but some reason the data is not getting populated in mySQL database - don't see any errors but no data gets populated.

Wanted to replicate and see what you did.

thanks.

Reply With Quote
  #10 (permalink)
dsraider
New York, NY
 
Posts: 142 since Dec 2009
Thanks Given: 41
Thanks Received: 87


Hey EJ,

As you've probably read, I'm going to be moving things around but this got me writing to MySQL through OnBarUpdate():

 
Code
                            
//create a MySQL connection with a query string

            
MySqlConnection connection = new MySqlConnection("Server=server;Database=database;Port=port;Uid=userid;Password=password");

            
//create a MySQL insert command with a query string
            
string myInsertQuery String.Format ("INSERT INTO tablename (column1, column2) values ({0}, {1})"value1value2);
            
MySqlCommand command = new MySqlCommand(myInsertQuery);

            
command.Connection connection;
            
connection.Open();

            
//insert info
            
command.ExecuteNonQuery();
           
            
//close the connection
            
connection.Close(); 
One thing worth noting is that my table has an auto-increment column, column 1, but I did NOT use that in this code. "column1" up above is the first variable I'm looking to save. I ignored AI completely and it worked perfectly.

I'm shutting down for the night but if you have any issues, please note any error messages or output window statements. I came across many during this journey and they might ring a bell for me.

Good luck!
DS

Reply With Quote
The following 6 users say Thank You to dsraider for this post:





Last Updated on February 2, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts