Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with chart trader and button

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

    #16
    Hello tkaboris,

    You've duplicated fibpressed = !fibpressed; instead of moving it.

    With the Object reference error, this may not be related to the bool, or the condition, or calling RemoveDrawObject..

    It might be due to calling a drawing object from a non-data-driven thread without using TriggerCustomEvent().

    Below is a link to the help guide.


    Also, are you certain the code below or elsewhere in the script is not causing an error?
    One line below the conditions action block, please add a print that just says Print("reached here");
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      i am sure that error doesnt come from anywhere else only this fib button. I am not sure how to go about TriggerCustomEvent

      i get that reached print after second toggle of the button
      draw fib (first toggle)
      hhPriceLevel:14987
      llPriceLevel:14977
      113
      13
      remove fib (second toggle)
      reached here​

      Comment


        #18
        Hello tkaboris,

        There is a code sample in the help guide linked in post # 16, under the heading 'Using TriggerCustomEvent to update a previously set custom Series<T> value'.

        You will need to call this method and put the logic in the callback to do anything related to bar information in a non-data-driven method.

        I am suggesting that either the Draw method call or the logic below the condition may be causing the order. This is still within the Click event hander method Button13Click().

        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 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


          #19
          hi looking at the example from
          https://ninjatrader.com/support/help...rcustomevent.h tm

          Do you mean i need to set values for draw fib method something like this?

          protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
          {

          if (conditionWhichRequiredUpdate)
          {

          TriggerCustomEvent(o =>
          {

          SomeVolumeData[20] = llPriceLevel;
          SomeVolumeData[21] = CurrentBar-llDrawnbar;
          SomeVolumeData[22] = CurrentBar-hhDrawnbar ;
          SomeVolumeData[23] = hhPriceLevel;

          }, null);


          conditionWhichRequiredUpdate = false;
          }​

          Comment


            #20
            i also begin to see this error when i click fib button to draw. But i dont have index parameter in the code
            Click image for larger version

Name:	image.png
Views:	118
Size:	74.3 KB
ID:	1276082

            Comment


              #21
              Hello tkaboris,

              The call to TriggerCustomEvent would be placed in your Button13Click in the if statement where the Draw method is being called.

              The Draw method would be in the callback function in TriggerCustomEvent. The bar series needs to be synchronized from a non-data-driven method so that you can attach a drawing object to a specific bar.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                can you please look at previous reply? i am getting a new error, is it related?

                Comment


                  #23
                  Hello tkaboris,

                  This error can also result from calling a draw method from a non-data-driven method without using TriggerCustomEvent().

                  May I confirm that you have added this?

                  But i dont have index parameter in the code
                  This is not correct. You are using two barsAgo indexes in your Draw.FibonacciRetracements() call, supplied by the CurrentBar-llDrawnbar and CurrentBar-hhDrawnbar variables.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    no i havent added TriggerCustomEvent. its still confusing how to add.

                    Comment


                      #25
                      Hello tkaboris,

                      Code:
                      fibpressed = !fibpressed;
                      
                      if (fibpressed)
                      {
                         TriggerCustomEvent(o =>
                         {​​
                             Draw.FibonacciRetracements(this, "fib", true, CurrentBar-llDrawnbar, llPriceLevel , CurrentBar-hhDrawnbar, hhPriceLevel);
                         }, null);
                      }
                      else
                      {
                      Print("remove fib");
                      RemoveDrawObject("fib");
                      }​
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        hi thank you it seems to be working at this point. I thought i had to do lot more coding from that example but it was just couple of lines.

                        May I ask another question.
                        as you probalby saw chart trader(indicator2) dependent on fvg indicator(indicator1)
                        indicator2 is on calcualte oneachtick
                        indicator1 is on calculate onbarclose.

                        when i print HH levels from indicator2, it prints all HH and LH levels, becacuse calculate mode different and i need to change indicator2 to onbarclose in order to print only HH levels.

                        if(IsFirstTickOfBar ){

                        Print("hhPriceLevel1 in Chart Trader:"+fvgInd.HHPriceLevel);

                        }

                        My question is there a work around that you can provide an idea to how to go about it so that when i print HH levels from indicator2 and it will print only HH levels? i need charttrader(indicator2) on everytick.​
                        Click image for larger version

Name:	image.png
Views:	178
Size:	88.8 KB
ID:	1276110

                        Comment


                          #27
                          Hello tkaboris,

                          Any hosted symbiote script must use the same Calculate setting as the host.

                          Meaning both should be Calculate.OnEachTick.

                          If you want to trigger some actions only after bar close, put this in a condition that checks IsFirstTickOfBar is true.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #28
                            ok.
                            upon checking futher i see that this code produces error, but it compiles and goes away, Once you start making other changes error comes up again
                            protected void Button13Click(object sender, RoutedEventArgs e) // Fib show
                            {
                            fibpressed = !fibpressed;

                            if (fibpressed)
                            {
                            TriggerCustomEvent(o =>
                            {
                            Print("fib drawn");​​
                            Draw.FibonacciRetracements(this, "fib", true, CurrentBar-llDrawnbar, llPriceLevel , CurrentBar-hhDrawnbar, hhPriceLevel);
                            }, null);
                            }
                            else
                            {
                            Print("remove fib");
                            RemoveDrawObject("fib");
                            }​


                            }​
                            Click image for larger version

Name:	image.png
Views:	123
Size:	291.1 KB
ID:	1276125

                            Comment


                              #29
                              Hello tkaboris,

                              If it goes away when you compile its a stale error.

                              Restart NinjaTrader.
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #30
                                thank you it worked, i also opened visual studio and it pipoints better where the stale character is.

                                I am also having one issue with something else. I was wondering if you can take a look at that thread?
                                primary index outside of bounds of array with initialiizing empty array thing. very simple script

                                HI i am converting simple indicator from pinescript that basically Congestion zone include at least 3 candle sticks that the next candle has an opening and closing price within the previous candle it gets compiled but i get error in logs error on calling onbarupdate method on bar 12, index was outside of the bounds of array how

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                607 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                353 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                105 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                560 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                561 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X