Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StreamWriter with Live Strategy

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

    #31
    mrlogik,

    I tried with arrays but I don't have any programming experience with them, and the C# guide didn't offer me any clue.

    I would be very grateful if you could hint how to use arrays for dealing with a PnL from an external strategy.
    Last edited by stefy; 08-31-2009, 02:18 PM.

    Comment


      #32
      Stefy,

      Remove the DataSeries variable first from GlobalStrategy.cs

      Add the following to the partial class Strategy

      Code:
      public static double[] gDataVal = new double[10000];
      Now, in the strategy you have setting ths PnL value, do something like this

      Code:
      if(CurrentBar >= 0 && CurrentBar < 10000)
          gDataVal[CurrentBar] = [I]whatever the PnL value is[/I]
      and get the data from the other strategy this way
      Code:
      if(CurrentBar >= 0 && CurrentBar < 10000)
          double pNL = gDataVal[CurrentBar][I];
      [/I]
      Note the max CurrentBar value is the same across all 3 locations (10000 in this case). You don't want to go out of bounds with your array. If the chart has more than 10000 bars, increase it to however many bars you have. Also, this will only work on the same chart type with the same amount of data loaded. The CurrentBar is being used as an indexer, so it must be synchronized across both charts / strategies. Am I clear?

      This is another quick and dirty way of doing things. Try this out first and see if it works for you. If it does what you need it to, you should make a class within the GlobalStrategy.cs file with get / set methods that do these checks for you.

      let us know.
      mrlogik
      NinjaTrader Ecosystem Vendor - Purelogik Trading

      Comment


        #33
        Thank you mrlogik.

        "Also, this will only work on the same chart type with the same amount of data loaded. "

        That's fine, I'm using this just between strategies, no charts involved.

        I tried this out, but I have some trouble with the last declaration:

        Code:
        if(CurrentBar >= 0 && CurrentBar < 10000)
        double pNL = gDataVal[CurrentBar];
        I get three error messages from the compiler:
        . expected
        statement expected
        Embedded statement cannot be a declaration

        Comment


          #34
          just a quick shot.

          Code:
          double pNL;
          
          if(CurrentBar >= 0 && CurrentBar < 10000)
              pNL = gDataVal[CurrentBar];
          mrlogik
          NinjaTrader Ecosystem Vendor - Purelogik Trading

          Comment


            #35
            Hi mrlogik,

            Sorry for the late reply, I was swamped with work in the last few days.

            Thank you very much for your snippet, now I can access the array from another strategy! I like your way of dealing with NT limitations in a quick and dirty way!

            If it does what you need it to, you should make a class within the GlobalStrategy.cs file with get / set methods that do these checks for you.
            Could you please explain what do you mean by that?

            Comment


              #36
              What i mean is, if its works for you (which it did) you shouldn't do a quick and dirty coding of this, as it may cause memory overwrites if you're not careful, or crashes.

              You should write Get / Set Methods which encapsulate the elements of the global variables. Does that clear it up?
              mrlogik
              NinjaTrader Ecosystem Vendor - Purelogik Trading

              Comment


                #37
                Not really. I understand what you mean, but I don't have a clue on how to implement it into the code.
                My knowledge of get-set methods is limited to the classic NT:
                Code:
                 #region Properties
                        [Description("")]
                        [Category("Parameters")]
                        public int P
                        {
                            get { return p; }
                            set { p = Math.Max(1, value); }
                        }
                        #endregion
                Maybe the concept is similar? Could you give me an example?

                Comment


                  #38
                  mrlogik,
                  I tried your code but received the following error: System.UnauthorizedAccessException: Access to the path 'C:\test.txt' is denied.
                  Do you have an idea why this is happening?

                  thanks.

                  Comment


                    #39
                    You are not autorized to access the file C:\Test.txt

                    In Vista (maybe also XP) do do not have write access to th root directory C:\

                    Choose another directory.

                    Comment


                      #40
                      Stefy,

                      What I mean is, in your Global file, you should write a class, something like the following...

                      Code:
                      public class GlobalData
                      {
                      public static double[] gDataVal;
                      
                      //Default constructor
                      public GlobalData()
                      {
                          this.gDataVal = new double[10000];
                      }
                      
                      // Access method
                      public double GetgDataVal(int idx)
                      {
                          doulble rVal = 0;
                          if(idx >= 0 && idx < 10000)
                              rVal = this.gDataVal[idx];
                          return rVal;
                      }
                      
                      // Set Method
                      public void SetgDataVal(int idx, double iVal)
                      {
                          if(idx >= 0 && idx < 10000)
                              this.gDataVal[idx] = iVal;
                      }
                      }
                      Then, in the section of the partial area of the global file, add this.

                      Code:
                      public static GlobalData gData = new GlobalData();
                      Now, when you set the GlobalData in strategy 1, it should be done as such

                      Code:
                      gData.Set(CurrentBar, pnl);
                      And read in strategy 2 as such.

                      Code:
                      double val = gData.Get(CurrentBar);
                      This is no longer a "quick and dirty way," as we now encapsulate our array with a class, get, and set methods which do all of our array indexing error conditions within.

                      Does this make sense?

                      mrLogik
                      mrlogik
                      NinjaTrader Ecosystem Vendor - Purelogik Trading

                      Comment


                        #41
                        Originally posted by astrolobe View Post
                        mrlogik,
                        I tried your code but received the following error: System.UnauthorizedAccessException: Access to the path 'C:\test.txt' is denied.
                        Do you have an idea why this is happening?

                        thanks.
                        Are you the admin on the computer you are working with?

                        Also, the Initialize section should read something like this...

                        Code:
                         
                        LogFile = new DataLogType(".csv", "NTLOGS\\", "aGridEntryV1_LOG")
                        Where
                        .csv = file extension
                        NTLOGS = the folder to write to (C:\NTLOGS)
                        aGridEntryV1_LOG = the log file name.

                        The NTLOGS director MUST exist in order to write a file to it.

                        hope this helps
                        mrlogik
                        NinjaTrader Ecosystem Vendor - Purelogik Trading

                        Comment


                          #42
                          Thanks.

                          MrLogik: Thanks for posting the GlobalStrategy.cs code. :-)

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          627 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          359 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
                          562 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