Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling void within OnRender

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

    Calling void within OnRender

    I need to call protected void Somebutton (object sender, RoutedEventArgs rea) within OnRender.

    If I do like this it doesn't work:

    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    Somebutton(sender, rea);
    }
    The name 'sender' and 'rea' does not exist in the current context.

    #2
    Hello Leeroy_Jenkins,

    Calling a buttons event handler is not likely the suggestion on how to execute that buttons code.

    You could make your own void method that takes no parameters and then move the buttons code to that void. Your buttons event and your logic could then call that void to execute the code.

    Here is a quick example of the structure I am referring to, Assume that Somebutton is your event handler for the button here.

    Code:
    private void MyVoid() 
    {
        //your code
    }
    
    void  Somebutton (object sender, RoutedEventArgs rea) 
    {
        MyVoid();
    }
    
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
      MyVoid();
    }

    Comment


      #3
      Ok, got it.

      My next question:

      LastVisibleBar = ChartBars.ToIndex;

      Let's assume I wanna move 100 bars forward. Is there any way to do so without pressing hotkeys? OnRender.

      Comment


        #4
        Hello Leeroy_Jenkins,

        There are not supported ways to move the chart in NinjaScript so however you want to approach that would be fine. I believe I have seen users use key presses to do that however I am not aware of a specific sample that I could link to. Using hotkeys would likely be needed here to use the existing chart hotkeys to advance the chart. You can see the Rollover Indications Indication on the user app share for an example of pressing keys in the chart.



        I look forward to being of further assistance.

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          You could make your own void method that takes no parameters and then move the buttons code to that void. Your buttons event and your logic could then call that void to execute the code.
          After few months same problem oh.



          Code:
          private void OnButtonClickHelper ()
          
          {
          System.Windows.Controls.Button button = sender as System.Windows.Controls.Button; //causes error - sender doesn't exist
          //some code
          }
          
          void OnButtonClick(object sender, RoutedEventArgs rea)
          {
          OnButtonClickHelper();
          }

          Comment


            #6
            Hello Leeroy_Jenkins,

            Yes that would cause an error, it looks like you have not correctly formed the void method you made. For an example of using a button and defining the method for the button you could see the following link: https://ninjatrader.com/support/help...ub=usercontrol

            You are calling a separate method in what you made here which you have not passed the sender to, if you want to make another separate method you would have to make it so it takes an object as its overload.

            I look forward to being of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            673 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            577 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X