Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Amount of Bars, which is added by Add()

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

    #16
    CalculateOnBarClose=true

    And extra question:

    In one place of code i write to binary file:

    Code:
                    using (FileStream stream = new FileStream("E:\\Alpari\\history\\Alpari-Demo\\"+c_symbol+i_period+".hst", FileMode.Create)){
                      //Log("FileStream: "+stream, NinjaTrader.Cbi.LogLevel.Information);                    
                      using (BinaryWriter writer = new BinaryWriter(stream))
                        {
                          //---- Write history file header    
                          c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";    
                          writer.Write(version);
                          writer.Write(c_copyright);
                          writer.Write(c_symbol);
                          writer.Write(i_period);                    
                          writer.Write(i_digits);
                          writer.Write(0);
                          writer.Write(0);
                          for (int i=0; i<13; i++) {
                            writer.Write(i_unused[i]);    
                          }
                          //writer.Close();
                        }
                    }
    In other place of code i want to countinue to write to this file from last using position

    How can i do it?
    Last edited by agafon2; 01-23-2013, 11:40 AM.

    Comment


      #17
      Hello agafon2,
      Thanks for the confirmation.

      If you set CalculateOnBarClose (COBC) to false then are you refer to Count -1.

      If you set COBC) to true then you have to refer it as Count - 2.


      To initialize any value we suggest using the OnStartUp method.

      If you want to do a job repeatedly then assign the code to the OnBarUpdate section of the code.

      Last edited by NinjaTrader_Joydeep; 01-23-2013, 11:43 AM.
      JoydeepNinjaTrader Customer Service

      Comment


        #18
        In one place of code i write to binary file:

        Code:
                        using (FileStream stream = new  FileStream("E:\\Alpari\\history\\Alpari-Demo\\"+c_symbol+i_period+".hst",  FileMode.Create)){
                          //Log("FileStream: "+stream, NinjaTrader.Cbi.LogLevel.Information);                    
                          using (BinaryWriter writer = new BinaryWriter(stream))
                            {
                              //---- Write history file header    
                              c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";    
                              writer.Write(version);
                              writer.Write(c_copyright);
                              writer.Write(c_symbol);
                              writer.Write(i_period);                    
                              writer.Write(i_digits);
                              writer.Write(0);
                              writer.Write(0);
                              for (int i=0; i<13; i++) {
                                writer.Write(i_unused[i]);    
                              }
                              //writer.Close();
                            }
                        }
        In other place of code i want to countinue to write to this file from last using position

        How can i do it?

        Comment


          #19
          Hello agafon2,
          If you want to write the values once then we suggest using the OnStartUp event.


          If you want to do a job repeatedly then assign the code to the OnBarUpdate section of the code.
          JoydeepNinjaTrader Customer Service

          Comment


            #20
            I want to continue to write to binary file and after
            Code:
            using (FileStream stream = new FileStream("E:\\Terminal_Alpari\\history\\Alpari-Demo\\"+c_symbol+i_period+".hst", FileMode.Create)){
                              //Log("FileStream: "+stream, NinjaTrader.Cbi.LogLevel.Information);                    
                              using (BinaryWriter writer = new BinaryWriter(stream))
                                {
                                  //---- Write history file header    
                                  c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";    
                                  writer.Write((long)version);
                                  writer.Write(c_copyright);
                                  writer.Write(c_symbol);
                                  writer.Write((long)i_period);                    
                                  writer.Write(i_digits);
                                  writer.Write((long)0);
                                  writer.Write((long)0);
                                  for (int i=0; i<13; i++) {
                                    writer.Write(i_unused[i]);    
                                  }
                                  //writer.Close();
                                }
                            }
            i use this code to continue to write:

            Code:
                                   using (BinaryWriter writer = new BinaryWriter(stream))
                                     {         
                                       writer.Write(i_time);
                                       writer.Write(d_low);
                                       writer.Write(d_high);
                                       writer.Write(d_close);
                                       writer.Write(d_volume);
                                       writer.Flush();
                                     }
            But it doesn't work - it can't find stream
            How to continue to write to the opend binary file?

            Comment


              #21
              Hello agafon2,
              Unfortunately this is more of a C# query and beyond what could support. I would however leave the thread open for our forum members for their valuable inputs.
              JoydeepNinjaTrader Customer Service

              Comment


                #22
                Can you help me, please, to rewrite this code

                Code:
                //---- History header
                   int    version=400;
                   string c_copyright;
                   string c_symbol=Symbol();
                   int    i_period=Period()*ExtPeriodMultiplier;
                   int    i_digits=Digits;
                   int    i_unused[13];
                //----  
                   ExtHandle=FileOpenHistory(c_symbol+i_period+".hst", FILE_BIN|FILE_WRITE);
                   if(ExtHandle < 0) return(-1);
                //---- write history file header
                   c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";
                   FileWriteInteger(ExtHandle, version, LONG_VALUE);
                   FileWriteString(ExtHandle, c_copyright, 64);
                   FileWriteString(ExtHandle, c_symbol, 12);
                   FileWriteInteger(ExtHandle, i_period, LONG_VALUE);
                   FileWriteInteger(ExtHandle, i_digits, LONG_VALUE);
                   FileWriteInteger(ExtHandle, 0, LONG_VALUE);       //timesign
                   FileWriteInteger(ExtHandle, 0, LONG_VALUE);       //last_sync
                   FileWriteArray(ExtHandle, i_unused, 0, 13);
                to NinjaScript
                Here is an explaination of File functions:


                There is my variant, but it isn't work corectly:

                Code:
                                c_symbol=Instrument.FullName;
                                i_period=BarsPeriod.Value*ExtPeriodMultiplier;
                                //----
                                // Set the stringformat parameter for decimal places to suit the instrument.
                                // This ensures that trailing zeros are always displayed - maybe an easier way to do this?
                                double temp1 = TickSize - (int)TickSize;// get fractional part of TickSize
                                decimals = temp1.ToString(); // make it into a string
                                int tickLength = decimals.Length; // get the number of characters in the string
                                switch (tickLength) // set format depending on length of string
                                {
                                  case 1: decimals = "f0"; // eg YM 1t = 1 point
                                          i_digits = 0;
                                  break;
                                  case 3: decimals = "f1"; // eg ER2 1t = 0.1 point
                                          i_digits = 1;                        
                                  break;
                                  case 4: decimals = "f2"; // eg NQ 1t = 0.25 point
                                          i_digits = 2;                        
                                  break; 
                                  case 5: decimals = "f3"; // eg 1t = 0.001 point
                                          i_digits = 3;                        
                                  break;
                                  case 6: decimals = "f4"; // eg 6E 1t = 0.0001 point
                                          i_digits = 4;                                                
                                  break;
                                  case 7: decimals = "f5"; // eg 1t = 0.00001 point
                                          i_digits = 5;                        
                                  break;
                                  default: decimals = ""; // default is no fixed decimal format
                                          i_digits = 0;
                                  break;
                                  // more options can be added if neccessary......
                                }
                                //Log("i_digits: "+i_digits, NinjaTrader.Cbi.LogLevel.Information);
                                using (FileStream stream = new FileStream("E:\\Terminal_Alpari\\history\\Alpari-Demo\\"+c_symbol+i_period+".hst", FileMode.Create)){
                                  //Log("FileStream: "+stream, NinjaTrader.Cbi.LogLevel.Information);                    
                                  using (BinaryWriter writer = new BinaryWriter(stream))
                                    {
                                      //---- Write history file header    
                                      c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";
                
                                      writer.Write((long)version);
                                      writer.Write(c_copyright);                
                                      writer.Write(c_symbol);                
                                      writer.Write((long)i_period);                    
                                      writer.Write((long)i_digits);
                                      writer.Write((long)0);
                                      writer.Write((long)0);
                                      for (int j=0; j<13; j++) {
                                        writer.Write(i_unused[j]);    
                                      }
                                      //writer.Close();
                                    }
                                }
                Last edited by agafon2; 01-23-2013, 01:30 PM.

                Comment


                  #23
                  Code:
                                         using (FileStream stream = new FileStream("E:\\Alpari\\history\\Alpari-Demo\\"+c_symbol+i_period+".hst", FileMode.Append)){
                                           using (BinaryWriter writer = new BinaryWriter(stream)){
                                             writer.Write(Open[0]);    
                                              writer.Close();                            
                                           }
                                         }
                  Open[0] looks like 1,3424 - with comma
                  How does look like a result of writing: writer.Write(Open[0]) - with comma like 1.3424 or dot: 1.3424?

                  Comment


                    #24
                    Hello agafon2,
                    You have to format the prints accordingly using the CultureInfo class. A sample code will be like:
                    Code:
                    Print(Open[0].ToString(new System.Globalization.CultureInfo("en-US")));
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #25
                      Originally posted by agafon2 View Post
                      Result of this code is like:
                      1358971008,03289
                      How to get an integer part of this number?
                      For example, for number 1358971008,03289 integer part is 1358971008
                      You cast it to an integer. e.g.,
                      Code:
                      double NumDouble = 125784.233;
                      int NumInt = (int)NumDouble;

                      Comment


                        #26
                        Hello
                        Expalin me, please, what is unit of measurement of Volume[] data. Is it measures in lots or not?

                        Image: http://saveimg.ru/show-image.php?id=717ca78b52e5e13f3015e320e8519f8b

                        Comment


                          #27
                          Please, give an answer on my last question

                          Comment


                            #28
                            Hello agafon2,
                            Yes, volume for futures contracts are measured in lots/number of contracts traded.
                            JoydeepNinjaTrader Customer Service

                            Comment


                              #29
                              Ok, thanks, i understood about unit of measurement of volume, but i have new question:

                              Why Last Volume is so small (1,2 lots for example), when Bid and Ask is more greater (28, 50 lots for example), than Last volume in the same time?

                              Look at this pictures, please:

                              SaveImg &#1087;&#1086;&#1079;&#1074;&#1086;&#1083;&#1080;&#1090; &#1074;&#1072;&#1084; &#1079;&#1072;&#1075;&#1088;&#1091;&#1079;&#1080;&#1090;&#1100; &#1092;&#1086;&#1090;&#1086; &#1080;&#1083;&#1080; &#1082;&#1072;&#1088;&#1090;&#1080;&#1085;&#1082;&#1091; &#1073;&#1077;&#1089;&#1087;&#1083;&#1072;&#1090;&#1085;&#1086; &#1080; &#1073;&#1077;&#1079; &#1088;&#1077;&#1075;&#1080;&#1089;&#1090;&#1088;&#1072;&#1094;&#1080;&#1080;


                              SaveImg &#1087;&#1086;&#1079;&#1074;&#1086;&#1083;&#1080;&#1090; &#1074;&#1072;&#1084; &#1079;&#1072;&#1075;&#1088;&#1091;&#1079;&#1080;&#1090;&#1100; &#1092;&#1086;&#1090;&#1086; &#1080;&#1083;&#1080; &#1082;&#1072;&#1088;&#1090;&#1080;&#1085;&#1082;&#1091; &#1073;&#1077;&#1089;&#1087;&#1083;&#1072;&#1090;&#1085;&#1086; &#1080; &#1073;&#1077;&#1079; &#1088;&#1077;&#1075;&#1080;&#1089;&#1090;&#1088;&#1072;&#1094;&#1080;&#1080;


                              SaveImg &#1087;&#1086;&#1079;&#1074;&#1086;&#1083;&#1080;&#1090; &#1074;&#1072;&#1084; &#1079;&#1072;&#1075;&#1088;&#1091;&#1079;&#1080;&#1090;&#1100; &#1092;&#1086;&#1090;&#1086; &#1080;&#1083;&#1080; &#1082;&#1072;&#1088;&#1090;&#1080;&#1085;&#1082;&#1091; &#1073;&#1077;&#1089;&#1087;&#1083;&#1072;&#1090;&#1085;&#1086; &#1080; &#1073;&#1077;&#1079; &#1088;&#1077;&#1075;&#1080;&#1089;&#1090;&#1088;&#1072;&#1094;&#1080;&#1080;

                              Comment


                                #30
                                Hello agafon2,
                                Last volume is the traded volume while the Bid/Ask Volume represents the number of contracts available only for trading at that price (and have not yet traded).
                                JoydeepNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

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