NexusFi: Find Your Edge


Home Menu

 





.NET advice for persistent graphics.DrawString and graphics.DrawRectangle


Discussion in NinjaTrader

Updated
    1. trending_up 1,658 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 9 posts
    2. attach_file 1 attachments




 
Search this Thread

.NET advice for persistent graphics.DrawString and graphics.DrawRectangle

  #1 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

Hello NET gurus...

I'm working on a new version of SlopeBox that would have multiple MA/slopeboxes in one indicator. It is working well, but only the last drawn box is staying on the screen.....the public SlopeBox (forgot where I found it, probably futures.io (formerly BMT)) uses .NET methods to draw, not NinjaTrader methods...

graphics.DrawRectangle
graphics.DrawString

For example, the indicator has three different MA, and three different SlopeBoxes. The boxes are drawn in an override to the Plot Method.

Here is the draw code in the Plot override method....for each Plot this is called. Only the last box remains on the screen. The other two appear to be erased as soon as the next one is written.

//the bounds offset is multiplied by the box number to properly position new instances of the SlopeBox
graphics.DrawRectangle
(new Pen(Plots[0].Pen.Color, 2),
bounds.X + bounds.Width - 60,
bounds.Y + bounds.Height - Boxnumber * 40,
46,
22);

StringBuilder strDegrees = new StringBuilder();
strDegrees.Append((degrees).ToString());
strDegrees.Append(Convert.ToChar(0176));
textBrush.Color=degreesColor;

graphics.DrawString
(strDegrees.ToString(),
textFont,
textBrush,
bounds.X + bounds.Width - 60,
bounds.Y + bounds.Height - Boxnumber * 40,
stringFormat);

Any ideas?

When I get it working I will post it.

Thanks.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Cheap historycal L1 data for stocks
Stocks and ETFs
Trade idea based off three indicators.
Traders Hideout
Quant vue
Trading Reviews and Vendors
About a successful futures trader who didn´t know anyth …
Psychology and Money Management
 
  #3 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401



vantojo View Post
Hello NET gurus...

I'm working on a new version of SlopeBox that would have multiple MA/slopeboxes in one indicator. It is working well, but only the last drawn box is staying on the screen.....the public SlopeBox (forgot where I found it, probably futures.io (formerly BMT)) uses .NET methods to draw, not NinjaTrader methods...

graphics.DrawRectangle
graphics.DrawString

For example, the indicator has three different MA, and three different SlopeBoxes. The boxes are drawn in an override to the Plot Method.

Here is the draw code in the Plot override method....for each Plot this is called. Only the last box remains on the screen. The other two appear to be erased as soon as the next one is written.

//the bounds offset is multiplied by the box number to properly position new instances of the SlopeBox
graphics.DrawRectangle
(new Pen(Plots[0].Pen.Color, 2),
bounds.X + bounds.Width - 60,
bounds.Y + bounds.Height - Boxnumber * 40,
46,
22);

StringBuilder strDegrees = new StringBuilder();
strDegrees.Append((degrees).ToString());
strDegrees.Append(Convert.ToChar(0176));
textBrush.Color=degreesColor;

graphics.DrawString
(strDegrees.ToString(),
textFont,
textBrush,
bounds.X + bounds.Width - 60,
bounds.Y + bounds.Height - Boxnumber * 40,
stringFormat);

Any ideas?

When I get it working I will post it.

Thanks.


I guess I would be verifying that the boxnumber is working as that is the key to offsetting the boxes from each other. If they are the same number of course will overlay on each other.
Hopefully others can give you more to go on.

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
  #4 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

yes, the boxnumber is working OK...because if I comment out plot1 and plot2, plot0 will draw its slopebox

if I comment out Plot2 only, then the Plot0 slopebox does not show, but the plot1 slopebox does show. Seems that only the last slopebox written remains.

Ninjatrader draw functions let the coder say whether the prior draw object is erased when a new one is written...but this does not seem to be in the .net methods mentioned

would post the indicator code here but I don't know how to export it...the public enums are in the mother indicator and it won't compile stand alone on the export

Started this thread Reply With Quote
  #5 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401


vantojo View Post
yes, the boxnumber is working OK...because if I comment out plot1 and plot2, plot0 will draw its slopebox

if I comment out Plot2 only, then the Plot0 slopebox does not show, but the plot1 slopebox does show. Seems that only the last slopebox written remains.

Ninjatrader draw functions let the coder say whether the prior draw object is erased when a new one is written...but this does not seem to be in the .net methods mentioned

would post the indicator code here but I don't know how to export it...the public enums are in the mother indicator and it won't compile stand alone on the export

You can just attach the CS file itself.

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
  #6 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

If you comment out Plot2 and Plot1 you will see that the box for Plot0 is on the chart.

When Plot0 and Plot1 are enabled (i.e. not commented), then the box for Plot 0 is not there

When Plot0, Plot1, and Plot2 are enabled, only the box for Plot 2 is on the chart

would like all three boxes to be on the chart

(also would like to know how to get rid of parameters that are no longer needed, but were in the mother code...)

Thank You!!

Attached Files
Elite Membership required to download: AASlopeBoxWORK.cs
Started this thread Reply With Quote
  #7 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401


vantojo View Post
If you comment out Plot2 and Plot1 you will see that the box for Plot0 is on the chart.

When Plot0 and Plot1 are enabled (i.e. not commented), then the box for Plot 0 is not there

When Plot0, Plot1, and Plot2 are enabled, only the box for Plot 2 is on the chart

would like all three boxes to be on the chart

(also would like to know how to get rid of parameters that are no longer needed, but were in the mother code...)

Thank You!!

I don't have much time to work on this but one thing you can look at is using 3 of:

graphics.DrawRectangle(new Pen(Plots[0].Pen.Color, 2), bounds.X + bounds.Width - 60,bounds.Y + bounds.Height - 2 * 40, 46,22); where boxnumber variable is replaced by the actual number (in this example "2")

Probably the same with the graphics drawstring.

If I can find the time this weekend I'll see how much I can do to help but thought maybe these clues would get you started.

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
  #8 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

after doing some testing with Replay...it appears I didn't understand the NT paradigm

in Replay (assuming that NT works the same with live data??) the Plot Override is called on each tick, even when CalculateOnBarClose is True

(In Replay) The Plot Override is called independently of the Plot(), and it appears that it is called after all the Plot() methods.

For my purposes I want the slope to be calculated on bar close...which is different than how most would use this....

I'm going to have to rethink how this is written (for my purpose)

(also Boxnumber should have been boxnumber)

Started this thread Reply With Quote
  #9 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401

You might consider using the bool FirstTickOfBar if you want to control the processing.

I just have to ask, why do you want to write an indicator to show 3 angles when you can simply put 3 instances of 1 on the chart?

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
  #10 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012


Yes, I will filter for first tick of bar....

This code is going to go into a mother indicator.

Rather than instantiate a bunch of separate indicators, I want them all in one codeset, for the most part, so that the data is easily shared by one single intelligent algorithm...for example, to know the simultaneous value of three different MA is valuable information. It is easier for a process to have all this information in one place, especially if it is going to be correlated with other live indicators / calculations.

Started this thread Reply With Quote




Last Updated on August 3, 2013


© 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