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;
}

http://s2.postimage.org/1aKNV9.jpg

Thank you ahmedalhoseny for the feedback.

Post's attachments

Inside Bar Sun.cs 4.93 kb, 51 downloads since 2009-12-19 

You don't have the permssions to download the attachments of this post.

Re: Inside Bar with Sunday correctuon

Thaaaaaaannnnnnxxxxxxxxxx

Attached here the results of test using the new tool

But it seams that its logic to consider the sunday candle as an inside day and make its action using that logic !!!

Any clues!!

Regards

http://s1.postimage.org/Nnz6i.jpg

http://s3.postimage.org/qKDCS.jpg

http://s1.postimage.org/NnJ4S.jpg

Re: Inside Bar with Sunday correctuon

Popov wrote:

If your broker starts quotation on Sunday, a short bars appear in the historical rates on a daily chart. This bar together with the following Monday bar forms an Inside Bar formation. To prevent this ahmedalhoseny suggested the Sunday bar to included in the Monday bar.

The "Inside Bar Sun" custom indicator checks the bar's date and if it's Monday that follows a Sunday bar, it merges the two bars (only to calculates the signal).

Hello Again
the sunday bar forms an inside day in comparison with previous friday not with next monday , am i right ?????
My idea is : we ignore all sunday candles when look for any narrow range formation
EX: if we scan all daily candles for narrow range formation or inside bar and we find that Friday candle is inside day in comparison to thursday , so we ignore the sunday candle from calculation and combine both sunday and monday together in calculation


Also when calculate any indicator like RSI we should use the new data from the ( combined new monday OHLC data )

http://s3.postimage.org/qXCLJ.jpg

http://s3.postimage.org/qXMKi.jpg

Re: Inside Bar with Sunday correctuon

EX: if we scan all daily candles for narrow range formation or inside bar and we find that Friday candle is inside day in comparison to thursday , so we ignore the sunday candle from calculation and combine both sunday and monday together in calculation

Done.

First post and indicator corrected.

Re: Inside Bar with Sunday correctuon

There is a side effect of this indicator:

When Thursday and Friday bars form a formation, it rises signals on Sunday and on Monday. One formation rises two signals.

You can prevent entering on Sunday by using Day of Week indicator:

[Opening Logic Condition]
Day of Week
     Enter the market between the specified days
     From (incl.)  -  Monday
     To (excl.)  -  Saturday

Re: Inside Bar with Sunday correctuon

Thnx popov
and still testing it , it will take time because i compare the charts of FSB with my MT4 charts

Thanx again

Re: Inside Bar with Sunday correctuon

I want to add something. It's easy to prevent entries on Sunday by adding this code in the calculation cycle.

if (Time[iBar].DayOfWeek == DayOfWeek.Sunday)
{   // Today is Sunday - no entry
    adIB[iBar] = 0;
}

Re: Inside Bar with Sunday correctuon

Dear popov ( and correct me if iam wrong)

This indicator adjust the signals comming from price value it self but has no function with the indicators wich use the price information( like rsi ) !!!!

Re: Inside Bar with Sunday correctuon

This indicator adjust the signals comming from price value it self but has no function with the indicators wich use the price information( like rsi ) !!!!

I cannot understand you. What is the difference between price vaue and price information.

Both "Inside Bar" and "RSI" use one and the same price data:

DateTime Time[Bars-1]; 
double   Open[Bars-1]; 
double   High[Bars-1]; 
double   Low[Bars-1]; 
double   Close[Bars-1]; 
int      Volume[Bars-1];

Re: Inside Bar with Sunday correctuon

Hello
I mean we are calculating RSI(14) , and we are in monday so it will use data from sunday to uppdate the indicator?

and now we are in tusday is it will use monday and sunday as 2 different days in the rsi calculation or it will use only ( combined monday ) = sunday + monday as one day ??
regards

Re: Inside Bar with Sunday correctuon

This problem exists for all indicators. It can be corrected  with special calculations for Sunday and Monday as shown above for each indicator. It is a little bit more complex taking into account not only the current Sunday but also the previous (RSI 14  includes 2 or 3 Sundays). Another possible options is to merge preliminarily Sundays and Mondays but this will reduce the number of bars.

Re: Inside Bar with Sunday correctuon

I got it smile it really will be a complicated issue

May you help me here
http://forexsb.com/forum/topic/1233/use-previous-bar-value-in-entering-and-closing-positions/

thanx again