Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

ChartTrader addon - how to make permanent?

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

    #31
    Hello DTSSTS,

    You are trying to retrieve an account assign to the account variable.

    Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") <- this gets the account selector

    chartTraderAccountSelector.SelectedAccount <- this is the selected account

    Assign the selected account to the account variable.

    account = chartTraderAccountSelector.SelectedAccount;


    Account.All.FirstOrDefault(a => a.Name == "Sim104"); <- this gets the Sim104 account. We don't want to force account, we want to use the SelectedAccount from the account selector.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #32
      this should not be used at all correct

      Account.All.FirstOrDefault(a => a.Name == "Sim104"); <- this gets the Sim104 account. We don't want to force account, we want to use the SelectedAccount from the account selector.


      AND DO NOT PLACE ALL THAT CODE FROM MY PREVIOUS POST IN THE INDICATOR

      Comment


        #33
        Hello DTSSTS,

        This gets the Sim104 account as an Account object. You don't want the Sim104 account. You want the Account from the AccountSelector.

        No, when looking at examples, these are education samples to learn from and not to copy all of the code from one script to another.

        I would recommend understanding every line of code. And then writing your custom logic in your script.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #34
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello DTSSTS,

          You are trying to retrieve an account assign to the account variable.

          Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") <- this gets the account selector

          chartTraderAccountSelector.SelectedAccount <- this is the selected account

          Assign the selected account to the account variable.

          account = chartTraderAccountSelector.SelectedAccount;


          Account.All.FirstOrDefault(a => a.Name == "Sim104"); <- this gets the Sim104 account. We don't want to force account, we want to use the SelectedAccount from the account selector.
          *******************************

          this is where so much confusion with support or the help guide, examples in the help guide are not real use examples

          you have

          Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector")

          example ChartTrader has

          NinjaTrader.Gui.Tools.AccountSelector chartTraderAccountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;

          SO I ADDED THE FOLLOWING

          // account = Account.All.FirstOrDefault(a => a.Name == "Sim104");// need modified
          NinjaTrader.Gui.Tools.AccountSelector chartTraderAccountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;

          // chartTraderAccountSelector.SelectedAccount
          account = chartTraderAccountSelector.SelectedAccount;


          THIS WAS ALREADY THERE
          if (account != null)
          account.OrderUpdate += Account_OrderUpdate;

          if (ChartControl != null)
          CreateWPFControls();

          ***************************************

          NO COMPILE ERRORS BUT ERRORS ON LOADING

          error on callin OnStateChange method; the calling thread cannot access this object becasue a different thread owns it.

          Comment


            #35
            while researching a solution i found a post about
            they wrote
            As it is running async, data might not be available immediately, which can be annoying.

            So I ended up using a parameter to specify my account:

            THEY DID SIMILAR TO WHAT YOU DID WITH "Sim101", which is ok if Sim101 could be called by a variable User Input

            then with a user input we could change you code

            account = Account.All.FirstOrDefault(a => a.Name == "Sim101");

            to be something like this

            account = Account.All.FirstOrDefault(a => a.Name == "tradeAccount");

            with user variable input TradeAccount: " "


            CAN THAT BE DONE?

            Comment


              #36
              Hello DTSSTS,

              Yes, assigning the <AccountSelector>.SelectedAccount to the account variable is correct.

              Each error experienced is an opportunity to learn C#.

              The 'as' keyword is cast. This takes an ambiguous object and casts it as a specific type. In this case, the 'as NinjaTrader.Gui.Tools.AccountSelector' is casting the returned object found in the window from an automation id as an AccountSelector. This allows the found object to be used as an AccountSelector.

              When attempting to access anything in another thread, such as attempting to access the window on the UI thread, requires invoking into the other thread.

              In the example, the code to traverse the window is run from ChartControl.Dispatcher.InvokeAsync on line 49.

              Below is a link to the help guide.



              If you would like to hard code the account instead of getting the account from account selector, this is your choice to make.

              The example I have provided you is a working example of getting the account from the account selector.


              You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #37
                CreateWPFControls();


                YOU USED create in the button example

                in the other example line 51 InsertWPFControls(); is being used

                I placed

                ChartControl.Dispatcher.InvokeAsync((Action)(() =>

                into the script but still have same error on calling OnStatChange method. The calling thread cannot access this object because a different thread owns it

                HOW DO I OWN IT or borrow it

                Comment


                  #38
                  Hello DTSSTS,

                  This is Jim responding on behalf of Chelsea, who is out of the office at this time.

                  We are not sure which example you are referring to by "other example." Do you mean the "ChartToolBarCustomMenuExample" example that calls InsertWPFControls on line 61?

                  I recommend following the SampleWPFModifications script and to gain a full understanding on how that script functions when performing WPF modifications as SampleWPFModifications is the most recent example that shares the most consistency among approaches.

                  You would not "own" another thread. Whatever is owned by a thread would be created on that thread and would have to be managed by that thread. For example, anything WPF related would be on the UI thread and would need to be accessed with a Dispatcher.
                  JimNinjaTrader Customer Service

                  Comment


                    #39
                    i hired some one to code we are not even going to use this method, I GAVE UP

                    Hiring is too expensive, so I just give up
                    Last edited by DTSSTS; 02-26-2021, 12:13 PM.

                    Comment


                      #40
                      I have decided to enter the Account Name and Quantity to trade from user input. But I am not sure how to place them in the proper script area

                      can you point me toward area in help guides or forum about this

                      I created public string AccountNametoTrade

                      current example has

                      account = Account.All.FirstOrDefault(a => a.Name == "Sim101");

                      would this

                      account = AccountNametoTrade;

                      or this


                      account = Account.All.FirstOrDefault(a => a.Name == "AccountNametoTrade");

                      be correct, I am thinking the LAST EXAMPLE

                      *************************

                      FOR ORDER QUANTITY USER INPUT I CREATED THE FOLLOWING

                      INPUT OrderQuantity = 2;

                      AS A public int OrderQuantity

                      then changed the order code as below, this does compile

                      Orignal Order code

                      Order mar****rder = account.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, 2, 0, 0, string.Empty, "Long conditional", new DateTime(), null);

                      THE 2 JUST AFTER TimeInForce.Day IS THE QUANTITY, so changed the 2 to OrderQuantity

                      Order mar****rder = account.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, OrderQuantity, 0, 0, string.Empty, "Long conditional", new DateTime(), null);




                      Thanks to anyone who can assist
                      Last edited by DTSSTS; 02-27-2021, 06:27 PM.

                      Comment


                        #41
                        Hello DTSSTS,

                        I encourage you to see your first inquiry out. It's possible to do, but will take some patience to fully understand. And I highly encourage you to ask clarifying questions about how things work along the way. I'm not able to write it for you at request, as we have an ecosystem of educators and developers at the ready to fill that service. But if you the time to learn, you become much more highly effective at being able more sophisticated tools that deliver more precise results.

                        With "AccountNametoTrade", the quotation marks indicate a string. Strings are characters like a sentence, message, or label, and are not variables that hold a value.

                        Variables do not use the quotation marks. Variables are a reference to a stored object.

                        As an example, a specific jar of strawberries that would would refer to as jar1 would be a variable holding an object where the properties are 'full of strawberries'.
                        A string would be written on a piece of masking tape on the front of the jar: "this is my first jar of strawberries".


                        With the code:
                        "INPUT OrderQuantity = 2;

                        AS A public int OrderQuantity"

                        This would not work at all, or compile.

                        Something declared as an int, does need to be casted. It's already an integer.

                        In the scope of the class:
                        public int OrderQuantity;

                        In OnStateChange() of an Indicator when State is State.DataLoaded, in the Loaded event of an addon:
                        OrderQuantity = 2;
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #42
                          All i got from this is what i am doing will NOT work,

                          Both now Working
                          Last edited by DTSSTS; 02-28-2021, 07:33 PM.

                          Comment


                            #43
                            Hello DTSSTS,

                            I'm not sure what you are doing. But what you are asking for can be created using the code I have provided you.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #44
                              they are working as expected now, with modifications

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Tim-c, Today, 02:10 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Taddypole, Today, 02:47 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Taddypole  
                              Started by chbruno, 04-24-2024, 04:10 PM
                              4 responses
                              50 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              10 responses
                              400 views
                              1 like
                              Last Post beobast
                              by beobast
                               
                              Started by lorem, Yesterday, 09:18 AM
                              5 responses
                              25 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X