View Full Version : Setup indicator
Mauro60
01-25-2007, 03:03 AM
Hi guys, I'm developing a new indicator, it's an average HILO crossover crossover, when the retr occours (on the lower avg) with close>previous bar then setup is confirmed. As you can see in the attached image, setup is marked with a "lime" bar, but it's wrong. I did many tests, but nothing to do. May someone help me coding better this indicator?
NinjaTrader_Ray
01-25-2007, 03:30 AM
To debug, have you tried sending data to the Output Window (Print) and traced the following information:
CurrentBar
BarTime
Data points used to trigger the condition
This is what I do to give me an idea what the conditions are when the bar is changing to lime.
Is this chart you provided real-time or historical? Meaning, does the indicator behave correctly on historical data but the error only shows up in real time?
Ray
Mauro60
01-25-2007, 03:54 AM
Thank Ray, I'm trying nt6beta (demo) with globalfutures, realtime eminis (the same occours with historical data). Sorry for the past message, I forgot to attach the code! attached datawindow image. Thanks
{
#region Variables
// Wizard generated variables
private int leng = 89; // Default setting for Leng
private DataSeries diff;
private int brk = 0;
private bool retr ;
private bool retr2 ;
private bool HiLo ;
private bool HiLo2 ;
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
diff = new DataSeries(this);
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
diff.Set (TickSize);
// double diff = High[0] - Low[0];
double MaCl = Low[0];
double MaCl2 = High[0];
double MaCl3 = Close[0];
double MaHi = HMA(High,Leng)[0];
double MaLo = HMA(Low,Leng)[0];
double offset = HMA(diff, Leng)[0];
double tlrnH = MaHi + offset;
double tlrnHH = MaHi - offset;
double tlrnL = MaLo - offset;
double tlrnLL = MaLo + offset;
if (CrossBelow(Close, MaLo, 1))
HiLo = false;
retr = false;
if(HiLo == true ){
if ((MaCl >= (tlrnL) && MaCl <= (tlrnLL)) && MaCl3 > MaLo)
retr = true;
else
retr = false;
//}
if (retr == true && (Close[1] <= Open[1] && Close[0] >= Open[0]))
BarColor = Color.Lime;
}
if (CrossAbove(Close, MaHi,1))
HiLo = true;
NinjaTrader_Ray
01-25-2007, 04:20 AM
Mauro60,
I can't easily tell why the lime bar is incorrect in your image? What condition is not true below:
if (retr == true && (Close[1] <= Open[1] && Close[0] >= Open[0]))
BarColor = Color.Lime;
Mauro60
01-25-2007, 05:22 AM
I hope you could understand what I'm meaning and what I would obtain. On the chart I reported conditions for setup.
NinjaTrader_Ray
01-25-2007, 07:34 AM
Thanks. So looks like the "retr" variableisnot being set based on your expectations.
What I suggest is adding a Print Statements such as:
Print(Time[0].ToString() + " 1" + retr)
Print(Time[0].ToString() + " 2" + retr)
Print(Time[0].ToString() + " 3" + retr)
Print(Time[0].ToString() + " Final" + retr)
Place the first three at the exact spots where you set the "retr" variable and the last one at the very end of the OnBarUpdate() method. Then look in the OutPut window to determine why the "retr" is not set to false at the lime bar is incorrect.
Ray
Mauro60
01-25-2007, 08:32 AM
Ok!
Mauro60
01-25-2007, 08:14 PM
The variable HiLo result always true instead result false, where is the mistake?
23/01/2007 20.39.33 1 False -- True
23/01/2007 20.39.33 2 True -- True
23/01/2007 20.39.33 3 True -- True
23/01/2007 20.39.33 Final True -- True
NinjaTrader_Ray
01-26-2007, 02:11 AM
I can't tell you where its wrong but its obvious then that the condition should be false when it is true. What I would do next is determine visuallly what bar on the chart should trigger the condition to be false and write and place more print statements to see what the logic flow is for that bar, print out value to see where you have a logic flaw in your code.
Ray