Topic: Inside Bar with Sunday correctuon
[Edited]
This correction was requested and inspired by ahmedalhoseny.
If your broker starts quotation on Sunday, short bars appear in the historical rates on a daily chart. This bar together with the previous Friday bar forms an Inside Bar formation.
To prevent this the indicator compares Firday and Thursday in order to rise a signal on Monday.
Further to this the indicator merges the bars from Sunday and Monday before comparing with the Friday bar.
The main part of the code is:
// Calculation
int iFirstBar = 4;
double[] adIB = new double[Bars];
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
if (Time[iBar].DayOfWeek == DayOfWeek.Monday && Time[iBar - 1].DayOfWeek == DayOfWeek.Sunday)
{ // Today is Monday and a Sunday bar exists
// Friday
double friHigh = High[iBar - 2];
double friLow = Low[iBar - 2];
// Thursday
double thuHigh = High[iBar - 3];
double thuLow = Low[iBar - 3];
adIB[iBar] = (friHigh < thuHigh && friLow > thuLow) ? 1 : 0;
}
else if (Time[iBar].DayOfWeek == DayOfWeek.Tuesday && Time[iBar - 2].DayOfWeek == DayOfWeek.Sunday)
{ // Today is Tuesday and a Sunday bar exists.
// Monday high and low include eventual Sunday extreme.
double monLow = Math.Min(Low[iBar - 1], Low[iBar - 2]);
double monHigh = Math.Max(High[iBar - 1], High[iBar - 2]);
// Friday
double friHigh = High[iBar - 3];
double friLow = Low[iBar - 3];
adIB[iBar] = (monHigh < friHigh && monLow > friLow) ? 1 : 0;
}
else
adIB[iBar] = (High[iBar - 1] < High[iBar - 2] && Low[iBar - 1] > Low[iBar - 2]) ? 1 : 0;
}
Thank you ahmedalhoseny for the feedback.