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

Problem using SampleFileReadWrite

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

    Problem using SampleFileReadWrite

    Using an indicator build from the SampleFileReadWrite code previously downloaded from this site, I'm trying to read 4 daily prices from a text file which holds these data :

    20080228 1381.50 1388.25 1359.00 1363.50

    I withdrawed this original instruction : "if (Historical) return;" because I'm using a Market Replay connection.

    As putting this custom indicator on my chart, I get the error message "Problem" in the output window.

    What did I do wrong ?

    Code:
          protected override void OnBarUpdate()
          {
            if (CurrentBar < 2)
    	{
    		Print("Problem");
    		return;
    	}
    		else if (File.Exists(path))
    	{
    		Print("File exists");
    		string readText = File.ReadAllText(path);
    		string [] split = readText.Split(new Char [] {' ', '\r', '\n'});
    		Print("File read");
    		int splitCounter = 0;
    		foreach (string s in split)
    		{
    			if (s.Trim() != "")
    			{
    				splitCounter++;
    				if (splitCounter == 1)
    					date = int.Parse(s);
    				if (ToDay(Time[0]) > date)
    				{
    					if (splitCounter == 2)
    						currentOpen = double.Parse(s);
    					else if (splitCounter == 3)
    						currentHigh = double.Parse(s);
    					else if (splitCounter == 4)
    						currentLow = double.Parse(s);
    					else if (splitCounter == 5)
    						currentClose = double.Parse(s);
    				}
    			}
    		}
    		string ohlc = date + " " + currentOpen + " " + currentHigh + " " + currentLow + " " + currentClose + Environment.NewLine;
    		Print(ohlc);
    	}
          }
    Sorry to bother anyone with such a 101 question.

    #2
    Well according to your code you will get prints of "Problem" simply because at one point in time there will be <2 bars.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for this quick response.
      I changed the code to
      Code:
       
             protected override void OnBarUpdate()
              {
       			if (File.Exists(path))
      so that it should work whatever the number of bars.
      The problem is that nothing gets displayed in the output window.
      Isn't there an easy way to read 5 pieces of data from a text file and display them ?

      Comment


        #4
        Sorry, this is beyond the scope of what we can support. As last resort you could contact a certified NinjaScript consultant for assistance on general C# programming issues: http://www.ninjatrader.com/webnew/pa...injaScript.htm

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TraderBCL, Today, 04:38 AM
        2 responses
        17 views
        0 likes
        Last Post TraderBCL  
        Started by martin70, 03-24-2023, 04:58 AM
        14 responses
        106 views
        0 likes
        Last Post martin70  
        Started by Radano, 06-10-2021, 01:40 AM
        19 responses
        609 views
        0 likes
        Last Post Radano
        by Radano
         
        Started by thanajo, 05-04-2021, 02:11 AM
        4 responses
        471 views
        0 likes
        Last Post tradingnasdaqprueba  
        Working...
        X