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

Indicator (IsVisible = false) but still continue to calculate in background

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

    Indicator (IsVisible = false) but still continue to calculate in background

    Hi, i load some indicators in my strategy and can make them visible or not visible with the IsVisible function. unfortunately, if IsVisible = false, no more calculations are made. how can i make the indicator temporarily invisible in the chart but still have it calculated, as if the colour is temporarily set to transparent? IsVisible = false, but with continuation calculation in background
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    #2
    Hello sidlercom80,

    Thank you for your post.

    You would be able to trigger a plot to be transparent and still calculate in the background by creating a bool property named something like 'PlotOnChart' in your indicator. Then, you would check if the bool is false and call PlotBrushes[0][0].Transparent to have the indicator temporarily transparent. If at any point you wish to view the indicator, you would open the Indicators screen and check the PlotOnChart checkbox.

    See the attached example that demonstrates how this could be accomplished. Also, please see the help guide documentation for more information.
    NinjaScript Property Attribute - https://ninjatrader.com/support/help...yattribute.htm
    PlotBrushes[][] - https://ninjatrader.com/support/help...lotbrushes.htm

    Please let us know if we may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi _BrandonH, thanks for the answer. the problem with this method is that the indicator has to be reloaded to update everything. since i run the indicator over my strategy, i can't restart the straegy every time i want to make the indicator visible and vice versa. how do i get it to redraw the indicator line from the beginning without reloading the strategy?

      Click image for larger version  Name:	Screenshot_1.jpg Views:	0 Size:	18.5 KB ID:	1144907

      there should be a function like "IsVisible" only that the indicator is always calculated in the background, even if "IsVisible = false", that would be the easiest solution ;-)
      Last edited by sidlercom80; 03-04-2021, 11:09 AM.
      sidlercom80
      NinjaTrader Ecosystem Vendor - Sidi Trading

      Comment


        #4
        Hello sidlercom80,

        Thank you for your note.

        You could accomplish your goal by creating a button within your indicator that triggers your plot color to change to PlotBrushes[0][0] == Brushes.Transparent when clicked and back to visible (PlotBrushes[0][0] == Brushes.Blue) when clicked again.

        Please see the attached example script that demonstrates how this would be done.

        Let us know if we may assist further.
        Attached Files
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hi _BrandonH, that doesn't solve my problem! with the button you can now only switch on and off, but not reload without also reloading the indicator. now it is the case that when the button is switched on, the line is displayed and when it is switched off, it is not. however, when the line is displayed again, the whole line should also be drawn and not only from the point in time when the button was activated again.

          Click image for larger version

Name:	Screenshot_2.jpg
Views:	268
Size:	21.6 KB
ID:	1144924
          sidlercom80
          NinjaTrader Ecosystem Vendor - Sidi Trading

          Comment


            #6
            Hello sidlercom80,

            Thank you for that information.

            To have the entire indicator show as transparent/visible when clicking the button, you would need to replace PlotBrushes[0][0] == Brushes.Transparent and PlotBrushes[0][0] == Brushes.Blue in the previously attached example script with Plots[0].Brush == Brushes.Transparent and Plots[0].Brush == Brushes.Blue.

            This is because PlotBrushes[0][0] holds an array of color series objects holding historical bar colors and Plots[0] is a collection holding all of the Plot objects that define their visual characteristics.

            See the help guide documentation below for more information.

            Plots[] - https://ninjatrader.com/support/help.../nt8/plots.htm
            PlotBrushes[][] - https://ninjatrader.com/support/help...lotbrushes.htm

            Let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Hi _BrandonH, thanks for your help! everything works now, except for one thing. i have a multi-coloured line, with Plots[].Brush the whole line has the same colour. how can i change this so that the line becomes multi-coloured again? do you have another tip for me ;-)

              the multi-coloured line is drawn like this until now:

              Code:
              if (IsRising(Line))
              {
                 PlotBrushes[0][0] = UpColor;
              }
              else if (IsFalling(Line))
              {
                 PlotBrushes[0][0] = DownColor;
              } 
              else
              {
                 PlotBrushes[0][0] = LineColor;
              }
              sidlercom80
              NinjaTrader Ecosystem Vendor - Sidi Trading

              Comment


                #8
                Hello sidlercom80,

                Thank you for your note.

                Please see the attached example script that was modified to demonstrate how you could accomplish your goal of setting a multicolored plot and triggering the plot to be transparent or visible when clicking a button. In the script, we set the plot color using PlotBrushes, then when the button is clicked the plot is turned off while still calculating in the background, and the chart re-renders. When the button is clicked again, the plot becomes visible again.

                Let us know if we may assist further.
                Attached Files
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Hi _BrandonH perfect thanks! last question is there also a way to hide/draw the price marker according to the plot, so that the price marker AND line are visible/invisible?
                  sidlercom80
                  NinjaTrader Ecosystem Vendor - Sidi Trading

                  Comment


                    #10
                    Hello sidlercom80,

                    Thank you for your inquiry.

                    See the attached example which has been modified to toggle both the indicator plot and price marker to be transparent or visible. Please note that we add the draw object Draw.Dot and use RemoveDrawObject to force the chart to re-render. Also, see the help guide documentation below for information about Draw.Dot, RemoveDrawObject, and TriggerCustomEvent.

                    Draw.Dot - https://ninjatrader.com/support/help...8/draw_dot.htm
                    RemoveDrawObject - https://ninjatrader.com/support/help...drawobject.htm
                    TriggerCustomEvent - https://ninjatrader.com/support/help...ustomevent.htm

                    Let us know if we may further assist.
                    Attached Files
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi _BrandonH, thanks for your help! i have everything as it should be and have learned a lot. I have solved it via a public mehode that I can access from anywhere.if anyone is interested in my solution:

                      Code:
                      public void Show(bool isVisible, bool isColorSlope)
                      {
                      if (!isVisible)
                      {
                      Plots[0].Brush = Brushes.Transparent;
                      TriggerCustomEvent((o) =>
                      {
                      for (int barIndex = 0; barIndex <= Count - 2; barIndex++)
                      PlotBrushes[0][barIndex] = Brushes.Transparent;
                      }, null);
                      ChartControl.Dispatcher.InvokeAsync(() => ChartControl.InvalidateVisual());
                      return;
                      }
                      else
                      {
                      Plots[0].Brush = LineColor;
                      TriggerCustomEvent((o) =>
                      {
                      for (int barIndex = 1; barIndex <= CurrentBar; barIndex++)
                      {
                      if (isColorSlope && Line[barIndex] < Line[barIndex - 1])
                      PlotBrushes[0][barIndex] = UpColor;
                      else if (isColorSlope && Line[barIndex] > Line[barIndex - 1])
                      PlotBrushes[0][barIndex] = DownColor;
                      else
                      PlotBrushes[0][barIndex] = LineColor;
                      }
                      }, null);
                      ChartControl.Dispatcher.InvokeAsync(() => ChartControl.InvalidateVisual());
                      return;
                      }
                      }
                      sidlercom80
                      NinjaTrader Ecosystem Vendor - Sidi Trading

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Brevo, Today, 01:45 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post Brevo
                      by Brevo
                       
                      Started by aussugardefender, Today, 01:07 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post aussugardefender  
                      Started by pvincent, 06-23-2022, 12:53 PM
                      14 responses
                      238 views
                      0 likes
                      Last Post Nyman
                      by Nyman
                       
                      Started by TraderG23, 12-08-2023, 07:56 AM
                      9 responses
                      384 views
                      1 like
                      Last Post Gavini
                      by Gavini
                       
                      Started by oviejo, Today, 12:28 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post oviejo
                      by oviejo
                       
                      Working...
                      X