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 CaptainJack, 05-29-2026, 05:09 AM
            0 responses
            262 views
            0 likes
            Last Post CaptainJack  
            Started by CaptainJack, 05-29-2026, 12:02 AM
            0 responses
            168 views
            0 likes
            Last Post CaptainJack  
            Started by charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            170 views
            1 like
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            257 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            209 views
            0 likes
            Last Post CarlTrading  
            Working...
            X