NexusFi: Find Your Edge


Home Menu

 





Need help with adding Indicator to chart via ToolStrip Button


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one erk707 with 3 posts (1 thanks)
    2. looks_two zr6bcm with 1 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 MrTrader with 1 posts (0 thanks)
    1. trending_up 3,428 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 3 attachments




 
Search this Thread

Need help with adding Indicator to chart via ToolStrip Button

  #1 (permalink)
 erk707 
Irvine, CA
 
Experience: Intermediate
Platform: Ninjatrader
Trading: Piano, ES, GC, CL, NQ, 6E
Posts: 21 since Feb 2011
Thanks Given: 5
Thanks Received: 4

Hey guys, I am still on the quest to have a ToolStrip button to be able to add my favor indicator and remove it at will without the hassle of opening the indicators window. I have the code working where it will add the indicator to the chart and remove it via this toolstrip button. I need help from one of the wizards in here to tackle the last part of the problems.

Problem 1 - It the button is clicked and the indicator is showing on the screen and I hit F5 I get one hell of a nasty NT error(See screenshot attached). This only happens if the indicator is added with the button. If it is not on the screen... no issues. My guess is I'm not disposing of this indicator object correctly in OnTermination() or maybe the problem is much bigger. I used Print and VS and I see that OnTermination() is being hit and processed through so i thought I could handle there but it doesn't seem to be working. When I debugged in VS and looked at the callstack (See screenshot) the first error occured in ChartControl.ApplyIndicatorsStrategies() which corresponds to the Ninja Error. This error list is way over my head so I'm looking for the wizards help here.

Problem 2 - If the toolstrip button is pressed and the indicator is showing on the chart and then I go into the Indicators window to manually add another indicator. When I click OK is reloads the chart just fine. I guess not really a problem. Just trying to figure out what is going wrong in reload ninjascript versus the indicator window reloading everything.

If you guys could look at the code and let me know what I am doing wrong i would appreciate it greatly.



Attached Files
Elite Membership required to download: ToolStripButtonADX.zip
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
Deepmoney LLM
Elite Quantitative GenAI/LLM
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Exit Strategy
NinjaTrader
 

  #3 (permalink)
 zr6bcm 
Heidelberg, Germany
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Stocks
Posts: 12 since Jun 2014
Thanks Given: 9
Thanks Received: 12


no, unfortunately I don't know (didn't find) the answer.

One comment: would recommend that you swap around the Remove(indicator) and then indicator.Dispose calls. Not that it helped in the big picture. Sorry.
 
Code
if (ChartControl!=null) foreach(Indicator indicator in ChartControl.Indicators)
  if (indicator.Name == "ADX")
  {
      ChartControl.Remove(indicator);
      indicator.Dispose();
  }
if (tsrTool!=null && btnIndicator!=null)
  tsrTool.Items.Remove(btnIndicator);

Reply With Quote
  #4 (permalink)
 erk707 
Irvine, CA
 
Experience: Intermediate
Platform: Ninjatrader
Trading: Piano, ES, GC, CL, NQ, 6E
Posts: 21 since Feb 2011
Thanks Given: 5
Thanks Received: 4

I got word back from NT support after i sweet talked them into looking into the problem and there response was that i wasnt releasing the indicator in OnTermination. Im not sure what they mean by that since im removing it from the chart and disposing of it in OnTermination. Im not sure if there is a different method of releasing indicators that anyone knows of.

Started this thread Reply With Quote
  #5 (permalink)
 MrTrader 
ITAJAI SC/BRAZIL
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Clear Corretora
Trading: DOLFUT, WINFUT
Posts: 332 since Jun 2014
Thanks Given: 1,314
Thanks Received: 225


erk707 View Post
I got word back from NT support after i sweet talked them into looking into the problem and there response was that i wasnt releasing the indicator in OnTermination. Im not sure what they mean by that since im removing it from the chart and disposing of it in OnTermination. Im not sure if there is a different method of releasing indicators that anyone knows of.

So.. is it working?
I am interested in remove indicator dynamically.. by code.

Reply With Quote
  #6 (permalink)
 erk707 
Irvine, CA
 
Experience: Intermediate
Platform: Ninjatrader
Trading: Piano, ES, GC, CL, NQ, 6E
Posts: 21 since Feb 2011
Thanks Given: 5
Thanks Received: 4

It does work. The biggest issue you will run into is when you dynamically put the indicator on the chart via code. You can place and remove without issue with the code provided in this post. The issue happens when the indicator is on the screen and F5 is hit to refresh ninjascript or ninjascript is refreshed via toolstrip menus. If you are working on something personal its no big deal you just cant do those things. If you are working on something you are looking to distribute than what I did was the indicator is added to the chart I would record the selected hotkey value for F5 and also refresh historical data. Then I would change the to an OEM default I.E. set them to 255. I also subscribed to the event handlers for toolstrip click, I.E. if a user clicked on refresh ninjascript via the toolstrip menu. Left click on ninjachart. What you have to do with the toolstrip command is quickly remove the indicator from the chart if that is selected before the refresh starts. I was sucessful with the toolstrip but not the F5. I used event handlers for keydown but wasnt fast enough to remove from chart before NT blew up. Your best bet is to overwrite the users hotkeys for F5 and then re-write them when the user pulls your indicator off the chart.

Hope this helps.

Started this thread Reply With Quote
Thanked by:





Last Updated on March 6, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts