NexusFi: Find Your Edge


Home Menu

 





ChartHelper in a Strategy


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one danjuma with 10 posts (1 thanks)
    2. looks_two Traderji with 5 posts (1 thanks)
    3. looks_3 sam028 with 4 posts (4 thanks)
    4. looks_4 gomi with 4 posts (19 thanks)
      Best Posters
    1. looks_one gomi with 4.8 thanks per post
    2. looks_two sam028 with 1 thanks per post
    3. looks_3 cory with 1 thanks per post
    4. looks_4 Traderji with 0.2 thanks per post
    1. trending_up 11,578 views
    2. thumb_up 29 thanks given
    3. group 11 followers
    1. forum 27 posts
    2. attach_file 5 attachments




 
Search this Thread

ChartHelper in a Strategy

  #1 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

Warning, this is a bit tricky/high level problem.
Some of our very good coders, @Mindset, @bukkan, @gomi, @eDanny, @Fat Tails, ... may have an idea.

I've been playing with ChartHelper.cs, which allow nice things, like calculate the price of the bar number, from the point you have clicked on a chart.
It works fine in an indicator, you can very quickly write an indicator which trap a mouse click, and then get the bar number, or the price level, and so on.
To calculate this, it use the Update() method, which seems to be called with a min and max, which can then be used to calculate the price.
It's also possible, with the Plot() method, where you have a min and a max.
But, AFAIK, these methods are not accessible in a Strategy, right ?

Any idea, to make a strategy able to get these min & max ?
Below a sample Strat, trying to get this price level.
The ChartHelper.cs is also here: ChartHelper.cs

 
Code
                            
namespace NinjaTrader.Strategy
{
    [
Description(" XY")]
    public class 
xyselect Strategy
    
{            
        private 
ChartHelper chartHelper;    
        private 
bool _found false;
        private 
double _t    0.0;
        
        protected 
override void Initialize() {
            
CalculateOnBarClose true;                        
        }
        
        protected 
override void OnStartUp() {
        }
                
        protected 
override void OnBarUpdate()
        {    
            if (!
_found) {
                
this.ChartControl.ChartPanel.MouseUp += new MouseEventHandler(chart_MouseClick);
                
chartHelper = new ChartHelper this.ChartControlthis.Barsthis.TickSize);
                
_t Instrument.MasterInstrument.TickSize;
                
_found=true;
            }            
        }
                
        private 
void chart_MouseClick(object senderMouseEventArgs e)
        {            
            
Panel chartPanel sender as Panel;    
            if (
chartPanel == null)
                return;                        
            if (
e.Clicks == && (e.Button == MouseButtons.Left) ) { 
                Print(
"e.X: "+e.X);
                Print(
"e.Y: "+e.Y);                
                Print(
"Price: "+chartHelper.ConvertYtoPrice(e.Y).ToString());
            }            
        }
        
        protected 
override void OnTermination() {        
            if(
ChartControl==null)
                return;
            
this.ChartControl.ChartPanel.MouseUp -= new MouseEventHandler(chart_MouseClick);            
            
base.Dispose();
        }        


Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
MC PL editor upgrade
MultiCharts
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Tao te Trade: way of the WLD
22 thanks
My NQ Trading Journal
16 thanks
HumbleTraders next chapter
9 thanks
  #3 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090


I use channel indicator it called chart helper to draw a channel but it has a bug. When you re-open a chart it draws down channel only, I have to delete then add it back then it draws both up and down channel.

Attached Files
Elite Membership required to download: a00Channels.cs
Reply With Quote
Thanked by:
  #4 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

Thanks Cory, but my problem is being able to use some of its classes in a Strategy.
In an Indicator, it works as expected.

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Started this thread Reply With Quote
  #5 (permalink)
 gomi 
Paris
Market Wizard
 
Experience: None
Platform: NinjaTrader
Posts: 1,270 since Oct 2009
Thanks Given: 282
Thanks Received: 4,505

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

Attached Files
Elite Membership required to download: TstGetMouse.cs
Reply With Quote
  #6 (permalink)
 gomi 
Paris
Market Wizard
 
Experience: None
Platform: NinjaTrader
Posts: 1,270 since Oct 2009
Thanks Given: 282
Thanks Received: 4,505

I might add that both the ChannelHelper.cs and the a00Channels.cs look to me as the Pepe Hershey Indicators PP_ChartHelper and PP_Channels, see here , except that there no mention to Pepe any more.

As a developer I find it rather uncool, so I'll grab this opportunity to make public mention of this awsome series of Indicators, and thank Pepe if he wanders here one day.

Pepe, your work was truly inspirational to me and helped me tremendously to deal with mouse/keyboard interaction with the Ninja charts. It really was an eye-opener.

Thanks again !

Reply With Quote
  #7 (permalink)
 gomi 
Paris
Market Wizard
 
Experience: None
Platform: NinjaTrader
Posts: 1,270 since Oct 2009
Thanks Given: 282
Thanks Received: 4,505

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.

Reply With Quote
  #8 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

Thanks @gomi.

I already had this piece of code, but I was trying to see if there was a simpler way to convert the Y value to a price.
As it seems there is not, I think I will have to modify this one (but I need to understand it first, not really an amateur's one ).
As this indicator/strategy can give the low of a bar if the mouse click is done below, it might be able to also give the high of the same bar. If I can have an Y' of low, and an Y'' for the high, with a know low and high, I should be able to translate my Y into a price.


Very clear for me now, let's see tomorrow morning...





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


Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Started this thread Reply With Quote
  #9 (permalink)
 gomi 
Paris
Market Wizard
 
Experience: None
Platform: NinjaTrader
Posts: 1,270 since Oct 2009
Thanks Given: 282
Thanks Received: 4,505

If you're willing to get an y outside of the bar, anywhere on the chart, here's what you can do:

 
Code
                            
        private bool GetBarnumPriceFromMouseClick(ref int barnumref double priceint mousexint mousey)
        {    
            
barnum=IntegerDichotomy0,CurrentBar,GetX,mousex);
            
            
price=IntegerDichotomyConvert.ToInt32(MIN(CurrentBar)[0]/this.TickSize),Convert.ToInt32(MAX(CurrentBar)[0]/this.TickSize),MinusGetY,-mousey)*this.TickSize;
            
            return 
true;
        } 

Reply With Quote
Thanked by:
  #10 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


Thanks, it works like a charm !!!


gomi View Post
If you're willing to get an y outside of the bar, anywhere on the chart, here's what you can do:

 
Code
                            
        private bool GetBarnumPriceFromMouseClick(ref int barnumref double priceint mousexint mousey)
        {    
            
barnum=IntegerDichotomy0,CurrentBar,GetX,mousex);
            
            
price=IntegerDichotomyConvert.ToInt32(MIN(CurrentBar)[0]/this.TickSize),Convert.ToInt32(MAX(CurrentBar)[0]/this.TickSize),MinusGetY,-mousey)*this.TickSize;
            
            return 
true;
        } 


Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Started this thread Reply With Quote




Last Updated on March 18, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts