Get Excel Data into Ninja Trader - futures io
futures io futures trading



Get Excel Data into Ninja Trader


Discussion in Traders Hideout

Updated by addchild
      Top Posters
    1. looks_one LionAgainst with 2 posts (0 thanks)
    2. looks_two Quick Summary with 1 posts (0 thanks)
    3. looks_3 rleplae with 1 posts (1 thanks)
    4. looks_4 addchild with 1 posts (0 thanks)
    1. trending_up 383 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 4 replies
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Get Excel Data into Ninja Trader

(login for full post details)
  #1 (permalink)
Munich
 
 
Posts: 2 since Feb 2019
Thanks: 1 given, 0 received

Hi,
i have an oscilator in excel based on cot data that saves a value depending on the date.
My mission is to access from NinjaTrader that excel file, search for todays date and give back the value to NinjaTrader.
I have already worked it out in VisualStudio, but i am now struggling to access the excel file with the same logic. And i wonder what my problem is. I have referenced the Microsoft.Office.Interop.Excel.dll in NinjaTrader but i dont know how to test if it actually works in NinjaTrader. Currently i just try to test it by running a backtest, but unfortunately it wont run the code linked to the excel file but only the strategy based on NinjaTraders indicators.
i will enclose the code from the already working visual studio application. I welcome every help on how to translate that code into Ninja and get it working


 
Code
public class KKK : Strategy
	{
		
		Microsoft.Office.Interop.Excel.Application excelApp;
        Microsoft.Office.Interop.Excel._Workbook excelWorkBook;
        Microsoft.Office.Interop.Excel._Worksheet excelSheet;
        Microsoft.Office.Interop.Excel.Range range;
		private string excelFile = @"C:\\Users\\Felix\\Documents\\C#\\ExcelAnfang\\Mappe6.xlsx";
		private string excelSheetName = "Tabelle";
		private bool excelSheetFound = false;
		private bool excelOpen = false;
		private string fullFileName;///dkasl
        private string simpleFileName;///aklsdf
            
			
	
	
	private void OpenWorkbook(string FileName)
        {
            try
            {
                excelApp = (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
            }
            catch
            {
                excelApp = new Microsoft.Office.Interop.Excel.Application();
            }
            
            try
            {
               excelWorkBook = excelApp.Workbooks.Open(excelFile);
            }
            catch
            {
                excelWorkBook = (Microsoft.Office.Interop.Excel._Workbook) (excelApp.Workbooks.Open(excelFile,
                    false, true, Type.Missing,Type.Missing, Type.Missing, Type.Missing,Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing, Type.Missing,Type.Missing));
            }
        }  
		
		private Microsoft.Office.Interop.Excel.Worksheet FindSheet(Microsoft.Office.Interop.Excel._Workbook excelWorkBook, string excelSheetName)
        {    
            foreach (Microsoft.Office.Interop.Excel.Worksheet excelSheet in excelWorkBook.Sheets)    
            {        
                if (excelSheet.Name == excelSheetName) return excelSheet;   
            }    
            return null;
        }
		
		 private void SetUpSpreadsheet()
        {
            OpenWorkbook(excelFile);
            excelSheet = (Microsoft.Office.Interop.Excel._Worksheet)FindSheet(excelWorkBook, excelSheetName);
			excelOpen = true;
            
                    

            // Set up some column colours
            
        }
		
	


public int searchExcelDate(int i)
    {
        
        
        var PCTime = DateTime.Today;
        string sDate = (excelSheet.Cells[i, 1] as Microsoft.Office.Interop.Excel.Range).Value2.ToString(); //holt Datum als String aus Zelle
        double date = double.Parse(sDate); // Double Datum der Zelle
        var excelTime = DateTime.FromOADate(date); //Excel Zeit -- Vergleich

        //Console.WriteLine(date);
        while (DateTime.Compare(excelTime, PCTime) != 0)
        {
            if ((excelSheet.Cells[i + 1, 1] as Microsoft.Office.Interop.Excel.Range).Value != null)
            {
                i++;
                sDate = (excelSheet.Cells[i, 1] as Microsoft.Office.Interop.Excel.Range).Value2.ToString();
                date = double.Parse(sDate);
                excelTime = DateTime.FromOADate(date);
            }
            else
            {
                return -1;
            }
        }
        Console.WriteLine("Datum gefunden!");
        return i;
    }

    

public double giveValueFromToday()
    {
        int d = searchExcelDate(1);
        
        if(d > 0)
        {
            double wert = double.Parse((excelSheet.Cells[d, 2] as Microsoft.Office.Interop.Excel.Range).Value.ToString());
			Console.WriteLine(wert);
            return wert;
        }
        else
        {
            Console.WriteLine("Datum nicht gefunden!");
            return -1;
        }
     }
		
	
	
           
		protected override void OnBarUpdate()
		{
			
			
			if (BarsInProgress != 0) 
				return;

			if (CurrentBars[0] < 1)
				return;
			if (CurrentBar < BarsRequiredToTrade)
				return;
			
			KKK hallo = new KKK();
	
                         if(excelOpen == false)
			{
				hallo.SetUpSpreadsheet();
			}
			cotData = hallo.gibWertVonAktuellemDatum();
			Console.WriteLine("Sieht man das?");
			System.Windows.Forms.MessageBox.Show("sieht man das?");
			
			excelApp.Visible = false;


	}
		
	
		#region Properties
       
        
        [Description("Excel File Name with full path. Information will be displayed in an Excel Spreadsheet which is included with this indicator")]
        public string ExcelFile
        {
            get { return excelFile; }
            set { excelFile = value; }
        }
        
        [Description("Excel Sheet name e.g. Sheet1, Sheet2, Sheet3. Case Sensitive")]
        public string ExcelSheetName
        {
            get { return excelSheetName; }
            set { excelSheetName = value; }
        }
        #endregion
	
	}
	}

Reply With Quote

 
 
(login for full post details)
  #3 (permalink)
Gits (Hooglede) Belgium
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,990 since Sep 2013
Thanks: 2,437 given, 5,793 received


you will have to add that library as an external reference
so that Ninja know how to resolve and link it

Follow me on Twitter Visit my Facebook Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to rleplae for this post:
 
(login for full post details)
  #4 (permalink)
Munich
 
 
Posts: 2 since Feb 2019
Thanks: 1 given, 0 received


rleplae View Post
you will have to add that library as an external reference
so that Ninja know how to resolve and link it

Ok thank you! But i dont really understand what you mean. I have referenced the Microsoft.Office.Interop.Excel.dll in NinjaTrader and moved that file in ninjatrader>bin>custom. If its what you mean? or what should i do
thank you

Reply With Quote
 
(login for full post details)
  #5 (permalink)
Bay Area California
 
Experience: None
Platform: TT T4
Broker: Phillip Capital
Trading: Futures
 
Posts: 778 since Nov 2011
Thanks: 776 given, 829 received

If you already successfully demonstrated the logic in visual studio, it should be pretty trivial to test it in ninjatrader. You can attach the visual studio debugger to a ninjascript strategy and hit any breakpoints you set to check that the excel workbook is being correctly bound to and retrieving your desired values.


Sent using the futures.io mobile app

.
Reply With Quote


futures io Trading Community Traders Hideout > Get Excel Data into Ninja Trader


September 28, 2019


Upcoming Webinars and Events
 

Introducing Edge Pools: Prop Pricing Model w/Edge Clear

Jul 9
 

Every journal equals ten meals for the hungry

Now
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts