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

Step through tool in NT?

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

    Step through tool in NT?

    Greetings,

    I've got an indicator showing some very odd behaviour. I'm simply using it to read a simple text file, and color the (historical) chart bars depending on values that have been read into the indicator from the input file.

    Using Print statements I have verified all the lines are being properly read from the input file. The general flow of the indicator works like this:

    try
    {
    //read each line from the input file...
    while ((line = sr.ReadLine()) != null)
    {
    //read each character on each line, to get some values...
    for(int index = 0; index < line.Length; index++)
    {
    ...
    }

    //Each line from input file represents data for each bar on the chart.
    //Using calculated values from each line, change bar to a certain color.
    //Different values should change bars to different colors...

    }
    }

    The problem is all the bars change to the same color. Even if I add a variable "counter" within the "while" loop to count the # of lines and use this to dictate some action (for example if(COUNTER == 12){do something;}) I see the same exact behaviour (all the bars have the same color regardless if it is bar #12 or not). It is very odd.

    I don't believe NT has a "step through" type of debug tool in order to follow how NT is reading the code line-by-line...is there such a tool or is there an obvious flaw in the program flow? Thanks for any input.

    #2
    You can use Visual Studio 05 or higher for true debugging.

    Information here - http://www.ninjatrader-support.com/H...ualStudio.html
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks. Since that option will not work with "Express" editions that kinda stops me dead in my tracks right there...

      I do have a related question. If I have a simple .txt file that contains lines representing information for a bar on a price chart, is it possible to backtest import line-by-line? For example:

      if my .txt file contains this information:

      3 0.00E+000 1.94E+001
      3 0.00E+000 8.88E+000
      6 3.18E+000 0.00E+000
      6 -2.20E+000 -1.74E+000
      6 -3.10E+000 -2.13E+000

      then the first line is used for the first bar on a (historical) chart, the second line for the second, and so on...do not read the lines in the file that don't apply to the bar in question.

      Normally doing a backtest on historical bars will load/read ALL the lines in the file for EACH bar included in the historical chart...hope that makes sense.

      Comment


        #4
        You would have to check MSDN DOC on StreamReader but I know some IO object has a method to read line by line...Something like object.ReadNextLine() etc..
        RayNinjaTrader Customer Service

        Comment


          #5
          Thank you. Are there no existing examples of this for NT? I find that a bit hard to believe...there must be similar type situations where, for example, a strategy/indicator is reading in trade entry signals from an external (text file) source?

          Comment


            #6
            A guess another (better) way to explain my question is how to populate the chart info using a .txt file if each line in the .txt file represents one bar on the chart...thus:

            line #1 in the .txt file = bar[0]
            line #2 in the .txt file = bar[1]
            line #3 in the .txt file = bar[2]
            line #4 in the .txt file = bar[3]
            etc...

            Comment


              #7
              You would have to figure out how to sync the current bar number with a line in the text file.
              RayNinjaTrader Customer Service

              Comment


                #8
                Thanks. I've written code to attempt to do that here:

                try
                {
                // Sets the file the StreamReader will read from
                sr = new System.IO.StreamReader(path);


                string line; NUMBER = 0; COUNTER = 95; AIindex = 0;



                FINDER:


                if(CurrentBar == (NUMBER + 20))
                {
                line = sr.ReadLine();

                }
                //CurrentBar equals NUMBER + 20 ("1st" written line in .txt file is "bar 20" of chart...)

                AIindex +=
                1; NUMBER += 1;
                if(AIindex < COUNTER){goto FINDER;} return;

                }
                //try


                The issue is the "sr.ReadLine()" command seems to be returning nothing...I don't understand why. Can somebody explain why that is the case, I believe the code as written is fine otherwise.

                Comment


                  #9
                  Have you checked error logs? Anything in there?
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Nothing in the logs at all. That code I posted works fine, however the Print statement I use for the "line" value outputs nothing at all...not even a "0", just blank space. Is there a better command statement to use?

                    Comment


                      #11
                      >> Is there a better command statement to use?
                      no

                      Comment


                        #12
                        Originally posted by Burga1 View Post
                        Thanks. Since that option will not work with &quot;Express&quot; editions that kinda stops me dead in my tracks right there...
                        Since the issue appears to lie with StreamReader specifically, rather then a NinjaTrader API, you could likely lift out just the StreamReader code into VS C# Express and debug the StreamReader issue specifically.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by traderqz, Today, 12:06 AM
                        6 responses
                        12 views
                        0 likes
                        Last Post traderqz  
                        Started by Skifree, Today, 03:41 AM
                        3 responses
                        12 views
                        0 likes
                        Last Post Skifree
                        by Skifree
                         
                        Started by traderqz, Yesterday, 09:06 AM
                        5 responses
                        33 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by guillembm, Today, 11:25 AM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by owensd, 04-21-2024, 11:34 PM
                        9 responses
                        34 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Working...
                        X