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

Reloading indicator from code

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

    Reloading indicator from code

    Hello,

    Is there any way to reload an indicator from code?

    (I would like that when you press a button on the chart the indicator will recalculate all your past data: Values, BackBrushes, Custom series, etc, and update your graphic output).

    Thanks in advance

    #2
    Hello cls71, and thank you for your question.

    With regard to your indicator's actual values, the values of the indicator associated with AddChartIndicator are constantly being re-read; if you change a historical value, the change should be updated on the chart. The easiest way to refresh these, then, would be to make a method similar to a copy constructor (link publicly available) which modifies your existing indicator treating values of a new version of your indicator as a prototype (link publicly available). Your signature would look like

    Code:
    [FONT=Courier New]
    myIndicatorReference.Refresh(MyIndicator(optionalSeries, arg1, arg2);[/FONT]
    This handles everything but rendering. To mark that your indicator needs to be re-rendered, you can use ForceRefresh to repaint a chart on demand.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thanks JessicaP, but I dont use AddChartIndicator (I think this method is only for strategies).

      I have an indicator (only one) wich load one button on chart. The same indicator has Plots, Drawings and paints also the background with BackBrushes.
      When I push the button I need the indicator recalculates all Plots, Drawings (Regions) and BackBrushes. Is this possible ?

      I have done tests but when I click the button, in the event handler method and therefore outside the OnBarUpdate, the BackBrushes for example are not reassignable.

      Thanks.

      Comment


        #4
        Thank you for this additional information. The method you will use will be the same for an Indicator :

        1. Write code which resets all your Values series, and other internal variables, with a passed in new Indicator. You can use the same signature I outlined in my previous post. The idea is to reset the variables your rendering elements will draw from, not your rendering elements themselves. Think of your rendering elements as dry erase boards. You are only swapping out the markers they will use and what they are instructed to draw, not the dry erase boards themselves.
        2. Call ForceRefresh.

        You should not be invalidating your backbrush references; OnRender should take care of this for you. You should write your code so that any frozen brush is reused and only disposed of once when your script terminates.
        Last edited by NinjaTrader_JessicaP; 03-16-2017, 10:42 AM.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Thanks JessicaP,

          but please, could you upload a simple example ?

          I dont understand how I can load a new indicator in the chart from code. I can create a new instance but it wont be renderized on the chart.

          Comment


            #6
            While I can provide a simple example, I highly encourage you to review the above link regarding copy constructors, as this is necessary to understand the meaning behind the sample. Code samples we provide are for educational purposes, and are not intended for live trading, and are not guaranteed to accomplish any user goal or to be maintained.
            Attached Files
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Thanks JessicaP,

              resolved

              Comment


                #8
                in your example code, what invokes the Reset() method?

                Or are you implying to simply call itself when a reload is needed?
                Last edited by tulanch; 04-03-2017, 12:31 AM.

                Comment


                  #9
                  Correct, the reset method is designed to be called on-demand. One way to call this would be to use a timer, as specified here,

                  Jessica P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Waxavi, Today, 02:10 AM
                  1 response
                  16 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by Kaledus, Today, 01:29 PM
                  5 responses
                  13 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by Waxavi, Today, 02:00 AM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by alifarahani, Today, 09:40 AM
                  5 responses
                  23 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by gentlebenthebear, Today, 01:30 AM
                  3 responses
                  17 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X