Go Back   NinjaTrader Support Forum > NinjaTrader 7 > General Development

General Development General NinjaScript development questions.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 04-04-2015, 11:23 AM   #1
umbertosm
Junior Member
 
Join Date: Jan 2015
Location: Rome, Italy
Posts: 15
Thanks: 7
Thanked 1 time in 1 post
Default TEXT object at 90 degrees?

hello,
I would like to draw a text on the chart at 90 degrees.
I do not know if NinjaScript allows you to do this.
For example I can print TEST object with
PHP Code:
DrawText("text"false"text in 0 degree"Time[20], Close[20]-100*TickSize10Color.Blue, new Font ("Arial"12FontStyle.Bold), StringAlignment.CenterColor.BlackColor.Yellow5); 

but.... I want to draw the TEST object at 90 degrees or 45 degrees, as I can do with metaquote language for Metatrader
Is it possible to do it with NinjaScript C# based?
If so, how?

thanks,
Umberto
umbertosm is offline  
Reply With Quote
Old 04-04-2015, 03:30 PM   #2
NinjaTrader_CalH
NinjaTrader Customer Service
 
NinjaTrader_CalH's Avatar
 
Join Date: Feb 2013
Location: Denver, CO
Posts: 3,302
Thanks: 161
Thanked 615 times in 594 posts
Default

Hello Umberto,

Thank you for your post.

This is not possible with the current DrawText object. However, this can be done using custom drawing in the Plot() method.

Please note that this is not supported programming but you can view a sample of the Plot by going to Tools -> Edit NinjaScript -> Indicator -> Custom Plot Sample

You can also review the Graphics class from the MSDN article below -
https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx
NinjaTrader_CalH is offline  
Reply With Quote
Old 04-05-2015, 10:40 AM   #3
umbertosm
Junior Member
 
Join Date: Jan 2015
Location: Rome, Italy
Posts: 15
Thanks: 7
Thanked 1 time in 1 post
Default

In the reported indicator and at the MSDN link I have not found a complete example of how to print a text in X degrees.
I have not found anything that can be done with a few lines of code ...
Is it possible that no developer needs to print on a chart a short sentence at 90 or X degrees?
... Or perhaps with C #, to be able to print an oblique phrase it is necessary to write dozens of lines of code?
Last edited by umbertosm; 04-05-2015 at 12:56 PM.
umbertosm is offline  
Reply With Quote
Old 04-05-2015, 02:01 PM   #4
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 3,289
Thanks: 248
Thanked 757 times in 578 posts
Default

With a custom plot this is pretty easy to do.

You need to know the (x,y) position of the text on your chart. Then within the custom plot you basically need to follow the steps as shown below

Code:
//Save the current graphics state
GraphicsState state =  graphics.Save();
graphics.ResetTransForm();
//Rotate
graphics.RotateTransform(angle);
//Translate to desired position on chart
graphics,TranslateTransform(x, y, MatrixOrder.Append);
//Draw Text at origin of chart
graphics.DrawString(text, textFont, textBrush, 0, 0, stringFormat);
//Restore the graphics state
graphics.Restore(state);
It is important to apply rotation first, then translation before drawing the string at the origin.

I had never done this before (do not know what it is good for ....), but the chart below shows that it is easy to do. All the labels are now shown in 45 degrees, Just for fun.
Attached Images
File Type: png ES 06-15 (15 Min) 02_04_2015.png (237.8 KB, 55 views)
Harry is offline  
Reply With Quote
The following 2 users say thank you to Harry for this post:
Old 01-06-2018, 08:39 PM   #5
dfogg
Junior Member
 
Join Date: Nov 2006
Location: , ,
Posts: 18
Thanks: 2
Thanked 1 time in 1 post
Default Function to create rotated text at any position and angle

As Harry stated, if one knows what to do, it is actually relatively easy to create rotated text. Thanks to his suggestions, a function which can be called to place text at a specified location with specified rotation was created. A indicator, dfExampleRotatedText.zip, demonstrating its use is attached.

HTML Code:
private StringFormat            stringFormat    = new StringFormat();
private SolidBrush              textBrush       = new SolidBrush(Color.Black);
private System.Drawing.Font     textFont        = new Font("Consolas", 10);

string RotatedText(Graphics gptr, string text, float x, float y, float rot)
{
    // Function to create rotated text
    // Requires stringFormat, textBrush and textFont to be defined.
    gptr.TranslateTransform(x,y);
    gptr.RotateTransform(rot);
    gptr.DrawString(text,textFont,textBrush,0,0,stringFormat);
    gptr.ResetTransform();
    return text;
}
Attached Images
File Type: png NT7_RotatedText.png (77.5 KB, 5 views)
Attached Files
File Type: zip dfExampleRotatedText.zip (3.1 KB, 1 views)
dfogg is offline  
Reply With Quote
The following user says thank you to dfogg for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Draw line in fixed degrees (45-90-135-180-etc) benharper Platform Technical Support 4 03-13-2016 01:47 AM
access text from text object td_910 General Development 9 04-18-2012 08:05 AM
Delete Text Object (???) xTrader1 General Development 2 08-20-2009 06:52 AM
Modify color of text object FireFly Indicator Development 2 11-10-2008 10:26 AM


All times are GMT -6. The time now is 09:19 PM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.