Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X