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?
Last edited by danjuma; March 11th, 2012 at 02:32 PM.
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.
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!
The following user says Thank You to danjuma for this post:
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.
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.
Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.
Need help? 1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first. 2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses. 3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make. 4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance. 5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers. 6) Help using the forum? Watch this video to learn general tips on using the site.
If you want to support our community, become an Elite Member.
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?