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

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();
    }
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by trilliantrader, 04-10-2024, 09:33 PM
            6 responses
            22 views
            0 likes
            Last Post trilliantrader  
            Started by traderqz, Today, 12:06 AM
            5 responses
            8 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Mongo, Today, 11:05 AM
            2 responses
            7 views
            0 likes
            Last Post Mongo
            by Mongo
             
            Started by guillembm, Today, 11:25 AM
            0 responses
            3 views
            0 likes
            Last Post guillembm  
            Started by Tim-c, Today, 10:58 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X