atxtrader
11-30-2009, 05:24 PM
I've been working with ElliotWave's FibLines indicator and have found it very useful in my day to day analysis (thanks so much for making it available, ElliotWave). However, I've noticed that it will only display the highest and lowest close for a given range rather than the absolute high and absolute low. I would guess that this throws off all of the fib levels slightly so I'd really like to get it corrected. I don't have programming experience but I'll post the relevant code and if anyone more experienced than me could help out, I would greatly appreciate it.:)
#region Variables
// Wizard generated variables
private DateTime startTime;
private string startDate = "3/01/2009 1:00:00 AM";
private double sessionLengthInHours=0;
// User defined variables (add any user defined variables below)
private double HighestHigh;
private double LowestLow;
private double Range;
private int HighBar=0,LowBar=0,FirstBar,LastBar;
private bool showHighAndLow=true;
private DateTime endTime;
private int lineWidth =2;
private int lineType =4;
private bool showLabel=true;
// User defined variables (add any user defined variables below)
#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()
{
Add(new Plot(Color.Transparent, PlotStyle.Line, "High"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "Low"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r200"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r176"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r161"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r150"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r138"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r123"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r76"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r61"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r50"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r38"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r23"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s23"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s38"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s50"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s61"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s76"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s100"));
ChartOnly = true;
AutoScale = false;
CalculateOnBarClose = true;
DisplayInDataBox = true;
Overlay = true;
PriceTypeSupported = false;
HighestHigh = Double.MinValue;
LowestLow = Double.MaxValue;
FirstBar = -1;
Range = 0;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{ if(CurrentBar<10) return;
try {
startTime = DateTime.Parse(startDate);
}
catch (FormatException) {
Print("Unable to convert " + startDate);
}
if(sessionLengthInHours == 0) endTime = DateTime.Now;
else endTime = startTime.AddHours(sessionLengthInHours);
if(Time[3]<=endTime && Time[2]>endTime) DrawLine("EndTime",3,HighestHigh,3,LowestLow,Color.Magenta,DashStyle .Solid,lineWidth);
Range = (HighestHigh - LowestLow);
if(DateTime.Compare(Time[0],startTime)>0 && DateTime.Compare(Time[0],endTime)<0)
{ if(FirstBar<0) FirstBar=CurrentBar;
if(HighestHigh<0.0)
{ HighestHigh = High[0];
LowestLow = Low[0];
} else
{ if(High[0]>HighestHigh)
{ HighestHigh = High[0];
HighBar=CurrentBar;
if(showHighAndLow) DrawHorizontalLine("High",HighestHigh,Color.Blue,DashStyle.Solid,lineWidth) ;
}
if(Low[0]<LowestLow)
{ LowestLow = Low[0];
LowBar=CurrentBar;
if(showHighAndLow) DrawHorizontalLine("Low",LowestLow,Color.Red,DashStyle.Solid,lineWidth);
}
}
if(CurrentBar-FirstBar>3) DrawLine("StartTime",CurrentBar-FirstBar,HighestHigh,CurrentBar-FirstBar,LowestLow,Color.Magenta,DashStyle.Solid,l ineWidth);
High.Set(HighestHigh); // high
Low.Set(LowestLow); //low
R200.Set(HighestHigh + Range * 1);
R176.Set(HighestHigh + Range * 0.764);
R161.Set(HighestHigh + Range * 0.618);
R150.Set(HighestHigh + Range * 0.5);
R138.Set(HighestHigh + Range * 0.382);
R123.Set(HighestHigh + Range * 0.236);
R76.Set(HighestHigh - Range * 0.236);
R61.Set(HighestHigh - Range * 0.382);
R50.Set(HighestHigh - Range * 0.5);
R38.Set(HighestHigh - Range * 0.618);
R23.Set(HighestHigh - Range * 0.764);
S23.Set (HighestHigh - Range * 1.236);
S38.Set (HighestHigh - Range * 1.382);
S50.Set (HighestHigh - Range * 1.5);
S61.Set (HighestHigh - Range * 1.618);
S76.Set (HighestHigh - Range * 1.764);
S100.Set (HighestHigh - Range * 2);
#region Variables
// Wizard generated variables
private DateTime startTime;
private string startDate = "3/01/2009 1:00:00 AM";
private double sessionLengthInHours=0;
// User defined variables (add any user defined variables below)
private double HighestHigh;
private double LowestLow;
private double Range;
private int HighBar=0,LowBar=0,FirstBar,LastBar;
private bool showHighAndLow=true;
private DateTime endTime;
private int lineWidth =2;
private int lineType =4;
private bool showLabel=true;
// User defined variables (add any user defined variables below)
#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()
{
Add(new Plot(Color.Transparent, PlotStyle.Line, "High"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "Low"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r200"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r176"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r161"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r150"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r138"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r123"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r76"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r61"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r50"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r38"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "r23"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s23"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s38"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s50"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s61"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s76"));
Add(new Plot(Color.Transparent, PlotStyle.Line, "s100"));
ChartOnly = true;
AutoScale = false;
CalculateOnBarClose = true;
DisplayInDataBox = true;
Overlay = true;
PriceTypeSupported = false;
HighestHigh = Double.MinValue;
LowestLow = Double.MaxValue;
FirstBar = -1;
Range = 0;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{ if(CurrentBar<10) return;
try {
startTime = DateTime.Parse(startDate);
}
catch (FormatException) {
Print("Unable to convert " + startDate);
}
if(sessionLengthInHours == 0) endTime = DateTime.Now;
else endTime = startTime.AddHours(sessionLengthInHours);
if(Time[3]<=endTime && Time[2]>endTime) DrawLine("EndTime",3,HighestHigh,3,LowestLow,Color.Magenta,DashStyle .Solid,lineWidth);
Range = (HighestHigh - LowestLow);
if(DateTime.Compare(Time[0],startTime)>0 && DateTime.Compare(Time[0],endTime)<0)
{ if(FirstBar<0) FirstBar=CurrentBar;
if(HighestHigh<0.0)
{ HighestHigh = High[0];
LowestLow = Low[0];
} else
{ if(High[0]>HighestHigh)
{ HighestHigh = High[0];
HighBar=CurrentBar;
if(showHighAndLow) DrawHorizontalLine("High",HighestHigh,Color.Blue,DashStyle.Solid,lineWidth) ;
}
if(Low[0]<LowestLow)
{ LowestLow = Low[0];
LowBar=CurrentBar;
if(showHighAndLow) DrawHorizontalLine("Low",LowestLow,Color.Red,DashStyle.Solid,lineWidth);
}
}
if(CurrentBar-FirstBar>3) DrawLine("StartTime",CurrentBar-FirstBar,HighestHigh,CurrentBar-FirstBar,LowestLow,Color.Magenta,DashStyle.Solid,l ineWidth);
High.Set(HighestHigh); // high
Low.Set(LowestLow); //low
R200.Set(HighestHigh + Range * 1);
R176.Set(HighestHigh + Range * 0.764);
R161.Set(HighestHigh + Range * 0.618);
R150.Set(HighestHigh + Range * 0.5);
R138.Set(HighestHigh + Range * 0.382);
R123.Set(HighestHigh + Range * 0.236);
R76.Set(HighestHigh - Range * 0.236);
R61.Set(HighestHigh - Range * 0.382);
R50.Set(HighestHigh - Range * 0.5);
R38.Set(HighestHigh - Range * 0.618);
R23.Set(HighestHigh - Range * 0.764);
S23.Set (HighestHigh - Range * 1.236);
S38.Set (HighestHigh - Range * 1.382);
S50.Set (HighestHigh - Range * 1.5);
S61.Set (HighestHigh - Range * 1.618);
S76.Set (HighestHigh - Range * 1.764);
S100.Set (HighestHigh - Range * 2);