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

Trade Buttons NT8

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

    #16
    Hello tonynt,

    I have attached a demonstration showing how Width, MinWidth, and MaxWidth can be modified change the button's width.

    Demo - https://drive.google.com/file/d/1T6u...w?usp=drivesdk
    JimNinjaTrader Customer Service

    Comment


      #17
      Thank you!

      Comment


        #18
        Hello,

        I couldn´t find how to close positions immediately when script is COBC=true. In the sample it works immediately/with next tick because sample script is COBCfalse.
        Is there a possibility to close positions of a trade (not all instruments like "NinjaTrader.Gui.SuperDom.SuperDom.FlattenEverythi ng();") and keep running trades in other instruments?

        If the answer will be no does "AtmStrategyClose(atmStrategyId);" close only that trade immediately, even with COBCtrue?

        Thank you!
        Tony

        Comment


          #19
          Hello tonynt,

          I would recommend following the example to use Calculate.OnEachTick so your buttons can have the quickest action to trigger actions in OnBarUpdate. If you would like to have the strategy be as performant as a script that uses Calculate.OnBarClose, then you can modify the logic to use IsFirstTickOfBar and adjust your barsAgo references from 0 to 1 to reference the bar that had just closed.

          IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

          AtmStrategyClose will close the ATM strategy immediately if you place that code with the Click event. If you place this code in OnBarUpdate it will close the Atm strategy based on the Calculate mode.

          Please let us know if you have any additional questions.
          JimNinjaTrader Customer Service

          Comment


            #20
            Hello Jim,

            thank you for your reply and the informaton with FirstTickOfBar. I was working with FirstTickOfBar and COBCfalse but I remember that I got the information that COBCfalse is more CPU intenvsive than COBCtrue. Therefore I switched all to COBCtrue to avoid frozen situation that occured frequently (in NT7) when more scripts running.

            I thought there might be a possibility outside onbarupdate to have immediate action with click on buttons. It will not work in OnExecution nor OnOrderUpdate. Maybe in "protected override void OnMarketData(MarketDataEventArgs e)" or anything else?

            Thank you!
            Tony

            Comment


              #21
              Hello tonynt,

              Calculating on each tick has a greater impact because the OnBarUpdate logic is processed numerous times per bar. Placing your OnBarUpdate logic within a check for IsFirstTickOfBar ensures that the logic is only iterated on the first tick of a new bar, or when the bar close would occur. The impact would be relatively equal.

              The concept behind the example is to set a bool when the button is pressed so your desired action that would be fired in OnBarUpdate happens on the next iteration of OnBarUpdate. Order methods can be fired from OnMarketData, however this method is always guaranteed to be called after OnBarUpdate. If you are looking for more immediacy, you can try using the Click event instead of waiting for the next tick to iterate your OnBarUpdate logic. See the example's OnButtonClick method for how the example fires code on button clicks.

              Please let us know if we can be of further assistance.
              JimNinjaTrader Customer Service

              Comment


                #22
                Hello Jim,

                thank you for your support referring this sample Helped me a lot and I can modify now.

                Best regards
                Tony

                Comment


                  #23
                  Hello,

                  another question for understanding OnButtonClick please:

                  with "button.Content = Position.Quantity.ToString();" one can update correctly in OnExecution and in OnBarUpdate.
                  But it does not work in OnButtonClick. It does exit "L1a" but it does not change button content form 2 to 1 (as it does eg in OnExecution with hit of stop or target)
                  if (Position.Quantity==2)
                  {ExitLong("L1a");
                  button.Content = Position.Quantity.ToString();}

                  Thank you!
                  Tony

                  Comment


                    #24
                    Hello tonynt,

                    NinjaTrader 8 is multi threaded. WPF controls will operate on the UI thread while Order/Position/Execution events all have separate threads. The UI thread may process the button click before the position update occurs.

                    You could use a dispatcher to update the UI element from the thread that will receive that update. For example, do this in OnPositionUpdate if you are referencing the Position object.

                    Please see Multi Threading Considerations in post #6 for further details on multi threading concepts with NinjaTrader 8.

                    We look forward to being of further assistance.
                    JimNinjaTrader Customer Service

                    Comment


                      #25
                      Hello,

                      from a reply in the forum I know that when I have the "button actions" in "private void onButtonClick..." the action is immediately and not with close of bar when script is running COBCtrue. I assume this is correct because the entry is immediately with the code
                      private void onbuttonclick....
                      if(button==shortbutton){
                      if(button.Content == "cS")
                      {
                      entryOrderSba1a=EnterShortLimit(0,true,1,GetCurren tBid(), "Sba1a");
                      entryOrderSba1b=EnterShortLimit(0,true,1,GetCurren tBid(), "Sba1b");

                      BUT the exit does not work with

                      if(button == closeButton && button.Name == "CloseButton" && button.Content == "C")
                      {
                      if(Positions[0].MarketPosition == MarketPosition.Short)
                      {
                      ExitShort();
                      shortButton.Background = Brushes.LightSalmon;
                      shortButton.Content = "cS";
                      shortButtonClicked = false;
                      return;
                      }

                      if(Positions[0].MarketPosition == MarketPosition.Long)
                      {
                      ExitLong();
                      longButton.Background = Brushes.LightGreen;
                      longButton.Content = "cL";
                      longButtonClicked = false;
                      return;
                      }

                      It changes immediately with click on my close button the color and the content of the ShortButton but the close of the trade is not immediately, its only with 2 clicks, another test with 3 clicks...


                      What might be the reason for this please?

                      Thank you!
                      Tony
                      Last edited by tonynt; 09-02-2019, 08:46 AM. Reason: adding info

                      Comment


                        #26
                        Hello,

                        with further testing I see that the close button is also working when the instrument in the chart where the strategy is enabled is the same as the added instruments. When I had the MNQ running the script with NQ as BIP1 and BIP2 the close does not work immediately. When I run the same script (!) on an NQ chart the close button works immediately. Strange. Its not important now why this is, I dont want to bother, we know now when it works and when not.

                        Best regards
                        Tony

                        Comment


                          #27
                          Hello tonynt,

                          Button clicks would not be processed synchronously to the strategies OnBarUpdate code. The strategy may be processing a different BarsInProgress index when your button is clicked.

                          I would suggest using order methods where you can specify the specific BarsInProgress you want to exit.

                          For example: ExitLong(BIP, Positions[BIP].Quantity, "Button Exit", "")

                          Please let me know if there is anything else we can do to help.
                          JimNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by sidlercom80, 10-28-2023, 08:49 AM
                          168 responses
                          2,262 views
                          0 likes
                          Last Post sidlercom80  
                          Started by Barry Milan, Yesterday, 10:35 PM
                          3 responses
                          10 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by WeyldFalcon, 12-10-2020, 06:48 PM
                          14 responses
                          1,429 views
                          0 likes
                          Last Post Handclap0241  
                          Started by DJ888, 04-16-2024, 06:09 PM
                          2 responses
                          9 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by jeronymite, 04-12-2024, 04:26 PM
                          3 responses
                          41 views
                          0 likes
                          Last Post jeronymite  
                          Working...
                          X