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 cmoran13, Yesterday, 01:02 PM
            0 responses
            31 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            22 views
            0 likes
            Last Post PaulMohn  
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            162 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            95 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            151 views
            2 likes
            Last Post CaptainJack  
            Working...
            X