MQL4 Real Time Clock (second by second) - page 5

 
7bit:

Its just a handful of lines in mql4 (of course you need DLL calls allowed to call the windows API, but you don't need to install anything):

I have this script in my favorites and when I need ticks I just drag it to the chart.


I also have a variation of this without the loop that only sends one tick and then exits and have bound this (one_tick.mq4) to hotkey ALT+T and now I can send a tick to the active chart by just pressing ALT-T. I need this for some of my stat-arb EAs when experimenting during the weekend to enforce start() to trigger their calculations and plotting of their graphs (I can move lines on the chart to change the interval and then I need a new tick to update their calculations).


7 I have never use dll imports so can you please explain the following.

+ Do you have to include the dll files in the folder of Meta Trader Client?

+ How can we enable this EA from MT client ?

Just please give us some examples of DLL imports in Meta Trader

 
spidermagos:


7 I have never use dll imports so can you please explain the following.

+ Do you have to include the dll files in the folder of Meta Trader Client?

+ How can we enable this EA from MT client ?

Just please give us some examples of DLL imports in Meta Trader

I am sorry to inform you that it will be completely impossible for you to make any use of it (or even understand for what purpose it could be used for) unless you learn the skill of reading a text that is longer than 140 characters.

As a start you could try to extract the meaning from the text that you just quoted in your last posting. You will then find that I described it as a script and not as an EA, furthermore you will to your great surprise find that I wrote that there is no need to install any dlls and you might even be able to find the portions of the text where I explained how it is supposed to be used.

 
7bit:

I am sorry to inform you that it will be completely impossible for you to make any use of it (or even understand for what purpose it could be used for) unless you learn the skill of reading a text that is longer than 140 characters.

As a start you could try to extract the meaning from the text that you just quoted in your last posting. You will then find that I described it as a script and not as an EA, furthermore you will to your great surprise find that I wrote that there is no need to install any dlls and you might even be able to find the portions of the text where I explained how it is supposed to be used.

I admire you arrogance and your english skills and probably your coding example.

But solving a problem without providing a solution is just avoiding the question.

7 bit instead of questioning my reading abilities and techniques, why don't you write the whole program and prove your self. instead of philosophising!

Do you know how to do a real-time clock second by second or not? this is the question ? this clock should be in the chart?

 

you can simply add 2 and 2.

Use 7bit's code to generate fake ticks in combination with the code i posted and you have all you need.

and btw, 7bit seems to be one of the top programmers who partecipate in this forum...

//z

 

spidermagos:

I admire you arrogance

Thank you.


spidermagos:

why don't you write the whole program and prove your self. instead of philosophising!

The script is complete and works standalone, exactly within the specifications I gave.

I posted it as a suggestion to solve the problem of indicators not being allowed to use blocking calls like sleep() and that there also exists no other way to generate timer events from within the indicator itself. This exact subproblem of the whole clock problem was mentioned immediately before in this thread and only this and nothing else was addressed by me. It can be treated as a completely independent problem on its own and my script is a generic (and completely independent) solution for it and can also be applied in many similar scenarios, and I even gave an example for a different use case.

If you want to write code then you must learn the skill of problem decomposition and you must also be able to immediately recognize a solution and also a partial solution whenever you happen to stumble upon one.

 
//< This is EA : Compile and run in folder "/experts" >
 
 
int start()
{
static int iClockPeriod = 1000 ;
 
static int iTimeStamp          ;
static int iRunTime            ;
 
while  ( ! IsStopped () )
       {
           iTimeStamp = GetTickCount ()                             ;
           Comment    ( TimeToStr ( TimeLocal () , TIME_SECONDS ) ) ;
           iRunTime   = GetTickCount () - iTimeStamp                ;
           Sleep      ( iClockPeriod    - iRunTime                ) ;
       }
}
//</This is EA : Compile and run in folder "/experts" > 

//< This is Indicator : Compile and run in folder "/experts/indicators" >
#property  indicator_chart_window
 
int start()
{
static int iClockPeriod = 1000 ;
 
static int iTimeStamp          ;
  
  
if     ( ( GetTickCount () - iTimeStamp ) < iClockPeriod )   return ;
       {
           iTimeStamp = GetTickCount ()                             ;
           Comment    ( TimeToStr ( TimeLocal () , TIME_SECONDS ) ) ;
  
 
       }
}
//</This is Indicator : Compile and run in folder "/experts/indicators" > 

Run these programs in different charts.

 
Ais:

Run these programs in different charts.


Ais ; 7bit is right this will not work! start function is tick by tick

dll imports are needed to solve this problem. ...

i.e. calling scripts from indicators

 
7bit:

Thank you.


The script is complete and works standalone, exactly within the specifications I gave.

I posted it as a suggestion to solve the problem of indicators not being allowed to use blocking calls like sleep() and that there also exists no other way to generate timer events from within the indicator itself. This exact subproblem of the whole clock problem was mentioned immediately before in this thread and only this and nothing else was addressed by me. It can be treated as a completely independent problem on its own and my script is a generic (and completely independent) solution for it and can also be applied in many similar scenarios, and I even gave an example for a different use case.

If you want to write code then you must learn the skill of problem decomposition and you must also be able to immediately recognize a solution and also a partial solution whenever you happen to stumble upon one.



7bit - how can you call a script from an indicator ?

can you give an example ?

 
spidermagos:

It is my understanting that the Start() function works tick by tick.

Is there a way to use real-time data from the computer clock and update every second? Not tick by tick but every second?

If so please give me some help.

thanks

hi, you can use a separate tick sender application instead of a script (there are several freeware ones; google "mt4 tick sender") and make it generating ticks every 200ms or so.., then make sure your PC's clock is synchronized frequently and use TimeLocal() + hour_difference_between_yourtimezone_and_servertimezone * 3600 instead of TimeCurrent() because with generated ticks, you "only" force the Start() to be executed, TimeCurrent() will NOT update itself unless the tick comes from your broker.. that way you'll get your broker time second by second.. this works for both indicators and EAs.. funny fact is there are a few brokers with there servers out of time sync, they lag several seconds but the timestamp only, unfortunately not the price, different candles, M1 completely different sometimes when there's momentum, lol
 

First put the logic that you have in start into a function.

Next make a while loop in the init() with a sleep and call the function from there. Remember sleep is in milliseconds.

This will allow you to control the timing instead of waiting for a price change.

It works perfectly provided your program logic is OK. The only problem is you cannot run it in the backtester. Do your testing using the Start() first then switch it to the init().

Reason: