Problems with the datetime-format

 

Hi,

I would like to create a simple rectangle with fixed times. For example:

ObjectCreate("Test", OBJ_RECTANGLE, 0, 8:00, 1.6300, 12:00, 1.6200);

As you can see, it should start at 8:00 and end at 12:00 with a 100 pip range. My problem is that I don't know how time1 and time2 must be formatted when I want to use a fixed time.

Any help is very appreciated.

 

mar:

I would like to create a simple rectangle with fixed times. For example:

ObjectCreate("Test", OBJ_RECTANGLE, 0, 8:00, 1.6300, 12:00, 1.6200);

As you can see, it should start at 8:00 and end at 12:00 with a 100 pip range. My problem is that I don't know how time1 and time2 must be formatted when I want to use a fixed time.

ObjectCreate() requires that arguments relating to time be passed in datetime format. See datetime data type.

 

I am sorry, I made a stupid mistake. I tried this:

ObjectCreate("Test", OBJ_RECTANGLE, 0, D'8:00', 1.6300, D'12:00', 1.6200);

That doesn't work. So what would be the correct syntax?

 
  1. D'8:00' is 8 AM of the day you compile the code, not 8 AM today.
  2. Either use inefficient
    datetime EightAM = StrToTime("08:00");
    or
    #define HR2400 86400       // 24 * 3600
    int      TimeOfDay(datetime when){  return( when % HR2400          );         }
    datetime DateOfDay(datetime when){  return( when - TimeOfDay(when) );         }
    datetime Today(){                   return(DateOfDay( TimeCurrent() ));       }
    datetime Tomorrow(){                return(Today() + HR2400);                 }
    datetime Yesterday(){               return( iTime(NULL, PERIOD_D1, 1) );      }
    :
    #define HR0800 28800 // 8 * 3600
    datetime EightAM = Today() + HR0800;

 

Thanks, William! For the beginning I use the inefficient first alternative. ;-)

I would like to ask you so much about your code/definitions but it seems to me that I will look like an idiot in your eyes... Therefore I keep my mouth shut and always look for the most simple way to solve my issues. And the first alternative is very understandable for me. There are just so many syntax-expressions I don't know and I still have not found any course or book which helps me learning mql4. But maybe someday I will understand what it means when you define variables with () and return(....). But for now it is far beyond my knowledge..

 
You MUST learn to code, Otherwise there is no common language for us to communicate with. You can't do calculus without knowing algebra and you can't do algebra without knowing how to add, subtract, multiply and divide.
 
mar:

Thanks, William! For the beginning I use the inefficient first alternative. ;-)

I would like to ask you so much about your code/definitions but it seems to me that I will look like an idiot in your eyes... Therefore I keep my mouth shut and always look for the most simple way to solve my issues. And the first alternative is very understandable for me. There are just so many syntax-expressions I don't know and I still have not found any course or book which helps me learning mql4. But maybe someday I will understand what it means when you define variables with () and return(....). But for now it is far beyond my knowledge..

These are not variables but functions. You can learn about that in the online mql4 Book for example.
 

William, I AM learning. But although you code for almost 40 years right now, you will surely know that it takes some time to learn. And when there is no course or book I have to learn by doing, trying, asking. And that is exactly what I do. Although you are often complaining about me (like my Dad did it in former times :) ), you and many others here in the Forum helped me a lot. Some months ago I had no idea about mql4 at all. But PLEASE remember your first months/years as a coder. I think you also had to learn, ask and try.. Nevertheless I really thank you and all the others for your help and patience!

By the way: the first link to forex-tsd is not working. Maybe you need a special membership to see that?

Angevoyageur, thank you! Another chapter of mql4, I have never looked at...

 
mar: the first link to forex-tsd is not working. Maybe you need a special membership to see that?
You do need to register (free) Try https://www.forex-tsd.com/metatrader-programming/134-welcome-mql4-course-2.html#post3746
 

Thanks, William! I was already registered but somehow the link didn't work before. Maybe it was a technical problem with forex-tsd. But now it works and I downloaded the course.

Something else: maybe you know this website: http://www.currencynewstrading.com/csm-3-0-6-currency-strength-meter-download/ ? My question is what do you think about analyzing the strength of a particular currency? Some say you should only buy a strong currency against a weak one. Therefore I thought if I have two or more trading setups in different currency pairs it would give me an edge to select this pair which offers the best strong/weak-ratio. Do you think that this make sense? On the other hand a currency strength meter can only reflect the current situation. Who knows if the strong pair won't get weaker during the trade? I read about the "Apollo currency strength meter". The developer said that you should avoid buying too strong currencies because they are overstretched and could easily snap back.

Besides this currency meter above I saw many coded for the MetaTrader. There you can see the currency's strength in different time frames. Does that make sense to you? And what do you generally think about using a currency strength meter for trading decisions?

In my opinion there is one situation a currency meter could make sense: news trading. When the GBP news at 10:30 am are released it may be that a long breakout trade could be more successful if choosing the GBP against the weakest currency.

Reason: