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

Help with chart trader and button

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

    Help with chart trader and button

    HI, original dev is no longer available and I need to change a button behavior and I am somewhat lossed at how to proceeed. I stripped code whatever is pertaining to show fib levels button.

    Originally developed to have a button click and wait for an event, and cant do anything else. I added button12 to be able to show fib levels. it currently shows as expected for now, but i cant enter order with my other buy market button.

    I need:
    - 1. button12 click on - show fib, click off - remove fib object (Currently if button is pressed it draws Fib and i have to press custom cancel button for it to stop drawing and only then ablle to press other buttons)
    - 2. if fib button is pressed or clicked, i can still enter market with other button

    I already looked though other examples of chart traders and understand what they are doing but I need help with my script as it is different.

    private enum WTROrderEntryCommandsState
    {
    Awaiting,
    FibRetraceShow,
    }
    private WTROrderEntryCommandsState wtrOrderEntryCommandsState = WTROrderEntryCommandsState.Awaiting;

    protected void Button13Click(object sender, RoutedEventArgs e) // Fib show
    {
    if (wtrOrderEntryCommandsState == WTROrderEntryCommandsState.Awaiting)
    {
    wtrOrderEntryCommandsState = WTROrderEntryCommandsState.FibRetraceShow;
    buttonsArray[12].Background = Brushes.DarkGray;
    buttonsArray[12].Foreground = Brushes.Black;

    Draw.TextFixed(this, "atmNotSelected", "Fib...", TextPosition.BottomRight);
    ForceRefresh();

    }
    }

    if (atmStrategy == null && atmStrategy1 == null)
    {
    if(wtrOrderEntryCommandsState == WTROrderEntryCommandsState.FibRetraceShow)
    {
    Print("condition1");
    Draw.FibonacciRetracements(this, "fib", true, 20, High[20], 2, Low[2]);
    }
    }

    region FIB retrace
    if (wtrOrderEntryCommandsState == WTROrderEntryCommandsState.FibRetraceShow)
    {

    Draw.FibonacciRetracements(this, "fib", true, CurrentBar-llDrawnbar, llPriceLevel , CurrentBar-hhDrawnbar, hhPriceLevel1);
    fibpressed = true;

    }
    if(fibpressed){

    }
    #endregion
    protected void CreateWPFControls()
    {
    chartTraderGrid = (chartWindow.FindFirst("ChartWindowChartTraderCont rol") as Gui.Chart.ChartTrader).Content as System.Windows.Controls.Grid;

    chartTraderButtonsGrid = chartTraderGrid.Children[0] as System.Windows.Controls.Grid;

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

    instrumentSelector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlInstrumentSelector") as System.Windows.Controls.ComboBox;
    chartTrader = Window.GetWindow(ChartControl.Parent).FindFirst("C hartWindowChartTraderControl") as ChartTrader;
    buyHighSellLowButtonsGrid1 = new System.Windows.Controls.Grid();
    System.Windows.Controls.Grid.SetColumnSpan(buyHigh SellLowButtonsGrid1, 12);

    buyHighSellLowButtonsGrid1.ColumnDefinitions.Add(n ew System.Windows.Controls.ColumnDefinition());
    buyHighSellLowButtonsGrid1.ColumnDefinitions.Add(n ew System.Windows.Controls.ColumnDefinition() { Width = new GridLength((double)Application.Current.FindResourc e("MarginBase"))});
    buyHighSellLowButtonsGrid1.ColumnDefinitions.Add(n ew System.Windows.Controls.ColumnDefinition());

    buttonsArray = new System.Windows.Controls.Button[13];
    buttonsArray[12] = new System.Windows.Controls.Button()
    {
    Content = "FIB",
    Height = BuySellButtonsHeight,
    Margin = new Thickness(0,0,0,0),
    Padding = new Thickness(0,0,0,0),
    Style = basicButtonStyle
    };
    buttonsArray[12].Background = Brushes.Red;
    buttonsArray[12].Click += Button13Click;
    System.Windows.Controls.Grid.SetColumn(buttonsArra y[12], 0);
    buyHighSellLowButtonsGrid1.Children.Add(buttonsArr ay[12]);

    public void DisposeWPFControls()
    {
    if (buttonsArray[12] != null)
    buttonsArray[12].Click -= Button13Click;
    RemoveWPFControls();
    }

    public void InsertWPFControls()
    {
    chartTraderButtonsGrid.RowDefinitions.Add(addedRow 10);
    System.Windows.Controls.Grid.SetRow(buyHighSellLow ButtonsGrid1, (chartTraderButtonsGrid.RowDefinitions.Count - 1));
    chartTraderButtonsGrid.Children.Add(buyHighSellLow ButtonsGrid1);

    panelActive = true;
    }

    protected void RemoveWPFControls()
    {
    if (buyHighSellLowButtonsGrid1 != null)
    {
    chartTraderButtonsGrid.Children.Remove(buyHighSell LowButtonsGrid1);
    chartTraderButtonsGrid.RowDefinitions.Remove(added Row10);
    }
    panelActive = false;
    }​

    #2
    Hello tkaboris,

    You have:
    buttonsArray[12].Click += Button13Click;

    Is this intentional that you are assigning the Button13Click method to the buttonsArray[12] Click event handler?

    Does Button13Click submit a market order?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      hI yes, its intentional and Button13Click draws fib levels and evaluates to true in to fibpressed = true;
      so button is pressed and i need to hit cancel button for it to cancel, and i need to click fib button again in order to cancel it, instead.

      Comment


        #4
        Hello tkaboris,

        I'm not certain I am understanding.

        I'm not seeing any cancel button or any other button than buttonsArray[12] in your code.

        There doesn't appear to be any other buttons or click handler methods in the code.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          HI as i mentioned in first post i tried to strip down code and didnt include other button code. I attached a code for chart trader if its easier... or i can post more code here for other button

          Comment


            #6
            Hello tkaboris,

            What is the name of the variable holding the button object that you are clicking?

            What is the logic in the event handler method for that button?

            Have you added prints in the hander method to understand why the logic is not evaluating as you expect?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              right now its button13click is the logic. What i did is i only added a button12 with button13 click and it mimicks other button behavior. I need a new behavior just click on show, click off remove object.



              protected void Button13Click(object sender, RoutedEventArgs e) // Fib show
              {
              if (wtrOrderEntryCommandsState == WTROrderEntryCommandsState.Awaiting)
              {
              wtrOrderEntryCommandsState = WTROrderEntryCommandsState.FibRetraceShow;

              buttonsArray[12].Background = Brushes.DarkGray;
              buttonsArray[12].Foreground = Brushes.Black;

              Draw.TextFixed(this, "atmNotSelected", "Fib...", TextPosition.BottomRight);
              ForceRefresh();

              }
              }

              Have you added prints in the hander method to understand why the logic is not evaluating as you expect? - There is no desired logic implemented by me yet becuse i am stuck.​

              Comment


                #8
                Hello tkaboris,

                There is no order submission from this code.

                Is the order supposed to be submitted from somewhere else?

                Is this based on the value of the wtrOrderEntryCommandsState variable?

                What code submits the order that is not appearing when expected?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I believe its based on value in wtrOrderEntryCommandsState variable and its ok for other buttons. For fib button it should be different, not based on wtrOrderEntryCommandsState, since its only click on click off...

                  Comment


                    #10
                    Hello tkaboris,

                    What is the issue you are having?

                    I was under the impression that you are clicking a button that is meant to submit an order and the order is not being submitted.

                    Is this not the case?

                    If this is the case, the Button13Click method does not submit any orders. Are you intending to call an order method in the Button13Click method?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I am sorry for the confusion..
                      I want button13click to show fib levels and when clicked again i want to remove those fib objects levels.

                      Not to submit order. There are so many parts to this chart trade buttons that i am not sure where and then what to place.

                      Comment


                        #12
                        Hello tkaboris,

                        I added button12 to be able to show fib levels. it currently shows as expected for now, but i cant enter order with my other buy market button.
                        Just to confirm, the issue you posted in post # 1 is not the issue.

                        The issue is that you want to remove a drawing object when the button is clicked.

                        If so, call RemoveDrawObject() and supply the tag name of the drawn object to remove it.
                        https://ninjatrader.com/support/help...drawobject.htm

                        Use a bool to know that the button was clicked once already.

                        Code:
                        private bool buttonClicked;
                        
                        In the Button13Click method:
                        
                        // toggle value if true set to false if false set to true, 
                        buttonClicked = !buttonClicked;
                        
                        if (buttonClicked)
                        {
                        // draw object
                        }
                        else
                        {
                        // remove draw object
                        }
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          thank you
                          i have in button13 area

                          if (fibpressed)
                          {
                          Print("draw fib");
                          Draw.FibonacciRetracements(this, "fib", true, CurrentBar-llDrawnbar, llPriceLevel , CurrentBar-hhDrawnbar, hhPriceLevel1);
                          }
                          else
                          {
                          Print("remove fib");
                          RemoveDrawObject("fib");
                          }
                          fibpressed = !fibpressed;


                          my output when i do first click and next click gets an error is:

                          remove fib
                          draw fib
                          hhPriceLevel1:14943.75

                          its kind of backwards.. fibpressed is initilazed as false​

                          Comment


                            #14
                            Hello tkaboris,

                            You have mentioned there is an error appearing?

                            What is the full error message on the Log tab of the Control Center?

                            You could call fibpressed = !fibpressed; before the condition sets.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              hi with this code i get

                              protected void Button13Click(object sender, RoutedEventArgs e) // Fib show
                              {
                              fibpressed = !fibpressed;
                              if (fibpressed)
                              {
                              Print("draw fib");
                              Print("hhPriceLevel:"+hhPriceLevel);
                              Print("llPriceLevel:"+llPriceLevel);
                              Print(CurrentBar-llDrawnbar);
                              Print(CurrentBar-hhDrawnbar);
                              Draw.FibonacciRetracements(this, "fib", true, CurrentBar-llDrawnbar, llPriceLevel , CurrentBar-hhDrawnbar, hhPriceLevel);
                              }
                              else
                              {
                              Print("remove fib");
                              RemoveDrawObject("fib");
                              }
                              fibpressed = !fibpressed;




                              buttonsArray[12].Background = Brushes.DarkGray;
                              buttonsArray[12].Foreground = Brushes.Black;

                              ForceRefresh();


                              }​

                              draw fib
                              hhPriceLevel:14965.75
                              llPriceLevel:14956.25
                              63
                              48
                              remove fib
                              remove fib
                              remove fib​
                              ​Obejct refereccnee not set on instance of an object

                              it doesnt draw and one i click on button it should draw/remove/draw/remove, not remove/remove/remove sequence...

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Option Whisperer, Today, 09:55 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post Option Whisperer  
                              Started by geddyisodin, 04-25-2024, 05:20 AM
                              8 responses
                              58 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by halgo_boulder, 04-20-2024, 08:44 AM
                              2 responses
                              22 views
                              0 likes
                              Last Post halgo_boulder  
                              Started by mishhh, 05-25-2010, 08:54 AM
                              19 responses
                              6,189 views
                              0 likes
                              Last Post rene69851  
                              Started by gwenael, Today, 09:29 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post gwenael
                              by gwenael
                               
                              Working...
                              X