I just tried the modieifed Prior OHLC indicator but it is making small problem.
The point of the modification is when the chart is shoewn in ETH session it will show
the prioir OHLC from start of the RTH session. The problem arise when
the ETH opening is higher then the RTH High. Then as Prior High it prints the High of the first bar of the ETH session. It is the same for the Prior Low. If the ETH opening is bellow the RTH Low, then as Prior Low it prints the Low of the first bar of the ETH session.
I tried to put - 100 and + 100 in the formula bellow to make sure that the High[0] and the Low[0] is always higher/lower but without succes.
currentHigh = Math.Max(currentHigh - 100, High[0]);
currentLow = Math.Min(currentLow + 100, Low[0]);
Any sugestions?
This is the code:
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
private DateTime currentDate = Cbi.Globals.MinDate;
private double currentOpen = 0;
private double currentHigh = 0;
private double currentLow = 0;
private double currentClose = 0;
private double priordayOpen = 0;
private double priordayHigh = 0;
private double priordayLow = 0;
private double priordayClose = 0;
private bool showOpen = true;
private bool showHigh = true;
private bool showLow = true;
private bool showClose = true;
#endregion
int dayStart = 800;
int dayEnd = 2200;
int onDay = 0;
int dayStartAdjusted = 0; //Added
/// <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.Orange, PlotStyle.Hash, "Prior Open"));
Add(new Plot(Color.Green, PlotStyle.Hash, "Prior High"));
Add(new Plot(Color.Red, PlotStyle.Hash, "Prior Low"));
Add(new Plot(Color.Firebrick, PlotStyle.Hash, "Prior Close"));
Plots[0].Pen.DashStyle = DashStyle.Dash;
Plots[3].Pen.DashStyle = DashStyle.Dash;
AutoScale = false;
Overlay = true; // Plots the indicator on top of price
}
protected override void OnStartUp() //Added
{
if (BarsPeriod.Id == PeriodType.Minute || BarsPeriod.Id == PeriodType.Second)
{
int dsTmp = dayStart * 100;
int dsTmpHrs = dsTmp / 10000;
int dsTmpMins = (dsTmp - dsTmpHrs * 10000) / 100;
int dsTmpSecs = dsTmp - dsTmpHrs * 10000 - dsTmpMins * 100;
TimeSpan dsTimeSpan = new TimeSpan(dsTmpHrs, dsTmpMins, dsTmpSecs);
TimeSpan dsAddTime = new TimeSpan(0, 0, 0);
if (BarsPeriod.Id == PeriodType.Minute) dsAddTime = new TimeSpan(0, BarsPeriod.Value, 0);
else if (BarsPeriod.Id == PeriodType.Second) dsAddTime = new TimeSpan(0, 0, BarsPeriod.Value);
dsTimeSpan = dsTimeSpan.Add(dsAddTime);
dayStartAdjusted = ToTime(Time[0].Date.Add(dsTimeSpan));
}
}
// end Additions
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (Bars == null)
return;
if (!Bars.BarsType.IsIntraday)
{
DrawTextFixed("error msg", "PriorDayOHLC only works on intraday intervals", TextPosition.BottomRight);
return;
}
//if (onDay != Time[0].Day)
//{
// if (currentOpen != 0)
// {
// priordayOpen = currentOpen;
// priordayHigh = currentHigh;
// priordayLow = currentLow;
// priordayClose = currentClose;
// if (ShowOpen) PriorOpen.Set(priordayOpen);
// if (ShowHigh) PriorHigh.Set(priordayHigh);
// if (ShowLow) PriorLow.Set(priordayLow);
// if (ShowClose) PriorClose.Set(priordayClose);
// }
// onDay = Time[0].Day;
//}
//else
//{
//}
// If the current data is not the same date as the current bar then its a new session
if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || currentOpen == 0)
{
// The current day OHLC values are now the prior days value so set
// them to their respect indicator series for plotting
if (currentOpen != 0)
{
priordayOpen = currentOpen;
priordayHigh = currentHigh;
priordayLow = currentLow;
priordayClose = currentClose;
if (ShowOpen) PriorOpen.Set(priordayOpen);
if (ShowHigh) PriorHigh.Set(priordayHigh);
if (ShowLow) PriorLow.Set(priordayLow);
if (ShowClose) PriorClose.Set(priordayClose);
}
// Initilize the current day settings to the new days data
currentOpen = Open[0];
currentHigh = High[0];
currentLow = Low[0];
currentClose = Close[0];
currentDate = Bars.GetTradingDayFromLocal(Time[0]);
}
else // The current day is the same day
{
// if (ToTime(Time[0]) == dayStart * 100) currentOpen = Open[0];
if (ToTime(Time[0]) == dayStartAdjusted) currentOpen = Open[0];
if (ToTime(Time[0]) > dayStart * 100 && ToTime(Time[0]) < dayEnd * 100)
{
// Set the current day OHLC values
currentHigh = Math.Max(currentHigh, High[0]);
currentLow = Math.Min(currentLow, Low[0]);
currentClose = Close[0];
}
if (ShowOpen) PriorOpen.Set(priordayOpen);
if (ShowHigh) PriorHigh.Set(priordayHigh);
if (ShowLow) PriorLow.Set(priordayLow);
if (ShowClose) PriorClose.Set(priordayClose);
}
}
#region Properties
[Description("")]
[Category("Parameters")]
public int DayStart
{
get { return dayStart; }
set { dayStart = Math.Max(0, value); }
}
[Description("")]
[Category("Parameters")]
public int DayStop
{
get { return dayEnd; }
set { dayEnd = Math.Max(1, value); }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries PriorOpen
{
get { return Values[0]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries PriorHigh
{
get { return Values[1]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries PriorLow
{
get { return Values[2]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries PriorClose
{
get { return Values[3]; }
}
[Browsable(true)]
[Gui.Design.DisplayNameAttribute("Show open")]
public bool ShowOpen
{
get { return showOpen; }
set { showOpen = value; }
}
[Browsable(true)]
[Gui.Design.DisplayNameAttribute("Show high")]
public bool ShowHigh
{
get { return showHigh; }
set { showHigh = value; }
}
[Browsable(true)]
[Gui.Design.DisplayNameAttribute("Show low")]
public bool ShowLow
{
get { return showLow; }
set { showLow = value; }
}
[Browsable(true)]
[Gui.Design.DisplayNameAttribute("Show close")]
public bool ShowClose
{
get { return showClose; }
set { showClose = value; }
}
#endregion
}
}
Comment