Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
the channel in the package has a diff problem, sometimes when you hit delete key to delete a channel it deletes all channels and removes itself from a chart indicator list.
Can you help answer these questions from other members on NexusFi?
What I am basically looking for is a way to be able to assign the price value I click on on a chart to a variable in an indicator. For example, if I have a variable in my custom indicator named entry price, then anytime I click on a price on the chart (for stocks or forex), this variable is assigned that price value. I could see from searching around that this involves some advance coding which is far beyond my very very basic understanding of NTScripts and C#. May I ask kindly if one you guys could assist with a code for achieving this in an indicator?
Ok, have managed to turn the above (with slight amendment) into an indicator and tested it and it does seem to do what I want - gets the price when I click on the chart. However, I can't seem to be able to figure out how to assign the price to a variable in a code I will eventually insert under "protected override void OnBarUpdate()". Any suggestions please? Thanks.
It looks like "price" is what you are looking to use in your OnUpdate() function. What you should do is remove the local variable reference for price in this function and move it to your "Variables" regeon to make it global.
That should get access to the value, you will need to make sure the value is valid.
Hi NJAMC,
Thanks for your suggestion. If I understand it correctly, I moved "double price=0.0;" to "Variables" region, and tested it out in a code under ' protected override void OnBarUpdate()', but it did not seem to work (just returning zero as price).
Another issue I forsee, even if I managed to figure out how to reference the price, is that for the code I want to use it for, the code has got a few calculations and so works bets with 'CalculateOnBarClose = true;". Unfortunately, it would appear this gomi's code I trying to use to get the price works with 'CalculateOnBarClose = false:". Tried it with 'CalculateOnBarClose = true;" and it did not seem to work properly. So, I have got a bit of problem there as well!
Hi NJAMC,
Thanks for your suggestion. If I understand it correctly, I moved "double price=0.0;" to "Variables" region, and tested it out in a code under ' protected override void OnBarUpdate()', but it did not seem to work (just returning zero as price).
Another issue I forsee, even if I managed to figure out how to reference the price, is that for the code I want to use it for, the code has got a few calculations and so works bets with 'CalculateOnBarClose = true;". Unfortunately, it would appear this gomi's code I trying to use to get the price works with 'CalculateOnBarClose = false:". Tried it with 'CalculateOnBarClose = true;" and it did not seem to work properly. So, I have got a bit of problem there as well!
Cheers
Dan
Maybe a simpler solution might be to add a draw object, like Horizontal Line, to the chart at the price you want. For example press F6 and click on the chart to add a Horizontal Line at whatever price you want. Then it is easy enough to just look at the Y-axis value of that drawing object to get the price.
foreach (IDrawObject draw in DrawObjects)
{
if (draw.DrawType == DrawType.HorizontalLine && draw.UserDrawn)
{
IHorizontalLine hLine = (IHorizontalLine) draw;
yvalue = Math.Round(hLine.Y, 5); // This is Price value
}
}
Maybe a simpler solution might be to add a draw object, like Horizontal Line, to the chart at the price you want. For example press F6 and click on the chart to add a Horizontal Line at whatever price you want. Then it is easy enough to just look at the Y-axis value of that drawing object to get the price.
foreach (IDrawObject draw in DrawObjects)
{
if (draw.DrawType == DrawType.HorizontalLine && draw.UserDrawn)
{
IHorizontalLine hLine = (IHorizontalLine) draw;
yvalue = Math.Round(hLine.Y, 5); // This is Price value
}
}
Sometimes one post replies on this forum and for some reason it does not show. I posted a reply to this post yesterday to say thank you very much Traderji, as your suggestion seems to have addressed my needs. I am most grateful. Also thanks for helping out with a request on NT forum (as rabcnesbit).
Sometimes one post replies on this forum and for some reason it does not show. I posted a reply to this post yesterday to say thank you very much Traderji, as your suggestion seems to have addressed my needs. I am most grateful. Also thanks for helping out with a request on NT forum (as rabcnesbit).
You are probably previewing instead of submitting.
A favour please if I may ask. Like I mentioned before, your suggestion/code serves my purpose. Only issue is that if I change stocks on the chart, if the new stock's price is not within the price range of the old stock's price, the new chart (all the bars) get compressed, if you know what I mean. I then have to draw a new line within the price range of the new stock and reload (F5) for the chart to come back to normal. Below is attached two charts with different stocks for illustration. Chart on the left is the old stock, and chart on the right is how the chart looks after switching to a new stock. Any suggestions as to how one could get it to adjust automatically after switching to a new stock, please?
A favour please if I may ask. Like I mentioned before, your suggestion/code serves my purpose. Only issue is that if I change stocks on the chart, if the new stock's price is not within the price range of the old stock's price, the new chart (all the bars) get compressed, if you know what I mean. I then have to draw a new line within the price range of the new stock and reload (F5) for the chart to come back to normal. Below is attached two charts with different stocks for illustration. Chart on the left is the old stock, and chart on the right is how the chart looks after switching to a new stock. Any suggestions as to how one could get it to adjust automatically after switching to a new stock, please?
Many thanks
Dan.
You could have your code remove the horizontal line(s) from the chart if the instrument changes or once it has obtained the price (and replace it with a text marker).