• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


changing instrument and period for the chart

  • Filter
  • Time
  • Show
Clear All
new posts

    changing instrument and period for the chart


    Is it possible to change the chart instrument from inside the indicator code? what I mean is: is it possible to implement the kinds of operations that you do on the control center (add a new chart, change the instrument, change the period, may be even change the style, etc) in code, ie from inside an indicator or strategy?

    I'm an experienced SW developer but very new to Ninja trader. I looked around in the manual and did some internet searches but so far I haven't seen any way of changing the current instrument from within the indicator code.

    Is this possible? if not, can anyone suggest a different approach?



    Hi Juan, thanks for the post - there would not be a supported method to create a new chart or change your settings unfortunately. What you could look into to change the symbol and periodicity / type would be for example a SendKeys.Wait command via C# as you could type onto our charts to change those items.

    See the third section here please - http://www.ninjatrader.com/support/h...price_data.htm
    BertrandNinjaTrader Customer Service



      First of all, thanks a lot for your prompt response! I have to tell you though that I'm a bit disappointed that switching a chart via code is not supported by Ninja Trader. It seems like the simple, basic type of function that a platform for automatic trading should offer. In any case, I really appreciate your quick response and offering an alternative.

      I did some research on SendKeys and got some example code in C#... see here:


      However I could not get this code to make Ninja switch a chart (hum!). I did more research and found out that, apparently, SendKeys has been superseded by something called SendInput. I got some sample C/C++ code for SendInput here (note that the source code file name is SendKeys.cpp but it actually uses SendInput):


      After trying, this didn't work either for getting the Ninja trader chart window to change the instrument. After some testing and more research I figured out that my problem was that the characters '#' and '-' require special treatment (wow!). These characters come up when using continuous contracts, like ES ##-##. After I fixed that, I was able to get the whole thing to work and I'm a happy camper. So the story has a happy ending.

      I made some modifications to the batchloaf SendInput code and I'm attaching it here in case someone else has a similar problem. It may help people to speed through the learning curve. The key changes I made are:

      - ability to send a string to the target window instead of a character at a time
      - special handling of '#' and '-' (basically send the Unicode code)
      - automatic [return] so ninja can accept the request

      I think that most folks in the Ninja Trader user community are not writing in C/C++. Perhaps some are and I'd like to volunteer my code in case someone can benefit from it.

      It is possible that my problem with SendKeys was actually due to the problem with '#' and '-'. If this is the case, people can use the "code project" reference on the first URL to get a good start in using Sendkeys to communicate with the Ninja Trader charts.

      Again, thanks for your help!

      Attached Files
      Last edited by jmroa; 10-18-2014, 07:30 PM.


      Latest Posts


      Topics Statistics Last Post
      Started by tilleulne, Today, 01:58 AM
      0 responses
      1 view
      Last Post tilleulne  
      Started by Ivantr, Yesterday, 05:24 PM
      1 response
      Last Post NinjaTrader_Marco  
      Started by ralett, Yesterday, 06:20 PM
      3 responses
      Last Post ralett
      by ralett
      Started by trader252, Yesterday, 08:38 PM
      1 response
      Last Post NinjaTrader_ChrisSch  
      Started by grizzlytrader, Yesterday, 06:24 AM
      1 response
      Last Post NinjaTrader_ChelseaB