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

Custom TextBlock OnPriceChange

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

    Custom TextBlock OnPriceChange

    Hello community,

    I have created a custom TextBlock which displays my calculated value in the specified area of the chart using a grid which is created during dispatcher.invokeasync and the textblock is added.

    This all works great, and I know it's a C# docs matter anyway, however the content of my textblock in the way I have it implemented is static and I need the text to update OnPriceChange. Can somebody help me with this? I tried a few solutions, one of which created catastrophe and came very close to reinstall as my only option, so now I am turning for help.

    Please let me know if you need any additional information, and as I side note I would like to ask if there is a simpler way to add text to a chart coordinate. Like Draw.TextFixed but with my freedom as to where I can place the fixed text. I want it top center and that isn't an option. Thank you!

    #2
    Hello lunardiplomacy,

    You can likely avoid a TextBlock or WPF elements for this purpose and just use OnRender to draw fixed text. The Draw.TextFixed has specific placements, you could instead use the SampleCustomRender indicator and how it draws text for any placement on the chart panel.

    If you do want to use a WPF control here I would need more details on what went wrong. It sounds like you had the right approach, if you are updating the value you would also need to invoke that on the UI thread, potentially that is what you were missing.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for the response, Jesse.

      I will look into sampleCustomRender, for this particular purpose it sounds like it would probably be sufficient.

      But yes, it was in trying to invoke on the UI thread that things started to go terribly wrong. I didn't know where I should attach the code, so I attached it to a mouse move event without realizing the fairly obvious consequences of that. Where should I be updating the content? OnBarUpdate? in that case I got a lot of object instance errors.

      Thanks, Jesse.

      Comment


        #4
        Hello lunardiplomacy,

        Yes the mouse move wouldn't be suggested, OnBarUpdate would be sufficient if that is the rate you wanted it to update. For example if the calculation is in OBU then that logic could go at the end of OBU.

        If you had object reference errors that likely relates to what you coded and where variables were used or when they are populated. Checking for null is a common C# topic which comes up frequently, in NinjaScript you can also need this in some cases. That is simply doing a condition like:

        Code:
        if(x != null)
        {
            x is valid here. x is your object reference or whatever object threw the error
        }
        If you have a small sample you can always upload those with your post as an attachment. The .cs file would be fine for that.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cutzpr, Today, 08:54 AM
        0 responses
        4 views
        0 likes
        Last Post cutzpr
        by cutzpr
         
        Started by benmarkal, Today, 08:44 AM
        0 responses
        4 views
        0 likes
        Last Post benmarkal  
        Started by Tin34, Today, 03:30 AM
        2 responses
        26 views
        0 likes
        Last Post Tin34
        by Tin34
         
        Started by sastrades, Yesterday, 09:59 AM
        2 responses
        38 views
        0 likes
        Last Post brucerobinson  
        Started by ETFVoyageur, Today, 12:52 AM
        1 response
        21 views
        0 likes
        Last Post Leeroy_Jenkins  
        Working...
        X