Go Back   NinjaTrader Support Forum > NinjaTrader 7 > General Development

General Development General NinjaScript development questions.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 10-19-2015, 03:02 PM   #1
FREEN
Senior Member
 
Join Date: Mar 2010
Location: Sweden
Posts: 171
Thanks: 17
Thanked 8 times in 7 posts
Default Point type to Bars/Price converter?

Probably asked before but can´t find it:

Is there a NinjaScript method or other easy solution for converting the .NET Point type to X/Y (Bars/Price) coordinates and vice versa?
Last edited by FREEN; 10-19-2015 at 03:14 PM.
FREEN is offline  
Reply With Quote
Old 10-19-2015, 03:30 PM   #2
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,854
Thanks: 30
Thanked 1,241 times in 1,162 posts
Default

Hello,

Thank you for the question.

There are easy methods for this hidden in the ChartControl.

For X coordinates by bar number, you can use:

Code:
ChartControl.GetXByBarIdx(BarsArray[0], 100)
or for TIme:

Code:
ChartControl.GetXByTime(Time[0]);
for Y:

Code:
ChartControl.GetYByValue(this, 2000);
Depending on where these are used, ChartControl can be null so a null check is always recommended as well:

Code:
if(ChartControl != null)
{
//do stuff
}
I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jesse for this post:
Old 10-19-2015, 04:48 PM   #3
FREEN
Senior Member
 
Join Date: Mar 2010
Location: Sweden
Posts: 171
Thanks: 17
Thanked 8 times in 7 posts
Default

Thanks for revealing unsupported methods Jesse!

So the null check is for checking for a chart instance, right?

No "visible" chart == null ?

//Fredrik
Last edited by FREEN; 10-19-2015 at 04:51 PM.
FREEN is offline  
Reply With Quote
Old 10-20-2015, 06:50 AM   #4
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,854
Thanks: 30
Thanked 1,241 times in 1,162 posts
Default

Hello,

Correct, a Situation you often run into ChartControl being null would be in an indicator that is in the Market Analyzer. There is no chart so any ChartControl calls would be null.

I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 07-09-2018, 02:42 PM   #5
mballagan
Senior Member
 
Join Date: Nov 2008
Posts: 109
Thanks: 0
Thanked 1 time in 1 post
Default

How do we convert back from the .NET x,y coordinates to NinjaTrader barnumber/price?


So we might have something like

double x = ChartControl.GetXByBarIdx(BarsArray[0], barnumber);
double y = ChartControl.GetYByValue(this, pricevalue);

//do some calculations using x,y and get updated values x1,y1

//we then want

int barnumber = GetBarNumber(x1);
double priceval = GetPrice(y1);

This is just dummy code but how would GetBarNumber(), GetPrice() be implemented?
mballagan is offline  
Reply With Quote
Old 07-09-2018, 03:00 PM   #6
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,854
Thanks: 30
Thanked 1,241 times in 1,162 posts
Default

Hello,

Thank you for the question.

For NT7 I would have no suggestion here as there are no exposed methods for this that I could relay. Going forward in NT8 the ChartControl and other chart-related coordinate methods have all been exposed so you can translate back and forth between coordinate and price/time.

If any other NT7 users have custom solutions for this question an answer would be welcome for any undocumented/unsupported solutions.

I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
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
Enum Parameter - Type converter afshinmoshrefi Indicator Development 4 07-15-2014 04:08 PM
Custom Type Converter is displaying an error in the NT Log only after compiling bmont General Development 9 03-18-2014 06:01 PM
C++ to C# Converter found, will it work? Elliott Wave Indicator Development 3 11-12-2008 09:14 AM


All times are GMT -6. The time now is 01:17 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.