NexusFi: Find Your Edge


Home Menu

 





Help with removing graphics.DrawLine


Discussion in NinjaTrader

Updated
    1. trending_up 2,830 views
    2. thumb_up 4 thanks given
    3. group 1 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Help with removing graphics.DrawLine

  #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

I am working on an order entry strategy that Draws Line in the override void Plot method. I am a beginner programmer and have figured out how to DrawLines under this method but need help with a few loose ends. I am drawing custom entry, stop loss and take profit line that are being updated tick by tick in OnBarUpdate. If I manually close the trade I am trying to figure out how I can remove the draw object created in this method. Here is where I am stuck:

1. How can I add a string tag so when I use graphics.DrawLine I can identify the lines based on a specific entry order.
2. If I close the trade out how can I remove or clear the DrawLine's based on this string tag.

With Ninja theres the RemoveDrawObject but since I am overriding the method I'm not sure how to achieve removing a specific "tagged" DrawLine.

Do I create a custom method to do this or create an additional overload for DrawLine method so I can add in string tag as a reference.

Then how do I clear or dispose the specific line.

I need to be able to do this with the following draws within Graphics(IE add a specific string tag and be able to clear/dispose/erase)
1. graphics.DrawLine
2. graphics.FillRectangle
3. graphics.DrawString


Thanks for any help that can be provided.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
How to apply profiles
Traders Hideout
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #3 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,426



erk707 View Post
I am working on an order entry strategy that Draws Line in the override void Plot method. I am a beginner programmer and have figured out how to DrawLines under this method but need help with a few loose ends. I am drawing custom entry, stop loss and take profit line that are being updated tick by tick in OnBarUpdate. If I manually close the trade I am trying to figure out how I can remove the draw object created in this method. Here is where I am stuck:

1. How can I add a string tag so when I use graphics.DrawLine I can identify the lines based on a specific entry order.
2. If I close the trade out how can I remove or clear the DrawLine's based on this string tag.

With Ninja theres the RemoveDrawObject but since I am overriding the method I'm not sure how to achieve removing a specific "tagged" DrawLine.

Do I create a custom method to do this or create an additional overload for DrawLine method so I can add in string tag as a reference.

Then how do I clear or dispose the specific line.

I need to be able to do this with the following draws within Graphics(IE add a specific string tag and be able to clear/dispose/erase)
1. graphics.DrawLine
2. graphics.FillRectangle
3. graphics.DrawString


Thanks for any help that can be provided.

The direct graphics methods are used whenever Plot is called to redraw the whole area, so you don't so much remove anything as just not draw it. Just trigger a ChartControl.Refresh() if it's really needed (shouldn't be, normally this will happen whenever the price needs updating on-screen anyway so is usually only needed for more special cases like user region moves or bitmap redirection).

See the standard Ninja VolumeProfiles indicator for example.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #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


ratfink View Post
The direct graphics methods are used whenever Plot is called to redraw the whole area, so you don't so much remove anything as just not draw it. Just trigger a ChartControl.Refresh() if it's really needed (shouldn't be, normally this will happen whenever the price needs updating on-screen anyway so is usually only needed for more special cases like user region moves or bitmap redirection).

See the standard Ninja VolumeProfiles indicator for example.

ratfink,

Do you know if you can call C# Graphics within a strategy. I know in an indicator you can override the Plot method. What if you wanted to use NT drawing method somethimes and custom C# drawings other times. I am trying to draw a custom line in a strategy with the below. It complies but does not draw anything. Can you point me in the right direction with what I am doing wrong.

 
Code
Graphics graphics;
graphics = this.CreateGraphics();

// Define Pen Color
Pen greenPen = new Pen(Color.Green,4);
// Draw connecting line
if(Close[0] != 0)
{
	graphics.DrawLine(greenPen, ChartControl.CanvasRight/2, ChartControl.CanvasBottom/2, 
ChartControl.CanvasRight, ChartControl.CanvasBottom/2);
				
	Print("Drawing called");
}
else
	Print("failure");

Started this thread Reply With Quote
  #5 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,426


erk707 View Post
ratfink,

Do you know if you can call C# Graphics within a strategy. I know in an indicator you can override the Plot method. What if you wanted to use NT drawing method somethimes and custom C# drawings other times. I am trying to draw a custom line in a strategy with the below. It complies but does not draw anything. Can you point me in the right direction with what I am doing wrong.

Can't override the Plot method in a strategy as far as my test shows, and that's where you would want to put any direct draw graphics, not in the main body, so it's an X (no) from me. Maybe one of the longer standing forum whizzes knows a better/correct route, otherwise back to indicator and strategy drawing board, they can be linked via globals if that is really needed.

(Direct draw graphics have to be re-drawn on any refresh, i.e. N times/sec or window change events, not just when you think they need to be, there is no persistence, unlike the illusion created by drawing object graphics).

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #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

I wanted to post back an indicator/strategy developed with the Ninja support. What it does is create a synced List between a strategy and indicator. You can dump all your data from within the strategy and it will sync up from within the indicator. You can modify the List from either side indicator or strategy. With this you can loop through the List from within the override Plot method of the indicator to "achieve" a work around override Plot of the strategy. I have uploaded the zip file to the below link.


Started this thread Reply With Quote
Thanked by:




Last Updated on August 12, 2014


© 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