Download MetaTrader 5
To add comments, please log in or register
Do you want to know about the MQL5.community development? Have a look at the Wall!
Andrew
71
Andrew 2014.04.10 14:55 

Hi folks,

I'm completely new to MQL4 and C++ programming, but I've managed to piece together (butcher) an indi that produces an opening range box based on the highs and low of the session opening candle.

My question (and problem) is, I'd like the range box to only be produced after the candle has closed. Currently, say it's 10 minutes until the NY open, a giant range box with undefined height is printed 10 minutes away.

I know I need to insert an "if" time > 8:05 then .... type of function, but not sure about the formatting etc. I'd like the indi to print once the clock strikes the defined parameter "nyperiodA_end".

Indi attached, any help or advice is greatly appreciated! :)

Thanks in advance, Andrew

Files:
nybox.mq4 6 kb
qjol
3243
qjol 2014.04.10 15:09  

have a look here

Andrew
71
Andrew 2014.04.10 15:14  
qjol:

have a look here


This indi has the same problem, the boxes print before the price. So you end up with giant colored boxes off to the right of the screen.

Thanks anyway though for answering, I'm hoping someone has a solution.

qjol
3243
qjol 2014.04.10 15:27  
  if (dtTimeObjEnd > TimeCurrent())    
  dtTimeObjEnd = TimeCurrent();
Andrew
71
Andrew 2014.04.10 15:44  
qjol:


I hadn't identified dtTimeObjEnd yet so assumed it was ok to replace it w/ nyperiodA_end (the identifier for the close of the opening candle)

I added the if into the code but now it's made my opening range as the high and low between the start of the session and *now* (or TimeCurrent())


void start() {

datetime dtTradeDate=TimeCurrent();

if (nyperiodA_end > TimeCurrent())

nyperiodA_end = TimeCurrent();

for (int i=0; i<nyNumberOfDays; i++)

{

DrawObjects(dtTradeDate, "nyBoxHL " + TimeToStr(dtTradeDate,TIME_DATE), nyperiodA_begin, nyperiodA_end, nyperiodB_end, nyrectAB_color, 0, 1, nyrectAB_background)

dtTradeDate=decrementTradeDate(dtTradeDate);

while (TimeDayOfWeek(dtTradeDate) > 5 || TimeDayOfWeek(dtTradeDate) < 1 ) dtTradeDate = decrementTradeDate(dtTradeDate); // Removed Sundays from plots

}

qjol
3243
qjol 2014.04.10 15:47  

after this line (CTRL + F to find it)

dtTimeObjEnd = StrToTime(TimeToStr(dtTradeDate, TIME_DATE) + " " + sTimeObjEnd);

put this 2 lines

  if (dtTimeObjEnd > TimeCurrent())    
  dtTimeObjEnd = TimeCurrent();
Andrew
71
Andrew 2014.04.10 15:57  
qjol:

after this line

put this 2 lines


Sorry, had to wait the 5 mins for the candle to close to see what happened! :P

Seems to be half way there, but where I used to have a range box spanning a few hours, I now have it spanning to time current (as we've defined the end of the object as time current).

So instead of a 3 hours range box it's only a 5 minute range box! :/

qjol
3243
qjol 2014.04.10 16:01  
jalapeno:


Sorry, had to wait the 5 mins for the candle to close to see what happened! :P

use the 1 Min. chart then you don't have to wait more than 1 min.

Seems to be half way there, but where I used to have a range box spanning a few hours, I now have it spanning to time current (as we've defined the end of the object as time current).

So instead of a 3 hours range box it's only a 5 minute range box! :/

isn't this what you want ?

Andrew
71
Andrew 2014.04.10 16:05  
Range Boxqjol:



Sorry for the confusion, and thankyou for your patience, I really mean it, this has been giving me a headache for a couple of days!

An attached screen shot of what I'm trying to get the range box to do..

As the indi currently sits, until the server time on MT4 passes nyperiodA_end there's a big blob on the screen:

Blob

qjol
3243
qjol 2014.04.10 16:53  
   if (TimeCurrent() > StringToTime(nyperiodA_end))
   DrawObjects(...);
Andrew
71
Andrew 2014.04.10 22:54  
qjol:


Thanks qjol, much appreciated. If this if statement to go in the same place as the previous one? What should replace the ... in the brackets?

>> A friend on babypips helped me out and suggest I add this: if(iForm==1 && TimeCurrent()>dtTimeBegin){

and it's seemed to have worked?

/
To add comments, please log in or register