Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strange effect

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

    Strange effect

    Greetings,

    I have the following code to write to a file, taken directly from MSDN, the file writes to the NT 6.5 folder, and it works just fine:

    string path = Cbi.Core.UserDataDir.ToString() + 17Closes.inp"; FileInfo fi1 = new FileInfo(path);
    if (!fi1.Exists)
    {
    //Create a file to write to.
    using (StreamWriter sw = fi1.CreateText())
    {
    sw.WriteLine("Hello");
    sw.WriteLine("And");
    sw.WriteLine("Welcome");
    sw.Close(); Print("Wrote a Line");
    }
    }

    If I add some code just before that, a "loop" designed to take a sequence of Close periods in order to average them, for example:

    COUNTER = 17; AI_index = 0; AVERAGE = 0; FIRST_ROUND = 0;


    LOADER:


    if(FIRST_ROUND == 0)
    {
    value = Close[AI_index];
    INPUTS.Set(AI_index, value);
    AVERAGE += INPUTS[AI_index];
    } //FIRST_ROUND is 0

    AI_index += 1; if(AI_index < COUNTER){goto LOADER;}

    Print( "0: " + INPUTS[0]); Print( "1: " + INPUTS[1]);
    ...etc to INPUTS[16]



    Suddenly everything changes. The previous output file does not get created, and the Output Window does not show the "Print" commands. Obviously there is a problem being caused by the "looping" code, but I have no idea what it is...seperately both sets of code work perfectly, combined not at all...why? Any ideas appreciated.

    #2
    You would need to roll up your sleeves and debug your code e.g. per here: http://www.ninjatrader-support.com/v...ead.php?t=3418

    Comment


      #3
      Thank you. Is there any efficient way to determine if a price of an instrument is an "even base" number, for example prices like: 1.5600, 1.5500, 1.5400, 1.5300...etc? I believe it is related to my problem.

      Comment


        #4
        Could could try playing with the '%' C# operator. This calculates the remainder.

        if ((value * 1000) % 100 == 0) { /* do something */ }

        Please check out the MS docs for how this works.

        Comment


          #5
          Thanks Dierk, that seems helpful. Is it possible to pass that Modulo info into another value such as a double or a string?

          Comment


            #6
            Yes it is.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            630 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            566 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X