Help With TimeCurrent function please - page 2

 
TraderJoe:
Works except once inside the no trade window, we're staying there in an endless loop :( Any ideas how to break out? Thanks. Tj


no way Tj... cannot accept this, try altering the inputs or manually setting source to a small start>end period of say couple mins.

Play computer and desk check with pencil and paper - stuff the computer, if not work in desk check mode then why bother (my old school practices kick in here! lol)

Run your code so that it starts before start time - then kick back and watch.

BTW - let's see code because that if(...) is very explicit. ie, will only get into no trade window IF local time is on or within start,end time range ELSE the statement will return false meaning the bracketed {...} block will not be entered. Do you have init() + deinit() functions? Are you running .ex4 as an Expert on a chart?

Use some Print() statements - say one per logical area ie, two statements. Watch the Terminal Experts tab...

Read and re-read MQL4 help docs.... after all you mention that new to it all - so really must crack the books else this environment will have you each and every time - for sure! - lol

Each time Client Terminal gets new data tic your EAs start() will be called and one or the other Print() statement will be executed according to if(...) statement's true or false value.

I appreciate your saying "...staying their in an endless loop" but you must also see my side of this too, yes? I have absolutely no idea what your code looks like or how you ran your tests etc, correct?

BTW - I'm doing a test EA which demonstrates your initial requirement and will post link to file when satisfied that no gremlins are alive in code. It will use Comment() and Print() to allow easy visual feedback to what is assigned to the two extern inputs via <F7> (the code will not ouput continuously so that log is swamped. .. just informs you of each state change between inside/outside of noTrade window) additionally the chart comment area will show data tic info as it is given to start() which will also give visual feedback that indeed... I do exist - lol

I bother to do this simply cause computing is [for me] constant [re-]learning exercise and at my grey hair 'n feeble grey cell period of life is only way to keep [hahaaa] on top of this hacking paradigm [sometimes - if lucky!]

Cheers

ps - when all's said 'n done - I still constantly screw up... so even what I say/write/whatever - is still a debateable thingy :-)

 

Tj - following is addition to above post:

2007.09.13 11:58:52    EA TEST noTradeWindowNODDY GBPUSD,M1: removed
2007.09.13 11:58:52    EA TEST noTradeWindowNODDY GBPUSD,M1: deinitialized
2007.09.13 11:58:28    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:58:08    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:57:56    EA TEST noTradeWindowNODDY GBPUSD,M1: INSIDE NO TRADE window
2007.09.13 11:57:55    EA TEST noTradeWindowNODDY GBPUSD,M1: INSIDE NO TRADE window
2007.09.13 11:57:42    EA TEST noTradeWindowNODDY GBPUSD,M1: INSIDE NO TRADE window
2007.09.13 11:57:40    EA TEST noTradeWindowNODDY GBPUSD,M1: INSIDE NO TRADE window
2007.09.13 11:57:34    EA TEST noTradeWindowNODDY GBPUSD,M1: INSIDE NO TRADE window
2007.09.13 11:57:14    EA TEST noTradeWindowNODDY GBPUSD,M1: INSIDE NO TRADE window
2007.09.13 11:56:51    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:56:50    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:56:29    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:56:27    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:56:24    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:56:16    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:56:16    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:56:01    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:55:46    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:55:44    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:55:43    EA TEST noTradeWindowNODDY GBPUSD,M1: OUTSIDE NO TRADE window
2007.09.13 11:55:36    EA TEST noTradeWindowNODDY GBPUSD,M1: initialized
2007.09.13 11:55:36    EA TEST noTradeWindowNODDY GBPUSD,M1 inputs: edtStartNoTrade='2007.09.13 11:57'; edtEndNoTrade='2007.09.13 11:58'; 
2007.09.13 11:54:48    EA TEST noTradeWindowNODDY GBPUSD,M1: loaded successfully
2007.09.13 11:53:00    Compiling 'EA TEST noTradeWindowNODDY'
//+------------------------------------------------------------------+
//|                                   EA TEST noTradeWindowNODDY.mq4 |
//+------------------------------------------------------------------+
#property show_inputs
 
//String value of date/time format as:
//                                    "yyyy.mm.dd hh:mi:ss"
extern datetime edtStartNoTrade =    D'2007.09.13 09:06:00';
extern datetime edtEndNoTrade   =    D'2007.09.13 09:09:00';
 
//+------------------------------------------------------------------+
int init()
{
    return(0);
}
//+------------------------------------------------------------------+
int deinit()
{
    return(0);
}
//+------------------------------------------------------------------+
int start()
{ 
 
    if( TimeLocal() >= edtStartNoTrade && TimeLocal() <= edtEndNoTrade )
    {
        //if here, then time is INSIDE NO TRADE window
        Print("INSIDE NO TRADE window");
        return(0);
    }
 
    //if here, then time is OUTSIDE NO TRADE window
    //so do OrderSend() if system says so...
    //...
    Print("OUTSIDE NO TRADE window");
    return(0);
 
}//start()
//+------------------------------------------------------------------+

When applied EA to chart, the inputs dialog came up and I set: edtStartNoTrade='2007.09.13 11:57'; edtEndNoTrade='2007. 09.13 11:58'

So... code as cut and pasted into editor with addition of init(), deinit() and two Print() statements, was then compiled and applied to a chart with the resulting Experts tab logged entries shown above.

am NOT saying I right, U wrong, ok? Never ever that clear cut - lol

This is learning thingy and there just is no way around it cept to just keep at it.

Regards and trust this puts you on a-ok path!

ps, will soon post working EA as promised previous post

 

As promised. Get file into ..\experts\ directory > in editor open file and compile > in terminal enter <Control-T> and select Experts tab, now apply EA to chart and when inputs box appears alter start,end times for noTrade window > with a fair wind, output should take form of what see below - sorry, but colors not included :-)

examples of Terminal > Experts tab and charts Comment() areas

2007.09.13 18:20:07 EA TEST noTradeWindow GBPUSD,M1: OK TO TRADE
2007.09.13 18:18:38 EA TEST noTradeWindow GBPUSD,M1: DO NOT TRADE
2007.09.13 18:16:50 EA TEST noTradeWindow GBPUSD,M1: OK TO TRADE
2007.09.13 18:16:44 EA TEST noTradeWindow GBPUSD,M1: initialized
2007.09.13 18:16:44 EA TEST noTradeWindow GBPUSD,M1: init(): Start_NO_Trade at 2007.09.13 18:18:00, End_NO_Trade at 2007.09.13 18:20:00
2007.09.13 18:16:44 EA TEST noTradeWindow GBPUSD,M1: init(): Previous Launch had UninitializeReason()="REASON_PARAMETERS"
2007.09.13 18:16:44 EA TEST noTradeWindow GBPUSD,M1 inputs: edtStartNoTrade='2007.09.13 18:18'; edtEndNoTrade='2007.09.13 18:20'; ebShowLatestServerClosePrice=true;
2007.09.13 18:16:44 EA TEST noTradeWindow GBPUSD,M1: deinitialized
2007.09.13 18:16:44 EA TEST noTradeWindow GBPUSD,M1: deinit(): UninitializeReason()="REASON_PARAMETERS"

2007.09.13 18:33:14 EA TEST noTradeWindow GBPUSD,M1: OK TO TRADE
2007.09.13 18:31:52 EA TEST noTradeWindow GBPUSD,M1: DO NOT TRADE
2007.09.13 18:31:33 EA TEST noTradeWindow GBPUSD,M1: initialized
2007.09.13 18:31:33 EA TEST noTradeWindow GBPUSD,M1: init(): Start_NO_Trade at 2007. 09.13 18:31:00, End_NO_Trade at 2007.09.13 18:32:00
2007.09.13 18:31:33 EA TEST noTradeWindow GBPUSD,M1: init(): Previous Launch had UninitializeReason()="REASON_PARAMETERS"
2007.09.13 18:31:33 EA TEST noTradeWindow GBPUSD,M1 inputs: edtStartNoTrade='2007.09.13 18:31'; edtEndNoTrade='2007.09.13 18:32'; ebShowLatestServerClosePrice=true;
2007.09.13 18:31:33 EA TEST noTradeWindow GBPUSD,M1: deinitialized
2007.09.13 18:31:33 EA TEST noTradeWindow GBPUSD,M1: deinit(): UninitializeReason()="REASON_PARAMETERS"

 

Hi!


I just want to be sure I am not missing something here, so please do not take this as a criticism.


Is the code posted by UKT near the beginning of the thread not overly complicated? Is it not more simple to use the TimeHour() function and compare it with the externs?


I am quite new to MQL4 programming so I would like to know if I have misunderstood something in my code below.


Thanks,

David


extern int eiStartNoTradeHH = 13;    //!24hrClock!        //D'01:00'  of  D'2006.01.09 01:00'
extern int eiEndNoTradeHH = 19;      //!24hrClock!        //D'07:00'  of  D'2006.01.09 07:00'
//
//+------------------------------------------------------------------+
//
int start()
{
 
    datetime dtNow = TimeLocal();
 
    if (TimeHour(dtNow) >= eiStartNoTrade || TimeHour(dtNow) < 19)
    {
       // .... disallow trading here ...
    }
    else
    {
       // ... allow trading.
    }
}

 
DavidArmour:

Is the code posted by UKT near the beginning of the thread not overly complicated? Is it not more simple to use the TimeHour() function and compare it with the externs?

It does indeed look unnecessarily complicated. (If nothing else, you can round a time down to the start of a day using MathFloor(time / 86400) * 86400 rather than calculating the number of seconds elapsed in the day so far.) 


I am quite new to MQL4 programming so I would like to know if I have misunderstood something in my code below.

if (TimeHour(dtNow) >= eiStartNoTrade || TimeHour(dtNow) < 19)

...but this doesn't look right either. It's checking if the current hour is beyond the start time or less than the end time. It looks as though it's going to evaluate to true - and block trading - from 00:00 up to 18:59.

Reason: