Download MetaTrader 5
To add comments, please log in or register
Read the interviews of the Automated Trading Championship participants
fonx
52
fonx 2015.01.07 12:50 

Hi there, I've been fighting this thing since yesterday, tried different things, googled like a mad... I can't make it work. Let me explain:

I want an indicator that marks with a vertical line the end of different times (end of day, end of week, end of month, end of quarter). The length of the vertical line goes from High to Low of the specific period, that way I can compare the end of the period with the overall range of the period:

- End of Day (5pm NY, only visible when TF is < PERIOD_D1). The line goes from High to Low of that day. WORKS.

- End of Week (Friday 5pm. Length of vertical line is from High to Low of that week. TF < PERIOD_W1). NOT WORKING

- Month and quarter not implemented yet, I'm stack in the week one.

 

Honestly, I don't know why the End of Week doesn't work, the logic should be quite similar than the End of Day. This is my Start() method. Below I'll copy the whole indicator code:

 

void start()
{
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) counted_bars=0;
   if(counted_bars > 0) counted_bars--;
   int limit = Bars-counted_bars;

   for(int i = 0 ;i <= limit ;i++)
   {
      datetime t = iTime(Symbol(), Period(), i);
      
      if(IsFriday(t) && IsEndOfDay(t) && DisplayEndOfWeek())
      {   
         int barShift = iBarShift(Symbol(), PERIOD_W1, Time[i], false);                       
         l2UpBuffer[i] = iHigh(Symbol(), PERIOD_W1, barShift);
         l2DnBuffer[i] = iLow(Symbol(), PERIOD_W1, barShift);
      }
      else if(IsEndOfDay(t) && DisplayEndOfDay())
      {
         int barShift = iBarShift(Symbol(),PERIOD_D1,Time[i]);
         l1UpBuffer[i] = iHigh(Symbol(),PERIOD_D1, barShift);
         l1DnBuffer[i] = iLow(Symbol(),PERIOD_D1, barShift);
      }    
   }
   
   return;
}

 

The Day mark works perfectly on H1 chart (aparently) but the weekly one at NY 5pm Friday does not work and I don't know why :(. Another problem that I just realised is that bars from D1 and above might not close at 5pm NY but that is an issue I'll fight later.

 

My plan B is to calculate the number of bars for each period per time frame (for instance in H1 there are 118 bars per week I think) and having that number I can get High[Highest] and Low[Lowest]. But this approach is a bit more complex and not flexible.

Any help is appreciated. Thanks in advance.

 

#### whole indicator code, also attached

 

//+------------------------------------------------------------------+
//|                                               End of Period.mq4 |
//|                               Copyright 2014, Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 DarkSlateGray
#property indicator_color2 DarkSlateGray
#property indicator_color3 DarkSlateGray
#property indicator_color4 DarkSlateGray
#property indicator_color5 DarkSlateGray
#property indicator_color6 DarkSlateGray
#property indicator_color7 Red
#property indicator_color8 Red

// external parameters  
extern bool EndOfDay = true;
extern bool EndOfWeek = true;
extern bool EndOfMonth = true; 
extern bool EndOfQuarter = true;  
                                 

// Global variables
double l1UpBuffer[];
double l1DnBuffer[];
double l2UpBuffer[];
double l2DnBuffer[];
double l3UpBuffer[];
double l3DnBuffer[];
double l4UpBuffer[];
double l4DnBuffer[];

string prefix = "eop_";
string shortName = "AMG End of Period";

int init()
{
   IndicatorBuffers(6);
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_DOT,1);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_DOT,1);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_DASH,1);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_DASH,1);
   SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(5,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(6,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(7,DRAW_HISTOGRAM,STYLE_SOLID,1);
   
   SetIndexBuffer(0,l1UpBuffer);
   SetIndexBuffer(1,l1DnBuffer);
   
   SetIndexBuffer(2,l2UpBuffer);
   SetIndexBuffer(3,l2DnBuffer);
   
   SetIndexBuffer(4,l3UpBuffer);
   SetIndexBuffer(5,l3DnBuffer);
   
   SetIndexBuffer(6,l4UpBuffer);
   SetIndexBuffer(7,l4DnBuffer);
 
   IndicatorShortName(shortName);
   
   return(INIT_SUCCEEDED);
}


void OnDeinit(const int reason)
{
   ObjectsDeleteAll();
   //ResetHud();
}


void ResetHud()
{

}

void start()
{
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) counted_bars=0;
   if(counted_bars > 0) counted_bars--;
   int limit = Bars-counted_bars;

   for(int i = 0 ;i <= limit ;i++)
   {
      datetime t = iTime(Symbol(), Period(), i);
      
      if(IsFriday(t) && IsEndOfDay(t) && DisplayEndOfWeek())
      {   
         int barShift = iBarShift(Symbol(), PERIOD_W1, Time[i], false);                       
         l2UpBuffer[i] = iHigh(Symbol(), PERIOD_W1, barShift);
         l2DnBuffer[i] = iLow(Symbol(), PERIOD_W1, barShift);
      }
      else if(IsEndOfDay(t) && DisplayEndOfDay())
      {
         int barShift = iBarShift(Symbol(),PERIOD_D1,Time[i]);
         l1UpBuffer[i] = iHigh(Symbol(),PERIOD_D1, barShift);
         l1DnBuffer[i] = iLow(Symbol(),PERIOD_D1, barShift);
      }    
   }
   
   return;
}

bool DisplayEndOfDay()
{
   return EndOfDay && Period() < PERIOD_D1;
}

bool DisplayEndOfWeek()
{
   return EndOfWeek && Period() <= PERIOD_D1;
}

bool DisplayEndOfMonth()
{
   return EndOfMonth && Period() <= PERIOD_W1;
}

bool DisplayEndOfQuarter()
{
   return EndOfQuarter;
}

// End of day is 5pm NY time
bool IsEndOfDay(datetime t)
{
   return TimeHour(t) == 17;
}


// 0-Sunday,1,2,3,4,5,6
bool IsFriday(datetime t)
{
   return TimeDayOfWeek(t) == 5;
}
Files:
fonx
52
fonx 2015.01.07 13:25  

Just in case anyone wonders why I'm doing this indicator it is because I've read that at the end of the day, end of the week, end of the month and end of quarter traders tend to close more positions. They are supposed to close first the winning ones and that creates a counter trend movement and at the very last moments they close the losing ones, and that creates a movement that resumes the trend.

I just wanted to ckeck that :) 

Alain Verleyen
Moderator
28606
Alain Verleyen 2015.01.07 13:40  
fonx:

Hi there, I've been fighting this thing since yesterday, tried different things, googled like a mad... I can't make it work. Let me explain:

I want an indicator that marks with a vertical line the end of different times (end of day, end of week, end of month, end of quarter). The length of the vertical line goes from High to Low of the specific period, that way I can compare the end of the period with the overall range of the period:

- End of Day (5pm NY, only visible when TF is < PERIOD_D1). The line goes from High to Low of that day. WORKS.

- End of Week (Friday 5pm. Length of vertical line is from High to Low of that week. TF < PERIOD_W1). NOT WORKING

- Month and quarter not implemented yet, I'm stack in the week one.

 

Honestly, I don't know why the End of Week doesn't work, the logic should be quite similar than the End of Day. This is my Start() method. Below I'll copy the whole indicator code:

 ...

 

What do you mean by "doesn't work" ?
fonx
52
fonx 2015.01.07 14:20  
angevoyageur:
What do you mean by "doesn't work" ?

I mean that I don't see a line that goes from the highest of the week to the lowest of the week at 5pm on Friday. There is no line at all. I can put:

      if(IsFriday(t) && IsEndOfDay(t) && DisplayEndOfWeek())
      {   
         l2UpBuffer[i] = High[i] + 0.01;
         l2DnBuffer[i] = Low[i] - 0.01;
      }


and it draws a vertical line from the H1 candle, 100 pips up from the high of i and 100 pips down from the low of i. But if I try to get the highest and lowest of the week nothing comes to the chart. 

Alain Verleyen
Moderator
28606
Alain Verleyen 2015.01.07 17:16  
fonx:

I mean that I don't see a line that goes from the highest of the week to the lowest of the week at 5pm on Friday. There is no line at all. I can put:


and it draws a vertical line from the H1 candle, 100 pips up from the high of i and 100 pips down from the low of i. But if I try to get the highest and lowest of the week nothing comes to the chart. 

 

Here is what I get. Seems to "work". My chart is GMT+2.


fonx
52
fonx 2015.01.07 19:23  
angevoyageur:

Here is what I get. Seems to "work". My chart is GMT+2.


Ummm strange, it didn't work for me like it does for you. Ok, I think this proves that the code works and it might be a problem of my MT4 installation. Weird thing of the double bars in your screenshot, my end of day mark doesn't come doble. 

Thanks for your time angevoyageur. I think it is an interesting piece of information to check for price movements as we get close to the end of a certain period. 

fonx
52
fonx 2015.01.07 20:30  
Ok, I realised why you get double lines, it is because your chart is M30, and there are two bars with hour == 5pm, I mean 5:00pm and 5:30pm lol! It just needs another filter for the minutes.
ffoorr
984
ffoorr 2015.01.07 21:16  

hi man

Try something like that, put different color for the buffers :

void start()
{
   int limit=-1,  counted_bars = IndicatorCounted();
   if(counted_bars < 100)  limit = Bars -1000 ;
   if(counted_bars > 0) counted_bars--;
    limit = Bars-counted_bars;

   for(int i = limit ;i >= 0 ;i--)
   {
      if(TimeDayOfWeek(iTime(Symbol(), Period(), i) )==5 && TimeHour(iTime(Symbol(), Period(), i) ) == 20 )
      {   
       int barShift = iBarShift(Symbol(), PERIOD_W1, Time[i]);                       
       if( iClose(Symbol(), PERIOD_W1, barShift) > iOpen(Symbol(), PERIOD_W1, barShift) )
         {
        l2DnBuffer[i]  = iHigh(Symbol(), PERIOD_W1, barShift);
        l2UpBuffer[i]  = iLow(Symbol(), PERIOD_W1, barShift);
         }
         else
        {
        l2UpBuffer[i] = iHigh(Symbol(), PERIOD_W1, barShift);
        l2DnBuffer[i] = iLow(Symbol(), PERIOD_W1, barShift);
         }
      }
   }
   return;
 }

what's showed up :

https://www.mql5.com/en/charts/2848613/eurusd-h1-fxpro-financial-services

It seem nothing special happen at the end of a week.

Traders may close winning orders and hedge loosing orders, waiting for the monday morning, but nothing can be see on the chart price ! ;-)

/
To add comments, please log in or register