Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple positions when not wanted

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

    #31
    Found it. For anyone interested, System.Data.dll is in Windows\Microsoft.Net\Framework64\v2.050727. Once referenced, the compiler recognises "DataTable"

    Comment


      #32
      I believe now that I do not need a DataTable. I just need all my strategies to enter their strategy id and market position in a Dictionary, so each strategy can see the Dictionary entry of other strategies. To be sure that every strategy is looking at the same Dictionary, is it enough to define the dictionary as public or static in each strategy, or must common access be via a user defined method?
      I've added methods to the UserDefinedMethod for indicators but my strategies do not find these methods when compiled: I get CS0I03 errors. I cannot see what I have missed out in the UDM or strategies. Can anyone suggest anything?

      Comment


        #33
        Xenophon99,

        There is a UserDefinedMethod.cs available for Strategies and one for Indicators. Each one will only affect the base that it is located in. You can open and add Defined methods for the strategy by going to Tools -> Edit NinjaScript -> Strategy -> User Defined Method
        Cal H.NinjaTrader Customer Service

        Comment


          #34
          Yes, that has been done. The UDM for indicators contains;

          namespace ..
          { partial class ...
          { public static Dictionary<string, bool> gvPosn = new Dictionary<string, bool>();
          public void SetStratPosn(string id, bool value)
          { ... update or add dictionary entry
          }

          public bool AccountFlat(string id)
          { if any dictionary entry is false, return false and print relevant ids.
          otherwise return true.
          }
          }
          }

          Each strategy invokes SetStratPosn in OnPositionUpdate(), and AccountFlat in the sequence of entry conditions. The strategies do not compile because these method names are not recognised. The documentation on UDMs doesn't say why. Is there something else required to make these methods accessible? Also, I can find nothing on Dictionaries in NT7 Help. Do I even need a UDM if the dictionary is public and static? Can't it therefore be accessed by any strategy?

          Comment


            #35
            Xenophon99,

            Are you calling these methods from a Strategy script or Indicator script?
            Cal H.NinjaTrader Customer Service

            Comment


              #36
              "Each strategy invokes SetStratPosn in OnPositionUpdate(), and AccountFlat in the sequence of entry conditions. The strategies do not compile because these method names are not recognised. "

              So, yes, they are being called from strategy scripts.
              I am in the process of adding the strategy code to each strategy as an internally declared function, which will likely be more efficient than accessing the UDM. So I will than have to transform the private dictionary declaration in #variables to public, which is another challenge.

              Comment


                #37
                Xenophon99,

                Let's take a step back here.

                You said that you have included these methods into your Indicatorbase for User Defined Methods.

                is this correct?

                If so, you would not be able to access them from the Strategy.

                There are two separate files for the User Defined Methods, one for Strategies and one for Indicators/
                Cal H.NinjaTrader Customer Service

                Comment


                  #38
                  Thankyou for that crucial correction to my understanding of UserDefinedMethods. I can now eliminate simultaneous positions on multiple strategies by accessing a global dictionary in a strategy type UDM. I understand that much of this is outside the scope of NinjaTrader, so your generous comments have been much appreciated.
                  I was unable to export this UDM script. Is that limitation there by design?. .

                  Comment


                    #39
                    Hi Xenophon99,

                    The UserDefinedMethods.cs file is not included with exports. This means if you call an enum or class that is written into this file, that script will not be exportable.

                    This is so that if you write something in there, it isn't overwritten on a computer that the script is being imported on. (UserDefinedMethods are mean for the end user that programs and creates his or her own indicators/strategies to add code to for a custom setup.)

                    If you plan to export this strategy, I would not recommend using either UserDefinedMethods files for either indicators or strategies. Instead, create a new file that has the same type of setup as the UserDefinedMethods in that it uses the same NinjaTrader.Indicator or NinjaTrader.Strategy namespace.

                    Then include that extra file with your export.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by judysamnt7, 03-13-2023, 09:11 AM
                    4 responses
                    57 views
                    0 likes
                    Last Post DynamicTest  
                    Started by ScottWalsh, Today, 06:52 PM
                    4 responses
                    36 views
                    0 likes
                    Last Post ScottWalsh  
                    Started by olisav57, Today, 07:39 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post olisav57  
                    Started by trilliantrader, Today, 03:01 PM
                    2 responses
                    19 views
                    0 likes
                    Last Post helpwanted  
                    Started by cre8able, Today, 07:24 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post cre8able  
                    Working...
                    X