PDA

View Full Version : Pattern detection via indicator


nybangali
08-19-2007, 09:41 PM
I am trying to create an indicator that detects a pattern of 3 bars with the high of the middle bar is higher than the high of the surrounding 2 bars.
Here is the code, with Overlay set to true and PlotStyle.Dot. I see nothing

if (CurrentBar == 0) {
Upfractal.Set(0);
} else {

if ((High[0] < High[1]) && (High[2] < High[1])) {
Upfractal.Set(High[1]);
} else {Upfractal.Set(0);}

}


I tried overlay set to false, and PlotStyle.Line to see if it paints in the lower panel, but in that case I see a blank panel below.

NinjaTrader_Dierk
08-19-2007, 09:47 PM
Whenever you experience something unexpected you should inspect the logs. In your case they will indicate that
High[2]
is the problem, since you need to change your code like this
if (CurrentBar <= 1) {

nybangali
08-19-2007, 10:32 PM
Good tip... never thought of looking at the log
Have the following log upon refreshing the chart
"Error on calling the 'OnBarUpdate' method for indicator 'Fractals2' on bar 3: Index was out of range. Must be non-negative and less than the size of the collection."

I did replace the (CurrentBar == 0) with (CurrentBar <= 1) and it gave the above error. With CurrentBar ==0 it just stated "bar 1" instead of "bar 3".

Hoping for another clue.

I have a different question. Who is Ninjatrader targeted to ? The programmer/investor demographic ? You need to get into super duper programming to implement anything beyond the most basic strategies. Is the average trader really into this learning curve? I really appreciate the fast response on this forum, but reading through the other posts, I see you folks do draw the line quite fast.
Don't get me wrong - I get a gut feeling for the power of NT, but having used Metastock for a while, this is far more complex.
Implementing the pattern detection exercise I am trying to do took me 30 seconds to do in Metastock after 2 days of using their experts !

Whenever you experience something unexpected you should inspect the logs. In your case they will indicate that
High[2]
is the problem, since you need to change your code like this
if (CurrentBar <= 1) {

NinjaTrader_Dierk
08-19-2007, 10:48 PM
(edited my post)
I suggest starting simple as possible and see where your code below causes the problem. You then could add more logic step-by-step.

On NT: It depends on what you want to do: A good starter is the strategy wizard where you can implement simple strategies. More flexibility comes at the expense of coding strategies/indicators manually.
Unfortunately we do not yet have a wizard for indicators or pattern detection.

nybangali
08-19-2007, 11:02 PM
re: starting simple as possible...
does it get any simpler than ..
if ((High[0] < High[1]) && (High[2] < High[1])) {
MyIndicator.Set(High[1]);
}
How about this... Can you provide a simple example of a simple historical pattern based indicator? I understand you're not here to code my problems. But I think its a fair question.

This thing takes 10 seconds in Metastock using the expert.
Fine.. so why I am I still struggling with NT ? Because I was using Metastock EOD, and now considering moving to Realtime... one advantage of NT is the cost.. the other is that I need a real time trade execution platform which I don't think Metastock has.

(edited my post)
I suggest starting simple as possible and see where your code below causes the problem. You then could add more logic step-by-step.

On NT: It depends on what you want to do: A good starter is the strategy wizard where you can implement simple strategies. More flexibility comes at the expense of coding strategies/indicators manually.
Unfortunately we do not yet have a wizard for indicators or pattern detection.

NinjaTrader_Dierk
08-20-2007, 12:04 AM
This code works perfectly on a wizard generated indicator template:
protected override void OnBarUpdate()
{
if (CurrentBar <= 1)
Plot0.Set(0);
else if (High[0] < High[1] && High[2] < High[1])
Plot0.Set(High[1]);
else
Plot0.Set(0);
}Note: You need to replace Plot0 by the name of your actual plot series you entered in the wizard.

nybangali
08-20-2007, 12:52 AM
Thank you. This works. And I even figured out to set the Displacement value to -1 manually and save the chart template so that it appears on the actual high bar.
Very nice.

This code works perfectly on a wizard generated indicator template:
protected override void OnBarUpdate()
{
if (CurrentBar <= 1)
Plot0.Set(0);
else if (High[0] < High[1] && High[2] < High[1])
Plot0.Set(High[1]);
else
Plot0.Set(0);
}Note: You need to replace Plot0 by the name of your actual plot series you entered in the wizard.