ChartHelper in a Strategy - NinjaTrader Programming | futures io social day trading
futures io futures trading


ChartHelper in a Strategy
Updated: Views / Replies:6,742 / 27
Created: by sam028 Attachments:5

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you dont need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 5  
 
Thread Tools Search this Thread
 

ChartHelper in a Strategy

  #11 (permalink)
Market Wizard
virginia
 
Futures Experience: Intermediate
Platform: ninja
Favorite Futures: ES
 
cory's Avatar
 
Posts: 5,220 since Jun 2009
Thanks: 628 given, 6,318 received
Forum Reputation: Legendary


gomi View Post
I downloaded the NT7 version of Pepe package I could find on ET ( Forums - Software Used to Trade Jack Hershey Methods) and it reloaded up and down channels on chart recreation.

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.

Reply With Quote
 
  #12 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker/Data: IB, Kinetic
Favorite Futures: Stocks, Forex
 
Posts: 97 since Nov 2011
Thanks: 47 given, 16 received

@sam028, @gomi, or anyone else,

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?

Many thanks
Dan


Last edited by danjuma; March 11th, 2012 at 03:32 PM.
Reply With Quote
 
  #13 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker/Data: IB, Kinetic
Favorite Futures: Stocks, Forex
 
Posts: 97 since Nov 2011
Thanks: 47 given, 16 received



gomi View Post
Here's some code I wrote some time ago, it computes BarNum and Price using dichotomy on

ChartControl.GetXByBarIdx() and
ChartControl.GetYByValue()

I converted it to Strategy and looks OK

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.



Quoting 
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using System.Windows.Forms;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;

namespace NinjaTrader.Indicator
{

public class TestGetMouse : Indicator
{
#region Variables
#endregion

/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
}

protected override void OnStartUp()
{
this.ChartControl.ChartPanel.MouseUp += new MouseEventHandler(MouseEventH);
}

//declaring a delegate to functions we will dichotomize.
delegate int Function(int x);

//make this negative so the function is increasing
private int MinusGetY(int x)
{
return(-ChartControl.GetYByValue(BarsArray[0],x*this.TickSize));
}

private int GetX(int x)
{
return ChartControl.GetXByBarIdx(BarsArray[0],x);
}


//the dichotomy function, we look for yToFind using paramFunction, starting at xL and ending at xR/
private int IntegerDichotomy(int xL,int xR,Function paramFunction,int yToFind)
{


int yL=paramFunction(xL);
//xl matches
if (yL>=yToFind)
return(xL);

int yR=paramFunction(xR);
//xR matches
if (yR<=yToFind)
return(xR);

if (xL==xR)
return xL;

// if xR=xL+1, we're between 2 points. we choose the closest.
if ((xR-xL)==1)
if (Math.Abs((yToFind-yL))>Math.Abs((yR-yToFind)))
return xR;
else
return xL;

//else we split interval in 2 and start again.
int xM= (xL+xR)/2;
int yM= paramFunction(xM);

if (Math.Sign(yL-yToFind) == Math.Sign((yM-yToFind)))
return IntegerDichotomy(xM,xR,paramFunction,yToFind);
else
return IntegerDichotomy(xL,xM,paramFunction,yToFind);


}
private bool GetBarnumPriceFromMouseClick(ref int barnum, ref double price, int mousex, int mousey)
{
barnum=IntegerDichotomy( 0,CurrentBar,GetX,mousex);

price=IntegerDichotomy( Convert.ToInt32(MIN(CurrentBar)[0]/this.TickSize),Convert.ToInt32(MAX(CurrentBar)[0]/this.TickSize),MinusGetY,-mousey)*this.TickSize;

return true;


}




private void MouseEventH(object sender,MouseEventArgs e)
{
int barnum=0;
double price=0.0;
bool result;

result=GetBarnumPriceFromMouseClick(ref barnum,ref price,e.X,e.Y);

if (result)
DrawDiamond("mousebar", true, CurrentBar-barnum, price, Color.Blue);

DrawTextFixed("Price","Price is " + price, TextPosition.BottomLeft); //my code for now just to see price selected
}

protected override void OnTermination()
{
if (this.ChartControl != null)
{
this.ChartControl.ChartPanel.MouseUp -= MouseEventH;
}
base.Dispose();
}


#region Properties

#endregion
}
}


Reply With Quote
 
  #14 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received


danjuma View Post
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.

Hi,

A quick glance of the function:
 
Code
 
private void MouseEventH(object sender,MouseEventArgs e)
{ 
int barnum=0;
double price=0.0;
bool result;
 
result=GetBarnumPriceFromMouseClick(ref barnum,ref price,e.X,e.Y);
 
if (result)
DrawDiamond("mousebar", true, CurrentBar-barnum, price, Color.Blue);
 
DrawTextFixed("Price","Price is " + price, TextPosition.BottomLeft); //my code for now just to see price selected
}
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.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
The following user says Thank You to NJAMC for this post:
 
  #15 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker/Data: IB, Kinetic
Favorite Futures: Stocks, Forex
 
Posts: 97 since Nov 2011
Thanks: 47 given, 16 received


NJAMC View Post
Hi,

A quick glance of the function:
 
Code
 
private void MouseEventH(object sender,MouseEventArgs e)
{ 
int barnum=0;
double price=0.0;
bool result;
 
result=GetBarnumPriceFromMouseClick(ref barnum,ref price,e.X,e.Y);
 
if (result)
DrawDiamond("mousebar", true, CurrentBar-barnum, price, Color.Blue);
 
DrawTextFixed("Price","Price is " + price, TextPosition.BottomLeft); //my code for now just to see price selected
}
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!

Cheers
Dan

Reply With Quote
The following user says Thank You to danjuma for this post:
 
  #16 (permalink)
Elite Member
Australia
 
Futures Experience: Advanced
Platform: NinjaTrader, Multicharts
Favorite Futures: Spot Forex, Gold, Silver
 
Posts: 176 since Oct 2010
Thanks: 114 given, 114 received


danjuma View Post
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.

 
Code
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
	}
}

https://futures.io/download/ninjatrader-7/indicators/845-download.html?view


Last edited by Traderji; March 12th, 2012 at 08:36 PM.
Reply With Quote
The following user says Thank You to Traderji for this post:
 
  #17 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker/Data: IB, Kinetic
Favorite Futures: Stocks, Forex
 
Posts: 97 since Nov 2011
Thanks: 47 given, 16 received


Traderji View 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.

 
Code
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
    }
}
https://futures.io/download/ninjatrader-7/indicators/845-download.html?view


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).

Reply With Quote
 
  #18 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,354 given, 83,237 received


danjuma View Post
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.

Mike

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.

Reply With Quote
 
  #19 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker/Data: IB, Kinetic
Favorite Futures: Stocks, Forex
 
Posts: 97 since Nov 2011
Thanks: 47 given, 16 received

Hello again Traderji,

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.

Attached Thumbnails
ChartHelper in a Strategy-example.jpg   ChartHelper in a Strategy-example2.jpg  
Reply With Quote
 
  #20 (permalink)
Elite Member
Australia
 
Futures Experience: Advanced
Platform: NinjaTrader, Multicharts
Favorite Futures: Spot Forex, Gold, Silver
 
Posts: 176 since Oct 2010
Thanks: 114 given, 114 received



danjuma View Post
Hello again Traderji,

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).

Reply With Quote

Reply



futures io > > > > > ChartHelper in a Strategy

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Call ATM Strategy on an automated strategy to control position jsengxx NinjaTrader Programming 7 May 31st, 2016 05:51 PM
Utility To Transpose Optimized Strategy Values From Excel Output to Actual Strategy mercuryfx NinjaTrader 5 April 7th, 2012 04:59 PM
Ninjatrader7 ATM Strategy combine with Strategy Wizard Ninja Script schuster21 NinjaTrader Programming 4 July 4th, 2011 05:39 PM
Ninja Strategy multi-timeframe issue/Strategy to indicator nw123 NinjaTrader Programming 2 December 20th, 2009 07:24 PM


All times are GMT -4. The time now is 12:41 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-16 in 0.18 seconds with 20 queries on phoenix via your IP 54.226.113.250