Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access data Series and Position data from UI Button click Events

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

    Access data Series and Position data from UI Button click Events

    Hello all!

    In my strategy, I create several UI elements including buttons.
    If I understand correctly, then indicator data (e.g. atr), price data (OHLC), Volume and position status are not always available from the thread where the buttons are running.
    How can I get a guaranteed access to this data from UI Event or Timer Event?​

    #2
    Hello tanas.eduard,

    Thanks for your post.

    The TriggerCustomEvent() method should be used to use your own custom events (such as a Timer object) so that internal NinjaScript indexes and pointers are correctly set prior to processing user code triggered by your custom event. When calling this event, NinjaTrader will synchronize all internal pointers and then call your custom event handler where your user code is located.

    See this help guide page for more information about TriggerCustomEvent() and sample code: https://ninjatrader.com/support/help...ustomevent.htm

    Let me know if I may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thanks! We wiil learn this method, i think this is all we need.

      Comment


        #4
        Hey tanas, I have had the same problem. I found running a AddDataSeries of 1-Second and just processing the buttons on close of bar that is quick enough and everything is addressable. Hope this helps.

        Comment


          #5
          Hello tanas.eduard,

          Thanks for your notes.

          You may view the SampleWPFModifications reference sample from the NinjaTrader 8 help guide for an example that adds event handler methods to buttons.

          SampleWPFModifications: https://ninjatrader.com/support/help...ui)-modifi.htm

          The ChartOrderButtonExamples script located on this help guide page might also be helpful to you view: https://forum.ninjatrader.com/forum/...18#post1126818

          Please let me know if I may assist further.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            Originally posted by kenz987 View Post
            Hey tanas, I have had the same problem. I found running a AddDataSeries of 1-Second and just processing the buttons on close of bar that is quick enough and everything is addressable. Hope this helps.
            Nice Cheat!!!! Thanks!

            Comment


              #7
              Originally posted by NinjaTrader_BrandonH View Post
              Hello tanas.eduard,

              Thanks for your notes.

              You may view the SampleWPFModifications reference sample from the NinjaTrader 8 help guide for an example that adds event handler methods to buttons.

              SampleWPFModifications: https://ninjatrader.com/support/help...ui)-modifi.htm

              The ChartOrderButtonExamples script located on this help guide page might also be helpful to you view: https://forum.ninjatrader.com/forum/...18#post1126818

              Please let me know if I may assist further.
              Thanks for example! I think is very cool example in thread.

              Comment


                #8
                Originally posted by NinjaTrader_BrandonH View Post
                Hello tanas.eduard,

                Thanks for your notes.

                You may view the SampleWPFModifications reference sample from the NinjaTrader 8 help guide for an example that adds event handler methods to buttons.

                SampleWPFModifications: https://ninjatrader.com/support/help...ui)-modifi.htm

                The ChartOrderButtonExamples script located on this help guide page might also be helpful to you view: https://forum.ninjatrader.com/forum/...18#post1126818

                Please let me know if I may assist further.


                Hi Brandon.
                I try to use TriggerCustomEvent, but in some cases have error.
                So i have OnClickEvent and in this event:
                PHP Code:
                  TriggerCustomEvent(o => { PlaceExitMar****rder(); }, null); 
                
                The function PlaceExitMar****rder have some logic but when they try access Position.Quantity - most times is zero.
                Can you help me and what the problem?

                Code of PlaceExitMar****rder
                PHP Code:
                 private void PlaceExitMar****rder()
                        {
                            LogEvent("PlaceExitMar****rder", "Entry");
                
                            CancelAllOrders();
                            ClearClosedOrders();
                
                            logDic.Add("Position.Quantity", Position.Quantity);
                
                            LogEvent("PlaceExitMar****rder", "Work", "Place exit order", logDic);
                
                            _trade.StopLoss.Quantity = Position.Quantity;
                            _trade.StopOrderPlaced = true;
                
                            if (IsLong)
                                _orderSL = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Market, Position.Quantity, 0, 0, "", _orderNameSL);
                
                            if (!IsLong)
                                _orderSL = SubmitOrderUnmanaged(0, OrderAction.BuyToCover, OrderType.Market, Position.Quantity, 0, 0, "", _orderNameSL);
                
                            LogEvent("PlaceExitMar****rder", "Exit");
                        }&#8203; 
                

                Comment


                  #9
                  Hello tanas.eduard,

                  Thanks for your notes.

                  What you could consider doing is using OnOrderUpdate() to check if the order.Name is equal to your entry order's SignalName that was placed and check if the orderState of the order is OrderState.Filled. Then, you could save the quantity of the order to a variable to use later in the script. This will allow you to get the position quantity of the order once the order was placed.

                  OnOrderUpdate() is an event driven method which is called each time an order managed by a strategy changes state. An order will change state when a change in order quantity, price or state (working to filled) occurs.

                  See this help guide page for more information about OnOrderUpdate(): https://ninjatrader.com/support/help...rderupdate.htm

                  Let me know if I may assist further.
                  <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                  Comment


                    #10
                    Originally posted by NinjaTrader_BrandonH View Post
                    Hello tanas.eduard,

                    Thanks for your notes.

                    What you could consider doing is using OnOrderUpdate() to check if the order.Name is equal to your entry order's SignalName that was placed and check if the orderState of the order is OrderState.Filled. Then, you could save the quantity of the order to a variable to use later in the script. This will allow you to get the position quantity of the order once the order was placed.

                    OnOrderUpdate() is an event driven method which is called each time an order managed by a strategy changes state. An order will change state when a change in order quantity, price or state (working to filled) occurs.

                    See this help guide page for more information about OnOrderUpdate(): https://ninjatrader.com/support/help...rderupdate.htm

                    Let me know if I may assist further.
                    Hello Brandon.
                    I know about this method by in my strategy i use IB connection and can't correct use OnOrderUpdate with stocks.
                    At this time i need use a TriggerCustomEvent for sync all data and access position from Button event.
                    Can i do this and if can - how?

                    Comment


                      #11
                      Hello tanas.eduard,

                      If the orders are being submitted through the strategy using native strategy methods, all orders will updated in OnOrderUpdate(), including Equity instruments (stocks).

                      Try printing the order object in OnOrderUpdate().

                      Code:
                      protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
                      {
                      Print(order.ToString());
                      }


                      The position is not a series, and does not need to be synchronized with TriggerCustomEvent(). This is necessary for using Series information such as the Close series or the Time series, or an indicator plot Value series.

                      Below is a link to a video that demonstrates.
                      Chelsea B.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by AHamxa, Today, 11:24 PM
                      0 responses
                      5 views
                      0 likes
                      Last Post AHamxa
                      by AHamxa
                       
                      Started by AHamxa, Today, 11:22 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post AHamxa
                      by AHamxa
                       
                      Started by AHamxa, Today, 11:17 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post AHamxa
                      by AHamxa
                       
                      Started by Spiderbird, 07-27-2018, 07:52 PM
                      12 responses
                      9,240 views
                      2 likes
                      Last Post Mountain_cast  
                      Started by chrischongpdx, Today, 09:39 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post chrischongpdx  
                      Working...
                      X