Download MetaTrader 5

Week Open Price for indicator

To add comments, please log in or register
All articles are available from MetaTrader 5. Contribute your own one!
Max Enrik
814
Max Enrik 2016.05.29 12:40 

Hi,

I try below code for Week Open Price on Indicator. I have not any error code but below code does not shows me correct time.

if(TimeDayOfWeek(Time[i]) != TimeDayOfWeek(Time[i+1]))

Any help would be better.

Best,

Max 

Max Enrik
814
Max Enrik 2016.05.29 13:30  

Thanks for your reply.

I use below code for Day Open Price.

if(TimeDay(Time[i]) != TimeDay(Time[i+1]))

It does work for me. Even Month and Year, but Week is not.

 

Thanks,

Max 

whroeder1
14519
whroeder1 2016.05.29 14:14  
Max-Enrik: I try below code for Week Open Price on Indicator. I have not any error code but below code does not shows me correct time.
if(TimeDayOfWeek(Time[i]) != TimeDayOfWeek(Time[i+1]))

Your code asks if bar i is the start of a new day not a new week. You want to find the "Week Open Price," here are three ways:

  1. double wop = iOpen(NULL, PERIOD_W1, 0)
  2. datetime  BOW = iTime(NULL, PERIOD_W1, 0);
    int      iBOW = iBarShift(NULL,0, BOW);
    double   wop  = Open[iBow];
  3. Find the first bar of the new week: the DOW(Monday) < DOW(Friday)
    int i=0;
    while( TimeDayOfWeek(Time[i]) >= TimeDayOfWeek(Time[i+1]) ) ++i;
    double wop = Open[i];

Max Enrik
814
Max Enrik 2016.05.29 15:04  

WHRoeder:

int i=0;
while( TimeDayOfWeek(Time[i]) >= TimeDayOfWeek(Time[i+1]) ) ++i;
double wop = Open[i];

That was awesome. Yeah, I found what I want. Thank you so much - @WHRoeder

Everything OK at any TimeFrames. But indicator Opened wrong Price & Time when I want to use it at the "W1 / Weekly" TimeFrame.


Best,

Max 

Max Enrik
814
Max Enrik 2016.10.17 18:16  
WHRoeder:
Thanks for your help, that was helped me and I was solved my issue.
Max Enrik
814
Max Enrik 2016.10.17 18:51  
Hi,

I am using this code for my Daily Fibo object.
So, everything ok, but when I start MT4 platform I should restart once for my indicator will refresh (for works today, otherwise won't shows correctly for today).

I cannot find whats wrong with this code.
Please help me.

All the best.

int start()
{
    int indicatorCounted = IndicatorCounted();
    if( indicatorCounted < 0 ) { }
    if( indicatorCounted > 0 ) { indicatorCounted--; }

    int days = 0;
    int limit = Bars - indicatorCounted;
    for(int i = 0; i < limit; i++) {
        if( TimeDay(Time[i]) != TimeDay(Time[i+1]) ) {

            double   openDay   = Open[i];
            datetime openTime  = Time[i];
            datetime closeTime = Time[i] + 60 * 60 * 24;

            string levelOpen = openDay + pips2dbl                                        ;
            ObjectCreate(levelName, OBJ_FIBO, 0, openTime, levelOpen, closeTime, openDay );
            ...

 

Max Enrik
814
Max Enrik 2016.10.20 01:26  

Please somebody help me about my above issue.

I am still waiting good reply, thanks. 

Keith Watford
Moderator
9624
Keith Watford 2016.10.20 02:25  
            string levelOpen = openDay + pips2dbl     

Why is this a string? It should be a double.

ObjectCreate(levelName, OBJ_FIBO, 0, openTime, levelOpen, closeTime, openDay );

Once this has been created it cannot be created again with the same name.

Max Enrik
814
Max Enrik 2016.10.20 04:17  
GumRai:

Once this has been created it cannot be created again with the same name.

Thanks for your answers.

As you mentioned, I has been fixed like below.

string levelName = "- Daily Open - " + TimeMonth( Time[0] ) + "/" + TimeDay(Time[0]);

I tested with 'Strategy Tester' right now yes new FIBO object opens, but previous day FIBOs does not remove even I choice History 1 like below code.

int History = 1;
...
days--;
}
if(days >= History ) { break; }

I need help, please. 

Keith Watford
Moderator
9624
Keith Watford 2016.10.20 05:57  

Please study this and fully understand what is happening in the code

   static datetime bar_time=0;
   if(bar_time==Time[0]) //Only check if a new bar///
      return(0);
   bar_time=Time[0];

   static datetime openTime=0;

   int i=0;

   while(TimeDay(Time[i])==TimeDay(Time[i+1]))
      i++;
   if(openTime!=Time[i])
     {
      openTime=Time[i];
      double   openDay   = Open[i];
      datetime closeTime = Time[i] + 60 * 60 * 24;
      double levelOpen=openDay+pips2dbl;

      if(ObjectFind(0,levelName)!=0)
         ObjectCreate(levelName,OBJ_FIBO,0,openTime,levelOpen,closeTime,openDay);
      else
        {
         ObjectMove(0,levelName,0,openTime,levelOpen);
         ObjectMove(0,levelName,1,closeTime,openDay);

        }
     }

The Fibo is only created once and then moved at the start of a new day.

Max Enrik
814
Max Enrik 2016.10.20 12:14  

Almost I will spend whole of my life for this code Man. I solved my issue with your brilliant code! I studied from your like an educational code.

Thank you so much more!

To add comments, please log in or register