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

changing instrument and period for the chart

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

    changing instrument and period for the chart

    Folks,

    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?

    Thanks!

    Juan

    #2
    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 - https://www.ninjatrader.com/support/...price_data.htm
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Betrand,

      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):

      In a previous post, I showed how a C program can simulate a keystroke in Windows using SendInput. I also posted a subsequent example showing how to simulate a keypress with the Control key included…


      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!

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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by LawrenHom, Today, 10:45 PM
      0 responses
      3 views
      0 likes
      Last Post LawrenHom  
      Started by love2code2trade, Yesterday, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Started by funk10101, Today, 09:43 PM
      0 responses
      7 views
      0 likes
      Last Post funk10101  
      Started by pkefal, 04-11-2024, 07:39 AM
      11 responses
      37 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Yesterday, 08:51 AM
      8 responses
      44 views
      0 likes
      Last Post bill2023  
      Working...
      X