Value of close price

 

Hi all

i am new in with mql4 and i am learning to programming in this language.

I want draw at time [i] the close value of Bar M5 at all hours 20 miinutes. Ie each H1 bar close i want draw  xx:20 (range xx:20-xx:24) M5 close bar.

For example:

Close bar H1 at 11:59 then mql4 draw close bar M5 11:20....

The code that i had is:

 

#property indicator_separate_window
#property indicator_buffers 1
double m5Value[];

int init()

{

 SetIndexBuffer(0,m5Value);
 SetIndexStyle(0,DRAW_LINE,STYLE_DOT,1);
 IndicatorDigits(Digits+0);

  
  return(0);
  
}

int start()

{

  int counted_bars=IndicatorCounted();
  
  if (counted_bars>0)
  counted_bars--;
  
  int limit = Bars-counted_bars;
  
  for (int i=0;i<limit;i++)
  
  {
    
    
    static datetime tmpDateM5;

    if (tmpDateM5 != iTime(Symbol(), PERIOD_M5,0)) // New M5 bar started
      {
        tmpDateM5 = iTime(Symbol(), PERIOD_M1,0); //if yes, save the date
        if (Minute() == 25)                       // if minute ==25 then save close value of this bar
          {
            m5Value[i] = iClose(Symbol(), PERIOD_M5,1);
            Comment(m5Value[i],tmpDateM5);

          }
       }   

   }

  return(0);
  
}  

 Any help will be much appreciated

Thank you very much 

 

As far as specifics how to code it, I cannot help as I am learning MQL as well.  But I do have an idea on the how to store it.  Use an array with 20 spots.  But if you want to only keep the last 20 items and keep it updated, every time a new bar is closed, you need to cycle through it and re-index so you drop the oldest value and move all down 1 before adding the newest value to the last position in the array.


This is only one possible solution, I am sure that there are many others.

 

Hi JD4 ,

can you put a simple example? i dont understand your solution.  

I dont  know what  i am having wrong in my code.

Thank you very much for your reply 

 
Any suggestions on my code would be very helpful.
thank you
 

Hi all, 

in this code

int limit = Bars-counted_bars;

 i must use ibars??

when i put the code in chart, the chart is black, no line.

Any help please?

 

This is not specific to MQL in any way, although it might work just straight copy.  This is to show concept only.

//  This is to show concept only



new float Array = BarCloseValueArray[20];

// to load it with zero values
for (i = 0; i < BarCloseValueArray.length(); i++)
{
   BarCloseValueArray[i] = 0;
}

// to place latest bar value at last array position
for (i = 0; i < BarCloseValueArray.length() - 1; i++)
{
   int j = i + 1;                                  // sets j index to value of i + 1 to get next index for next step in process
   BarCloseValueArray[i] = BarCloseValueArray[j];  // sets value at index location i to value of number at index i + i, index[0] set to index[1],
                                                   // index[1] then set to index[2], and so on
}
BarCloseValueArray[19] = LastBarCloseValue;        // loads value of last bar close to last index of array

I hope this is clearly showing you the thought process I had on how I would do it.

 
JD4:

This is not specific to MQL in any way, although it might work just straight copy.  This is to show concept only.

I hope this is clearly showing you the thought process I had on how I would do it.

Thank you very much JD4. I am going to apply to my code
 
Messi86:
Thank you very much JD4. I am going to apply to my code
You will likely need to modify the example I showed you to be able to work within how MQL does.  I hope this at least gets you started along the path that leads to solving your problem. :)
Reason: