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

Regression tool end anchor auto update after each new bar

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

    Regression tool end anchor auto update after each new bar

    Hi -

    I am looking to implement a modified regression channel drawing tool. This would allow the regression channel to have a fixed start anchor (as originally specified when drawing the tool) but the end anchor should auto-update with each new bar close. I imagine this should be possible now using ninjascript because the volume profile drawing tool (in order flow+ package) allows user to specify end anchor points in the future and the volume profile gets updated in real time as each new bar is formed.

    I can modify the ninjascript code if I can get some hint on how the end anchor can be automatically updated. Can OnBarUpdate method be called within the drawing tools ninjascript code to achieve this?

    #2

    Hello samanruptrader,

    You would likely need to use OnRender and get the Count of the bar series to know when a bar changed in a drawing object. Drawing tools normally dont update for bar events and just render so you would have to make code to update the anchors being used when the bar changes.

    You can get the bar count like the following:
    ChartBars chartBars = GetAttachedToChartBars();
    int barCount = chartBars.Bars.Count​;

    If you store that to a class level variable you could make a condition checking if the bar count is greater than your stored variable, if so do your update and reset the bar count variable.



    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you NinjaTrader_Jesse for your input.

      I did implement this and it works however I request you to please look at a minor issue concerning updating the drawing.

      I have attached a small video recording ​of the issue and the ninja script "RegressionChannelAuto".

      The issue is that when I first add the drawing "RegressionChannelAuto" it doesn't update with each new bar. However, after I have changed its "drawingstate" to "editing" or "moving" using the mouse gesture, the tool starts updating from the next new bar onwards.

      The main code snippet I added is in the lines 688 to 712 which I believe is causing the issue. I guess that for this code snippet to run it needs the DrawingState to not be DrawingState.Building. However, I need to add a check for this using 'if' condition in line 696 otherwise the drawing is not added or "built" initially.
      Attached Files
      Last edited by samanruptrader; 12-01-2023, 12:53 PM.

      Comment


        #4
        Hello samanruptrader,

        You may need to set the drawing state in the code when you update the tool, unfortunately I don't have any other tool which works that way to provide a specific suggestion on how to proceed. I would suggest trying to use the same type of code that you see in the mouse down event that toggles the drawing of the object, that may work to allow you to update it.





        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,406 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        98 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        8 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        160 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        9 views
        0 likes
        Last Post Belfortbucks  
        Working...
        X