Taking a periodic screenshot in Mt4 (every 5 mins)

 

I would like to be able to take the function below which saves a screenshot to a file and attach a listening function that saves a screenshot every 5 minutes or so. What would be the best way to go about this in mql?


int start()

{ 

 if(!WindowScreenShot(StringConcatenate(Symbol(),"_",Period(),"_",TimeToStr(TimeCurrent(),TIME_DATE),"_",Hour(),".",Minute(),".gif"),1280,1024)) Print(GetLastError()); 
 return(0);
}
 
feeblefx:

I would like to be able to take the function below which saves a screenshot to a file and attach a listening function that saves a screenshot every 5 minutes or so. What would be the best way to go about this in mql?

<SNIP>


Please edit your post . .  . .



Please use this to post code . . . it makes it easier to read.

 

 
feeblefx:

I would like to be able to take the function below which saves a screenshot to a file and attach a listening function that saves a screenshot every 5 minutes or so. What would be the best way to go about this in mql? 

Make a note of the current time ( TimeCurrent() ) to a variable, take a screenshot . . .  on the next tick check if 5 mins or more have elapsed,  if they have take a screenshot and reset your time variable to the current time.
 

Thanks Raptor,

The issue here is that I need to run this as a script, which is not run tick-wise like an EA. So it seems that for scripts the script() function terminates is only loaded again on the next request not on the next tick.

 
feeblefx:

Thanks Raptor,

The issue here is that I need to run this as a script, which is not run tick-wise like an EA. So it seems that for scripts the script() function terminates is only loaded again on the next request not on the next tick.

You can have an infinite loop within start() and a 5 min ( 300000 ms ) Sleep() . . .   
 

Raptor, that is exactly that I came up with. Turns out my problems extend beyond this issue, but thank you.

You would not happen to know the state of the art concerning HTTP Posts from Mt4? ;-)

Most solutions out there seem to be broken in one way or another. Has MetaTrader come out with an official approach? 

 
Raptor's code will hinder other operations like trading etc since the entire EA will sleep. Try this
int NextSave;

int init()
{
 NextSave=0;
}

int start()
{

...// other code

 while(TimeCurrent()>NextSave)
 {
  ...    // code to take screenshot goes where dots are
  NextSave=TimeCurrent()+300;
 }

//--------------------------------------
return();
}
 
tonny:
Raptor's code will hinder other operations like trading etc since the entire EA will sleep. Try this
Please read all the posts in the tread . . .  I suggested checking the time and doing a screen shot every 5 mins . . .  but the OP wanted a script.
 
feeblefx:

I would like to be able to take the function below which saves a screenshot to a file and attach a listening function that saves a screenshot every 5 minutes or so. What would be the best way to go about this in mql?



 Hi feeblefx

 You can use MathMod to do this. Try the following;

 

//Vars
extern string Info = "RunFunctionveryXMins 1 - 60";
extern int RunFunctionveryXMins = 5; 
bool functionCalled = false;

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
      //Reset functionCalled boolean
      if(MathMod(Minute(),RunFunctionveryXMins)) {
         functionCalled = false;
      }
      
      //
      if(functionCalled == false) {
         if(MathMod(Minute(),RunFunctionveryXMins)) {
            Print("Don't Run Function");
         }
         else {
            Print("Call Function");
            //Call Your Function Here
            
            //Stop Function being called again
            functionCalled = true;
            
         }
      }
      
  }
//+------------------------------------------------------------------+
 
Thanks for this example!!!
 
  1. Shouldn't use MathMod which functions on doubles. Minute is an int; a simple modulo (%) would so.
  2. It also doesn't handle missing bars (think over the weekend.)
  3. No need for the boolean if you just convert new bar code to new five (5) minute one:
    //Vars
    extern int RunFunctionveryXMins = 5; 
    
    //+------------------------------------------------------------------+
    //| Expert tick function                                             |
    //+------------------------------------------------------------------+
    void OnTick()
      {
         datetime now = TimeCurrent(), xMin = now - now % (60*RunFunctionveryXMins);
         static datetime currXmin=0; datetime prevXmin = currXmin; currXmin=xMin;
         if(prevXmin != currXmin){
                Print("Call Function");
                //Call Your Function Here
          }
      }

Reason: